[AI-163] google_adk_agents: support ToolContext session state in activity_tool - #1683
Open
DABH wants to merge 1 commit into
Open
[AI-163] google_adk_agents: support ToolContext session state in activity_tool#1683DABH wants to merge 1 commit into
DABH wants to merge 1 commit into
Conversation
…pshot Activities wrapped with activity_tool could not access the ADK ToolContext: declaring a tool_context parameter put it in the LLM-facing tool schema and then failed at runtime trying to serialize the live ToolContext as an activity argument (#1470). An activity can now declare a parameter named tool_context annotated with the new ToolContextSnapshot dataclass. Exactly like a native ADK function tool's tool_context parameter, it is excluded from the tool schema (ADK reserves the name) and filled at invocation time — with a serializable snapshot of the live ToolContext (session state as a plain dict, plus the function-call id) taken workflow-side before the activity is scheduled. The live ToolContext never crosses the activity boundary. Annotating the parameter with an ADK context type raises an actionable error at wrap time instead of failing at serialization time. The snapshot is one-way by design: activities may run on different workers, so session-state modifications must happen workflow-side using information returned from the activity. Closes #1470
DABH
force-pushed
the
activity-tool-context-state
branch
from
July 27, 2026 20:39
f05c905 to
6b80002
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was changed
Adds
ToolContextSnapshottotemporalio.contrib.google_adk_agents.workflow: a frozen, serializable dataclass carrying the session state (as a plain dict) and the function-call id of an ADKToolContext.An activity wrapped with
activity_toolcan now declare a parameter namedtool_contextannotated withToolContextSnapshot:Exactly like a native ADK function tool's
tool_contextparameter, it is excluded from the LLM-facing tool schema (ADK reserves the parameter name) and filled in at invocation time — the wrapper snapshots the liveToolContextworkflow-side before scheduling the activity. Annotating the parameter with a live ADK context type raises an actionableValueErrorat wrap time instead of a serialization failure at runtime.Why
Closes #1470 (JIRA AI-163). The reporter's tools read configuration seeded into session state (
tool_context.state.get("key")), which previously required hand-writing a plain tool function around each activity.The design follows the constraints laid out in the issue discussion:
ToolContextnever crosses the activity boundary — activity inputs go to the server and may run on a different worker, so only the explicitly-called-out serializable subset is passed, extracted workflow-side before invocation.tool_contextname-reservation, so declarations exclude it on both the legacy and JSON-schema paths.ToolContext.state(plus the function-call id), as a single input object so more fields can be added later without breaking activity signatures.Checklist
tests/contrib/google_adk_agents/test_adk_tool_context.py— end-to-end workflow run withmax_cached_workflows=0(state read from a seeded session, default parameter handling, populated function-call id,tool_contextmid-signature to prove positional slotting), local-ADK-run parity outside a workflow, schema-exclusion assertions for tools with and without the parameter, and wrap-time rejection of ADK-context / unrelated annotations. Full contrib suite: 23 passed, 5 skipped (pre-existing). pyright/basedpyright/mypy/ruff/pydocstyle clean.