Skip to content

Commit 9d91851

Browse files
fix: docs clarify temp namespace (#612)
This commit clarifies the behavior of the `temp:` namespace in the documentation. The following changes were made: - Updated `docs/sessions/state.md` to provide a more detailed explanation of the `temp:` namespace. - Updated `docs/context/index.md` to improve the clarity of an example related to passing data between tools. - Updated `docs/runtime/index.md` to add a note about the scope of `temp:` variables. - Updated `docs/agents/multi-agents.md` and `docs/agents/workflow-agents/sequential-agents.md` to clarify how the `temp:` namespace is propagated to sub-agents. - Updated `docs/tools/function-tools.md` to explain how to use the `temp:` namespace to pass data between tool calls. fixes #160 Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Joe Fernandez <[email protected]>
1 parent 050c051 commit 9d91851

File tree

6 files changed

+27
-7
lines changed

6 files changed

+27
-7
lines changed

docs/agents/multi-agents.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ The most fundamental way for agents operating within the same invocation (and th
236236
* **Nature:** Asynchronous, passive communication. Ideal for pipelines orchestrated by `SequentialAgent` or passing data across `LoopAgent` iterations.
237237
* **See Also:** [State Management](../sessions/state.md)
238238

239+
!!! note "Invocation Context and `temp:` State"
240+
When a parent agent invokes a sub-agent, it passes the same `InvocationContext`. This means they share the same temporary (`temp:`) state, which is ideal for passing data that is only relevant for the current turn.
241+
239242
=== "Python"
240243

241244
```python

docs/agents/workflow-agents/sequential-agents.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ SequentialAgent(sub_agents=[CodeWriterAgent, CodeReviewerAgent, CodeRefactorerAg
3737

3838
This ensures the code is written, *then* reviewed, and *finally* refactored, in a strict, dependable order. **The output from each sub-agent is passed to the next by storing them in state via [Output Key](../llm-agents.md#structuring-data-input_schema-output_schema-output_key)**.
3939

40+
!!! note "Shared Invocation Context"
41+
The `SequentialAgent` passes the same `InvocationContext` to each of its sub-agents. This means they all share the same session state, including the temporary (`temp:`) namespace, making it easy to pass data between steps within a single turn.
42+
4043
???+ "Code"
4144

4245
=== "Python"

docs/context/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,13 @@ You'll frequently need to read information stored within the context.
447447
}
448448
```
449449

450-
### Managing Session State
450+
### Managing State
451451

452452
State is crucial for memory and data flow. When you modify state using `CallbackContext` or `ToolContext`, the changes are automatically tracked and persisted by the framework.
453453

454454
* **How it Works:** Writing to `callback_context.state['my_key'] = my_value` or `tool_context.state['my_key'] = my_value` adds this change to the `EventActions.state_delta` associated with the current step's event. The `SessionService` then applies these deltas when persisting the event.
455-
* **Passing Data Between Tools:**
455+
456+
#### Passing Data Between Tools
456457

457458
=== "Python"
458459

docs/runtime/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ Several components work together within the ADK Runtime to execute an agent invo
260260
6. ### `Invocation`
261261

262262
* **Role:** A conceptual term representing everything that happens in response to a *single* user query, from the moment the `Runner` receives it until the agent logic finishes yielding events for that query.
263-
* **Function:** An invocation might involve multiple agent runs (if using agent transfer or `AgentTool`), multiple LLM calls, tool executions, and callback executions, all tied together by a single `invocation_id` within the `InvocationContext`.
263+
* **Function:** An invocation might involve multiple agent runs (if using agent transfer or `AgentTool`), multiple LLM calls, tool executions, and callback executions, all tied together by a single `invocation_id` within the `InvocationContext`. State variables prefixed with `temp:` are strictly scoped to a single invocation and discarded afterwards.
264264

265265
These players interact continuously through the Event Loop to process a user's request.
266266

docs/sessions/state.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,17 @@ Prefixes on state keys define their scope and persistence behavior, especially w
5858
* **Use Cases:** Global settings (e.g., `'app:api_endpoint'`), shared templates.
5959
* **Example:** `session.state['app:global_discount_code'] = 'SAVE10'`
6060

61-
* **`temp:` Prefix (Temporary Session State):**
61+
* **`temp:` Prefix (Temporary Invocation State):**
6262

63-
* **Scope:** Specific to the *current* session processing turn.
64-
* **Persistence:** **Never Persistent.** Guaranteed to be discarded, even with persistent services.
65-
* **Use Cases:** Intermediate results needed only immediately, data you explicitly don't want stored.
63+
* **Scope:** Specific to the current **invocation** (the entire process from an agent receiving user input to generating the final output for that input).
64+
* **Persistence:** **Not Persistent.** Discarded after the invocation completes and does not carry over to the next one.
65+
* **Use Cases:** Storing intermediate calculations, flags, or data passed between tool calls within a single invocation.
66+
* **When Not to Use:** For information that must persist across different invocations, such as user preferences, conversation history summaries, or accumulated data.
6667
* **Example:** `session.state['temp:raw_api_response'] = {...}`
6768

69+
!!! note "Sub-Agents and Invocation Context"
70+
When a parent agent calls a sub-agent (e.g., using `SequentialAgent` or `ParallelAgent`), it passes its `InvocationContext` to the sub-agent. This means the entire chain of agent calls shares the same invocation ID and, therefore, the same `temp:` state.
71+
6872
**How the Agent Sees It:** Your agent code interacts with the *combined* state through the single `session.state` collection (dict/ Map). The `SessionService` handles fetching/merging state from the correct underlying storage based on prefixes.
6973

7074
### Accessing Session State in Agent Instructions

docs/tools/function-tools.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ Strive to make your return values as descriptive as possible. *For example,* ins
104104

105105
The docstring of your function serves as the tool's **description** and is sent to the LLM. Therefore, a well-written and comprehensive docstring is crucial for the LLM to understand how to use the tool effectively. Clearly explain the purpose of the function, the meaning of its parameters, and the expected return values.
106106

107+
### Passing Data Between Tools
108+
109+
When an agent calls multiple tools in a sequence, you might need to pass data from one tool to another. The recommended way to do this is by using the `temp:` prefix in the session state.
110+
111+
A tool can write data to a `temp:` variable, and a subsequent tool can read it. This data is only available for the current invocation and is discarded afterwards.
112+
113+
!!! note "Shared Invocation Context"
114+
All tool calls within a single agent turn share the same `InvocationContext`. This means they also share the same temporary (`temp:`) state, which is how data can be passed between them.
115+
107116
### Example
108117

109118
??? "Example"

0 commit comments

Comments
 (0)