Files
google__adk-docs/docs/a2a/quickstart-exposing-go.md
Ivan Cheung 8834593806 [ADK Go] Merging all Go docs from the private repo (#885)
* docs: Add Go language quickstart

* updates based on review comments

* fix tab stops

* update based on review comments

* sync with main

* update to tested version

* Added google_search snippet

* Fix: Address Go style guide issues in google_search.go

* Migrated to new API

* Fixed tool info in md file

* Added partial check

* Added function-tools sample

* Migrated to new API

* Added partial check

* Ran linter

* feat: add go fmt check

* Run go fmt only on changed files

* Added google_search snippet

* Fix: Address Go style guide issues in google_search.go

* Migrated to new API

* Added partial check

* Added function-tools sample

* Migrated to new API

* Added partial check

* Ran linter

* feat: add go fmt check

* Run go fmt only on changed files

* Feat: Add Golang example for LLM agents

* Added schema agent

* Added session support

* Migrated to new API

* Added back OutputKey

* Added missing snippets

* Moved snipped to its own package

* Minor cleanup

* Reverted llm-agents.md

* Added back correct changes to llm-agents.md

* Updated to newest API

* Ran linter

* WIP

* WIP: Added the rest of the agents

* Added sequential agent

* Migrated agents to new API

* Fixed snippet tags

* Updated parallel and sequential with OutputKey

* Updated loop agent

* Cleanup

* Fixed and ran linter

* Removed comment

* Ran linter

* Added custom agent snippets

* Migrated to new API

* Fixed incorrect info about channels since run returns an Iterator, not Channel

* Cleanup and renaming

* Ran linter

* Fixed md

* Added multi-agent docs

* Updated to use AgentTool

* Split snippets

* Added missing file

* Ran linter and fixed API

* Added Models snippets

* Migrated to new API

* Embedded imports

* Ran linter

* Added long running tool

* Ran linter and fixed API

* Switched to two-turn style

* Ran linter

* Added callback snippets

* Added back imports

* Added types of callbacks snippets

* feat(go): align callback snippets with other languages

* Ran linter and updated API

* Added tool callbacks

* Added artifact snippets

* Use story.pdf instead of random bytes

* Fixed issue with artifact loading

* Cleanup unneeded fixes

* Added back inadvertently removed GCS section

* Addressed PR comments

* Ran linter

* feat: Added context snippets

* Fixed callback signature

* Fixed additional callbacks

* Added remaining snippets

* Added conceptual runner example

* Removed duplicate code

* Clean up tags and imports

* Updated API

* Twaked text

* Ran linter

* Fixed broken API issues

* Updated to latest Go ADK API

* Added func param info

* Interleaved Py and Go

* Revert mistakes

* Removed extra newline

* Added example cloud run code and update md with Go (#41)

* Added example cloud run code and update md with Go

* Added a2a_agent_url and fixed future tense

* Moved Go before Java

---------

Co-authored-by: ivanmkc <ivanmkc@google.com>

* adding go snippets to runconfig docs

* realigning runconfig go examples with current state of adk-go.

* adding language support tags to individual runtime config fields

* removing unsupported supportcfc go examples

* removing unsupported streamingmode.bidi go snippets

* Added AgentTool examples (#31)

* Added AgentTool example

* Ran formatter

---------

Co-authored-by: ivanmkc <ivanmkc@google.com>

* adding initial go sessions.sessions snippets

* updating go session docs + session examples

* update go session snippets

* updating DatabaseSessionService language support tag

* cleaning up go vertex ai comments

* removing go.mod for session_management_example

* docs: add language support tags for Go

* initial go runtime sample updates

* fixing runtime go snippet formatting

* formatting updates to runtime go snippets

* updating runtime go examples to streamline to newer go features

* adding go snippets for events

* updating go snippets for events

* adding artifactdelta snippet for go

* minor java fixes, cleaning up go event.content

* Custom tools: Merging again  (#44)

* Added missing custom-tools snippets

* Split user_preference runner code

* Split more files

* Tweaks

* Split session into 1 and 2 and added artifact saving

* Fixed conflict

---------

Co-authored-by: ivanmkc <ivanmkc@google.com>

* Fixed tab issue with cloud-run md (#45)

Co-authored-by: ivanmkc <ivanmkc@google.com>

* adding initial go snippets for memory services

* updating go memory sample, adding python formatting in docs to clarify current support.

* removing go replace for memory example

* removing go.sum from memory_example

* fixing go formatting for memory example

* fixing go memory snippets to streamline examples in docs

* removing unnecessary go.mod for memory_example.go and snippet cleanup

* adding go session state snippets."

* adding additional go state examples for state injection

* fixing go formatting

* fixing language ordering on session/state.md; removing unnecessary go.mod files

* reworking error functions in go session state samples

* fixing go formatting on session state samples

* initial go snippets for safety tools

* fixing go snippet formatting in safety/index.md

* temp storing safety example

* cleaning up go snippets in safety docs; deferring safety go full example

* cleaning up go safety snippets

* Added link to Go API docs (#47)

Co-authored-by: ivanmkc <ivanmkc@google.com>

* Added a2a_basic sample (#46)

* Added a2a_basic sample

* Removed dummy LLMs

* Added md

Fix inaccuracies in md

Ran formatter

* Cleaned up index

---------

Co-authored-by: ivanmkc <ivanmkc@google.com>

* Reverted to proper ToC and added missing links (#48)

Co-authored-by: ivanmkc <ivanmkc@google.com>

* Added missing get-started/go.md (#50)

Co-authored-by: ivanmkc <ivanmkc@google.com>

* Added missing JSON tags for Go structs (#51)

* Added json tags

* Added jsonschema and json tags

---------

Co-authored-by: ivanmkc <ivanmkc@google.com>

* Renamed Golang to Go (#52)

Co-authored-by: ivanmkc <ivanmkc@google.com>

---------

Co-authored-by: Joe Fernandez <joefernandez@google.com>
Co-authored-by: ivanmkc <ivanmkc@google.com>
Co-authored-by: Toni Klopfenstein <tklopfenstein@google.com>
2025-11-06 14:13:13 -05:00

5.1 KiB

Quickstart: Exposing a remote agent via A2A

Supported in ADKGoExperimental

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.

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.

In Go, you expose an agent by using the A2A launcher, which dynamically generates an agent card for you.

┌─────────────────┐                             ┌───────────────────────────────┐
│   Root Agent    │       A2A Protocol          │ A2A-Exposed Check Prime Agent │
│                 │────────────────────────────▶│      (localhost: 8001)        │
└─────────────────┘                             └───────────────────────────────┘

The sample consists of :

  • Remote Prime Agent (remote_a2a/check_prime_agent/main.go): This is the agent that you want to expose so that other agents can use it via A2A. It is an agent that handles prime number checking. It becomes exposed using the A2A launcher.
  • Root Agent (main.go): A simple agent that is just calling the remote prime agent.

Exposing the Remote Agent with the A2A Launcher

You can take an existing agent built using the Go ADK and make it A2A-compatible by using the A2A launcher.

1. Getting the Sample Code

First, make sure you have Go installed and your environment is set up.

You can clone and navigate to the a2a_basic sample here:

cd examples/go/a2a_basic

As you'll see, the folder structure is as follows:

a2a_basic/
├── remote_a2a/
│   └── check_prime_agent/
│       └── main.go    # Remote Prime Agent
├── go.mod
├── go.sum
└── main.go            # Root agent

Root Agent (a2a_basic/main.go)

  • newRootAgent: A local agent that connects to the remote A2A service.

Remote Prime Agent (a2a_basic/remote_a2a/check_prime_agent/main.go)

  • checkPrimeTool: Function for prime number checking.
  • main: The main function that creates the agent and starts the A2A server.

2. Start the Remote A2A Agent server

You can now start the remote agent server, which will host the check_prime_agent:

# Start the remote agent
go run remote_a2a/check_prime_agent/main.go

Once executed, you should see something like:

2025/11/06 11:00:19 Starting A2A prime checker server on port 8001
2025/11/06 11:00:19 Starting the web server: &{port:8001}
2025/11/06 11:00:19 
2025/11/06 11:00:19 Web servers starts on http://localhost:8001
2025/11/06 11:00:19        a2a:  you can access A2A using jsonrpc protocol: http://localhost:8001

3. Check that your remote agent is running

You can check that your agent is up and running by visiting the agent card that was auto-generated by the A2A launcher:

http://localhost:8001/.well-known/agent-card.json

You should see the contents of the agent card.

4. Run the Main (Consuming) Agent

Now that your remote agent is running, you can run the main agent.

# In a separate terminal, run the main agent
go run main.go

How it works

The remote agent is exposed using the A2A launcher in the main function. The launcher takes care of starting the server and generating the agent card.

--8<-- "examples/go/a2a_basic/remote_a2a/check_prime_agent/main.go:a2a-launcher"

Example Interactions

Once both services are running, you can interact with the root agent to see how it calls the remote agent via A2A:

Prime Number Checking:

This interaction uses a remote agent via A2A, the Prime Agent:

User: roll a die and check if it's a prime
Bot: Okay, I will first roll a die and then check if the result is a prime number.

Bot calls tool: transfer_to_agent with args: map[agent_name:roll_agent]
Bot calls tool: roll_die with args: map[sides:6]
Bot calls tool: transfer_to_agent with args: map[agent_name:prime_agent]
Bot calls tool: prime_checking with args: map[nums:[3]]
Bot: 3 is a prime number.
...

Next Steps

Now that you have created an agent that's exposing a remote agent via an A2A server, the next step is to learn how to consume it from another agent.