InvocationContext
An invocation context represents the data of a single invocation of an agent.
An invocation:
Starts with a user message and ends with a final response.
Can contain one or multiple agent calls.
Is handled by runner.run_async().
An invocation runs an agent until it does not request to transfer to another agent.
An agent call:
Is handled by agent.run().
Ends when agent.run() ends.
An LLM agent call is an agent with a BaseLLMFlow. An LLM agent call can contain one or multiple steps.
An LLM agent runs steps in a loop until:
A final response is generated.
The agent transfers to another agent.
The end_invocation is set to true by any callbacks or tools.
A step:
Calls the LLM only once and yields its response.
Calls the tools and yields their responses if requested.
The summarization of the function response is considered another step, since it is another llm call. A step ends when it's done calling llm and tools, or if the end_invocation is set to true at any time.
┌─────────────────────── invocation ──────────────────────────┐
┌──────────── llm_agent_call_1 ────────────┐ ┌─ agent_call_2 ─┐
┌──── step_1 ────────┐ ┌───── step_2 ──────┐
[call_llm] [call_tool] [call_llm] [transfer]Constructors
Properties
The state of the agent for this invocation.
The end of agent status for each agent in this invocation.
Extra tools injected dynamically during invocation (e.g., by SequentialAgent).
The id of this invocation context. Readonly.
Whether to end this invocation.
Returns whether the current invocation is resumable.
The manager for keeping track of plugins in this invocation.
Optional resumability configuration for this invocation.
The user content that started this invocation. Readonly.
Functions
Creates a new InvocationContext for a child agent, derived from this context. Appends the given agent's name to the branch path.
Executes a single function call synchronously and builds a corresponding response event.
Finds the function call event in the current invocation that matches the function response id.
Processes a list of function calls by executing them efficiently and safely.
Populates agent states for the current invocation if it is resumable.
Resets the state of all sub-agents of the given agent recursively.
Set state of an agent explicitly. Does not implicitly initialize.
Returns whether to pause the invocation right after this event.