|
5 | 5 |
|
6 | 6 | from datetime import datetime, timezone |
7 | 7 |
|
8 | | -from uvicorn import Config, Server |
| 8 | +import uvicorn |
9 | 9 |
|
10 | 10 | from a2a.server.agent_execution.agent_executor import AgentExecutor |
11 | 11 | from a2a.server.agent_execution.context import RequestContext |
12 | | -from a2a.server.apps.jsonrpc.fastapi_app import A2AFastAPIApplication |
| 12 | +from a2a.server.apps import A2AStarletteApplication |
13 | 13 | from a2a.server.events.event_queue import EventQueue |
14 | | -from a2a.server.events.in_memory_queue_manager import InMemoryQueueManager |
15 | 14 | from a2a.server.request_handlers.default_request_handler import ( |
16 | 15 | DefaultRequestHandler, |
17 | 16 | ) |
|
28 | 27 | ) |
29 | 28 |
|
30 | 29 |
|
31 | | -# Configure logging |
| 30 | +JSONRPC_URL = '/a2a/jsonrpc' |
| 31 | + |
32 | 32 | logging.basicConfig(level=logging.INFO) |
33 | 33 | logger = logging.getLogger('SUTAgent') |
34 | 34 |
|
@@ -124,24 +124,15 @@ async def execute( |
124 | 124 | await event_queue.enqueue_event(final_update) |
125 | 125 |
|
126 | 126 |
|
127 | | -async def main() -> None: |
| 127 | + |
| 128 | +def main() -> None: |
128 | 129 | """Main entrypoint.""" |
129 | 130 | http_port = int(os.environ.get('HTTP_PORT', '41241')) |
130 | 131 |
|
131 | | - agent_executor = SUTAgentExecutor() |
132 | | - task_store = InMemoryTaskStore() |
133 | | - queue_manager = InMemoryQueueManager() |
134 | | - |
135 | | - request_handler = DefaultRequestHandler( |
136 | | - task_store=task_store, |
137 | | - queue_manager=queue_manager, |
138 | | - agent_executor=agent_executor, |
139 | | - ) |
140 | | - |
141 | | - sut_agent_card = AgentCard( |
| 132 | + agent_card = AgentCard( |
142 | 133 | name='SUT Agent', |
143 | | - description='A sample agent to be used as SUT against tck tests.', |
144 | | - url=f'http://localhost:{http_port}/a2a/jsonrpc', |
| 134 | + description='An agent to be used as SUT against TCK tests.', |
| 135 | + url=f'http://localhost:{http_port}{JSONRPC_URL}', |
145 | 136 | provider=AgentProvider( |
146 | 137 | organization='A2A Samples', |
147 | 138 | url='https://example.com/a2a-samples', |
@@ -170,26 +161,27 @@ async def main() -> None: |
170 | 161 | preferred_transport='JSONRPC', |
171 | 162 | additional_interfaces=[ |
172 | 163 | { |
173 | | - 'url': f'http://localhost:{http_port}/a2a/jsonrpc', |
| 164 | + 'url': f'http://localhost:{http_port}{JSONRPC_URL}', |
174 | 165 | 'transport': 'JSONRPC', |
175 | 166 | }, |
176 | 167 | ], |
177 | 168 | ) |
178 | 169 |
|
179 | | - json_rpc_app = A2AFastAPIApplication( |
180 | | - agent_card=sut_agent_card, |
181 | | - http_handler=request_handler, |
| 170 | + request_handler = DefaultRequestHandler( |
| 171 | + agent_executor=SUTAgentExecutor(), |
| 172 | + task_store=InMemoryTaskStore(), |
182 | 173 | ) |
183 | | - app = json_rpc_app.build( |
184 | | - rpc_url='/a2a/jsonrpc', agent_card_url='/.well-known/agent-card.json' |
| 174 | + |
| 175 | + server = A2AStarletteApplication( |
| 176 | + agent_card=agent_card, |
| 177 | + http_handler=request_handler, |
185 | 178 | ) |
186 | 179 |
|
187 | | - logger.info('Starting HTTP server on port %s...', http_port) |
188 | | - config = Config(app, host='127.0.0.1', port=http_port, log_level='info') |
189 | | - server = Server(config) |
| 180 | + app = server.build(rpc_url=JSONRPC_URL) |
190 | 181 |
|
191 | | - await server.serve() |
| 182 | + logger.info('Starting HTTP server on port %s...', http_port) |
| 183 | + uvicorn.run(app, host='127.0.0.1', port=http_port, log_level='info') |
192 | 184 |
|
193 | 185 |
|
194 | 186 | if __name__ == '__main__': |
195 | | - asyncio.run(main()) |
| 187 | + main() |
0 commit comments