-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathworkflow_sequential.py
More file actions
84 lines (70 loc) · 2.65 KB
/
Copy pathworkflow_sequential.py
File metadata and controls
84 lines (70 loc) · 2.65 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import restate
from google.adk import Runner
from google.adk.agents.llm_agent import Agent
from google.adk.apps import App
from google.genai.types import Content, Part
from restate.ext.adk import RestatePlugin, RestateSessionService
from utils.models import ClaimData, ClaimPrompt
from utils.utils import parse_agent_response, convert_currency, process_payment
# <start_here>
parse_agent = Agent(
model="gemini-2.5-flash",
name="document_parser",
instruction="Extract the claim amount, currency, category, and description.",
output_schema=ClaimData,
)
parse_app = App(name="claims", root_agent=parse_agent, plugins=[RestatePlugin()])
parse_runner = Runner(app=parse_app, session_service=RestateSessionService())
analysis_agent = Agent(
model="gemini-2.5-flash",
name="claims_analyst",
instruction="Assess whether this claim is valid and determine the approved amount.",
)
analysis_app = App(name="claims", root_agent=analysis_agent, plugins=[RestatePlugin()])
analysis_runner = Runner(app=analysis_app, session_service=RestateSessionService())
claim_service = restate.VirtualObject("ClaimReimbursement")
@claim_service.handler()
async def process(ctx: restate.ObjectContext, req: ClaimPrompt) -> dict:
# Step 1: Parse the claim document (LLM step)
parsing_events = parse_runner.run_async(
user_id=ctx.key(),
session_id=req.session_id,
new_message=Content(role="user", parts=[Part.from_text(text=req.message)]),
)
parsed = await parse_agent_response(parsing_events)
claim = ClaimData.model_validate_json(parsed)
# Step 2: Analyze the claim (LLM step)
analysis_events = analysis_runner.run_async(
user_id=ctx.key(),
session_id=req.session_id,
new_message=Content(role="user", parts=[Part.from_text(text=parsed)]),
)
analysis = await parse_agent_response(analysis_events)
# Step 3: Convert currency (regular step)
amount_usd = await ctx.run_typed(
"Convert currency",
convert_currency,
amount=claim.amount,
source=claim.currency,
target="USD",
)
# Step 4: Process reimbursement (regular step)
confirmation = await ctx.run_typed(
"Process payment",
process_payment,
claim_id=str(ctx.uuid()),
amount=amount_usd,
)
return {
"analysis": analysis,
"amount_usd": amount_usd,
"confirmation": confirmation,
}
# <end_here>
if __name__ == "__main__":
import hypercorn
import asyncio
restate_app = restate.app(services=[claim_service])
conf = hypercorn.Config()
conf.bind = ["0.0.0.0:9080"]
asyncio.run(hypercorn.asyncio.serve(restate_app, conf))