Skip to content

Commit e4ced98

Browse files
authored
Merge branch 'main' into kthota/typechanges
2 parents 4affcb1 + c027843 commit e4ced98

File tree

15 files changed

+132
-17
lines changed

15 files changed

+132
-17
lines changed

src/a2a/client/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
SetTaskPushNotificationConfigRequest,
2525
SetTaskPushNotificationConfigResponse,
2626
)
27+
from a2a.utils.telemetry import SpanKind, trace_class
2728

2829

2930
class A2ACardResolver:
@@ -59,6 +60,7 @@ async def get_agent_card(
5960
) from e
6061

6162

63+
@trace_class(kind=SpanKind.CLIENT)
6264
class A2AClient:
6365
"""A2A Client."""
6466

@@ -111,7 +113,7 @@ async def send_message_streaming(
111113
request: SendStreamingMessageRequest,
112114
*,
113115
http_kwargs: dict[str, Any] | None = None,
114-
) -> AsyncGenerator[SendStreamingMessageResponse, None]:
116+
) -> AsyncGenerator[SendStreamingMessageResponse]:
115117
if not request.id:
116118
request.id = str(uuid4())
117119

src/a2a/server/agent_execution/context.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
InvalidParamsError,
55
Message,
66
MessageSendParams,
7+
MessageSendConfiguration,
78
Task,
89
)
910
from a2a.utils import get_message_text
@@ -79,6 +80,10 @@ def task_id(self) -> str | None:
7980
def context_id(self) -> str | None:
8081
return self._context_id
8182

83+
@property
84+
def configuration(self) -> MessageSendConfiguration | None:
85+
return self._params.configuration
86+
8287
def _check_or_generate_task_id(self) -> None:
8388
if not self._params:
8489
return

src/a2a/server/events/event_consumer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
TaskStatusUpdateEvent,
1313
)
1414
from a2a.utils.errors import ServerError
15+
from a2a.utils.telemetry import SpanKind, trace_class
1516

1617

1718
logger = logging.getLogger(__name__)
1819

1920

21+
@trace_class(kind=SpanKind.SERVER)
2022
class EventConsumer:
2123
"""Consumer to read events from the agent event queue."""
2224

src/a2a/server/events/event_queue.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
TaskArtifactUpdateEvent,
1212
TaskStatusUpdateEvent,
1313
)
14+
from a2a.utils.telemetry import SpanKind, trace_class
1415

1516

1617
logger = logging.getLogger(__name__)
@@ -26,6 +27,7 @@
2627
)
2728

2829

30+
@trace_class(kind=SpanKind.SERVER)
2931
class EventQueue:
3032
"""Event queue for A2A responses from agent."""
3133

src/a2a/server/events/in_memory_queue_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
QueueManager,
77
TaskQueueExists,
88
)
9+
from a2a.utils.telemetry import SpanKind, trace_class
910

1011

12+
@trace_class(kind=SpanKind.SERVER)
1113
class InMemoryQueueManager(QueueManager):
1214
"""InMemoryQueueManager is used for a single binary management.
1315

src/a2a/server/request_handlers/default_request_handler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
UnsupportedOperationError,
2828
)
2929
from a2a.utils.errors import ServerError
30+
from a2a.utils.telemetry import SpanKind, trace_class
3031

3132

3233
logger = logging.getLogger(__name__)
3334

3435

36+
@trace_class(kind=SpanKind.SERVER)
3537
class DefaultRequestHandler(RequestHandler):
3638
"""Default request handler for all incoming requests."""
3739

@@ -128,7 +130,7 @@ async def on_message_send(
128130
# agents.
129131
queue = await self._queue_manager.create_or_tap(task_id)
130132
result_aggregator = ResultAggregator(task_manager)
131-
# TODO to manage the non-blocking flows.
133+
# TODO: to manage the non-blocking flows.
132134
producer_task = asyncio.create_task(
133135
self._run_event_stream(
134136
request_context,

src/a2a/server/request_handlers/jsonrpc_handler.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@
3636
)
3737
from a2a.utils.errors import ServerError
3838
from a2a.utils.helpers import validate
39+
from a2a.utils.telemetry import SpanKind, trace_class
3940

4041

4142
logger = logging.getLogger(__name__)
4243

4344

45+
@trace_class(kind=SpanKind.SERVER)
4446
class JSONRPCHandler:
45-
"""A handler that maps the JSONRPC Objects to the request handler and back."""
47+
"""Maps the JSONRPC Objects to the request handler and back."""
4648

4749
def __init__(
4850
self,
@@ -53,7 +55,7 @@ def __init__(
5355
5456
Args:
5557
agent_card: The AgentCard describing the agent's capabilities.
56-
request_handler: The handler instance responsible for processing A2A requests.
58+
request_handler: The handler instance to process A2A requests.
5759
"""
5860
self.agent_card = agent_card
5961
self.request_handler = request_handler

