---
title: "Multi-Tool Reasoning"
description: "Learn how to build coding assistants that use multiple tools across turns with the Autohand Code Agent SDK. Available in TypeScript, Python, and Java."
slug: "agent-sdk/tutorials/200-multi-tool-reasoning"
sidebar:
  label: "Multi-tool reasoning"
seo:
  title: "Multi-Tool Reasoning | Autohand Code"
  description: "Learn how to build coding assistants that use multiple tools across turns with the Autohand Code Agent SDK."
---

In this tutorial, you'll build a coding assistant that uses multiple tools across different turns to understand code, run tests, and report a summary. This demonstrates the ReAct loop with multi-tool turns.

:::note
**Prerequisites:**

- Completed [Code Reviewer Agent](/agent-sdk/tutorials/100-code-reviewer-agent)
- Node.js 16+ (for TypeScript), Python 3.10+ (for Python), or Java 11+ (for Java)
- SDK installed for your chosen language
- API key from your LLM provider (set as `AUTOHAND_API_KEY`)
:::

## What You'll Build

A code analyst coding assistant that:

- Uses READ\_FILE to examine source code
- Uses BASH to run commands and tests
- Uses GLOB to find files
- Coordinates multiple tools across turns
- Provides a comprehensive codebase summary

## Step 1: Direct Tool Execution

Before building the agent, let's understand direct tool execution in your chosen language:

```ts title="TypeScript"
import { ReadFileTool, BashTool } from "@autohandai/agent-sdk";

const readTool = new ReadFileTool();
const bashTool = new BashTool();

// Read a file
const readResult = await readTool.execute({
  file_path: "math-utils.ts",
  work_dir: "./my-project",
});

console.log(readResult.data || readResult.error);

// Run a command
const testResult = await bashTool.execute({
  command: "npm test",
  working_directory: "./my-project",
});

console.log(testResult.data || testResult.error);
```

```python title="Python"
from autohand_agent_sdk.tools import ReadFileTool, BashTool

read_tool = ReadFileTool()
bash_tool = BashTool()

# Read a file
read_result = await read_tool.execute(
    file_path="math-utils.py",
    work_dir="./my-project"
)

print(read_result.data or read_result.error)

# Run a command
test_result = await bash_tool.execute(
    command="pytest",
    working_directory="./my-project"
)

print(test_result.data or test_result.error)
```

```java title="Java"
import ai.autohand.agent.sdk.tools.*;

ReadFileTool readTool = new ReadFileTool();
BashTool bashTool = new BashTool();

// Read a file
ToolResult readResult = readTool.execute(
    new ReadFileInput("math-utils.java", "./my-project")
);

System.out.println(readResult.getData() != null ? readResult.getData() : readResult.getError());

// Run a command
ToolResult testResult = bashTool.execute(
    new BashInput("mvn test", "./my-project")
);

System.out.println(testResult.getData() != null ? testResult.getData() : testResult.getError());
```

```go title="Go"
package main

import (
    "fmt"
    "github.com/autohandai/agentsdk-go/pkg/autohand"
)

readTool := autohand.NewReadFileTool()
bashTool := autohand.NewBashTool()

// Read a file
readResult, err := readTool.Execute(map[string]interface{}{
    "file_path": "math-utils.go",
    "work_dir":  "./my-project",
})
if err != nil {
    log.Fatal(err)
}
fmt.Println(readResult["data"])

// Run a command
testResult, err := bashTool.Execute(map[string]interface{}{
    "command":            "go test",
    "working_directory": "./my-project",
})
if err != nil {
    log.Fatal(err)
}
fmt.Println(testResult["data"])
```

```swift title="Swift"
import AutohandAgentSDK

let readTool = ReadFileTool()
let bashTool = BashTool()

// Read a file
let readResult = try readTool.execute(
    file_path: "math-utils.swift",
    work_dir: "./my-project"
)

print(readResult.data ?? readResult.error ?? "")

// Run a command
let testResult = try bashTool.execute(
    command: "swift test",
    working_directory: "./my-project"
)

print(testResult.data ?? testResult.error ?? "")
```

