Skip to main content
This guide demonstrates how to build an intelligent code agent that can analyze and manipulate codebases.
The agent has access to powerful code viewing and manipulation tools powered by Codegen, including:
  • ViewFileTool: View contents and metadata of files
  • SemanticEditTool: Make intelligent edits to files
  • RevealSymbolTool: Analyze symbol dependencies and usages
  • MoveSymbolTool: Move symbols between files with import handling
  • ReplacementEditTool: Make regex-based replacement editing on files
  • ListDirectoryTool: List directory contents
  • SearchTool: Search for files and symbols
  • CreateFileTool: Create new files
  • DeleteFileTool: Delete files
  • RenameFileTool: Rename files
  • EditFileTool: Edit files
View the full code for the default tools and agent implementation in our examples repository

Basic Usage

The following example shows how to create and run a CodeAgent:
Your ANTHROPIC_API_KEY must be set in your env.
The default implementation uses anthropic/claude-3-5-sonnet-latest for the model but this can be changed through the model_provider and model_name arguments.
If using a non-default model provider, make sure to set the appropriate API key (e.g., OPENAI_API_KEY for OpenAI models) in your env.

Available Tools

The agent comes with a comprehensive set of tools for code analysis and manipulation. Here are some key tools:
View the full set of tools on Github
Each tool provides specific capabilities:

Extensions

GitHub Integration

The agent includes tools for GitHub operations like PR management. Set up GitHub access with:
Import the GitHub tools:
These tools enable:
  • Creating pull requests
  • Viewing PR contents and diffs
  • Adding general PR comments
  • Adding inline review comments
View all Github tools on Github

Linear Integration

The agent can interact with Linear for issue tracking and project management. To use Linear tools, set the following environment variables:
Import and use the Linear tools:
These tools allow the agent to:
  • Create and search issues
  • Get issue details and comments
  • Add comments to issues
  • View team information
View all Linear tools on Github

Adding Custom Tools

You can extend the agent with custom tools: