Skip to content

Commit 2a7d74c

Browse files
committed
Reformat
1 parent 6f0f71d commit 2a7d74c

1 file changed

Lines changed: 49 additions & 44 deletions

File tree

tck/sut_agent.py

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import asyncio
32
import logging
43
import os
@@ -15,7 +14,9 @@
1514
from a2a.server.agent_execution.context import RequestContext
1615
from a2a.server.events.event_queue import EventQueue
1716
from a2a.server.events.in_memory_queue_manager import InMemoryQueueManager
18-
from a2a.server.request_handlers.default_request_handler import DefaultRequestHandler
17+
from a2a.server.request_handlers.default_request_handler import (
18+
DefaultRequestHandler,
19+
)
1920
from a2a.server.apps.jsonrpc.fastapi_app import A2AFastAPIApplication
2021
from a2a.server.apps.jsonrpc.fastapi_app import A2AFastAPIApplication
2122
from a2a.types import (
@@ -34,14 +35,17 @@
3435

3536
# Configure logging
3637
logging.basicConfig(level=logging.INFO)
37-
logger = logging.getLogger("SUTAgent")
38+
logger = logging.getLogger('SUTAgent')
39+
3840

3941
class SUTAgentExecutor(AgentExecutor):
4042
def __init__(self):
4143
self.running_tasks = set()
4244
self.last_context_id = None
4345

44-
async def cancel(self, context: RequestContext, event_queue: EventQueue) -> None:
46+
async def cancel(
47+
self, context: RequestContext, event_queue: EventQueue
48+
) -> None:
4549
api_task_id = context.task_id
4650
if api_task_id in self.running_tasks:
4751
self.running_tasks.remove(api_task_id)
@@ -57,7 +61,9 @@ async def cancel(self, context: RequestContext, event_queue: EventQueue) -> None
5761
)
5862
await event_queue.enqueue_event(status_update)
5963

60-
async def execute(self, context: RequestContext, event_queue: EventQueue) -> None:
64+
async def execute(
65+
self, context: RequestContext, event_queue: EventQueue
66+
) -> None:
6167
user_message = context.message
6268
task_id = context.task_id
6369
context_id = context.context_id
@@ -66,8 +72,8 @@ async def execute(self, context: RequestContext, event_queue: EventQueue) -> Non
6672
self.running_tasks.add(task_id)
6773

6874
logger.info(
69-
f"[SUTAgentExecutor] Processing message {user_message.message_id} "
70-
f"for task {task_id} (context: {context_id})"
75+
f'[SUTAgentExecutor] Processing message {user_message.message_id} '
76+
f'for task {task_id} (context: {context_id})'
7177
)
7278