```rust title="Rust"
use autohand_agents::tools::{ReadFileTool, BashTool};

let read_tool = ReadFileTool::new();
let bash_tool = BashTool::default();

// Read a file
let read_result = read_tool.execute(
    serde_json::json!({
        "file_path": "math-utils.rs",
        "work_dir": "./my-project"
    })
).await?;
println!("{}", read_result);

// Run a command
let test_result = bash_tool.execute(
    serde_json::json!({
        "command": "cargo test",
        "working_directory": "./my-project"
    })
).await?;
println!("{}", test_result);
```

## Step 2: Create the Multi-Tool Agent

Now create an agent that uses multiple tools across turns in your chosen language:

```ts title="TypeScript"
import { Agent, Runner } from "@autohandai/agent-sdk";
import { OpenRouterProvider } from "@autohandai/agent-sdk";

const agent = new Agent(
  "code-analyst",
  "You are a code analyst agent. Your job is to read source files, understand the code, run tests, and report a summary. Use read_file to examine code and bash to run commands. After reading files, run the tests and report whether they pass.",
  ["read_file","bash", "glob"],
  6
);

agent.setProvider(
  new OpenRouterProvider(
    process.env.AUTOHAND_API_KEY!,
    "z-ai/glm-5.2"
  )
);
```

```python title="Python"
from autohand_agent_sdk import Agent, Runner, OpenRouterProvider

agent = Agent(
    name="code-analyst",
    instructions="You are a code analyst agent. Your job is to read source files, understand the code, run tests, and report a summary. Use read_file to examine code and bash to run commands. After reading files, run the tests and report whether they pass.",
    tools=["read_file", "bash", "glob"],
    max_turns=6
)

agent.set_provider(OpenRouterProvider(
    api_key=os.getenv("AUTOHAND_API_KEY"),
    model="z-ai/glm-5.2"
))
```

```java title="Java"
import ai.autohand.agent.sdk.*;
import ai.autohand.agent.sdk.providers.*;

Agent agent = new Agent(
    "code-analyst",
    "You are a code analyst agent. Your job is to read source files, understand the code, run tests, and report a summary. Use read_file to examine code and bash to run commands. After reading files, run the tests and report whether they pass.",
    DefaultToolRegistry.getTools("read_file", "bash", "glob"),
    6
);

agent.setProvider(new OpenRouterProvider(
    System.getenv("AUTOHAND_API_KEY"),
    "z-ai/glm-5.2"
));
```

```go title="Go"
package main

import (
    "os"
    "github.com/autohandai/agentsdk-go/pkg/autohand"
)

agent := autohand.Agent{
    Name:         "code-analyst",
    Instructions: "You are a code analyst agent. Your job is to read source files, understand the code, run tests, and report a summary. Use read_file to examine code and bash to run commands. After reading files, run the tests and report whether they pass.",
    Tools:        []autohand.Tool{autohand.ReadFile, autohand.Bash, autohand.Glob},
    MaxTurns:     6,
}

provider := autohand.NewOpenRouterProvider(
    os.Getenv("AUTOHAND_API_KEY"),
    "z-ai/glm-5.2",
)
agent.Provider = &provider
```

```swift title="Swift"
import AutohandAgentSDK

let agent = Agent(
    name: "code-analyst",
    instructions: "You are a code analyst agent. Your job is to read source files, understand the code, run tests, and report a summary. Use read_file to examine code and bash to run commands. After reading files, run the tests and report whether they pass.",
    tools: [.readFile, .bash, .glob],
    maxTurns: 6
)

agent.provider = try OpenRouterProvider(
    apiKey: ProcessInfo.processInfo.environment["AUTOHAND_API_KEY"] ?? "your-api-key",
    model: "z-ai/glm-5.2"
)
```