src/a2a/server/tasks/task_updater.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def add_artifact(
4242
parts: list[Part],
4343
artifact_id=str(uuid.uuid4()),
4444
name: str | None = None,
45+
metadata: dict[str, any] | None = None,
4546
):
4647
"""Add an artifact to the task."""
4748
self.event_queue.enqueue_event(
@@ -52,6 +53,7 @@ def add_artifact(
5253
artifactId=artifact_id,
5354
name=name,
5455
parts=parts,
56+
metadata=metadata,
5557
),
5658
)
5759
)
@@ -64,6 +66,14 @@ def complete(self, message: Message | None = None):
6466
final=True,
6567
)
6668

69+
def failed(self, message: Message | None = None):
70+
"""Mark the task as failed."""
71+
self.update_status(
72+
TaskState.failed,
73+
message=message,
74+
final=True
75+
)
76+
6777
def submit(self, message: Message | None = None):
6878
"""Mark the task as submitted."""
6979
self.update_status(

src/a2a/utils/__init__.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
from a2a.utils.artifact import new_text_artifact
1+
from a2a.utils.artifact import (
2+
new_artifact,
3+
new_data_artifact,
4+
new_text_artifact,
5+
)
26
from a2a.utils.helpers import (
37
append_artifact_to_task,
48
build_text_artifact,
59
create_task_obj,
10+
are_modalities_compatible,
611
)
712
from a2a.utils.message import (
813
get_message_text,
914
get_text_parts,
1015
new_agent_text_message,
16+
new_agent_parts_message,
17+
)
18+
from a2a.utils.task import (
19+
new_task,
20+
completed_task,
1121
)
12-
from a2a.utils.task import new_task
1322

1423

1524
__all__ = [
@@ -21,4 +30,9 @@
2130
'new_agent_text_message',
2231
'new_task',
2332
'new_text_artifact',
33+
'new_agent_parts_message',
34+
'completed_task',
35+
'new_artifact',
36+
'new_data_artifact',
37+
'are_modalities_compatible',
2438
]

src/a2a/utils/artifact.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,30 @@
33
from a2a.types import Artifact, Part, TextPart
44

55

6-
def new_text_artifact(
7-
name: str,
8-
text: str,
9-
description: str = '',
6+
def new_artifact(
7+
parts: list[Part], name: str, description: str = ''
108
) -> Artifact:
119
return Artifact(
1210
artifactId=str(uuid.uuid4()),
13-
parts=[Part(root=TextPart(text=text))],
11+
parts=parts,
1412
name=name,
1513
description=description,
1614
)
15+
16+
def new_text_artifact(
17+
name: str,
18+
text: str,
19+
description: str = '',
20+
) -> Artifact:
21+
return new_artifact(
22+
[Part(root=TextPart(text=text))], name, description,
23+
)
24+
25+
def new_data_artifact(
26+
name: str,
27+
data: dict[str, any],
28+
description: str = '',
29+
):
30+
return new_artifact(
31+
[Part(root=DataPart(data=data))], name, description,
32+
)

0 commit comments

Comments
 (0)