7379
working_status = TaskStatusUpdateEvent(
@@ -76,9 +82,9 @@ async def execute(self, context: RequestContext, event_queue: EventQueue) -> Non
7682
status=TaskStatus(
7783
state=TaskState.working,
7884
message=Message(
79-
role="agent",
85+
role='agent',
8086
message_id=str(uuid.uuid4()),
81-
parts=[TextPart(text="Processing your question")],
87+
parts=[TextPart(text='Processing your question')],
8288
task_id=task_id,
8389
context_id=context_id,
8490
),
@@ -88,17 +94,17 @@ async def execute(self, context: RequestContext, event_queue: EventQueue) -> Non
8894
)
8995
await event_queue.enqueue_event(working_status)
9096

91-
agent_reply_text = "Hello world!"
97+
agent_reply_text = 'Hello world!'
9298
await asyncio.sleep(3) # Simulate processing delay
9399

94100
if task_id not in self.running_tasks:
95-
logger.info(f"Task {task_id} was cancelled.")
101+
logger.info(f'Task {task_id} was cancelled.')
96102
return
97103

98-
logger.info(f"[SUTAgentExecutor] Response: {agent_reply_text}")
104+
logger.info(f'[SUTAgentExecutor] Response: {agent_reply_text}')
99105

100106
agent_message = Message(
101-
role="agent",
107+
role='agent',
102108
message_id=str(uuid.uuid4()),
103109
parts=[TextPart(text=agent_reply_text)],
104110
task_id=task_id,
@@ -118,72 +124,71 @@ async def execute(self, context: RequestContext, event_queue: EventQueue) -> Non
118124
await event_queue.enqueue_event(final_update)
119125

120126

121-
122127
async def main():
123-
HTTP_PORT = int(os.environ.get("HTTP_PORT", 41241))
124-
125-
# 1. Setup Executor and Handlers
128+
HTTP_PORT = int(os.environ.get('HTTP_PORT', 41241))
129+
126130
agent_executor = SUTAgentExecutor()
127131
task_store = InMemoryTaskStore()
128132
queue_manager = InMemoryQueueManager()
129-
133+
130134
request_handler = DefaultRequestHandler(
131135
task_store=task_store,
132136
queue_manager=queue_manager,
133137
agent_executor=agent_executor,
134138
)
135139

136-
# 2. Create Agent Card (JSON-RPC only)
137140
sut_agent_card = AgentCard(
138-
name="SUT Agent",
139-
description="A sample agent to be used as SUT against tck tests.",
140-
url=f"http://localhost:{HTTP_PORT}/a2a/jsonrpc",
141+
name='SUT Agent',
142+
description='A sample agent to be used as SUT against tck tests.',
143+
url=f'http://localhost:{HTTP_PORT}/a2a/jsonrpc',
141144
provider=AgentProvider(
142-
organization="A2A Samples",
143-
url="https://example.com/a2a-samples",
145+
organization='A2A Samples',
146+
url='https://example.com/a2a-samples',
144147
),
145-
version="1.0.0",
146-
protocol_version="0.3.0",
148+
version='1.0.0',
149+
protocol_version='0.3.0',
147150
capabilities=AgentCapabilities(
148151
streaming=True,
149152
push_notifications=False,
150153
state_transition_history=True,
151154
),
152-
default_input_modes=["text"],
153-
default_output_modes=["text", "task-status"],
155+
default_input_modes=['text'],
156+
default_output_modes=['text', 'task-status'],
154157
skills=[
155158
{
156-
"id": "sut_agent",
157-
"name": "SUT Agent",
158-
"description": "Simulate the general flow of a streaming agent.",
159-
"tags": ["sut"],
160-
"examples": ["hi", "hello world", "how are you", "goodbye"],
161-
"input_modes": ["text"],
162-
"output_modes": ["text", "task-status"],
159+
'id': 'sut_agent',
160+
'name': 'SUT Agent',
161+
'description': 'Simulate the general flow of a streaming agent.',
162+
'tags': ['sut'],
163+
'examples': ['hi', 'hello world', 'how are you', 'goodbye'],
164+
'input_modes': ['text'],
165+
'output_modes': ['text', 'task-status'],
163166
}
164167
],
165168
supports_authenticated_extended_card=False,
166-
preferred_transport="JSONRPC",
169+
preferred_transport='JSONRPC',
167170
additional_interfaces=[
168-
{"url": f"http://localhost:{HTTP_PORT}/a2a/jsonrpc", "transport": "JSONRPC"},
171+
{
172+
'url': f'http://localhost:{HTTP_PORT}/a2a/jsonrpc',
173+
'transport': 'JSONRPC',
174+
},
169175
],
170176
)
171177

172-
# 3. Setup HTTP App
173178
json_rpc_app = A2AFastAPIApplication(
174179
agent_card=sut_agent_card,
175180
http_handler=request_handler,
176181
)
177182
app = json_rpc_app.build(
178-
rpc_url="/a2a/jsonrpc",
179-
agent_card_url="/.well-known/agent-card.json"
183+
rpc_url='/a2a/jsonrpc', agent_card_url='/.well-known/agent-card.json'
180184
)
181185

182-
logger.info(f"Starting HTTP server on port {HTTP_PORT}...")
183-
config = Config(app, host="0.0.0.0", port=HTTP_PORT, log_level="info")
186+
logger.info(f'Starting HTTP server on port {HTTP_PORT}...')
187+
config = Config(app, host='0.0.0.0', port=HTTP_PORT, log_level='info')
184188
server = Server(config)
185-
189+
186190
await server.serve()
187191

188-
if __name__ == "__main__":
192+
193+
if __name__ == '__main__':
189194
asyncio.run(main())

0 commit comments

Comments
 (0)