You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/a2a/quickstart-consuming.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ The A2A Basic sample consists of:
27
27
28
28
In the a2a_basic example, you will first need to expose the `check_prime_agent` via an A2A server, so that the local root agent can use it.
29
29
30
-
### 1. Getting the Sample Code
30
+
### 1. Getting the Sample Code { #getting-the-sample-code }
31
31
32
32
First, make sure you have the necessary dependencies installed:
33
33
@@ -68,7 +68,7 @@ a2a_basic/
68
68
-**`agent.json`**: Agent card of the A2A agent
69
69
-**`check_prime(nums: list[int])`**: Prime number checking algorithm
70
70
71
-
### 2. Start the Remote Prime Agent server
71
+
### 2. Start the Remote Prime Agent server { #start-the-remote-prime-agent-server }
72
72
73
73
To show how your ADK agent can consume a remote agent via A2A, you'll first need to start a remote agent server, which will host the prime agent (under `check_prime_agent`).
INFO: Uvicorn running on http://127.0.0.1:8001 (Press CTRL+C to quit)
97
97
```
98
98
99
-
### 3. Look out for the required agent card (`agent.json`) of the remote agent
99
+
### 3. Look out for the required agent card (`agent.json`) of the remote agent { #look-out-for-the-required-agent-card-agent-json-of-the-remote-agent }
100
100
101
101
A2A Protocol requires that each agent must have an agent card that describes what it does.
102
102
@@ -129,7 +129,7 @@ In the sample, the `check_prime_agent` already has an agent card provided:
129
129
130
130
In ADK, you can use a `to_a2a(root_agent)` wrapper which automatically generates an agent card for you. If you're interested in learning more about how to expose your existing agent so others can use it, then please look at the [A2A Quickstart (Exposing)](quickstart-exposing.md) tutorial.
131
131
132
-
### 4. Run the Main (Consuming) Agent
132
+
### 4. Run the Main (Consuming) Agent { #run-the-main-consuming-agent }
INFO: Uvicorn running on http://localhost:8001 (Press CTRL+C to quit)
126
126
```
127
127
128
-
### 3. Check that your remote agent is running
128
+
### 3. Check that your remote agent is running { #check-that-your-remote-agent-is-running }
129
129
130
130
You can check that your agent is up and running by visiting the agent card that was auto-generated earlier as part of your `to_a2a()` function in `a2a_root/remote_a2a/hello_world/agent.py`:
131
131
@@ -137,7 +137,7 @@ You should see the contents of the agent card, which should look like:
137
137
{"capabilities":{},"defaultInputModes":["text/plain"],"defaultOutputModes":["text/plain"],"description":"hello world agent that can roll a dice of 8 sides and check prime numbers.","name":"hello_world_agent","protocolVersion":"0.2.6","skills":[{"description":"hello world agent that can roll a dice of 8 sides and check prime numbers. \n I roll dice and answer questions about the outcome of the dice rolls.\n I can roll dice of different sizes.\n I can use multiple tools in parallel by calling functions in parallel(in one request and in one round).\n It is ok to discuss previous dice roles, and comment on the dice rolls.\n When I are asked to roll a die, I must call the roll_die tool with the number of sides. Be sure to pass in an integer. Do not pass in a string.\n I should never roll a die on my own.\n When checking prime numbers, call the check_prime tool with a list of integers. Be sure to pass in a list of integers. I should never pass in a string.\n I should not check prime numbers before calling the tool.\n When I are asked to roll a die and check prime numbers, I should always make the following two function calls:\n 1. I should first call the roll_die tool to get a roll. Wait for the function response before calling the check_prime tool.\n 2. After I get the function response from roll_die tool, I should call the check_prime tool with the roll_die result.\n 2.1 If user asks I to check primes based on previous rolls, make sure I include the previous rolls in the list.\n 3. When I respond, I must include the roll_die result from step 1.\n I should always perform the previous 3 steps when asking for a roll and checking prime numbers.\n I should not rely on the previous history on prime results.\n ","id":"hello_world_agent","name":"model","tags":["llm"]},{"description":"Roll a die and return the rolled result.\n\nArgs:\n sides: The integer number of sides the die has.\n tool_context: the tool context\nReturns:\n An integer of the result of rolling the die.","id":"hello_world_agent-roll_die","name":"roll_die","tags":["llm","tools"]},{"description":"Check if a given list of numbers are prime.\n\nArgs:\n nums: The list of numbers to check.\n\nReturns:\n A str indicating which number is prime.","id":"hello_world_agent-check_prime","name":"check_prime","tags":["llm","tools"]}],"supportsAuthenticatedExtendedCard":false,"url":"http://localhost:8001","version":"0.0.1"}
138
138
```
139
139
140
-
### 4. Run the Main (Consuming) Agent
140
+
### 4. Run the Main (Consuming) Agent { #run-the-main-consuming-agent }
141
141
142
142
Now that your remote agent is running, you can launch the dev UI and select "a2a_root" as your agent.
Copy file name to clipboardExpand all lines: docs/agents/custom-agents.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -141,7 +141,7 @@ Let's illustrate the power of custom agents with an example pattern: a multi-sta
141
141
142
142
---
143
143
144
-
### Part 1: Simplified custom agent Initialization
144
+
### Part 1: Simplified custom agent Initialization { #part-1-simplified-custom-agent-initialization }
145
145
146
146
=== "Python"
147
147
@@ -160,7 +160,7 @@ Let's illustrate the power of custom agents with an example pattern: a multi-sta
160
160
```
161
161
---
162
162
163
-
### Part 2: Defining the Custom Execution Logic
163
+
### Part 2: Defining the Custom Execution Logic { #part-2-defining-the-custom-execution-logic }
164
164
165
165
=== "Python"
166
166
@@ -193,7 +193,7 @@ Let's illustrate the power of custom agents with an example pattern: a multi-sta
193
193
194
194
---
195
195
196
-
### Part 3: Defining the LLM Sub-Agents
196
+
### Part 3: Defining the LLM Sub-Agents { #part-3-defining-the-llm-sub-agents }
197
197
198
198
These are standard `LlmAgent` definitions, responsible for specific tasks. Their `output key` parameter is crucial for placing results into the `session.state` where other agents or the custom orchestrator can access them.
199
199
@@ -214,7 +214,7 @@ These are standard `LlmAgent` definitions, responsible for specific tasks. Their
214
214
215
215
---
216
216
217
-
### Part 4: Instantiating and Running the custom agent
217
+
### Part 4: Instantiating and Running the custom agent { #part-4-instantiating-and-running-the-custom-agent }
218
218
219
219
Finally, you instantiate your `StoryFlowAgent` and use the `Runner` as usual.
Copy file name to clipboardExpand all lines: docs/agents/multi-agents.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,14 +12,14 @@ You can compose various types of agents derived from `BaseAgent` to build these
12
12
13
13
The following sections detail the core ADK primitives—such as agent hierarchy, workflow agents, and interaction mechanisms—that enable you to construct and manage these multi-agent systems effectively.
14
14
15
-
## 1. ADK Primitives for Agent Composition
15
+
## 1. ADK Primitives for Agent Composition { #adk-primitives-for-agent-composition }
16
16
17
17
ADK provides core building blocks—primitives—that enable you to structure and manage interactions within your multi-agent system.
18
18
19
19
!!! Note
20
20
The specific parameters or method names for the primitives may vary slightly by SDK language (e.g., `sub_agents` in Python, `subAgents` in Java). Refer to the language-specific API documentation for details.
21
21
22
-
### 1.1. Agent Hierarchy (Parent agent, Sub Agents)
### 1.2. Workflow Agents as Orchestrators { #workflow-agents-as-orchestrators }
81
81
82
82
ADK includes specialized agents derived from `BaseAgent` that don't perform tasks themselves but orchestrate the execution flow of their `sub_agents`.
83
83
@@ -223,7 +223,7 @@ ADK includes specialized agents derived from `BaseAgent` that don't perform task
223
223
// until Checker escalates (state.get("status") == "completed") or 10 iterations pass.
224
224
```
225
225
226
-
### 1.3. Interaction & Communication Mechanisms
226
+
### 1.3. Interaction & Communication Mechanisms { #interaction-communication-mechanisms }
227
227
228
228
Agents within a system often need to exchange data or trigger actions in one another. ADK facilitates this through:
229
229
@@ -444,7 +444,7 @@ Allows an [`LlmAgent`](llm-agents.md) to treat another `BaseAgent` instance as a
444
444
445
445
These primitives provide the flexibility to design multi-agent interactions ranging from tightly coupled sequential workflows to dynamic, LLM-driven delegation networks.
446
446
447
-
## 2. Common Multi-Agent Patterns using ADK Primitives
447
+
## 2. Common Multi-Agent Patterns using ADK Primitives { #common-multi-agent-patterns-using-adk-primitives }
448
448
449
449
By combining ADK's composition primitives, you can implement various established patterns for multi-agent collaboration.
***Pattern:** Intercept requests before they reach the LLM or tools to enforce rules.
12
12
***How:** Use `before_model_callback` to inspect the `LlmRequest` prompt or `before_tool_callback` to inspect tool arguments. If a policy violation is detected (e.g., forbidden topics, profanity), return a predefined response (`LlmResponse` or `dict`/ `Map`) to block the operation and optionally update `context.state` to log the violation.
13
13
***Example:** A `before_model_callback` checks `llm_request.contents` for sensitive keywords and returns a standard "Cannot process this request" `LlmResponse` if found, preventing the LLM call.
14
14
15
-
### 2. Dynamic State Management
15
+
### 2. Dynamic State Management { #dynamic-state-management }
16
16
17
17
***Pattern:** Read from and write to session state within callbacks to make agent behavior context-aware and pass data between steps.
18
18
***How:** Access `callback_context.state` or `tool_context.state`. Modifications (`state['key'] = value`) are automatically tracked in the subsequent `Event.actions.state_delta` for persistence by the `SessionService`.
19
19
***Example:** An `after_tool_callback` saves a `transaction_id` from the tool's result to `tool_context.state['last_transaction_id']`. A later `before_agent_callback` might read `state['user_tier']` to customize the agent's greeting.
20
20
21
-
### 3. Logging and Monitoring
21
+
### 3. Logging and Monitoring { #logging-and-monitoring }
22
22
23
23
***Pattern:** Add detailed logging at specific lifecycle points for observability and debugging.
24
24
***How:** Implement callbacks (e.g., `before_agent_callback`, `after_tool_callback`, `after_model_callback`) to print or send structured logs containing information like agent name, tool name, invocation ID, and relevant data from the context or arguments.
25
25
***Example:** Log messages like `INFO: [Invocation: e-123] Before Tool: search_api - Args: {'query': 'ADK'}`.
26
26
27
-
### 4. Caching
27
+
### 4. Caching { #caching }
28
28
29
29
***Pattern:** Avoid redundant LLM calls or tool executions by caching results.
30
30
***How:** In `before_model_callback` or `before_tool_callback`, generate a cache key based on the request/arguments. Check `context.state` (or an external cache) for this key. If found, return the cached `LlmResponse` or result directly, skipping the actual operation. If not found, allow the operation to proceed and use the corresponding `after_` callback (`after_model_callback`, `after_tool_callback`) to store the new result in the cache using the key.
31
31
***Example:**`before_tool_callback` for `get_stock_price(symbol)` checks `state[f"cache:stock:{symbol}"]`. If present, returns the cached price; otherwise, allows the API call and `after_tool_callback` saves the result to the state key.
***Pattern:** Alter data just before it's sent to the LLM/tool or just after it's received.
36
36
***How:**
@@ -40,21 +40,21 @@ These patterns demonstrate typical ways to enhance or control agent behavior usi
40
40
*`after_tool_callback`: Modify the `tool_response` dictionary (or Map in Java).
41
41
***Example:**`before_model_callback` appends "User language preference: Spanish" to `llm_request.config.system_instruction` if `context.state['lang'] == 'es'`.
42
42
43
-
### 6. Conditional Skipping of Steps
43
+
### 6. Conditional Skipping of Steps { #conditional-skipping-of-steps }
44
44
45
45
***Pattern:** Prevent standard operations (agent run, LLM call, tool execution) based on certain conditions.
46
46
***How:** Return a value from a `before_` callback (`Content` from `before_agent_callback`, `LlmResponse` from `before_model_callback`, `dict` from `before_tool_callback`). The framework interprets this returned value as the result for that step, skipping the normal execution.
47
47
***Example:**`before_tool_callback` checks `tool_context.state['api_quota_exceeded']`. If `True`, it returns `{'error': 'API quota exceeded'}`, preventing the actual tool function from running.
***Pattern:** Handle actions specific to the tool lifecycle, primarily authentication and controlling LLM summarization of tool results.
52
52
***How:** Use `ToolContext` within tool callbacks (`before_tool_callback`, `after_tool_callback`).
53
53
***Authentication:** Call `tool_context.request_credential(auth_config)` in `before_tool_callback` if credentials are required but not found (e.g., via `tool_context.get_auth_response` or state check). This initiates the auth flow.
54
54
***Summarization:** Set `tool_context.actions.skip_summarization = True` if the raw dictionary output of the tool should be passed back to the LLM or potentially displayed directly, bypassing the default LLM summarization step.
55
55
***Example:** A `before_tool_callback` for a secure API checks for an auth token in state; if missing, it calls `request_credential`. An `after_tool_callback` for a tool returning structured JSON might set `skip_summarization = True`.
56
56
57
-
### 8. Artifact Handling
57
+
### 8. Artifact Handling { #artifact-handling }
58
58
59
59
***Pattern:** Save or load session-related files or large data blobs during the agent lifecycle.
60
60
***How:** Use `callback_context.save_artifact` / `await tool_context.save_artifact` to store data (e.g., generated reports, logs, intermediate data). Use `load_artifact` to retrieve previously stored artifacts. Changes are tracked via `Event.actions.artifact_delta`.
If you find a bug in the framework or an error in the documentation:
60
60
61
61
***Framework Bugs:** Open an issue in [`google/adk-python`](https://github.com/google/adk-python/issues/new) or in [`google/adk-java`](https://github.com/google/adk-java/issues/new)
62
62
***Documentation Errors:**[Open an issue in `google/adk-docs` (use bug template)](https://github.com/google/adk-docs/issues/new?template=bug_report.md)
Have an idea for a new feature or an improvement to an existing one?
67
67
68
68
***Framework Enhancements:** Open an issue in [`google/adk-python`](https://github.com/google/adk-python/issues/new) or in [`google/adk-java`](https://github.com/google/adk-java/issues/new)
69
69
***Documentation Enhancements:**[Open an issue in `google/adk-docs`](https://github.com/google/adk-docs/issues/new)
0 commit comments