Skip to content
Closed
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
5 changes: 5 additions & 0 deletions src/google/adk/agents/readonly_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def state(self) -> MappingProxyType[str, Any]:
def session(self) -> Session:
"""The current session for this invocation."""
return self._invocation_context.session

@property
def user_id(self) -> str:
"""The id of the user. READONLY field."""
return self._invocation_context.user_id

@property
def run_config(self) -> Optional[RunConfig]:
Expand Down
6 changes: 6 additions & 0 deletions tests/unittests/agents/test_readonly_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def mock_invocation_context():
mock_context.invocation_id = "test-invocation-id"
mock_context.agent.name = "test-agent-name"
mock_context.session.state = {"key1": "value1", "key2": "value2"}
mock_context.user_id = "test-user-id"
return mock_context


Expand All @@ -31,3 +32,8 @@ def test_state_content(mock_invocation_context):
assert isinstance(state, MappingProxyType)
assert state["key1"] == "value1"
assert state["key2"] == "value2"


def test_user_id(mock_invocation_context):
readonly_context = ReadonlyContext(mock_invocation_context)
assert readonly_context.user_id == "test-user-id"
Loading