An invocation context represents the data of a single invocation of an agent. An invocation: 1. Starts with a user message and ends with a final response. 2. Can contain one or multiple agent calls. 3. Is handled by runner.run_async(). An invocation runs an agent until it does not
| 101 | |
| 102 | |
| 103 | class InvocationContext(BaseModel): |
| 104 | """An invocation context represents the data of a single invocation of an agent. |
| 105 | |
| 106 | An invocation: |
| 107 | 1. Starts with a user message and ends with a final response. |
| 108 | 2. Can contain one or multiple agent calls. |
| 109 | 3. Is handled by runner.run_async(). |
| 110 | |
| 111 | An invocation runs an agent until it does not request to transfer to another |
| 112 | agent. |
| 113 | |
| 114 | An agent call: |
| 115 | 1. Is handled by agent.run(). |
| 116 | 2. Ends when agent.run() ends. |
| 117 | |
| 118 | An LLM agent call is an agent with a BaseLLMFlow. |
| 119 | An LLM agent call can contain one or multiple steps. |
| 120 | |
| 121 | An LLM agent runs steps in a loop until: |
| 122 | 1. A final response is generated. |
| 123 | 2. The agent transfers to another agent. |
| 124 | 3. The end_invocation is set to true by any callbacks or tools. |
| 125 | |
| 126 | A step: |
| 127 | 1. Calls the LLM only once and yields its response. |
| 128 | 2. Calls the tools and yields their responses if requested. |
| 129 | |
| 130 | The summarization of the function response is considered another step, since |
| 131 | it is another llm call. |
| 132 | A step ends when it's done calling llm and tools, or if the end_invocation |
| 133 | is set to true at any time. |
| 134 | |
| 135 | ``` |
| 136 | ┌─────────────────────── invocation ──────────────────────────┐ |
| 137 | ┌──────────── llm_agent_call_1 ────────────┐ ┌─ agent_call_2 ─┐ |
| 138 | ┌──── step_1 ────────┐ ┌───── step_2 ──────┐ |
| 139 | [call_llm] [call_tool] [call_llm] [transfer] |
| 140 | ``` |
| 141 | """ |
| 142 | |
| 143 | model_config = ConfigDict( |
| 144 | arbitrary_types_allowed=True, |
| 145 | extra="forbid", |
| 146 | ) |
| 147 | """The pydantic model config.""" |
| 148 | |
| 149 | artifact_service: Optional[BaseArtifactService] = None |
| 150 | session_service: BaseSessionService |
| 151 | memory_service: Optional[BaseMemoryService] = None |
| 152 | credential_service: Optional[BaseCredentialService] = None |
| 153 | context_cache_config: Optional[ContextCacheConfig] = None |
| 154 | |
| 155 | invocation_id: str |
| 156 | """The id of this invocation context. Readonly.""" |
| 157 | branch: Optional[str] = None |
| 158 | """The branch of the invocation context. |
| 159 | |
| 160 | The format is like agent_1.agent_2.agent_3, where agent_1 is the parent of |
no outgoing calls