Open-Source Wikis

/

Zed

/

Features

/

AI agent

zed-industries/zed

AI agent

Active contributors: rtfeldman, benbrandt, danilo-leal, bennetbo

Purpose

Zed's "Agent Panel" is an in-editor coding agent that can read and edit project files, run shell commands, search the codebase, and call external tools. It can run with Zed's first-party stack (Anthropic, OpenAI, Google, Bedrock, Ollama, …) or delegate to an external agent backend through the Agent Client Protocol (ACP) — Codex, Gemini CLI, OpenCode, and Copilot Chat all plug in this way.

Crates

Crate Role
crates/agent Core: threads, tools, history, settings (~100k LOC)
crates/agent_ui The Agent Panel and its widgets (~63k LOC)
crates/agent_servers External agent backends (Codex, Gemini CLI, OpenCode, …)
crates/agent_settings Settings owned by the agent
crates/acp_thread Agent Client Protocol thread model
crates/acp_tools ACP tool definitions
crates/ai_onboarding First-run AI feature setup
crates/anthropic, crates/open_ai, crates/google_ai, crates/bedrock, crates/ollama, crates/mistral, crates/deepseek, crates/open_router, crates/codestral, crates/lmstudio, crates/x_ai Provider-specific clients
crates/language_model, crates/language_model_core, crates/language_models, crates/language_models_cloud Provider abstractions and Zed's cloud gateway
crates/prompt_store Prompt templating + storage
crates/zeta_prompt First-party edit-prediction prompt (used in edit_prediction)
crates/copilot, crates/copilot_chat, crates/copilot_ui Microsoft Copilot adapter
crates/context_server MCP (Model Context Protocol) server adapter
crates/web_search, crates/web_search_providers Web-search tool surface
crates/rules_library Reusable system rules (.rules-style guardrails)

Key abstractions

Type File Description
Thread crates/agent/src/thread.rs One conversation, with messages, tool calls, edits
ThreadStore crates/agent/src/thread_store.rs Persistent collection of threads
Tool / ToolRegistry crates/agent/src/tools/ Callables the agent can invoke
LanguageModel trait crates/language_model_core/src/... Provider-agnostic completion API
LanguageModelRegistry crates/language_models/src/... Selection of available models
PromptBuilder crates/prompt_store/src/... Builds the system prompt from templates + context
AgentPanel crates/agent_ui/src/agent_ui.rs The view
SharedThread crates/agent/src/... Streamed multi-client thread (for collaboration)
ACP Connection crates/acp_thread/src/... Wire to an external agent backend

How it works

sequenceDiagram
    participant U as User
    participant AP as AgentPanel
    participant T as Thread
    participant LM as LanguageModel
    participant TR as Tool runner
    participant Pr as Project

    U->>AP: enter prompt
    AP->>T: send_message(text + attachments)
    T->>LM: stream_completion(messages, tools, ctx)
    LM-->>T: stream chunks (text + tool_call)
    T->>TR: dispatch tool call
    TR->>Pr: read/write/search/run
    Pr-->>TR: result
    TR-->>T: tool_result
    T->>LM: stream_completion(...continued)
    LM-->>T: assistant text
    T-->>AP: stream renderable chunks

Tools

Built-in tool kinds include:

  • File operations (read, edit, search, list).
  • Shell command runner.
  • Project / workspace navigation (open file, jump to symbol).
  • Code search across the project.
  • Web search (via crates/web_search).
  • Diagnostics readout.
  • "Now thinking" / scratchpad for long reasoning.

Each tool has a JSON schema served to the model so it knows how to call it. Tools can stream partial output back into the thread.

Context

The agent's context for a turn includes:

  • The system prompt (built by PromptBuilder, may include user .rules and project .rules).
  • Recent thread history.
  • Attached files / selections / images.
  • Indexed project knowledge if enabled.
  • Tool definitions.

Provider abstraction

crates/language_model_core defines the trait every provider implements. crates/language_models aggregates first-party implementations (anthropic, open_ai, …). crates/language_models_cloud wraps Zed's own cloud gateway (which proxies to upstream providers but adds metering and metering features).

MCP

crates/context_server connects to external Model Context Protocol servers — these are user-supplied tool servers the agent treats as additional tools. The MCP version is bumped recently (Support latest MCP protocol version (#54494)).

ACP

External agents speak the Agent Client Protocol via stdio. crates/acp_thread and crates/acp_tools model the same Thread/Tool concepts but route them out-of-process. crates/agent_servers ships first-party adapters:

  • Codex
  • Gemini CLI
  • OpenCode (the open-source Crush-style agent)
  • Copilot Chat (via crates/copilot_chat)

Switching the active agent is a setting; the UI is unchanged.

Streaming edits

Tool calls that edit code stream into a MultiBuffer-backed diff view (crates/acp_thread), so the user can review and accept/reject. The streaming edit feature was originally behind a flag and was removed (graduated to default) in agent: Remove streaming edit feature flag (#55152).

Integration points

  • Project: the agent reads buffers and watches edits via crates/project.
  • Editor: edit suggestions are previewed in MultiBuffer views.
  • Telemetry: anonymised tool-use metrics flow through crates/telemetry.
  • Cloud: crates/language_models_cloud and crates/cloud_llm_client reach the Zed-hosted gateway.
  • Crash investigation: script/crash-to-prompt builds prompts the agent can act on.

Entry points for modification

  • New built-in tool — crates/agent/src/tools/. Register in the tool registry.
  • New provider — implement LanguageModel in a new crate, register in crates/language_models.
  • Prompt tweaks — crates/prompt_store, crates/zeta_prompt.
  • New ACP backend — crates/agent_servers/src/<name>.rs.
  • Panel UI — crates/agent_ui/src/.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

AI agent – Zed wiki | Factory