Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

AgentKit Coding Agent with E2B Code Interpreter

This example demonstrates how to build an AI coding agent using AgentKit and E2B Code Interpreter. The agent can execute code and help with programming tasks.

coding-agent-2.mp4

Setup

  1. Install dependencies:
npm install
  1. Create a .env file in the root of the project with the following environment variables:
E2B_API_KEY=your_e2b_api_key # Get one at https://e2b.dev/docs
ANTHROPIC_API_KEY=your_anthropic_api_key # Get one at https://console.anthropic.com/settings/keys

# Optional: Specify which Claude model to use (defaults to claude-haiku-4-5)
# All models: https://console.anthropic.com/docs/en/about-claude/models/overview
ANTHROPIC_MODEL=claude-sonnet-4-5-20250929
  1. Start the Inngest Dev Server:
npx inngest-cli@latest dev
  1. Start the program:
npm run start
  1. Open the Inngest Dev Server at http://127.0.0.1:8288/functions

  1. Trigger the Coding Agent with the following input:
{
  "data": {
    "input": "Create a Next.js TodoList demo and its associated unit tests. Save the contents into /tmp/todolist-demo/. Finally run the tests with coverage"
  }
}

  1. The agent will start executing the task and you will see the output in the Inngest Dev Server.

Features

  • Code execution using E2B Code Interpreter
  • Built with AgentKit for robust agent capabilities
  • TypeScript support
  • Hot reloading during development
  • Durable execution (retries on rate limits, etc) with Inngest
  • Context Window Management - Handles long conversations without hitting token limits
  • Smart Error Handling - Validates model names and provides helpful error messages

Project Structure

The project uses TypeScript and is set up with the following key dependencies:

  • @e2b/code-interpreter: For code execution capabilities
  • @inngest/agent-kit: For building the AI agent
  • zod: For runtime type checking
  • typescript: For static type checking

Context Window Management

This agent includes automatic output truncation to prevent large outputs from bloating the conversation context:

Automatic Output Truncation

  • Terminal commands: Output truncated to 15,000 characters
  • File reads: Individual files limited to 20,000 characters, batch reads to 50,000 characters
  • Code execution: Output truncated to 10,000 characters

Configuration

Adjust limits in src/contextManager.ts:

export const CONTEXT_CONFIG = {
  MAX_TERMINAL_OUTPUT: 15000,
  MAX_FILE_CONTENT: 20000,
  MAX_TOTAL_FILE_CONTENT: 50000,
  MAX_CODE_OUTPUT: 10000,
};