Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
f0e895a
Added google_search snippet
ivanmkc Oct 1, 2025
0bbd08f
Fix: Address Go style guide issues in google_search.go
ivanmkc Oct 1, 2025
6f2ed49
Migrated to new API
ivanmkc Oct 10, 2025
bb0c68a
Fixed tool info in md file
ivanmkc Oct 10, 2025
67e76e5
Added partial check
ivanmkc Oct 10, 2025
639a122
Added function-tools sample
ivanmkc Sep 30, 2025
cbd8d68
Migrated to new API
ivanmkc Oct 10, 2025
276bcff
Added partial check
ivanmkc Oct 10, 2025
6460c0b
Ran linter
ivanmkc Oct 10, 2025
40bba52
feat: add go fmt check
ivanmkc Oct 23, 2025
3b1408a
Run go fmt only on changed files
ivanmkc Oct 23, 2025
b383c51
Feat: Add Golang example for LLM agents
ivanmkc Oct 2, 2025
69bffb5
Added schema agent
ivanmkc Oct 2, 2025
69f76c3
Added session support
ivanmkc Oct 2, 2025
33b0f8e
Migrated to new API
ivanmkc Oct 10, 2025
27a2d4e
Added back OutputKey
ivanmkc Oct 14, 2025
8e4299e
Added missing snippets
ivanmkc Oct 14, 2025
a447247
Moved snipped to its own package
ivanmkc Oct 14, 2025
a98771d
Minor cleanup
ivanmkc Oct 14, 2025
053fb1e
Reverted llm-agents.md
ivanmkc Oct 24, 2025
2373171
Added back correct changes to llm-agents.md
ivanmkc Oct 24, 2025
0946d2f
Updated to newest API
ivanmkc Oct 24, 2025
26d7874
Ran linter
ivanmkc Oct 24, 2025
76a20d3
Added google_search snippet
ivanmkc Oct 1, 2025
484aa5d
Fix: Address Go style guide issues in google_search.go
ivanmkc Oct 1, 2025
a37af75
Migrated to new API
ivanmkc Oct 10, 2025
c81d7dd
Fixed tool info in md file
ivanmkc Oct 10, 2025
641e8f9
Added partial check
ivanmkc Oct 10, 2025
2bda3e2
Added function-tools sample
ivanmkc Sep 30, 2025
ca5fb1c
Migrated to new API
ivanmkc Oct 10, 2025
d6d5c1b
Added partial check
ivanmkc Oct 10, 2025
b5e1b45
Ran linter
ivanmkc Oct 10, 2025
0bf6c79
feat: add go fmt check
ivanmkc Oct 23, 2025
12f395b
Run go fmt only on changed files
ivanmkc Oct 23, 2025
496071f
Added callback snippets
ivanmkc Oct 11, 2025
fa61ea3
Added back imports
ivanmkc Oct 11, 2025
bfa4aea
Added types of callbacks snippets
ivanmkc Oct 11, 2025
813799c
feat(go): align callback snippets with other languages
ivanmkc Oct 12, 2025
bc1ebfa
Ran linter and updated API
ivanmkc Oct 24, 2025
c009869
Added tool callbacks
ivanmkc Oct 28, 2025
502c8af
WIP
ivanmkc Oct 1, 2025
8f49b8f
WIP: Added the rest of the agents
ivanmkc Oct 2, 2025
662b9b9
Added sequential agent
ivanmkc Oct 9, 2025
2fe362b
Migrated agents to new API
ivanmkc Oct 9, 2025
7d8173e
Fixed snippet tags
ivanmkc Oct 9, 2025
45a75e9
Updated parallel and sequential with OutputKey
ivanmkc Oct 11, 2025
7595a74
Updated loop agent
ivanmkc Oct 11, 2025
82bbcd3
Cleanup
ivanmkc Oct 11, 2025
f04c67f
Fixed and ran linter
ivanmkc Oct 24, 2025
f3770a1
Removed comment
ivanmkc Oct 24, 2025
e6a107a
Merge pull request #3 from ivanmkc/imkc--llm-agents
ivanmkc Oct 29, 2025
cdfdbf9
Ran linter
ivanmkc Oct 29, 2025
8907683
Merge pull request #5 from ivanmkc/imkc--sequential-agents
ivanmkc Oct 29, 2025
6a7ee1e
Added custom agent snippets
ivanmkc Oct 4, 2025
08e03ea
Migrated to new API
ivanmkc Oct 9, 2025
ac22318
Fixed incorrect info about channels since run returns an Iterator, no…
ivanmkc Oct 9, 2025
d0df423
Cleanup and renaming
ivanmkc Oct 11, 2025
2682afa
Ran linter
ivanmkc Oct 24, 2025
10f9ea1
Fixed md
ivanmkc Oct 24, 2025
cac045b
Merge pull request #6 from ivanmkc/imkc--custom-agent
ivanmkc Oct 29, 2025
50f3c6a
Added multi-agent docs
ivanmkc Oct 4, 2025
6ba4990
Updated to use AgentTool
ivanmkc Oct 14, 2025
e9f7489
Split snippets
ivanmkc Oct 15, 2025
33c85b2
Added missing file
ivanmkc Oct 15, 2025
4d286bc
Ran linter and fixed API
ivanmkc Oct 24, 2025
280b5a1
Added Models snippets
ivanmkc Oct 4, 2025
d4f8b9c
Migrated to new API
ivanmkc Oct 9, 2025
dcc3443
Embedded imports
ivanmkc Oct 20, 2025
0a5a5c2
Ran linter
ivanmkc Oct 24, 2025
b263958
Merge pull request #7 from ivanmkc/imkc--multi-agents
ivanmkc Oct 29, 2025
0be619b
Added long running tool
ivanmkc Oct 10, 2025
8652b03
Ran linter and fixed API
ivanmkc Oct 23, 2025
a4f60f9
Switched to two-turn style
ivanmkc Oct 23, 2025
29b7628
Ran linter
ivanmkc Oct 24, 2025
5027020
Merge pull request #8 from ivanmkc/imkc--models
ivanmkc Oct 29, 2025
d7e586a
Merge pull request #11 from ivanmkc/imkc--long-running-tool
ivanmkc Oct 29, 2025
663c302
Added artifact snippets
ivanmkc Oct 8, 2025
2f15661
Use story.pdf instead of random bytes
ivanmkc Oct 9, 2025
f4359f6
Fixed issue with artifact loading
ivanmkc Oct 9, 2025
40b4834
Cleanup unneeded fixes
ivanmkc Oct 9, 2025
ed9384b
Added back inadvertently removed GCS section
ivanmkc Oct 9, 2025
9985fc8
Addressed PR comments
ivanmkc Oct 24, 2025
ee44434
Merge pull request #12 from ivanmkc/imkc--callbacks
ivanmkc Oct 29, 2025
34672d7
Ran linter
ivanmkc Oct 29, 2025
d185166
Merge pull request #10 from ivanmkc/imkc--artifacts
ivanmkc Oct 29, 2025
3f9950e
feat: Added context snippets
ivanmkc Oct 15, 2025
304c71b
Fixed callback signature
ivanmkc Oct 16, 2025
71e8a16
Fixed additional callbacks
ivanmkc Oct 16, 2025
0b3053e
Added remaining snippets
ivanmkc Oct 16, 2025
dbcaf19
Added conceptual runner example
ivanmkc Oct 16, 2025
bd7d89f
Removed duplicate code
ivanmkc Oct 16, 2025
0e83c62
Clean up tags and imports
ivanmkc Oct 16, 2025
6f2b603
Updated API
ivanmkc Oct 24, 2025
280a4b0
Twaked text
ivanmkc Oct 24, 2025
e79b595
Ran linter
ivanmkc Oct 29, 2025
7d054d4
Merge pull request #16 from ivanmkc/imkc--context
ivanmkc Oct 29, 2025
857a709
Initial TODOs
kdroste-google Oct 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/go-fmt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Go Fmt

