Repository navigation
Expand file tree
/
Copy pathremote_agents.py
More file actions
53 lines (36 loc) · 1.61 KB
/
Copy pathremote_agents.py
File metadata and controls
53 lines (36 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import restate
from agents import Agent
from restate.ext.openai import restate_context, DurableRunner, durable_function_tool
from utils.utils import InsuranceClaim, run_eligibility_agent, run_fraud_agent
# Durable service call to the eligibility agent; persisted and retried by Restate
@durable_function_tool
async def check_eligibility(claim: InsuranceClaim) -> str:
"""Analyze claim eligibility."""
return await restate_context().service_call(run_eligibility_agent, claim)
# <start_here>
# Durable service call to the fraud agent; persisted and retried by Restate
@durable_function_tool
async def check_fraud(claim: InsuranceClaim) -> str:
"""Analyze the probability of fraud."""
return await restate_context().service_call(run_fraud_agent, claim)
agent = Agent(
name="ClaimApprovalCoordinator",
instructions="You are a claim approval engine. Analyze the claim and use your tools to decide whether to approve it.",
tools=[check_eligibility, check_fraud],
)
agent_service = restate.Service("MultiAgentClaimApproval")
@agent_service.handler()
async def run(_ctx: restate.Context, claim: InsuranceClaim) -> str:
result = await DurableRunner.run(agent, f"Claim: {claim.model_dump_json()}")
return result.final_output
# <end_here>
if __name__ == "__main__":
import hypercorn
import asyncio
from utils.utils import fraud_agent_service, eligibility_agent_service
app = restate.app(
services=[agent_service, fraud_agent_service, eligibility_agent_service]
)
conf = hypercorn.Config()
conf.bind = ["0.0.0.0:9080"]
asyncio.run(hypercorn.asyncio.serve(app, conf))