Skip to content
/

Trae Agent

trae-agent · bytedance/trae-agent · ★ 12k · last commit 2026-02-05

Primitive shape 4 total
Commands 4
00

Summary

Trae Agent — Summary

Trae Agent is ByteDance's open-source, research-oriented CLI coding agent (MIT license, 11,591 stars) designed for transparent, modular software engineering automation. Its primary differentiator is explicit research-friendliness: the architecture is intentionally legible so researchers can perform ablation studies, modify components, and publish academic work. It ships as trae-cli (Python), supports 7+ LLM providers (OpenAI, Anthropic, Google Gemini, Doubao, Azure, OpenRouter, Ollama), has a "Lakeview" summarization feature for step-level concise output, and supports Docker container execution for isolation.

The tool operates in a one-shot or interactive mode against a working directory, using tools: bash, str_replace_based_edit_tool, sequentialthinking, json_edit_tool, task_done. It records full trajectory JSON logs for analysis. Optionally integrates with any MCP server via YAML config.

Closest seed: taskmaster-ai — both are Python/CLI tools with multi-provider LLM support, trajectory logging, and a research/enterprise orientation. Trae Agent differs by being purely a CLI agent (no task management graph), by emphasizing Docker isolation, by having trajectory recording as a first-class feature for academic research, and by integrating sequential thinking as a named tool rather than a prompt instruction.

01

Overview

Trae Agent — Overview

Origin

Created by ByteDance and published in 2025. Has an accompanying arXiv technical report (arXiv:2507.23370). The "Trae" name connects to ByteDance's Trae IDE (a VSCode fork). Actively maintained with 11,591 stars, 1,271 forks.

Philosophy

From README: "Trae Agent offers a transparent, modular architecture that researchers and developers can easily modify, extend, and analyze, making it an ideal platform for studying AI agent architectures, conducting ablation studies, and developing novel agent capabilities. This research-friendly design enables the academic and open-source communities to contribute to and build upon the foundational agent framework."

Unlike production tools that hide complexity, Trae Agent intentionally exposes its internals. The --trajectory-file flag saves every action to JSON for post-analysis. The sequentialthinking tool makes reasoning visible as a named tool call.

Key Design Principles

  1. Research-first: Designed for ablation studies and academic contribution
  2. Modular: Each tool is a separate class; providers are swappable via config
  3. Multi-provider: Not locked to one LLM — explicit support for 7+ providers
  4. Transparent: Lakeview provides concise step summaries; trajectory JSON captures everything
  5. Reproducible: YAML/JSON config enables reproducible experiments

Lakeview Feature

"Provides short and concise summarisation for agent steps" — each agent step's output is distilled into a short summary visible in the terminal, preventing wall-of-text noise.

Connection to Trae IDE

ByteDance also develops Trae IDE (a VSCode fork). Trae Agent is the standalone CLI counterpart — independent of the IDE but sharing the brand.

02

Architecture

Trae Agent — Architecture

Distribution

  • Type: Python package (pip/uv installable)
  • CLI binary: trae-cli (entry point via pyproject.toml)
  • Stars: 11,591 | License: MIT

Install

git clone https://github.com/bytedance/trae-agent.git
cd trae-agent
uv sync --all-extras
source .venv/bin/activate
trae-cli run "Fix the bug in main.py"

Config Files

  • trae_config.yaml (recommended, gitignored) — agents, model_providers, models, mcp_servers
  • trae_config.json (legacy JSON format)
  • .env — API keys via environment variables

YAML Config Structure

agents:
  trae_agent:
    enable_lakeview: true
    model: trae_agent_model
    max_steps: 200
    tools: [bash, str_replace_based_edit_tool, sequentialthinking, task_done]

model_providers:
  anthropic:
    api_key: ...
    provider: anthropic

models:
  trae_agent_model:
    model_provider: anthropic
    model: claude-sonnet-4-20250514
    max_tokens: 4096
    temperature: 0.5

mcp_servers:
  playwright:
    command: npx
    args: ["@playwright/mcp@0.0.27"]

Source Structure

trae_agent/
├── agent/
│   ├── agent.py          — base agent loop
│   ├── trae_agent.py     — TraeAgent (SWE-specialized)
│   ├── base_agent.py     — abstract base
│   └── docker_manager.py — Docker isolation
├── cli.py                — trae-cli entry point
├── prompt/
│   └── agent_prompt.py   — TRAE_AGENT_SYSTEM_PROMPT constant
├── tools/
│   ├── bash_tool.py
│   ├── edit_tool.py
│   ├── sequential_thinking_tool.py
│   ├── json_edit_tool.py
│   ├── task_done_tool.py
│   └── mcp_tool.py
└── utils/
    └── config.py

Required Runtime

  • Python 3.12+
  • UV (recommended)
  • Docker (optional, for --docker-image mode)
  • API key for chosen provider

Supported Providers

OpenAI, Anthropic, Google Gemini, Doubao (ByteDance), Azure, OpenRouter, Ollama (local)

03

Components

Trae Agent — Components

CLI Commands (4 subcommands of trae-cli)

Command Description
trae-cli run "<task>" Execute a task (one-shot)
trae-cli interactive Interactive conversational mode
trae-cli show-config Display current configuration
trae-cli tools List available tools

Built-in Tools (5 core + MCP optional)

Tool name Description
bash Execute bash commands in working directory or Docker container
str_replace_based_edit_tool File editing via string replacement (read/write/patch)
sequentialthinking Named reasoning tool — forces structured step-by-step thinking (up to 25 thoughts)
json_edit_tool JSON-aware file editing
task_done Signal task completion (terminates the agent loop)
mcp_tool Dynamic — any MCP server tool discovered at init

Agent Classes

Class Description
BaseAgent Abstract base with LLM client, tool registry, step loop
TraeAgent SWE-specialized agent — adds MCP discovery, Docker support, project path context

Docker Execution Modes

Mode Flag Description
New container from image --docker-image python:3.11 Spin up fresh container
Existing container --docker-container-id <id> Attach to running container
Dockerfile build --dockerfile-path <path> Build then run
Tar archive image --docker-image-file <path> Load from local .tar

CLI Flags

Flag Description
--provider LLM provider override
--model Model override
--working-dir Project directory
--trajectory-file Save execution trace to JSON
--must-patch Force patch generation
--max-steps Maximum agent steps

Evaluation Suite (evaluation/)

  • Docker-based SWE-bench style evaluation
  • datasets integration for loading test cases
  • Trajectory comparison tooling

Server Mode (server/)

  • HTTP server wrapper for Trae Agent (REST API for remote execution)
05

Prompts

Trae Agent — Prompts

System Prompt (verbatim, from trae_agent/prompt/agent_prompt.py)

TRAE_AGENT_SYSTEM_PROMPT = """You are an expert AI software engineering agent.

File Path Rule: All tools that take a `file_path` as an argument require an **absolute path**. You MUST construct the full, absolute path by combining the `[Project root path]` provided in the user's message with the file's path inside the project.

For example, if the project root is `/home/user/my_project` and you need to edit `src/main.py`, the correct `file_path` argument is `/home/user/my_project/src/main.py`. Do NOT use relative paths like `src/main.py`.

Your primary goal is to resolve a given GitHub issue by navigating the provided codebase, identifying the root cause of the bug, implementing a robust fix, and ensuring your changes are safe and well-tested.

Follow these steps methodically:

1.  Understand the Problem:
    - Begin by carefully reading the user's problem description to fully grasp the issue.
    - Identify the core components and expected behavior.

2.  Explore and Locate:
    - Use the available tools to explore the codebase.
    - Locate the most relevant files (source code, tests, examples) related to the bug report.

3.  Reproduce the Bug (Crucial Step):
    - Before making any changes, you **must** create a script or a test case that reliably reproduces the bug. This will be your baseline for verification.
    - Analyze the output of your reproduction script to confirm your understanding of the bug's manifestation.

4.  Debug and Diagnose:
    - Inspect the relevant code sections you identified.
    - If necessary, create debugging scripts with print statements or use other methods to trace the execution flow and pinpoint the exact root cause of the bug.

5.  Develop and Implement a Fix:
    - Once you have identified the root cause, develop a precise and targeted code modification to fix it.
    - Use the provided file editing tools to apply your patch. Aim for minimal, clean changes.

6.  Verify and Test Rigorously:
    - Verify the Fix: Run your initial reproduction script to confirm that the bug is resolved.
    - Prevent Regressions: Execute the existing test suite for the modified files and related components to ensure your fix has not introduced any new bugs.
    - Write New Tests: Create new, specific test cases (e.g., using `pytest`) that cover the original bug scenario. This is essential to prevent the bug from recurring in the future. Add these tests to the codebase.
    - Consider Edge Cases: Think about and test potential edge cases related to your changes.

7.  Summarize Your Work:
    - Conclude your trajectory with a clear and concise summary. Explain the nature of the bug, the logic of your fix, and the steps you took to verify its correctness and safety.

**Guiding Principle:** Act like a senior software engineer. Prioritize correctness, safety, and high-quality, test-driven development.

Prompting technique: Linear numbered-phase decomposition with iron-law enforcement at each phase (bold text for mandatory steps). Notable: explicit "Reproduce the Bug (Crucial Step)" before any fixes — enforces test-driven debugging. The system prompt ends with a guiding principle rather than constraints, implying positive framing over prohibition lists.


Sequential Thinking Tool Usage (from prompt)

"""
# GUIDE FOR HOW TO USE "sequential_thinking" TOOL:
- Your thinking should be thorough and so it's fine if it's very long. Set total_thoughts to at least 5, 
  but setting it up to 25 is fine as well. You'll need more total thoughts when you are considering 
  multiple possible solutions or root causes for an issue.
