Skip to content

Commit 091e7c5

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 12f395b + 099846c commit 091e7c5

79 files changed

Lines changed: 7091 additions & 793 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/agents/config.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ To create an ADK project for use with Agent Config:
8787
GOOGLE_GENAI_USE_VERTEXAI=0
8888
GOOGLE_API_KEY=<your-Google-Gemini-API-key>
8989

90-
You can get an API key from the Google AI Studio
90+
You can get an API key from the Google AI Studio
9191
[API Keys](https://aistudio.google.com/app/apikey) page.
9292

9393
1. For Gemini model access through Google Cloud, add these lines to the file:
@@ -125,7 +125,7 @@ the web interface, command line terminal execution, or API server mode.
125125

126126
To run your Agent Config-defined agent:
127127

128-
1. In your terminal, navigate to the `my_agent/` directory containing the
128+
1. In your terminal, navigate to the `my_agent/` directory containing the
129129
`root_agent.yaml` file.
130130
1. Type one of the following commands to run your agent:
131131
- `adk web` - Run web UI interface for your agent.
@@ -137,7 +137,7 @@ To run your Agent Config-defined agent:
137137
For more information on the ways to run your agent, see the *Run Your Agent*
138138
topic in the
139139
[Quickstart](/adk-docs/get-started/quickstart/#run-your-agent).
140-
For more information about the ADK command line options, see the
140+
For more information about the ADK command line options, see the
141141
[ADK CLI reference](/adk-docs/api-reference/cli/).
142142

143143
## Example configs
@@ -222,12 +222,12 @@ For more details, see the full code for this sample in the
222222

223223
## Deploy agent configs
224224

225-
You can deploy Agent Config agents with
226-
[Cloud Run](/adk-docs/deploy/cloud-run/) and
227-
[Agent Engine](/adk-docs/deploy/agent-engine/),
228-
using the same procedure as code-based agents. For more information on how
229-
to prepare and deploy Agent Config-based agents, see the
230-
[Cloud Run](/adk-docs/deploy/cloud-run/) and
225+
You can deploy Agent Config agents with
226+
[Cloud Run](/adk-docs/deploy/cloud-run/) and
227+
[Agent Engine](/adk-docs/deploy/agent-engine/),
228+
using the same procedure as code-based agents. For more information on how
229+
to prepare and deploy Agent Config-based agents, see the
230+
[Cloud Run](/adk-docs/deploy/cloud-run/) and
231231
[Agent Engine](/adk-docs/deploy/agent-engine/)
232232
deployment guides.
233233

@@ -251,21 +251,19 @@ limitations:
251251
- `enterprise_web_search`
252252
- `load_web_page`: Requires a fully-qualified path to access web
253253
pages.
254-
- **Agent Type Support:** The `LangGraphAgent` and `A2aAgent` types are
254+
- **Agent Type Support:** The `LangGraphAgent` and `A2aAgent` types are
255255
not yet supported.
256256
- `AgentTool`
257257
- `LongRunningFunctionTool`
258258
- `VertexAiSearchTool`
259259
- `MCPToolset`
260-
- `CrewaiTool`
261-
- `LangchainTool`
262260
- `ExampleTool`
263261

264262
## Next steps
265263

266264
For ideas on how and what to build with ADK Agent Configs, see the yaml-based
267265
agent definitions in the ADK
268266
[adk-samples](https://github.com/search?q=repo:google/adk-python+path:/%5Econtributing%5C/samples%5C//+root_agent.yaml&type=code)
269-
repository. For detailed information on the syntax and settings supported by
267+
repository. For detailed information on the syntax and settings supported by
270268
the Agent Config format, see the
271269
[Agent Config syntax reference](/adk-docs/api-reference/agentconfig/).

docs/agents/custom-agents.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ The core of any custom agent is the method where you define its unique asynchron
4949
* **Reactive Stream (`Flowable`):** It must return an `io.reactivex.rxjava3.core.Flowable<Event>`. This `Flowable` represents a stream of events that will be produced by the custom agent's logic, often by combining or transforming multiple `Flowable` from sub-agents.
5050
* **`ctx` (InvocationContext):** Provides access to crucial runtime information, most importantly `ctx.session().state()`, which is a `java.util.concurrent.ConcurrentMap<String, Object>`. This is the primary way to share data between steps orchestrated by your custom agent.
5151

52+
=== "Go"
53+
54+
In Go, you implement the `Run` method as part of a struct that satisfies the `agent.Agent` interface. The actual logic is typically a method on your custom agent struct.
55+
56+
* **Signature:** `Run(ctx agent.InvocationContext) iter.Seq2[*session.Event, error]`
57+
* **Iterator:** The `Run` method returns an iterator (`iter.Seq2`) that yields events and errors. This is the standard way to handle streaming results from an agent's execution.
58+
* **`ctx` (InvocationContext):** The `agent.InvocationContext` provides access to the session, including state, and other crucial runtime information.
59+
* **Session State:** You can access the session state through `ctx.Session().State()`.
60+
5261
**Key Capabilities within the Core Asynchronous Method:**
5362

5463
=== "Python"
@@ -123,6 +132,46 @@ The core of any custom agent is the method where you define its unique asynchron
123132
* **Conditional:** `Flowable.defer()` to choose which `Flowable` to subscribe to based on a condition, or `filter()` if you're filtering events within a stream.
124133
* **Iterative:** Operators like `repeat()`, `retry()`, or by structuring your `Flowable` chain to recursively call parts of itself based on conditions (often managed with `flatMapPublisher` or `concatMap`).
125134

135+
=== "Go"
136+
137+
1. **Calling Sub-Agents:** You invoke sub-agents by calling their `Run` method.
138+
139+
```go
140+
// Example: Running one sub-agent and yielding its events
141+
for event, err := range someSubAgent.Run(ctx) {
142+
if err != nil {
143+
// Handle or propagate the error
144+
return
145+
}
146+
// Yield the event up to the caller
147+
yield(event, nil)
148+
}
149+
```
150+
151+
2. **Managing State:** Read from and write to the session state to pass data between sub-agent calls or make decisions.
152+
```go
153+
// The `ctx` (`agent.InvocationContext`) is passed directly to your agent's `Run` function.
154+
// Read data set by a previous agent
155+
previousResult, err := ctx.Session().State().Get("some_key")
156+
if err != nil {
157+
// Handle cases where the key might not exist yet
158+
}
159+
160+
// Make a decision based on state
161+
if val, ok := previousResult.(string); ok && val == "some_value" {
162+
// ... call a specific sub-agent ...
163+
} else {
164+
// ... call another sub-agent ...
165+
}
166+
167+
// Store a result for a later step
168+
if err := ctx.Session().State().Set("my_custom_result", "calculated_value"); err != nil {
169+
// Handle error
170+
}
171+
```
172+
173+
3. **Implementing Control Flow:** Use standard Go constructs (`if`/`else`, `for`/`switch` loops, goroutines, channels) to create sophisticated, conditional, or iterative workflows involving your sub-agents.
174+
126175
## Managing Sub-Agents and State
127176

128177
Typically, a custom agent orchestrates other agents (like `LlmAgent`, `LoopAgent`, etc.).
@@ -158,6 +207,14 @@ Let's illustrate the power of custom agents with an example pattern: a multi-sta
158207
```java
159208
--8<-- "examples/java/snippets/src/main/java/agents/StoryFlowAgentExample.java:init"
160209
```
210+
211+
=== "Go"
212+
213+
We define the `StoryFlowAgent` struct and a constructor. In the constructor, we store the necessary sub-agents and tell the `BaseAgent` framework about the top-level agents this custom agent will directly orchestrate.
214+
215+
```go
216+
--8<-- "examples/go/snippets/agents/custom-agent/storyflow_agent.go:init"
217+
```
161218
---
162219

163220
### Part 2: Defining the Custom Execution Logic { #part-2-defining-the-custom-execution-logic }
@@ -191,6 +248,20 @@ Let's illustrate the power of custom agents with an example pattern: a multi-sta
191248
3. Then, the `sequentialAgent's` Flowable executes. It calls the `grammar_check` then `tone_check`, reading `current_story` and writing `grammar_suggestions` and `tone_check_result` to the state.
192249
4. **Custom Part:** After the sequentialAgent completes, logic within a `Flowable.defer` checks the "tone_check_result" from `invocationContext.session().state()`. If it's "negative", the `storyGenerator` Flowable is *conditionally concatenated* and executed again, overwriting "current_story". Otherwise, an empty Flowable is used, and the overall workflow proceeds to completion.
193250

251+
=== "Go"
252+
253+
The `Run` method orchestrates the sub-agents by calling their respective `Run` methods in a loop and yielding their events.
254+
255+
```go
256+
--8<-- "examples/go/snippets/agents/custom-agent/storyflow_agent.go:executionlogic"
257+
```
258+
**Explanation of Logic:**
259+
260+
1. The initial `storyGenerator` runs. Its output is expected to be in the session state under the key `"current_story"`.
261+
2. The `revisionLoopAgent` runs, which internally calls the `critic` and `reviser` sequentially for `max_iterations` times. They read/write `current_story` and `criticism` from/to the state.
262+
3. The `postProcessorAgent` runs, calling `grammar_check` then `tone_check`, reading `current_story` and writing `grammar_suggestions` and `tone_check_result` to the state.
263+
4. **Custom Part:** The code checks the `tone_check_result` from the state. If it's "negative", the `story_generator` is called *again*, overwriting the `current_story` in the state. Otherwise, the flow ends.
264+
194265
---
195266

196267
### Part 3: Defining the LLM Sub-Agents { #part-3-defining-the-llm-sub-agents }
@@ -212,6 +283,12 @@ These are standard `LlmAgent` definitions, responsible for specific tasks. Their
212283
--8<-- "examples/java/snippets/src/main/java/agents/StoryFlowAgentExample.java:llmagents"
213284
```
214285

286+
=== "Go"
287+
288+
```go
289+
--8<-- "examples/go/snippets/agents/custom-agent/storyflow_agent.go:llmagents"
290+
```
291+
215292
---
216293

217294
### Part 4: Instantiating and Running the custom agent { #part-4-instantiating-and-running-the-custom-agent }
@@ -230,6 +307,12 @@ Finally, you instantiate your `StoryFlowAgent` and use the `Runner` as usual.
230307
--8<-- "examples/java/snippets/src/main/java/agents/StoryFlowAgentExample.java:story_flow_agent"
231308
```
232309

310+
=== "Go"
311+
312+
```go
313+
--8<-- "examples/go/snippets/agents/custom-agent/storyflow_agent.go:story_flow_agent"
314+
```
315+
233316
*(Note: The full runnable code, including imports and execution logic, can be found linked below.)*
234317

235318
---
@@ -251,3 +334,10 @@ Finally, you instantiate your `StoryFlowAgent` and use the `Runner` as usual.
251334
# Full runnable code for the StoryFlowAgent example
252335
--8<-- "examples/java/snippets/src/main/java/agents/StoryFlowAgentExample.java:full_code"
253336
```
337+
338+
=== "Go"
339+
340+
```go
341+
# Full runnable code for the StoryFlowAgent example
342+
--8<-- "examples/go/snippets/agents/custom-agent/storyflow_agent.go:full_code"
343+
```

docs/agents/llm-agents.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ First, you need to establish what the agent *is* and what it's *for*.
6262
.build();
6363
```
6464

65+
=== "Golang"
66+
67+
```go
68+
// Example: Defining the basic identity
69+
--8<-- "examples/go/snippets/agents/llm-agents/snippets/main.go:identity"
70+
```
71+
6572

6673
## Guiding the Agent: Instructions (`instruction`)
6774

@@ -132,6 +139,13 @@ tells the agent:
132139
.build();
133140
```
134141

142+
=== "Golang"
143+
144+
```go
145+
// Example: Adding instructions
146+
--8<-- "examples/go/snippets/agents/llm-agents/snippets/main.go:instruction"
147+
```
148+
135149
*(Note: For instructions that apply to *all* agents in a system, consider using
136150
`global_instruction` on the root agent, detailed further in the
137151
[Multi-Agents](multi-agents.md) section.)*
@@ -204,6 +218,12 @@ on the conversation and its instructions.
204218
.build();
205219
```
206220

221+
=== "Golang"
222+
223+
```go
224+
--8<-- "examples/go/snippets/agents/llm-agents/snippets/main.go:tool_example"
225+
```
226+
207227
Learn more about Tools in the [Tools](../tools/index.md) section.
208228

209229
## Advanced Configuration & Control
@@ -251,6 +271,14 @@ You can adjust how the underlying LLM generates responses using `generate_conten
251271
.build();
252272
```
253273

274+
=== "Golang"
275+
276+
```go
277+
import "google.golang.org/genai"
278+
279+
--8<-- "examples/go/snippets/agents/llm-agents/snippets/main.go:gen_config"
280+
```
281+
254282
### Structuring Data (`input_schema`, `output_schema`, `output_key`)
255283

256284
For scenarios requiring structured data exchange with an `LLM Agent`, the ADK provides mechanisms to define expected input and desired output formats using schema definitions.
@@ -262,6 +290,7 @@ For scenarios requiring structured data exchange with an `LLM Agent`, the ADK pr
262290
* **`output_key` (Optional):** Provide a string key. If set, the text content of the agent's *final* response will be automatically saved to the session's state dictionary under this key. This is useful for passing results between agents or steps in a workflow.
263291
* In Python, this might look like: `session.state[output_key] = agent_response_text`
264292
* In Java: `session.state().put(outputKey, agentResponseText)`
293+
* In Golang, within a callback handler: `ctx.State().Set(output_key, agentResponseText)`
265294

266295
=== "Python"
267296

@@ -311,6 +340,14 @@ For scenarios requiring structured data exchange with an `LLM Agent`, the ADK pr
311340
.build();
312341
```
313342

343+
=== "Golang"
344+
345+
The input and output schema is a `google.genai.types.Schema` object.
346+
347+
```go
348+
--8<-- "examples/go/snippets/agents/llm-agents/snippets/main.go:schema_example"
349+
```
350+
314351
### Managing Context (`include_contents`)
315352

316353
Control whether the agent receives the prior conversation history.
@@ -340,6 +377,14 @@ Control whether the agent receives the prior conversation history.
340377
.build();
341378
```
342379

380+
=== "Golang"
381+
382+
```go
383+
import "google.golang.org/adk/agent/llmagent"
384+
385+
--8<-- "examples/go/snippets/agents/llm-agents/snippets/main.go:include_contents"
386+
```
387+
343388
### Planner
344389

345390
![python_only](https://img.shields.io/badge/Currently_supported_in-Python-blue){ title="This feature is currently available for Python. Java support is planned/ coming soon."}
@@ -543,6 +588,12 @@ call_agent("If it's raining in New York right now, what is the current temperatu
543588
--8<-- "examples/java/snippets/src/main/java/agents/LlmAgentExample.java:full_code"
544589
```
545590

591+
=== "Golang"
592+
593+
```go
594+
--8<-- "examples/go/snippets/agents/llm-agents/main.go:full_code"
595+
```
596+
546597
_(This example demonstrates the core concepts. More complex agents might incorporate schemas, context control, planning, etc.)_
547598

548599
## Related Concepts (Deferred Topics)

docs/agents/models.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,18 @@ For deployed applications, a service account is the standard method.
183183
// different availability or quota limitations.
184184
```
185185
186+
=== "Go"
187+
188+
```go
189+
import (
190+
"google.golang.org/adk/agent/llmagent"
191+
"google.golang.org/adk/model/gemini"
192+
"google.golang.org/genai"
193+
)
194+
195+
--8<-- "examples/go/snippets/agents/models/models.go:gemini-example"
196+
```
197+
186198
!!!warning "Secure Your Credentials"
187199
Service account credentials or API keys are powerful credentials. Never expose them publicly. Use a secret manager like [Google Secret Manager](https://cloud.google.com/secret-manager) to store and access them securely in production.
188200

0 commit comments

Comments
 (0)