Skip to content

Commit 1037f87

Browse files
committed
Simplify boilerplate
1 parent eaf0cb9 commit 1037f87

1 file changed

Lines changed: 21 additions & 29 deletions

File tree

tck/sut_agent.py

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55

66
from datetime import datetime, timezone
77

8-
from uvicorn import Config, Server
8+
import uvicorn
99

1010
from a2a.server.agent_execution.agent_executor import AgentExecutor
1111
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
1313
from a2a.server.events.event_queue import EventQueue
14-
from a2a.server.events.in_memory_queue_manager import InMemoryQueueManager
1514
from a2a.server.request_handlers.default_request_handler import (
1615
DefaultRequestHandler,
1716
)
@@ -28,7 +27,8 @@
2827
)
2928

3029

31-
# Configure logging
30+
JSONRPC_URL = '/a2a/jsonrpc'
31+
3232
logging.basicConfig(level=logging.INFO)
3333
logger = logging.getLogger('SUTAgent')
3434

@@ -124,24 +124,15 @@ async def execute(
124124
await event_queue.enqueue_event(final_update)
125125

126126

127-
async def main() -> None:
127+
128+
def main() -> None:
128129
"""Main entrypoint."""
129130
http_port = int(os.environ.get('HTTP_PORT', '41241'))
130131

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(
142133
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}',
145136
provider=AgentProvider(
146137
organization='A2A Samples',
147138
url='https://example.com/a2a-samples',
@@ -170,26 +161,27 @@ async def main() -> None:
170161
preferred_transport='JSONRPC',
171162
additional_interfaces=[
172163
{
173-
'url': f'http://localhost:{http_port}/a2a/jsonrpc',
164+
'url': f'http://localhost:{http_port}{JSONRPC_URL}',
174165
'transport': 'JSONRPC',
175166
},
176167
],
177168
)
178169

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(),
182173
)
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,
185178
)
186179

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)
190181

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')
192184

193185

194186
if __name__ == '__main__':
195-
asyncio.run(main())
187+
main()

0 commit comments

Comments
 (0)