- Use this tool as much as you find necessary to improve the quality of your answers.
- You can run bash commands (like tests, a reproduction script, or 'grep'/'find' to find relevant context) 
  in between thoughts.
- The sequential_thinking tool can help you break down complex problems, analyze issues step-by-step, 
  and ensure a thorough approach to problem-solving.
- Don't hesitate to use it multiple times throughout your thought process to enhance the depth and 
  accuracy of your solutions.
"""

Prompting technique: Tool usage coaching embedded in the system prompt — instructs the LLM on how to use a specific tool (set total_thoughts to 5-25), not just what the tool does. Interleaved tool calls (bash between thoughts) are explicitly encouraged.

09

Uniqueness

Trae Agent — Uniqueness

Differs From Seeds

Closest to taskmaster-ai (both are Python CLI tools with multi-provider LLM support and a research/pragmatic orientation), but the architectural delta is significant: taskmaster-ai is a task management graph (break → track → expand → complete), while Trae Agent is a single-session SWE agent (run one task end-to-end). Taskmaster persists tasks in tasks.json; Trae Agent is stateless between runs. Trae Agent's trajectory recording is analogous to taskmaster's tasks.json but is read-only audit rather than writeable state. The sequentialthinking tool has no analog in any seed framework — it makes the reasoning chain a first-class API call rather than invisible chain-of-thought.

Distinctive Opinion

Research-friendliness as a first-class design goal: "ideal platform for studying AI agent architectures, conducting ablation studies." This is unique in the corpus — every other framework optimizes for user productivity; Trae Agent co-optimizes for academic reproducibility.

Positioning

  • ByteDance's answer to Anthropic's Claude Code and OpenAI's Codex CLI
  • Explicitly targets academic/research community alongside developers
  • Docker support positions it for SWE-bench-style benchmark evaluation

Observable Failure Modes

  • No persistent state: killed session = all work lost (file edits persist, but agent progress does not)
  • max_steps=200 hard limit: long tasks may hit ceiling
  • No built-in retry on tool failure: agent must handle errors via sequential thinking

Anti-Patterns (implied from design)

  • Don't use for multi-session project management (no task tracking)
  • Don't use for tasks requiring human approval at intermediate steps (no gate mechanism in one-shot mode)
  • Don't use relative file paths in tool calls (system prompt explicitly forbids this)

Cross-References

  • ByteDance's Trae IDE (VS Code fork) is the desktop counterpart
  • arXiv:2507.23370 — technical report documenting the architecture
  • SWE-bench evaluation harness in evaluation/ — connects to academic benchmarking community
04

Workflow

Trae Agent — Workflow

Standard One-Shot Workflow

1. trae-cli run "Fix the authentication bug"
2. Agent reads TRAE_AGENT_SYSTEM_PROMPT
3. Agent receives: task + project root path
4. Loop (up to max_steps=200):
   a. sequentialthinking: plan next action
   b. bash / str_replace_based_edit_tool / json_edit_tool: execute
   c. Lakeview summarizes each step output
5. Agent calls task_done → loop exits
6. Trajectory JSON written (if --trajectory-file set)

Phases + Artifacts

Phase Artifact
Task intake CLI args parsed, config loaded
Context setup Working directory + project root path injected
Exploration bash commands (find, grep, ls)
Reproduction Script that reproduces the bug created
Debugging Print statements, execution traces
Implementation File edits via str_replace_based_edit_tool
Verification Bug reproduction script re-run; existing tests run; new tests written
Completion task_done called; trajectory JSON saved

Approval Gates

None in automated mode — the agent runs to completion without user confirmation.

Interactive mode: User provides follow-up instructions after each agent response; agent waits for input.

Trajectory Recording

When --trajectory-file debug_session.json is set, every tool call, input, output, and LLM response is recorded to JSON. This is the primary research artifact:

{
  "steps": [
    {"step": 1, "tool": "sequentialthinking", "input": {...}, "output": {...}},
    {"step": 2, "tool": "bash", "input": {"command": "..."}, "output": {...}},
    ...
  ]
}

Docker Workflow

trae-cli run "Fix the bug" --docker-image python:3.12
→ Docker container spawned
→ Working directory mounted into container
→ All bash commands execute inside container
→ Container torn down on completion
06

Memory Context

Trae Agent — Memory & Context

Memory Type

File-based, session-scoped — no persistent memory between sessions. Each trae-cli run starts fresh.

Context Injection at Session Start

  • [Project root path] injected into every task prompt
  • --working-dir sets the base directory for all file tool absolute paths
  • Agent explores the codebase via bash (find, grep, ls) to build its own working context

Trajectory File (Audit / Research Memory)

  • --trajectory-file <path> saves full execution JSON
  • Not used by the agent as memory; used by humans/researchers for analysis
  • Contains: all tool calls, inputs, outputs, LLM responses, step numbers

Lakeview Summaries

  • Short summaries of each step displayed in terminal
  • Not persisted to a file by default
  • Purpose: reduce cognitive load during interactive monitoring

MCP State

  • MCP tools are discovered once at agent init (initialise_mcp())
  • MCP server connections are maintained for the duration of the session
  • mcp_clients list tracked for cleanup

Cross-Session Handoff

None — no state files written between sessions. Each run is independent.

Context Compaction

Unknown — not documented. Agent has max_steps=200 limit which may implicitly bound context.

Docker State Persistence

When using Docker:

  • --docker-keep flag: whether to keep the container after completion
  • Working directory can be mounted for persistent file access
  • Without mounting, all file changes are lost when container is destroyed
07

Orchestration

Trae Agent — Orchestration

Multi-Agent

No — single-agent design. One TraeAgent instance per trae-cli run invocation.

Orchestration Pattern

None (single sequential loop)

Isolation Mechanism

Container (optional) — via --docker-image, --docker-container-id, --dockerfile-path, or --docker-image-file. Docker mode is the only isolation; without it, the agent edits files in-place on the local filesystem.

Execution Mode

  • One-shot (trae-cli run): run to completion, no user interaction
  • Interactive loop (trae-cli interactive): conversational, waits for user after each response

Multi-Model

Yes — different tasks can use different providers/models via CLI flags (--provider, --model). Within a single session, one model is used. Config supports multiple provider definitions but doesn't auto-route by task type.

Sequential Thinking Integration

The sequentialthinking tool effectively creates an internal monologue layer before each action. This is prompt chaining within the agent loop: each thought can trigger bash commands, and conclusions from thoughts feed into the next tool call.

Crash Recovery

No — no checkpoint/resume mechanism. If the process dies mid-run, work is lost (though file edits made by bash/edit tools persist on disk).

Streaming Output

Yes (terminal) — Lakeview summarizes steps in real-time; Rich library renders progress.

Prompt Chaining

Yes — sequentialthinking output → bash → more thoughts → edit. The structured thinking chain is explicit via the named sequentialthinking tool.

08

Ui Cli Surface

Trae Agent — UI & CLI Surface

CLI Binary

  • Name: trae-cli
  • Entry point: trae_agent.cli:main (via pyproject.toml)
  • Subcommands: run, interactive, show-config, tools (4 total)

Terminal UI

  • Library: Rich (Python) — renders colored output, tables, panels
  • Lakeview: Per-step summaries displayed in terminal during execution
  • Not a full TUI (no keyboard shortcuts, no panels) — just styled stdout

Server Mode

  • server/ directory contains an HTTP server wrapper
  • Exposes Trae Agent as a REST API (for remote invocation or CI integration)
  • Port: undocumented

VS Code Integration

  • .vscode/ directory exists (settings for development, not user-facing integration)
  • No official VS Code extension

Docker Dashboard

No dedicated Docker UI — Docker mode is driven entirely via CLI flags.

Observability

  • Trajectory file: --trajectory-file <path> → JSON log of all agent actions
  • Lakeview: Step summaries in terminal
  • Rich tables: Config display via show-config subcommand
  • Pre-commit hooks: .pre-commit-config.yaml for development workflow
  • CI: GitHub Actions (unit-test.yml, pre-commit.yml)

Evaluation Suite

  • evaluation/ directory: Docker-based SWE-bench evaluation harness
  • Batch job runner for academic benchmarking
  • Outputs comparison metrics for trajectory analysis

Related frameworks

same archetype · same primary tool · same memory type

OpenHarness ★ 13k

Open-source Python agent runtime providing complete harness infrastructure: tools, memory, governance, swarm coordination, and…

Sweep AI ★ 7.7k

Autonomous GitHub bot that converts issues to pull requests using a sequential multi-agent pipeline.

Agent Governance Toolkit (microsoft) ★ 2.3k

Enterprise-grade AI agent governance: YAML policy enforcement, 12-vector prompt injection defense, zero-trust identity,…

TDD Guard ★ 2.1k

Mechanically enforces the Red-Green-Refactor TDD cycle by blocking file writes that violate TDD principles via a PreToolUse hook…

Agentic Coding Flywheel Setup (ACFS) ★ 1.5k

Take a complete beginner from laptop to three AI coding agents running on a VPS in 30 minutes via an idempotent manifest-driven…

leash (strongdm) ★ 565

Wraps AI coding agents in containers with eBPF-enforced Cedar policies, making policy violations (unauthorized file access,…