[pull] main from temporalio:main - #192
Merged
Merged
Conversation
…vity_tool (#1683) * Support ToolContext session state in activity_tool via ToolContextSnapshot 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 * Harden tool_context validation, close annotation-based injection bypass ADK detects the context parameter annotation-first across all parameters (find_context_parameter), falling back to the name 'tool_context', so the previous name-only validation missed cases where ADK would still inject the live, non-serializable context: - Reject an ADK context annotation on any parameter, not just 'tool_context' (e.g. 'ctx: ToolContext' previously passed wrap-time validation, then failed payload serialization at runtime — the exact failure mode from #1470 — and, when combined with a 'tool_context: ToolContextSnapshot' parameter, leaked that parameter into the LLM-facing tool schema as required). - Reject ToolContextSnapshot on a parameter not named 'tool_context' (ADK never injects it there, so it would leak into the tool schema). - Reject an unannotated 'tool_context' (public docs already required the annotation; without it the activity decoded the snapshot as a plain dict under Temporal but received a ToolContextSnapshot in local runs). - Route Optional[ToolContext] to the ADK-specific error message and render union annotations readably. Docs: state serializability/payload-size constraints under Temporal and read-only snapshot semantics (nested values may alias live session state in local runs); add missing timedelta import to the README snippet. Tests: new wrap-time acceptance/rejection matrix (Optional form, ADK context under any name, misplaced snapshot, unannotated), legacy (non-JSON-schema) declaration path, context-only tool schema, mixed-type session state round-trip, and an in-activity marker proving the snapshot crosses a real activity boundary; drop incorrect copyright header. Verified against google-adk 2.2.0 (locked) and 2.5.0. * README: note local-run nested state aliasing in the read-only caveat
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )