# Quickstart: Exposing a remote agent via A2A

<div class="language-support-tag">
  <span class="lst-supported">Supported in ADK</span><span class="lst-go">Go</span><span class="lst-preview">Experimental</span>
</div>

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.

```text
┌─────────────────┐                             ┌───────────────────────────────┐
│   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 { #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](https://github.com/google/adk-docs/tree/main/examples/go/a2a_basic) here:

```bash
cd examples/go/a2a_basic
```

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

```text
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 { #start-the-remote-a2a-agent-server }

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

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

Once executed, you should see something like:

```shell
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 { #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](http://localhost:8001/.well-known/agent-card.json)

You should see the contents of the agent card.

### 4. Run the Main (Consuming) Agent { #run-the-main-consuming-agent }

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

```bash
# 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.

```go title="remote_a2a/check_prime_agent/main.go"
--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:

```text
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.

- [**A2A Quickstart (Consuming)**](./quickstart-consuming-go.md): Learn how your agent can use other agents using the A2A Protocol.