on:
pull_request:
paths:
- '**.go'

jobs:
gofmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all tags and branches
- uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Run gofmt on changed files
run: |
# List changed Go files in the pull request.
# The `|| true` is to prevent the command from failing if no go files are found
changed_files=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} | grep '\.go$' || true)

if [ -z "$changed_files" ]; then
echo "No Go files changed in this PR."
exit 0
fi

echo "Checking formatting for the following files:"
echo "$changed_files"

# Check formatting of changed files
unformatted_files=$(gofmt -l $changed_files)

if [ -n "$unformatted_files" ]; then
echo "Unformatted Go files found:"
echo "$unformatted_files"
exit 1
else
echo "All changed Go files are formatted correctly."
fi
2 changes: 2 additions & 0 deletions docs/a2a/quickstart-consuming.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This quickstart covers the most common starting point for any developer: **"There is a remote agent, how do I let my ADK agent use it via A2A?"**. This is crucial for building complex multi-agent systems where different agents need to collaborate and interact.

<!-- TODO: Golang version -->

## Overview

This sample demonstrates the **Agent-to-Agent (A2A)** architecture in the Agent Development Kit (ADK), showcasing how multiple agents can work together to handle complex tasks. The sample implements an agent that can roll dice and check if numbers are prime.
Expand Down
3 changes: 3 additions & 0 deletions docs/a2a/quickstart-exposing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

