File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
src/a2a/server/agent_execution
tests/server/agent_execution Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 11import uuid
22
3+ from typing import Any
4+
35from a2a .server .context import ServerCallContext
46from a2a .types import (
57 InvalidParamsError ,
@@ -134,6 +136,13 @@ def call_context(self) -> ServerCallContext | None:
134136 """The server call context associated with this request."""
135137 return self ._call_context
136138
139+ @property
140+ def metadata (self ) -> dict [str , Any ]:
141+ """Metadata associated with the request, if available."""
142+ if not self ._params :
143+ return {}
144+ return self ._params .metadata or {}
145+
137146 def _check_or_generate_task_id (self ) -> None :
138147 """Ensures a task ID is present, generating one if necessary."""
139148 if not self ._params :
Original file line number Diff line number Diff line change @@ -211,6 +211,17 @@ def test_message_property_with_params(self, mock_params):
211211 context = RequestContext (request = mock_params )
212212 assert context .message == mock_params .message
213213
214+ def test_metadata_property_without_content (self ):
215+ """Test metadata property returns empty dict when no content are provided."""
216+ context = RequestContext ()
217+ assert context .metadata == {}
218+
219+ def test_metadata_property_with_content (self , mock_params ):
220+ """Test metadata property returns the metadata from params."""
221+ mock_params .metadata = {'key' : 'value' }
222+ context = RequestContext (request = mock_params )
223+ assert context .metadata == {'key' : 'value' }
224+
214225 def test_init_with_existing_ids_in_message (self , mock_message , mock_params ):
215226 """Test initialization with existing IDs in the message."""
216227 mock_message .taskId = 'existing-task-id'
You can’t perform that action at this time.
0 commit comments