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

Build a Code Reviewer Agent

Learn how to create a coding assistant that reads and analyzes your codebase with the Autohand Code Agent SDK. Available in TypeScript, Python, and Java.

In this tutorial, you’ll build a code reviewer coding assistant that can read files, analyze code, and provide feedback. This is a great starting point for learning the Agent SDK basics.

What You’ll Build

A code reviewer coding assistant that:

  • Reads source files from your codebase
  • Analyzes code for bugs and improvement opportunities
  • Provides specific feedback with file and line numbers
  • Uses only the tools it needs (READ_FILE, GLOB, SEARCH_IN_FILES)

Step 1: Set Up Your Project

Create a new file for your agent in your chosen language:

import { Agent, Runner } from "@autohandai/agent-sdk";
import { OpenRouterProvider } from "@autohandai/agent-sdk";

// Create a code reviewer agent
const agent = new Agent(
  "Code Reviewer",
  "You are a senior TypeScript engineer. Read code files, identify bugs, and suggest improvements. Be specific about file and line numbers.",
  ["read_file", "glob", "search_in_files"],
  15
);

// Set the provider
agent.setProvider(
  new OpenRouterProvider(
    process.env.AUTOHAND_API_KEY || "your-api-key",
    "z-ai/glm-5.2"
  )
);
from autohand_agent_sdk import Agent, Runner, OpenRouterProvider

# Create a code reviewer agent
agent = Agent(
    name="Code Reviewer",
    instructions="You are a senior Python engineer. Read code files, identify bugs, and suggest improvements. Be specific about file and line numbers.",
    tools=["read_file", "glob", "search_in_files"],
    max_turns=15
)

# Set the provider
agent.set_provider(OpenRouterProvider(
    api_key=os.getenv("AUTOHAND_API_KEY", "your-api-key"),
    model="z-ai/glm-5.2"
))
import ai.autohand.agent.sdk.*;
import ai.autohand.agent.sdk.providers.*;

// Create a code reviewer agent
Agent agent = new Agent(
    "Code Reviewer",
    "You are a senior Java engineer. Read code files, identify bugs, and suggest improvements. Be specific about file and line numbers.",
    DefaultToolRegistry.getTools("read_file", "glob", "search_in_files"),
    15
);

// Set the provider
agent.setProvider(new OpenRouterProvider(
    System.getenv("AUTOHAND_API_KEY", "your-api-key"),
    "z-ai/glm-5.2"
));
package main

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

// Create a code reviewer agent
agent := autohand.Agent{
    Name:         "Code Reviewer",
    Instructions: "You are a senior Go engineer. Read code files, identify bugs, and suggest improvements. Be specific about file and line numbers.",
    Tools:        []autohand.Tool{autohand.ReadFile, autohand.Glob, autohand.SearchInFiles},
    MaxTurns:     15,
}

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

// Create a code reviewer agent
let agent = Agent(
    name: "Code Reviewer",
    instructions: "You are a senior Swift engineer. Read code files, identify bugs, and suggest improvements. Be specific about file and line numbers.",
    tools: [.readFile, .glob, .searchInFiles],
    maxTurns: 15
)

// Set the provider
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;

// Create a code reviewer agent
let mut agent = AgentBuilder::new()
    .name("Code Reviewer")
    .instructions("You are a senior Rust engineer. Read code files, identify bugs, and suggest improvements. Be specific about file and line numbers.")
    .tools(vec![Tool::ReadFile, Tool::Glob, Tool::SearchInFiles])
    .max_turns(15)
    .build()?;

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

Step 2: Run the Agent

Now run the agent to analyze your codebase:

const result = await Runner.run(
  agent,
  "What TypeScript files are in the current directory? Read each one and report any issues."
);

console.log(result.finalOutput);
result = Runner.run(
    agent,
    "What Python files are in the current directory? Read each one and report any issues."
)

print(result.final_output)
String result = Runner.run(
    agent,
    "What Java files are in the current directory? Read each one and report any issues."
);

System.out.println(result);
result, err := Runner.Run(&agent, "What Go files are in the current directory? Read each one and report any issues.")
if err != nil {
    log.Fatal(err)
}
fmt.Println(result)
let result = try Runner.run(
    agent,
    "What Swift files are in the current directory? Read each one and report any issues."
)

print(result)
let result = Runner::run(&agent, "What Rust files are in the current directory? Read each one and report any issues.").await?;
println!("{}", result.final_output);