This quickstart covers the most common starting point for any developer: **"I have an agent. How do I expose it so that other agents can use my agent via A2A?"**. This is crucial for building complex multi-agent systems where different agents need to collaborate and interact.

<!-- TODO: Golang version -->


## Overview

This sample demonstrates how you can easily expose an ADK agent so that it can be then consumed by another agent using the A2A Protocol.
Expand Down
90 changes: 90 additions & 0 deletions docs/agents/custom-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ The core of any custom agent is the method where you define its unique asynchron
* **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.
* **`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.

=== "Go"

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.

* **Signature:** `Run(ctx agent.InvocationContext) iter.Seq2[*session.Event, error]`
* **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.
* **`ctx` (InvocationContext):** The `agent.InvocationContext` provides access to the session, including state, and other crucial runtime information.
* **Session State:** You can access the session state through `ctx.Session().State()`.

**Key Capabilities within the Core Asynchronous Method:**

=== "Python"
Expand Down Expand Up @@ -123,6 +132,46 @@ The core of any custom agent is the method where you define its unique asynchron
* **Conditional:** `Flowable.defer()` to choose which `Flowable` to subscribe to based on a condition, or `filter()` if you're filtering events within a stream.
* **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`).

=== "Go"

1. **Calling Sub-Agents:** You invoke sub-agents by calling their `Run` method.

```go
// Example: Running one sub-agent and yielding its events
for event, err := range someSubAgent.Run(ctx) {
if err != nil {
// Handle or propagate the error
return
}
// Yield the event up to the caller
yield(event, nil)
}
```

2. **Managing State:** Read from and write to the session state to pass data between sub-agent calls or make decisions.
```go
// The `ctx` (`agent.InvocationContext`) is passed directly to your agent's `Run` function.
// Read data set by a previous agent
previousResult, err := ctx.Session().State().Get("some_key")
if err != nil {
// Handle cases where the key might not exist yet
}

// Make a decision based on state
if val, ok := previousResult.(string); ok && val == "some_value" {
// ... call a specific sub-agent ...
} else {
// ... call another sub-agent ...
}

// Store a result for a later step
if err := ctx.Session().State().Set("my_custom_result", "calculated_value"); err != nil {
// Handle error
}
```

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.

## Managing Sub-Agents and State

Typically, a custom agent orchestrates other agents (like `LlmAgent`, `LoopAgent`, etc.).
Expand Down Expand Up @@ -158,6 +207,14 @@ Let's illustrate the power of custom agents with an example pattern: a multi-sta
```java
--8<-- "examples/java/snippets/src/main/java/agents/StoryFlowAgentExample.java:init"
```

=== "Go"

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.

```go
--8<-- "examples/go/snippets/agents/custom-agent/storyflow_agent.go:init"
```
---

### Part 2: Defining the Custom Execution Logic { #part-2-defining-the-custom-execution-logic }
Expand Down Expand Up @@ -191,6 +248,20 @@ Let's illustrate the power of custom agents with an example pattern: a multi-sta
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.
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.

