Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -52,3 +52,8 @@ def agent_name(self) -> str:
def state(self) -> MappingProxyType[str, Any]:
"""The state of the current session. READONLY field."""
return MappingProxyType(self._invocation_context.session.state)

@property
def user_id(self) -> str:
"""The id of the user. READONLY field."""
return self._invocation_context.user_id
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"