class documentation

class ToolContextSnapshot: (source)

View In Hierarchy

Serializable snapshot of the ADK ToolContext for activity-backed tools.

Warning

This class is experimental and may change in future versions. Use with caution in production environments.

ADK's ToolContext holds live, non-serializable objects, so it cannot cross the activity boundary: activity inputs are sent to the server and may run on a different worker than the workflow. This snapshot carries the serializable subset instead.

Declare a parameter named tool_context annotated with this type (or ToolContextSnapshot | None) on an activity wrapped by activity_as_tool:

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

Exactly like a native ADK function tool's tool_context parameter, it is excluded from the LLM-facing tool schema and filled in at invocation time — here with a snapshot taken from the live ToolContext before the activity is scheduled.

When running under Temporal, the entire session state crosses the activity boundary: every value in it must be serializable by the configured data converter and the total size must fit within payload limits, even for keys the tool never reads. A non-serializable value fails the workflow task when the activity is scheduled. Local ADK runs pass the snapshot in memory and have no such constraint.

The snapshot is one-way and should be treated as read-only: mutating it inside the activity does not propagate back to the session (and in local runs nested values may alias the live session state, so mutating them can corrupt the session). To modify session state, return the needed information from the activity and apply it in workflow-side code (for example an ADK callback or a plain tool function).

Instance Variable function_call_id The id of the function call being handled, when available.
Instance Variable state The session state visible to this tool call, as a plain dict.
function_call_id: str | None = (source)

The id of the function call being handled, when available.

The session state visible to this tool call, as a plain dict.