Key Concepts

Agent Configuration

The Agent class takes a name, instructions, tools, and max turns configuration.

Tool Selection

We only give the coding assistant the tools it needs: read_file, glob, and search_in_files.

Provider Setup

The OpenRouterProvider connects your coding assistant to an LLM provider.

Running the Coding Assistant

Runner.run() executes the coding assistant with a prompt and returns the result.

Complete Example

Use this as the full runnable shape for the language you chose:

import { Agent, Runner, SDKError } from "@autohandai/agent-sdk";
import { OpenRouterProvider } from "@autohandai/agent-sdk";

async function main(): Promise<void> {
  try {
    const agent = new Agent(
      "Code Reviewer",
      "You are a senior TypeScript engineer. Read code files, identify bugs, and suggest improvements. Be specific about file and line numbers.",
      ["read_file", "glob", "search_in_files"],
      15
    );

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

    const result = await Runner.run(
      agent,
      "What TypeScript files are in the current directory? Read each one and report any issues."
    );

    console.log(result.finalOutput);
  } catch (error) {
    if (error instanceof SDKError) {
      console.error("SDK Error: " + error.message);
    } else {
      console.error("Error: " + (error instanceof Error ? error.message : String(error)));
    }
    throw error;
  }
}

main();
import os
from autohand_agent_sdk import Agent, Runner, OpenRouterProvider, SDKError

def main():
    try:
        agent = Agent(
            name="Code Reviewer",
            instructions="You are a senior Python engineer. Read code files, identify bugs, and suggest improvements. Be specific about file and line numbers.",
            tools=["read_file", "glob", "search_in_files"],
            max_turns=15,
        )

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

        result = Runner.run(
            agent,
            "What Python files are in the current directory? Read each one and report any issues.",
        )
        print(result.final_output)
    except SDKError as error:
        print("SDK Error: " + str(error))
        raise

main()
import ai.autohand.agent.sdk.*;
import ai.autohand.agent.sdk.providers.*;

public class Main {
    public static void main(String[] args) {
        try {
            Agent agent = new Agent(
                "Code Reviewer",
                "You are a senior Java engineer. Read code files, identify bugs, and suggest improvements. Be specific about file and line numbers.",
                DefaultToolRegistry.getTools("read_file", "glob", "search_in_files"),
                15
            );

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

            String result = Runner.run(
                agent,
                "What Java files are in the current directory? Read each one and report any issues."
            );

            System.out.println(result);
        } catch (SDKError error) {
            System.err.println("SDK Error: " + error.getMessage());
            throw error;
        }
    }
}
package main

import (
    "fmt"
    "log"
    "os"

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

func main() {
    agent := autohand.Agent{
        Name:         "Code Reviewer",
        Instructions: "You are a senior Go engineer. Read code files, identify bugs, and suggest improvements. Be specific about file and line numbers.",
        Tools:        []autohand.Tool{autohand.ReadFile, autohand.Glob, autohand.SearchInFiles},
        MaxTurns:     15,
    }

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

    result, err := autohand.Runner.Run(&agent, "What Go files are in the current directory? Read each one and report any issues.")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(result)
}
import AutohandAgentSDK

func main() {
    do {
        let agent = Agent(
            name: "Code Reviewer",
            instructions: "You are a senior Swift engineer. Read code files, identify bugs, and suggest improvements. Be specific about file and line numbers.",
            tools: [.readFile, .glob, .searchInFiles],
            maxTurns: 15
        )

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

        let result = try Runner.run(
            agent,
            "What Swift files are in the current directory? Read each one and report any issues."
        )

        print(result)
    } catch {
        print("Error: \(error)")
    }
}
use autohand_agents::{AgentBuilder, Runner};
use autohand_agents::config::ConfigLoader;
use autohand_agents::providers::ProviderFactory;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut agent = AgentBuilder::new()
        .name("Code Reviewer")
        .instructions("You are a senior Rust engineer. Read code files, identify bugs, and suggest improvements. Be specific about file and line numbers.")
        .tools(vec![Tool::ReadFile, Tool::Glob, Tool::SearchInFiles])
        .max_turns(15)
        .build()?;

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

    let result = Runner::run(&agent, "What Rust files are in the current directory? Read each one and report any issues.").await?;
    println!("{}", result.final_output);
    Ok(())
}

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