Skip to content

[Feature Request] Support ToolContext for ADK function tools #1470

Closed

Description

@kawolum

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.

@activity.defn
async def get_weather(query:str, tool_context: ToolContext) -> dict:
    db_url = tool_context.state.get("url", "")
    return requests.get(db_url).json()

search_tool = activity_tool(search_database, start_to_close_timeout=timedelta(seconds=30))

Describe the solution you'd like

Support tool_context from ADK.

Additional context

Not sure what's the best way to support this.

Activity

  1. added
    enhancement
    on Apr 22, 2026
  2. tconley1428 commented on Apr 22, 2026

    @tconley1428
    Contributor

    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 ToolContext is 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 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:

    @activity.defn
    def some_activity(something: T1, something_else: T2):
        pass
    
    def some_tool(context: ToolContext):
        return await workflow.execute_activity(some_activity, args=[context.Something, context.SomethingElse])
    

    (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.

  3. kawolum commented on Apr 22, 2026

    @kawolum
    Author

    Thank you for looking, I did something similar to what you described as a workaround.

  4. tconley1428 commented on Apr 22, 2026

    @tconley1428
    Contributor

    What portion of ToolContext do you actually use? We're considering a helper for activities which specifically use ToolContext.state.

  5. kawolum commented on Apr 22, 2026

    @kawolum
    Author

    We use ToolContext.state.get("key") in function tools to deterministically retrieve data that was set initially in the ADK agent session.

  6. added
    ai-sdk
    on Jul 17, 2026
  7. DABH commented on Aug 10, 2026

    @DABH
    Contributor

    @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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-sdkenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions