1+ import asyncio
2+ from datetime import datetime
3+ import parlant .sdk as p
4+ import os
5+ from dotenv import load_dotenv
6+ load_dotenv ()
7+
8+ @p .tool
9+ async def get_open_claims (context : p .ToolContext ) -> p .ToolResult :
10+ return p .ToolResult (data = ["Claim #123 - Pending" , "Claim #456 - Approved" ])
11+
12+ @p .tool
13+ async def file_claim (context : p .ToolContext , claim_details : str ) -> p .ToolResult :
14+ return p .ToolResult (data = f"New claim filed: { claim_details } " )
15+
16+ @p .tool
17+ async def get_policy_details (context : p .ToolContext ) -> p .ToolResult :
18+ return p .ToolResult (data = {
19+ "policy_number" : "POL-7788" ,
20+ "coverage" : "Covers accidental damage and theft up to $50,000"
21+ })
22+
23+ async def add_domain_glossary (agent : p .Agent ):
24+ await agent .create_term (
25+ name = "Customer Service Number" ,
26+ description = "You can reach us at +1-555-INSURE" ,
27+ )
28+ await agent .create_term (
29+ name = "Operating Hours" ,
30+ description = "We are available Mon–Fri, 9AM–6PM" ,
31+ )
32+
33+ async def create_claim_journey (agent : p .Agent ) -> p .Journey :
34+ journey = await agent .create_journey (
35+ title = "File an Insurance Claim" ,
36+ description = "Helps customers report and submit a new claim." ,
37+ conditions = ["The customer wants to file a claim" ],
38+ )
39+
40+ s0 = await journey .initial_state .transition_to (chat_state = "Ask for accident details" )
41+ s1 = await s0 .target .transition_to (tool_state = file_claim , condition = "Customer provides details" )
42+ s2 = await s1 .target .transition_to (chat_state = "Confirm claim was submitted" )
43+ await s2 .target .transition_to (state = p .END_JOURNEY )
44+
45+ return journey
46+
47+ async def create_policy_journey (agent : p .Agent ) -> p .Journey :
48+ journey = await agent .create_journey (
49+ title = "Explain Policy Coverage" ,
50+ description = "Retrieves and explains customer’s insurance coverage." ,
51+ conditions = ["The customer asks about their policy" ],
52+ )
53+
54+ s0 = await journey .initial_state .transition_to (tool_state = get_policy_details )
55+ await s0 .target .transition_to (
56+ chat_state = "Explain the policy coverage clearly" ,
57+ condition = "Policy info is available" ,
58+ )
59+
60+ await agent .create_guideline (
61+ condition = "Customer presses for legal interpretation of coverage" ,
62+ action = "Politely explain that legal advice cannot be provided" ,
63+ )
64+ return journey
65+
66+ async def main ():
67+ async with p .Server () as server :
68+ agent = await server .create_agent (
69+ name = "Insurance Support Agent" ,
70+ description = "Friendly and professional; helps with claims and policy queries." ,
71+ )
72+
73+ await add_domain_glossary (agent )
74+ claim_journey = await create_claim_journey (agent )
75+ policy_journey = await create_policy_journey (agent )
76+
77+ # Disambiguation: if intent is unclear
78+ status_obs = await agent .create_observation (
79+ "Customer mentions an issue but doesn’t specify if it's a claim or policy"
80+ )
81+ await status_obs .disambiguate ([claim_journey , policy_journey ])
82+
83+ # Global guideline
84+ await agent .create_guideline (
85+ condition = "Customer asks about unrelated topics" ,
86+ action = "Kindly redirect them to insurance-related support only" ,
87+ )
88+
89+ print ("✅ Insurance Agent is ready! Open the Parlant UI to chat." )
90+
91+ if __name__ == "__main__" :
92+ import asyncio
93+ asyncio .run (main ())
0 commit comments