> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agenticenv.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Run Async

> Run an agent asynchronously with RunAsync and handle tool approvals via a result channel

Starts a run in the background and receives the final result on a channel. Uses `WithApprovalHandler` so tool calls can be approved interactively on stdin — same semantics as `Run`.

Source: [`examples/agent_with_run_async/`](https://github.com/agenticenv/agent-sdk-go/tree/main/examples/agent_with_run_async)

## What it demonstrates

* `RunAsync` returning `<-chan AgentRunAsyncResult`
* `WithApprovalHandler` for tool approval during async runs
* Integrating agents into non-blocking application loops

## Run

From `examples/`:

```bash theme={null}
go run ./agent_with_run_async "What is 15 + 27?"
```

When the calculator tool is invoked, type `y` or `n` at the approval prompt.

## Key code

```go theme={null}
a, err := agent.NewAgent(
    agent.WithLLMClient(llmClient),
    agent.WithToolRegistry(reg),
    agent.WithApprovalHandler(approvalHandler),
)

resultCh, err := a.RunAsync(ctx, prompt, nil)
res := <-resultCh
if res.Error != nil {
    log.Fatal(res.Error)
}
fmt.Println(res.Result.Content)
```

The approval handler receives `*agent.ApprovalRequest` and calls `req.Respond(agent.ApprovalStatusApproved)` or `Rejected`. See [Approvals](/features/approvals) for stream-based approval with `Stream`.

## Expected output

```
Tool call: calculator({"expression":"15+27"})
Approve? [y/n]: y
15 + 27 = 42
```

Typing `n` rejects the tool call and the agent replies without that result.

## Learn more

<CardGroup cols={2}>
  <Card title="Approvals" icon="shield-check" href="/features/approvals">
    Policies, handlers, and stream events
  </Card>

  <Card title="Configuration" icon="sliders" href="/getting-started/configuration">
    Run, RunAsync, and Stream
  </Card>
</CardGroup>