=== "Go"

The `Run` method orchestrates the sub-agents by calling their respective `Run` methods in a loop and yielding their events.

```go
--8<-- "examples/go/snippets/agents/custom-agent/storyflow_agent.go:executionlogic"
```
**Explanation of Logic:**

1. The initial `storyGenerator` runs. Its output is expected to be in the session state under the key `"current_story"`.
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.
3. The `postProcessorAgent` runs, calling `grammar_check` then `tone_check`, reading `current_story` and writing `grammar_suggestions` and `tone_check_result` to the state.
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.

---

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

=== "Go"

```go
--8<-- "examples/go/snippets/agents/custom-agent/storyflow_agent.go:llmagents"
```

---

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

=== "Go"

```go
--8<-- "examples/go/snippets/agents/custom-agent/storyflow_agent.go:story_flow_agent"
```

*(Note: The full runnable code, including imports and execution logic, can be found linked below.)*

---
Expand All @@ -251,3 +334,10 @@ Finally, you instantiate your `StoryFlowAgent` and use the `Runner` as usual.
# Full runnable code for the StoryFlowAgent example
--8<-- "examples/java/snippets/src/main/java/agents/StoryFlowAgentExample.java:full_code"
```

=== "Go"

```go
# Full runnable code for the StoryFlowAgent example
--8<-- "examples/go/snippets/agents/custom-agent/storyflow_agent.go:full_code"
```
1 change: 1 addition & 0 deletions docs/agents/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ADK provides distinct agent categories to build sophisticated applications:
## Choosing the Right Agent Type

The following table provides a high-level comparison to help distinguish between the agent types. As you explore each type in more detail in the subsequent sections, these distinctions will become clearer.
<!-- TODO: subclass is not valid in Golang -->

| Feature | LLM Agent (`LlmAgent`) | Workflow Agent | Custom Agent (`BaseAgent` subclass) |
| :------------------- | :---------------------------------- | :------------------------------------------ |:-----------------------------------------|
Expand Down
56 changes: 56 additions & 0 deletions docs/agents/llm-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ First, you need to establish what the agent *is* and what it's *for*.
.build();
```

=== "Golang"

```go
// Example: Defining the basic identity
--8<-- "examples/go/snippets/agents/llm-agents/snippets/main.go:identity"
```


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

Expand Down Expand Up @@ -132,6 +139,14 @@ tells the agent:
.build();
```

=== "Go"

```go
// Example: Adding instructions
--8<-- "examples/go/snippets/agents/llm-agents/snippets/main.go:instruction"
```

<!-- TODO: Golang version: global_instruction are not supported -->
*(Note: For instructions that apply to *all* agents in a system, consider using
`global_instruction` on the root agent, detailed further in the
[Multi-Agents](multi-agents.md) section.)*
Expand All @@ -144,6 +159,9 @@ calculations, fetch real-time data, or execute specific actions.

* **`tools` (Optional):** Provide a list of tools the agent can use. Each item in the list can be:
* A native function or method (wrapped as a `FunctionTool`). Python ADK automatically wraps the native function into a `FuntionTool` whereas, you must explicitly wrap your Java methods using `FunctionTool.create(...)`
<!-- TODO: Golang version, to be described, -->
<!-- TODO: Golang version - no class inheritance -->

* An instance of a class inheriting from `BaseTool`.
* An instance of another agent (`AgentTool`, enabling agent-to-agent delegation - see [Multi-Agents](multi-agents.md)).

Expand Down Expand Up @@ -204,6 +222,13 @@ on the conversation and its instructions.
.build();
```

=== "Go"
<!-- TODO: Golang version -->

```go
--8<-- "examples/go/snippets/agents/llm-agents/snippets/main.go:tool_example"
```

Learn more about Tools in the [Tools](../tools/index.md) section.

## Advanced Configuration & Control
Expand Down Expand Up @@ -251,6 +276,14 @@ You can adjust how the underlying LLM generates responses using `generate_conten
.build();
```

=== "Go"

