Skip to content

feat: add user_id in readonly context #1083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -33,6 +33,11 @@ def __init__(
) -> None:
self._invocation_context = invocation_context

@property
def user_id(self) -> str:
"""The user id that start this invocation. READONLY field."""
return self._invocation_context.user_id

@property
def user_content(self) -> Optional[types.Content]:
"""The user content that started this invocation. READONLY field."""
Expand Down
8 changes: 8 additions & 0 deletions tests/unittests/agents/test_readonly_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@
@pytest.fixture
def mock_invocation_context():
mock_context = MagicMock()

mock_context.user_id = "test-user-id"
mock_context.invocation_id = "test-invocation-id"
mock_context.agent.name = "test-agent-name"
mock_context.session.state = {"key1": "value1", "key2": "value2"}

return mock_context


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


def test_invocation_id(mock_invocation_context):
readonly_context = ReadonlyContext(mock_invocation_context)
assert readonly_context.invocation_id == "test-invocation-id"
Expand Down