```rust title="Rust"
use autohand_agents::{AgentBuilder, Runner};
use autohand_agents::providers::ProviderFactory;
use autohand_agents::config::ConfigLoader;

let mut agent = AgentBuilder::new()
    .name("code-analyst")
    .instructions("You are a code analyst agent. Your job is to read source files, understand the code, run tests, and report a summary. Use read_file to examine code and bash to run commands. After reading files, run the tests and report whether they pass.")
    .tools(vec![Tool::ReadFile, Tool::Bash, Tool::Glob])
    .max_turns(6)
    .build()?;

let config = ConfigLoader::from_env()?;
let provider = ProviderFactory::from_env(&config.provider)?;
agent.set_provider(provider);
```

## Step 3: Run the Agent

Run the agent with a complex prompt that requires multiple tools in your chosen language:

```ts title="TypeScript"
const result = await Runner.run(
  agent,
  "First, glob for all TypeScript files in this directory. Then read each TypeScript file. Finally, run "npm test" and report the test results. Summarize the codebase."
);

console.log(result.finalOutput);
```

```python title="Python"
result = Runner.run(
    agent,
    "First, glob for all Python files in this directory. Then read each Python file. Finally, run "pytest" and report the test results. Summarize the codebase."
)

print(result.final_output)
```

```java title="Java"
String result = Runner.run(
    agent,
    "First, glob for all Java files in this directory. Then read each Java file. Finally, run "mvn test" and report the test results. Summarize the codebase."
);

System.out.println(result);
```

```go title="Go"
result, err := autohand.Runner.Run(&agent, "First, glob for all Go files in this directory. Then read each Go file. Finally, run "go test" and report the test results. Summarize the codebase.")
if err != nil {
    log.Fatal(err)
}
fmt.Println(result)
```

```swift title="Swift"
let result = try Runner.run(
    agent,
    "First, glob for all Swift files in this directory. Then read each Swift file. Finally, run "swift test" and report the test results. Summarize the codebase."
)

print(result)
```

```rust title="Rust"
let result = Runner::run(&agent, "First, glob for all Rust files in this directory. Then read each Rust file. Finally, run "cargo test" and report the test results. Summarize the codebase.").await?;
println!("{}", result.final_output);
```

## Key Concepts

**Tool Coordination**

The coding assistant automatically coordinates multiple tools across turns to complete complex tasks.

**ReAct Loop**

The ReAct (Reason + Act) loop allows the coding assistant to reason about what to do, take action, and repeat.

**State Management**

The coding assistant maintains context across turns, remembering what it has done and what it needs to do next.

**Turn Limits**

Setting `maxTurns` prevents infinite loops and controls resource usage.

## Complete Example

Here's the complete example with a sample project:

```ts
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import { Agent, Runner } from "@autohandai/agent-sdk";

async function main() {
  const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), "multi-tool-example-"));
  const oldCwd = process.cwd();
  try {
    fs.writeFileSync(path.join(tmpdir, "math-utils.ts"), "export const add = (a: number, b: number) => a + b;\n");
    const agent = new Agent("code-analyst", "Read files, run tools, and summarize findings.", ["read_file", "bash", "glob"], 6);
    process.chdir(tmpdir);
    const result = await Runner.run(agent, "Glob for TypeScript files, read them, and summarize the project.");
    console.log(result.finalOutput);
  } finally {
    process.chdir(oldCwd);
    fs.rmSync(tmpdir, { recursive: true, force: true });
  }
}

main();
```

## Next Steps

**[📁 View the Example](https://github.com/autohandai/agent-sdk-typescript/tree/main/examples/10-multi-tool-reasoning)**

See the complete example in the TypeScript SDK repository.

**[🔧 Sequential Agent Pipeline](https://github.com/autohandai/agent-sdk-typescript/tree/main/examples/22-sequential-agent-pipeline)**

Learn how to chain multiple agents together for complex workflows.

**[📚 Code Modernization](/agent-sdk/tutorials/400-code-modernization)**

Advance to code modernization and real-world applications.
