Skip to content
Esc
↑↓navigate↵open⌘Jpreview
Start
On this page

Multi-Tool Reasoning

Learn how to build coding assistants that use multiple tools across turns with the Autohand Code Agent SDK. Available in TypeScript, Python, and Java.

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.

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:

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);
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)
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());
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"])
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 ?? "")
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:

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"
  )
);
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"
))
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"
));
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
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"
)
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:

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);
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)
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);
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)
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)
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:

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

Last updated on

Was this helpful?

Send Feedback

Help us improve this documentation page. Your feedback is valuable.

We'll only contact you if we need clarification