-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathworkflow_sequential.py
More file actions
65 lines (53 loc) · 1.78 KB
/
Copy pathworkflow_sequential.py
File metadata and controls
65 lines (53 loc) · 1.78 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
import restate
from agents import Agent
from restate.ext.openai import DurableRunner
from utils.models import ClaimPrompt, ClaimData
from utils.utils import convert_currency, process_payment
# <start_here>
claim_service = restate.Service("ClaimReimbursement")
@claim_service.handler()
async def process(ctx: restate.Context, req: ClaimPrompt) -> dict:
# Step 1: Parse the claim document (LLM step)
parse_agent = Agent(
name="DocumentParser",
instructions="Extract the claim amount, currency, category, and description.",
output_type=ClaimData,
)
parsed = await DurableRunner.run(parse_agent, req.message)
claim = parsed.final_output
# Step 2: Analyze the claim (LLM step)
analysis_agent = Agent(
name="ClaimsAnalyst",
instructions="Assess whether this claim is valid and determine the approved amount.",
)
analysis = await DurableRunner.run(
analysis_agent, f"Claim: {parsed.final_output.model_dump_json()}"
)
# 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.final_output,
"amount_usd": amount_usd,
"confirmation": confirmation,
}
# <end_here>
if __name__ == "__main__":
import hypercorn
import asyncio
app = restate.app(services=[claim_service])
conf = hypercorn.Config()
conf.bind = ["0.0.0.0:9080"]
asyncio.run(hypercorn.asyncio.serve(app, conf))