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
9 changes: 9 additions & 0 deletions src/a2a/server/agent_execution/context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import uuid

from typing import Any

from a2a.server.context import ServerCallContext
from a2a.types import (
InvalidParamsError,
Expand Down Expand Up @@ -134,6 +136,13 @@ def call_context(self) -> ServerCallContext | None:
"""The server call context associated with this request."""
return self._call_context

@property
def metadata(self) -> dict[str, Any]:
"""Metadata associated with the request, if available."""
if not self._params:
return {}
return self._params.metadata or {}

def _check_or_generate_task_id(self) -> None:
"""Ensures a task ID is present, generating one if necessary."""
if not self._params:
Expand Down
11 changes: 11 additions & 0 deletions tests/server/agent_execution/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@ def test_message_property_with_params(self, mock_params):
context = RequestContext(request=mock_params)
assert context.message == mock_params.message

def test_metadata_property_without_content(self):
"""Test metadata property returns empty dict when no content are provided."""
context = RequestContext()
assert context.metadata == {}

def test_metadata_property_with_content(self, mock_params):
"""Test metadata property returns the metadata from params."""
mock_params.metadata = {'key': 'value'}
context = RequestContext(request=mock_params)
assert context.metadata == {'key': 'value'}

def test_init_with_existing_ids_in_message(self, mock_message, mock_params):
"""Test initialization with existing IDs in the message."""
mock_message.taskId = 'existing-task-id'
Expand Down
Loading