Skip to content

Commit e17fc3e

Browse files
committed
Fix sut_agent.py
1 parent 7d2e35e commit e17fc3e

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed

tck/sut_agent.py

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
from a2a.types import (
1919
AgentCapabilities,
2020
AgentCard,
21+
AgentInterface,
2122
AgentProvider,
23+
AgentSkill,
2224
Message,
25+
Part,
2326
TaskState,
2427
TaskStatus,
2528
TaskStatusUpdateEvent,
26-
TextPart,
2729
)
2830

2931

@@ -38,24 +40,25 @@ class SUTAgentExecutor(AgentExecutor):
3840

3941
def __init__(self) -> None:
4042
"""Initializes the SUT agent executor."""
41-
self.running_tasks = set()
43+
self.running_tasks: set[str] = set()
4244

4345
async def cancel(
4446
self, context: RequestContext, event_queue: EventQueue
4547
) -> None:
4648
"""Cancels a task."""
4749
api_task_id = context.task_id
50+
if api_task_id is None:
51+
return
4852
if api_task_id in self.running_tasks:
4953
self.running_tasks.remove(api_task_id)
5054

5155
status_update = TaskStatusUpdateEvent(
5256
task_id=api_task_id,
5357
context_id=context.context_id or str(uuid.uuid4()),
5458
status=TaskStatus(
55-
state=TaskState.canceled,
56-
timestamp=datetime.now(timezone.utc).isoformat(),
59+
state=TaskState.TASK_STATE_CANCELED,
60+
timestamp=datetime.now(timezone.utc),
5761
),
58-
final=True,
5962
)
6063
await event_queue.enqueue_event(status_update)
6164

@@ -65,6 +68,8 @@ async def execute(
6568
"""Executes a task."""
6669
user_message = context.message
6770
task_id = context.task_id
71+
if user_message is None or task_id is None:
72+
return
6873
context_id = context.context_id
6974

7075
self.running_tasks.add(task_id)
@@ -80,17 +85,16 @@ async def execute(
8085
task_id=task_id,
8186
context_id=context_id,
8287
status=TaskStatus(
83-
state=TaskState.working,
88+
state=TaskState.TASK_STATE_WORKING,
8489
message=Message(
8590
role='agent',
8691
message_id=str(uuid.uuid4()),
87-
parts=[TextPart(text='Processing your question')],
92+
parts=[Part(text='Processing your question')],
8893
task_id=task_id,
8994
context_id=context_id,
9095
),
91-
timestamp=datetime.now(timezone.utc).isoformat(),
96+
timestamp=datetime.now(timezone.utc),
9297
),
93-
final=False,
9498
)
9599
await event_queue.enqueue_event(working_status)
96100

@@ -106,7 +110,7 @@ async def execute(
106110
agent_message = Message(
107111
role='agent',
108112
message_id=str(uuid.uuid4()),
109-
parts=[TextPart(text=agent_reply_text)],
113+
parts=[Part(text=agent_reply_text)],
110114
task_id=task_id,
111115
context_id=context_id,
112116
)
@@ -115,11 +119,10 @@ async def execute(
115119
task_id=task_id,
116120
context_id=context_id,
117121
status=TaskStatus(
118-
state=TaskState.input_required,
122+
state=TaskState.TASK_STATE_INPUT_REQUIRED,
119123
message=agent_message,
120-
timestamp=datetime.now(timezone.utc).isoformat(),
124+
timestamp=datetime.now(timezone.utc),
121125
),
122-
final=True,
123126
)
124127
await event_queue.enqueue_event(final_update)
125128

@@ -131,38 +134,34 @@ def main() -> None:
131134
agent_card = AgentCard(
132135
name='SUT Agent',
133136
description='An agent to be used as SUT against TCK tests.',
134-
url=f'http://localhost:{http_port}{JSONRPC_URL}',
137+
supported_interfaces=[
138+
AgentInterface(
139+
url=f'http://localhost:{http_port}{JSONRPC_URL}',
140+
protocol_binding='JSONRPC',
141+
protocol_version='0.3.0',
142+
),
143+
],
135144
provider=AgentProvider(
136145
organization='A2A Samples',
137146
url='https://example.com/a2a-samples',
138147
),
139148
version='1.0.0',
140-
protocol_version='0.3.0',
141149
capabilities=AgentCapabilities(
142150
streaming=True,
143151
push_notifications=False,
144-
state_transition_history=True,
145152
),
146153
default_input_modes=['text'],
147154
default_output_modes=['text', 'task-status'],
148155
skills=[
149-
{
150-
'id': 'sut_agent',
151-
'name': 'SUT Agent',
152-
'description': 'Simulate the general flow of a streaming agent.',
153-
'tags': ['sut'],
154-
'examples': ['hi', 'hello world', 'how are you', 'goodbye'],
155-
'input_modes': ['text'],
156-
'output_modes': ['text', 'task-status'],
157-
}
158-
],
159-
supports_authenticated_extended_card=False,
160-
preferred_transport='JSONRPC',
161-
additional_interfaces=[
162-
{
163-
'url': f'http://localhost:{http_port}{JSONRPC_URL}',
164-
'transport': 'JSONRPC',
165-
},
156+
AgentSkill(
157+
id='sut_agent',
158+
name='SUT Agent',
159+
description='Simulate the general flow of a streaming agent.',
160+
tags=['sut'],
161+
examples=['hi', 'hello world', 'how are you', 'goodbye'],
162+
input_modes=['text'],
163+
output_modes=['text', 'task-status'],
164+
)
166165
],
167166
)
168167

0 commit comments

Comments
 (0)