```go
import "google.golang.org/genai"

--8<-- "examples/go/snippets/agents/llm-agents/snippets/main.go:gen_config"
```

### Structuring Data (`input_schema`, `output_schema`, `output_key`)

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.
Expand All @@ -262,6 +295,7 @@ For scenarios requiring structured data exchange with an `LLM Agent`, the ADK pr
* **`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.
* In Python, this might look like: `session.state[output_key] = agent_response_text`
* In Java: `session.state().put(outputKey, agentResponseText)`
* In Golang, within a callback handler: `ctx.State().Set(output_key, agentResponseText)`

=== "Python"

Expand Down Expand Up @@ -311,6 +345,14 @@ For scenarios requiring structured data exchange with an `LLM Agent`, the ADK pr
.build();
```

=== "Go"

The input and output schema is a `google.genai.types.Schema` object.

```go
--8<-- "examples/go/snippets/agents/llm-agents/snippets/main.go:schema_example"
```

### Managing Context (`include_contents`)

Control whether the agent receives the prior conversation history.
Expand Down Expand Up @@ -340,6 +382,14 @@ Control whether the agent receives the prior conversation history.
.build();
```

=== "Go"

```go
import "google.golang.org/adk/agent/llmagent"

--8<-- "examples/go/snippets/agents/llm-agents/snippets/main.go:include_contents"
```

### Planner

![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."}
Expand Down Expand Up @@ -543,6 +593,12 @@ call_agent("If it's raining in New York right now, what is the current temperatu
--8<-- "examples/java/snippets/src/main/java/agents/LlmAgentExample.java:full_code"
```

=== "Golang"

```go
--8<-- "examples/go/snippets/agents/llm-agents/main.go:full_code"
```

_(This example demonstrates the core concepts. More complex agents might incorporate schemas, context control, planning, etc.)_

## Related Concepts (Deferred Topics)
Expand Down
21 changes: 20 additions & 1 deletion docs/agents/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

!!! Note
Java ADK currently supports Gemini and Anthropic models. More model support coming soon.
<!-- TODO: Golang version -->

The Agent Development Kit (ADK) is designed for flexibility, allowing you to
integrate various Large Language Models (LLMs) into your agents. While the setup
Expand All @@ -23,6 +24,7 @@ ADK primarily uses two mechanisms for model integration:
configurations (like models accessed via LiteLLM). You instantiate a specific
wrapper class (e.g., `LiteLlm`) and pass this object as the `model` parameter
to your `LlmAgent`.
<!-- TODO: Golang version -->

The following sections guide you through using these methods based on your needs.

Expand Down Expand Up @@ -50,6 +52,9 @@ This section covers authenticating with Google's Gemini models, either through G

### Google AI Studio

<!-- TODO: Golang version: check what's applicable, GOOGLE_APPLICATION_CREDENTIALS etc -->


This is the simplest method and is recommended for getting started quickly.

* **Authentication Method:** API Key
Expand Down Expand Up @@ -183,11 +188,23 @@ For deployed applications, a service account is the standard method.
// different availability or quota limitations.
```

=== "Go"

```go
import (
"google.golang.org/adk/agent/llmagent"
"google.golang.org/adk/model/gemini"
"google.golang.org/genai"
)

--8<-- "examples/go/snippets/agents/models/models.go:gemini-example"
```

!!!warning "Secure Your Credentials"
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.

## Using Anthropic models

<!-- TODO: Golang version: comment needed -->
![java_only](https://img.shields.io/badge/Supported_in-Java-orange){ title="This feature is currently available for Java. Python support for direct Anthropic API (non-Vertex) is via LiteLLM."}

You can integrate Anthropic's Claude models directly using their API key or from a Vertex AI backend into your Java ADK applications by using the ADK's `Claude` wrapper class.
Expand Down Expand Up @@ -646,6 +663,8 @@ agent_finetuned_gemini = LlmAgent(

### Third-Party Models on Vertex AI (e.g., Anthropic Claude)

<!-- TODO: Golang version: comment needed-->

Some providers, like Anthropic, make their models available directly through
Vertex AI.

Expand Down
Loading