You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature Request] Support ToolContext for ADK function tools #1470
Is your feature request related to a problem? Please describe.
ADK activity_tool cannot wrap ADK function tools that use ToolContext.
When an activity_tool has a tool_context: ToolContext parameter, the wrapper tries to serialize ToolContext for workflow.execute_activity(). Since ToolContext holds non-serializable objects, serialization fails at runtime.
What I would recommend is to explicitly call out the pieces of ToolContext which are actually needed by your tool. If those are serializable, you can populate those activity inputs from the tool context before activity invocation, though you won't be able to use activity_tool because that would add those inputs to the tool schema. Instead, you can define an adk tool function directly something like so:
(Though we actually recommend a single input object for extensibility if you need to add things)
If you need to modify the tool context, those modifications need to happen inside the tool function, not the activity, because they are executing on different objects. You can return the information needed from the activity and use the result in the tool to do what is needed. This is what we do for approval of MCP tools.
@kawolum This has been resolved via #1683 - please feel free to try things out and let me know if there are any further issues or rough edges around this use case. The fix in that PR should go out in the next SDK minor version release. Thanks!
Activity
tconley1428 commentedon Apr 22, 2026
Unfortunately I don't think this is something that we can solve generically for you.
Any input type to an activity absolutely does have to be serializable. The activity inputs need to be sent to the server and back, and may run on a different worker entirely than the workflow itself. Because
ToolContextis not serializable, it cannot be an activity argument. You can take a look at https://github.com/temporalio/sdk-python/blob/0795a654977dc5c79cb55db7a41155a9d5ccccf8/temporalio/contrib/google_adk_agents/_mcp.py to see how we worked around this in the particular case of MCP tools.What I would recommend is to explicitly call out the pieces of
ToolContextwhich are actually needed by your tool. If those are serializable, you can populate those activity inputs from the tool context before activity invocation, though you won't be able to useactivity_toolbecause that would add those inputs to the tool schema. Instead, you can define an adk tool function directly something like so:(Though we actually recommend a single input object for extensibility if you need to add things)
If you need to modify the tool context, those modifications need to happen inside the tool function, not the activity, because they are executing on different objects. You can return the information needed from the activity and use the result in the tool to do what is needed. This is what we do for approval of MCP tools.
kawolum commentedon Apr 22, 2026
Thank you for looking, I did something similar to what you described as a workaround.
tconley1428 commentedon Apr 22, 2026
What portion of
ToolContextdo you actually use? We're considering a helper for activities which specifically useToolContext.state.kawolum commentedon Apr 22, 2026
We use
ToolContext.state.get("key")in function tools to deterministically retrieve data that was set initially in the ADK agent session.Support ToolContext session state in activity_tool via ToolContextSna…
Harden tool_context validation, close annotation-based injection bypass
DABH commentedon Aug 10, 2026
@kawolum This has been resolved via #1683 - please feel free to try things out and let me know if there are any further issues or rough edges around this use case. The fix in that PR should go out in the next SDK minor version release. Thanks!
[AI-163] google_adk_agents: support ToolContext session state in acti…
[AI-163] google_adk_agents: support ToolContext session state in acti…