forked from nicknochnack/ACPWalkthrough
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy patha2a_policy_agent.py
More file actions
81 lines (66 loc) · 2.25 KB
/
a2a_policy_agent.py
File metadata and controls
81 lines (66 loc) · 2.25 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
import os
import uvicorn
from a2a.server.agent_execution import AgentExecutor, RequestContext
from a2a.server.apps import A2AStarletteApplication
from a2a.server.events import EventQueue
from a2a.server.request_handlers import DefaultRequestHandler
from a2a.server.tasks import InMemoryTaskStore
from a2a.types import (
AgentCapabilities,
AgentCard,
AgentSkill,
)
from a2a.utils import new_agent_text_message
from helpers import setup_env
from policy_agent import PolicyAgent
class PolicyAgentExecutor(AgentExecutor):
def __init__(self) -> None:
self.agent = PolicyAgent()
async def execute(
self,
context: RequestContext,
event_queue: EventQueue,
) -> None:
prompt = context.get_user_input()
response = self.agent.answer_query(prompt)
message = new_agent_text_message(response)
await event_queue.enqueue_event(message)
async def cancel(
self,
context: RequestContext,
event_queue: EventQueue,
) -> None:
pass
def main() -> None:
print("Running A2A Health Insurance Policy Agent")
setup_env()
PORT = int(os.getenv("POLICY_AGENT_PORT", 9999))
HOST = os.getenv("AGENT_HOST", "localhost")
skill = AgentSkill(
id="insurance_coverage",
name="Insurance coverage",
description="Provides information about insurance coverage options and details.",
tags=["insurance", "coverage"],
examples=["What does my policy cover?", "Are mental health services included?"],
)
agent_card = AgentCard(
name="InsurancePolicyCoverageAgent",
description="Provides information about insurance policy coverage options and details.",
url=f"http://{HOST}:{PORT}/",
version="1.0.0",
default_input_modes=["text"],
default_output_modes=["text"],
capabilities=AgentCapabilities(streaming=False),
skills=[skill],
)
request_handler = DefaultRequestHandler(
agent_executor=PolicyAgentExecutor(),
task_store=InMemoryTaskStore(),
)
server = A2AStarletteApplication(
agent_card=agent_card,
http_handler=request_handler,
)
uvicorn.run(server.build(), host=HOST, port=PORT)
if __name__ == "__main__":
main()