|

How to Create Reliable Conversational AI Agents Using Parlant?

✅

Parlant is a framework designed to assist builders construct production-ready AI brokers that behave persistently and reliably. A typical problem when deploying giant language mannequin (LLM) brokers is that they usually carry out nicely in testing however fail when interacting with actual customers. They might ignore rigorously designed system prompts, generate inaccurate or irrelevant responses at important moments, wrestle with edge circumstances, or produce inconsistent conduct from one dialog to one other. 

Parlant addresses these challenges by shifting the main focus from immediate engineering to principle-driven growth. Instead of counting on prompts alone, it gives mechanisms to outline clear guidelines and gear integrations, guaranteeing that an agent can entry and course of real-world information safely and predictably.

In this tutorial, we are going to create an insurance coverage agent that may retrieve open claims, file new claims, and supply detailed coverage info, demonstrating how to combine domain-specific instruments right into a Parlant-powered AI system for constant and dependable buyer assist. Check out the FULL CODES here

Installing & importing the dependencies

import asyncio
from datetime import datetime
import parlant.sdk as p

Defining the instruments

The following code block introduces three instruments that simulate interactions an insurance coverage assistant would possibly want. 

  • The get_open_claims device represents an asynchronous operate that retrieves an inventory of open insurance coverage claims, permitting the agent to present customers with up-to-date details about pending or accepted claims. 
  • The file_claim device accepts declare particulars as enter and simulates the method of submitting a brand new insurance coverage declare, returning a affirmation message to the person. 

Finally, the get_policy_details device gives important coverage info, such because the coverage quantity and protection limits, enabling the agent to reply precisely to questions on insurance coverage protection. Check out the FULL CODES here

@p.device
async def get_open_claims(context: p.ToolContext) -> p.ToolResult:
    return p.ToolResult(information=["Claim #123 - Pending", "Claim #456 - Approved"])
@p.device
async def file_claim(context: p.ToolContext, claim_details: str) -> p.ToolResult:
    return p.ToolResult(information=f"New declare filed: {claim_details}")
@p.device
async def get_policy_details(context: p.ToolContext) -> p.ToolResult:
    return p.ToolResult(information={
        "policy_number": "POL-7788",
        "protection": "Covers unintended harm and theft up to $50,000"
    })

Defining Glossary & Journeys

In this part, we outline the glossary and journeys that form how the agent handles area data and conversations. The glossary incorporates vital enterprise phrases, such because the customer support quantity and working hours, permitting the agent to reference them precisely when wanted. 

The journeys describe step-by-step processes for particular duties. In this instance, one journey walks a buyer by way of submitting a brand new insurance coverage declare, whereas one other focuses on retrieving and explaining coverage protection particulars. Check out the FULL CODES here

async def add_domain_glossary(agent: p.Agent):
    await agent.create_term(
        identify="Customer Service Number",
        description="You can attain us at +1-555-INSURE",
    )
    await agent.create_term(
        identify="Operating Hours",
        description="We can be found Mon-Fri, 9AM-6PM",
    )
async def create_claim_journey(agent: p.Agent) -> p.Journey:
    journey = await agent.create_journey(
        title="File an Insurance Claim",
        description="Helps clients report and submit a brand new declare.",
        situations=["The customer wants to file a claim"],
    )
    s0 = await journey.initial_state.transition_to(chat_state="Ask for accident particulars")
    s1 = await s0.goal.transition_to(tool_state=file_claim, situation="Customer gives particulars")
    s2 = await s1.goal.transition_to(chat_state="Confirm declare was submitted")
    await s2.goal.transition_to(state=p.END_JOURNEY)
    return journey
async def create_policy_journey(agent: p.Agent) -> p.Journey:
    journey = await agent.create_journey(
        title="Explain Policy Coverage",
        description="Retrieves and explains buyer's insurance coverage protection.",
        situations=["The customer asks about their policy"],
    )
    s0 = await journey.initial_state.transition_to(tool_state=get_policy_details)
    await s0.goal.transition_to(
        chat_state="Explain the coverage protection clearly",
        situation="Policy data is out there",
    )
    await agent.create_guideline(
        situation="Customer presses for authorized interpretation of protection",
        motion="Politely clarify that authorized recommendation can't be offered",
    )
    return journey

Defining the primary runner

The predominant runner ties collectively all of the elements outlined in earlier cells and launches the agent. It begins a Parlant server, creates the insurance coverage assist agent, and hundreds its glossary, journeys, and world pointers. It additionally handles edge circumstances resembling ambiguous buyer intent by prompting the agent to select between related journeys. Finally, as soon as the script is executed, the server turns into energetic and prints a affirmation message. You can then open your browser and navigate to http://localhost:8800 to entry the Parlant UI and start interacting with the insurance coverage agent in actual time. Check out the FULL CODES here

async def predominant():
    async with p.Server() as server:
        agent = await server.create_agent(
            identify="Insurance Support Agent",
            description="Friendly {and professional}; helps with claims and coverage queries.",
        )
        await add_domain_glossary(agent)
        claim_journey = await create_claim_journey(agent)
        policy_journey = await create_policy_journey(agent)
        # Disambiguation: if intent is unclear
        status_obs = await agent.create_observation(
            "Customer mentions a difficulty however would not specify if it is a declare or coverage"
        )
        await status_obs.disambiguate([claim_journey, policy_journey])
        # Global guideline
        await agent.create_guideline(
            situation="Customer asks about unrelated subjects",
            motion="Kindly redirect them to insurance-related assist solely",
        )
        print("✅ Insurance Agent is prepared! Open the Parlant UI to chat.")
if __name__ == "__main__":
    import asyncio
    asyncio.run(predominant())

Check out the FULL CODES here. Feel free to take a look at our GitHub Page for Tutorials, Codes and Notebooks. Also, be at liberty to observe us on Twitter and don’t neglect to be part of our 100k+ ML SubReddit and Subscribe to our Newsletter.

For content material partnership with marktechpost.com, please TALK to us

The submit How to Create Reliable Conversational AI Agents Using Parlant? appeared first on MarkTechPost.

Similar Posts