Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/packages/a2a/agent_framework_a2a/_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,14 @@ def _prepare_message_for_a2a(self, message: Message) -> A2AMessage:
raise ValueError(f"Unknown content type: {content.type}")

# Exclude framework-internal keys (e.g. attribution) from wire metadata
internal_keys = {"_attribution"}
internal_keys = {"_attribution", "context_id"}
metadata = {k: v for k, v in message.additional_properties.items() if k not in internal_keys} or None

return A2AMessage(
role=A2ARole("user"),
parts=parts,
message_id=message.message_id or uuid.uuid4().hex,
context_id=message.additional_properties.get("context_id"),
metadata=metadata,
Comment thread
eavanvalkenburg marked this conversation as resolved.
)

Expand Down
17 changes: 17 additions & 0 deletions python/packages/a2a/tests/test_a2a_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,23 @@ def test_prepare_message_for_a2a_with_multiple_contents() -> None:
assert result.parts[3].root.kind == "text" # JSON text remains as text (no parsing)


def test_prepare_message_for_a2a_forwards_context_id() -> None:
"""Test conversion of Message preserves context_id without duplicating it in metadata."""

agent = A2AAgent(client=MagicMock(), _http_client=None)

message = Message(
role="user",
contents=[Content.from_text(text="Continue the task")],
additional_properties={"context_id": "ctx-123", "trace_id": "trace-456"},
)

result = agent._prepare_message_for_a2a(message)

assert result.context_id == "ctx-123"
assert result.metadata == {"trace_id": "trace-456"}


def test_parse_contents_from_a2a_with_data_part() -> None:
"""Test conversion of A2A DataPart."""

Expand Down
Loading