|
5 | 5 | from dotenv import load_dotenv |
6 | 6 | from fastapi import FastAPI |
7 | 7 |
|
8 | | -from src.a2a.a2a_fastapi_app import A2AFastApiApp, get_agent_request_handler |
9 | | -from src.agent.analyzer_agent import analyzer_agent, get_analyzer_agent_card |
10 | | -from src.agent.conversation_agent import get_conversational_agent_card, conversational_agent |
11 | | -from src.agent.trending_topics_agent import trending_topics_agent, get_trending_topics_agent_card |
| 8 | +from src.a2a.a2a_utils import A2AUtils |
| 9 | +from src.agent.analyzer_agent import get_analyzer_agent_card, get_analyzer_agent |
| 10 | +from src.agent.conversation_agent import get_conversational_agent_card, get_conversational_agent |
| 11 | +from src.agent.trending_topics_agent import get_trending_topics_agent_card, get_trending_topics_agent |
12 | 12 |
|
13 | 13 | load_dotenv() |
14 | 14 |
|
15 | 15 | logging.basicConfig(level=logging.INFO) |
16 | 16 | logger = logging.getLogger() |
17 | 17 |
|
18 | 18 | AGENT_BASE_URL = os.getenv('AGENT_BASE_URL') |
| 19 | + |
| 20 | +if not AGENT_BASE_URL: |
| 21 | + raise ValueError("AGENT_BASE_URL environment variable must be set") |
| 22 | + |
| 23 | +MODEL_NAME = os.getenv('MODEL_NAME') |
| 24 | + |
| 25 | +if not MODEL_NAME: |
| 26 | + raise ValueError("MODEL_NAME environment variable must be set") |
19 | 27 | logger.info(f"AGENT BASE URL {AGENT_BASE_URL}") |
20 | 28 |
|
21 | 29 | app: FastAPI = FastAPI(title="Run multiple agents on single host using A2A protocol.", |
22 | 30 | description="Run multiple agents on single host using A2A protocol.", |
23 | 31 | version="1.0.0", |
24 | | - root_path=f"/a2a") |
| 32 | + root_path="/a2a") |
25 | 33 |
|
26 | 34 |
|
27 | 35 | @app.get("/health") |
28 | 36 | async def health_check() -> dict[str, str]: |
29 | 37 | return {"status": "ok"} |
30 | 38 |
|
31 | 39 |
|
32 | | -conversation_agent_request_handler = get_agent_request_handler(conversational_agent) |
33 | | -conversational_agent_card = get_conversational_agent_card(f"{AGENT_BASE_URL}/conversation/") |
34 | | -conversational_agent_server = A2AFastApiApp(fastapi_app=app, agent_card=conversational_agent_card, http_handler=conversation_agent_request_handler) |
35 | | -# {path:path} added into the agent card url path to handle both 'agent-card.json' and '/.well-known/agent-card.json' |
36 | | -conversational_agent_server.build(rpc_url="/conversation/", agent_card_url="/conversation/{path:path}") |
| 40 | +# conversation agent integration with A2A server |
| 41 | +A2AUtils.build(name="conversation", get_agent=get_conversational_agent, get_agent_card=get_conversational_agent_card, |
| 42 | + model_name=MODEL_NAME, |
| 43 | + agent_base_url=AGENT_BASE_URL, app=app) |
37 | 44 |
|
38 | | -trending_agent_request_handler = get_agent_request_handler(trending_topics_agent) |
39 | | -trending_topics_agent_card = get_trending_topics_agent_card(f"{AGENT_BASE_URL}/trending/") |
40 | | -trending_agent_server = A2AFastApiApp(fastapi_app=app, agent_card=trending_topics_agent_card, |
41 | | - http_handler=trending_agent_request_handler) |
42 | | -trending_agent_server.build(rpc_url="/trending/", agent_card_url="/trending/{path:path}") |
| 45 | +# trending_topics agent integration with A2A server |
| 46 | +A2AUtils.build(name="trending_topics", get_agent=get_trending_topics_agent, |
| 47 | + get_agent_card=get_trending_topics_agent_card, |
| 48 | + model_name=MODEL_NAME, |
| 49 | + agent_base_url=AGENT_BASE_URL, app=app) |
43 | 50 |
|
44 | | -analyzer_agent_request_handler = get_agent_request_handler(analyzer_agent) |
45 | | -analyzer_agent_card = get_analyzer_agent_card(f"{AGENT_BASE_URL}/analyzer/") |
46 | | -analyzer_agent_server = A2AFastApiApp(fastapi_app=app, agent_card=analyzer_agent_card, |
47 | | - http_handler=analyzer_agent_request_handler) |
48 | | -analyzer_agent_server.build(rpc_url="/analyzer/", agent_card_url="/analyzer/{path:path}") |
| 51 | +# analyzer agent integration with A2A server |
| 52 | +A2AUtils.build(name="analyzer", get_agent=get_analyzer_agent, get_agent_card=get_analyzer_agent_card, |
| 53 | + model_name=MODEL_NAME, |
| 54 | + agent_base_url=AGENT_BASE_URL, app=app) |
49 | 55 |
|
50 | 56 | if __name__ == '__main__': |
51 | 57 | uvicorn.run(app, host="0.0.0.0", port=8000) |
0 commit comments