Skip to content

Add create_thread and list_agents_and_models agent tools - #57987

Merged
eholk merged 4 commits into
mainfrom
create-thread-tool
Jun 1, 2026
Merged

Add create_thread and list_agents_and_models agent tools#57987
eholk merged 4 commits into
mainfrom
create-thread-tool

Conversation

@eholk

@eholk eholk commented May 28, 2026

Copy link
Copy Markdown
Contributor

Adds two built-in agent tools, behind the staff-only create-thread-tool feature flag, that let the agent spawn independent sibling threads:

  • create_thread creates a new thread with a title and initial prompt. It runs on the user's behalf and shows up in the agent sidebar like a thread the user started themselves, but it runs in the background — the active thread is never interrupted — and it does not report results back to the caller. (Use spawn_agent when you want the results.)
  • list_agents_and_models enumerates the configured agents and, for the native agent, the available models, so the agent can pick a cheaper/faster model for bulk work. The motivating stress test was "spawn 100 threads that each write a haiku, using Haiku instead of Opus."

By default the sibling shares the parent's project and worktree. If use_new_worktree is set, create_thread instead opens a new background workspace backed by fresh linked git worktrees of the project's repos — the same flow you get from the worktree picker's "Create worktree" — and starts the thread there. The new workspace opens as a background tab so it doesn't pull you away from what you're doing.

A few notes on the design:

  • The agent crate can't depend on the UI, so there's a SiblingThreadHost trait that agent_ui::AgentPanel implements and installs on the NativeAgent. Tool calls in a native-agent thread route through it.
  • Sibling threads go through the same create_agent_threadConversationView path as the user-facing "new thread" action, so eviction, persistence, and sidebar rendering match user-created threads.
  • An explicit agent/model override doesn't clobber the panel's selected agent or the last-used-agent preference — those are snapshotted and restored around the call.
  • The worktree path reuses the existing "Create worktree" machinery rather than reimplementing it; the agent flow just opens the new workspace in the background instead of activating it.

A couple of things I left out or want to call out:

  • There's no tool to operate on an already-created sibling by session id. The success payload deliberately omits it, since the session is populated asynchronously and nothing consumes it yet.
  • When a project has multiple worktrees that are linked worktrees of the same underlying repo, they collapse into a single new worktree (they resolve to the same target path). The tool returns a warning in that case rather than failing — and this also fixes a latent collision the manual "Create worktree" flow would hit in the same situation.

Release Notes:

  • N/A

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label May 28, 2026
@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label May 28, 2026
@eholk
eholk force-pushed the create-thread-tool branch 4 times, most recently from 1f987de to 7e1a9a2 Compare May 28, 2026 22:52
eholk added 4 commits May 29, 2026 15:46
Introduces two new built-in agent tools that let an agent spawn independent sibling threads which appear in the agent sidebar and run in parallel with the current conversation.
Adds CreateThreadToolFeatureFlag (enabled for staff) and conditionally registers create_thread and list_agents_and_models in Thread::add_default_tools only when the flag is set.
When create_thread is called with use_new_worktree, open a new
background workspace backed by linked git worktrees of the project's
git repos (reusing the worktree picker's create flow) and spawn the
thread there, rather than only sharing the parent's worktree.

- Add git_ui::worktree_service::create_worktree_workspace, a Task-
  returning variant of handle_create_worktree that hands back the new
  workspace so the agent tool can create a thread in it.
- Open the agent's worktree workspace in the background via a new
  MultiWorkspace::add_background_workspace, leaving the user where they
  are and giving the new workspace a clean checkout (no inherited open
  files or dock layout). This matches how non-worktree sibling threads
  are created in the background.
- Dedup linked worktrees of the same underlying repo in
  start_worktree_creations so they don't collide on the same target
  path (previously a hard 'already exists' failure for both this flow
  and the manual Create worktree UI).
- Report a non-fatal warning back to the calling agent when the project
  had multiple worktrees of the same repo and they were consolidated.
- Add optional worktree_name to the create_thread tool input.

Release Notes:

- N/A
@eholk
eholk force-pushed the create-thread-tool branch from 7e1a9a2 to 497bf37 Compare May 29, 2026 22:55
@eholk
eholk added this pull request to the merge queue Jun 1, 2026
Merged via the queue into main with commit 59f32d2 Jun 1, 2026
32 checks passed
@eholk
eholk deleted the create-thread-tool branch June 1, 2026 23:47
TomPlanche pushed a commit to TomPlanche/zed that referenced this pull request Jun 2, 2026
…ies#57987)

Adds two built-in agent tools, behind the staff-only
`create-thread-tool` feature flag, that let the agent spawn independent
sibling threads:

- **`create_thread`** creates a new thread with a title and initial
prompt. It runs on the user's behalf and shows up in the agent sidebar
like a thread the user started themselves, but it runs in the background
— the active thread is never interrupted — and it does **not** report
results back to the caller. (Use `spawn_agent` when you want the
results.)
- **`list_agents_and_models`** enumerates the configured agents and, for
the native agent, the available models, so the agent can pick a
cheaper/faster model for bulk work. The motivating stress test was
"spawn 100 threads that each write a haiku, using Haiku instead of
Opus."

By default the sibling shares the parent's project and worktree. If
`use_new_worktree` is set, `create_thread` instead opens a new
background workspace backed by fresh linked git worktrees of the
project's repos — the same flow you get from the worktree picker's
"Create worktree" — and starts the thread there. The new workspace opens
as a background tab so it doesn't pull you away from what you're doing.

A few notes on the design:

- The `agent` crate can't depend on the UI, so there's a
`SiblingThreadHost` trait that `agent_ui::AgentPanel` implements and
installs on the `NativeAgent`. Tool calls in a native-agent thread route
through it.
- Sibling threads go through the same `create_agent_thread` →
`ConversationView` path as the user-facing "new thread" action, so
eviction, persistence, and sidebar rendering match user-created threads.
- An explicit `agent`/`model` override doesn't clobber the panel's
selected agent or the last-used-agent preference — those are snapshotted
and restored around the call.
- The worktree path reuses the existing "Create worktree" machinery
rather than reimplementing it; the agent flow just opens the new
workspace in the background instead of activating it.

A couple of things I left out or want to call out:

- There's no tool to operate on an already-created sibling by session
id. The success payload deliberately omits it, since the session is
populated asynchronously and nothing consumes it yet.
- When a project has multiple worktrees that are linked worktrees of the
*same* underlying repo, they collapse into a single new worktree (they
resolve to the same target path). The tool returns a warning in that
case rather than failing — and this also fixes a latent collision the
manual "Create worktree" flow would hit in the same situation.

Release Notes:

- N/A
This was referenced Jun 18, 2026
jonx pushed a commit to jonx/zed-aros that referenced this pull request Jul 17, 2026
…ies#57987)

Adds two built-in agent tools, behind the staff-only
`create-thread-tool` feature flag, that let the agent spawn independent
sibling threads:

- **`create_thread`** creates a new thread with a title and initial
prompt. It runs on the user's behalf and shows up in the agent sidebar
like a thread the user started themselves, but it runs in the background
— the active thread is never interrupted — and it does **not** report
results back to the caller. (Use `spawn_agent` when you want the
results.)
- **`list_agents_and_models`** enumerates the configured agents and, for
the native agent, the available models, so the agent can pick a
cheaper/faster model for bulk work. The motivating stress test was
"spawn 100 threads that each write a haiku, using Haiku instead of
Opus."

By default the sibling shares the parent's project and worktree. If
`use_new_worktree` is set, `create_thread` instead opens a new
background workspace backed by fresh linked git worktrees of the
project's repos — the same flow you get from the worktree picker's
"Create worktree" — and starts the thread there. The new workspace opens
as a background tab so it doesn't pull you away from what you're doing.

A few notes on the design:

- The `agent` crate can't depend on the UI, so there's a
`SiblingThreadHost` trait that `agent_ui::AgentPanel` implements and
installs on the `NativeAgent`. Tool calls in a native-agent thread route
through it.
- Sibling threads go through the same `create_agent_thread` →
`ConversationView` path as the user-facing "new thread" action, so
eviction, persistence, and sidebar rendering match user-created threads.
- An explicit `agent`/`model` override doesn't clobber the panel's
selected agent or the last-used-agent preference — those are snapshotted
and restored around the call.
- The worktree path reuses the existing "Create worktree" machinery
rather than reimplementing it; the agent flow just opens the new
workspace in the background instead of activating it.

A couple of things I left out or want to call out:

- There's no tool to operate on an already-created sibling by session
id. The success payload deliberately omits it, since the session is
populated asynchronously and nothing consumes it yet.
- When a project has multiple worktrees that are linked worktrees of the
*same* underlying repo, they collapse into a single new worktree (they
resolve to the same target path). The tool returns a warning in that
case rather than failing — and this also fixes a latent collision the
manual "Create worktree" flow would hit in the same situation.

Release Notes:

- N/A
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
…ies#57987)

Adds two built-in agent tools, behind the staff-only
`create-thread-tool` feature flag, that let the agent spawn independent
sibling threads:

- **`create_thread`** creates a new thread with a title and initial
prompt. It runs on the user's behalf and shows up in the agent sidebar
like a thread the user started themselves, but it runs in the background
— the active thread is never interrupted — and it does **not** report
results back to the caller. (Use `spawn_agent` when you want the
results.)
- **`list_agents_and_models`** enumerates the configured agents and, for
the native agent, the available models, so the agent can pick a
cheaper/faster model for bulk work. The motivating stress test was
"spawn 100 threads that each write a haiku, using Haiku instead of
Opus."

By default the sibling shares the parent's project and worktree. If
`use_new_worktree` is set, `create_thread` instead opens a new
background workspace backed by fresh linked git worktrees of the
project's repos — the same flow you get from the worktree picker's
"Create worktree" — and starts the thread there. The new workspace opens
as a background tab so it doesn't pull you away from what you're doing.

A few notes on the design:

- The `agent` crate can't depend on the UI, so there's a
`SiblingThreadHost` trait that `agent_ui::AgentPanel` implements and
installs on the `NativeAgent`. Tool calls in a native-agent thread route
through it.
- Sibling threads go through the same `create_agent_thread` →
`ConversationView` path as the user-facing "new thread" action, so
eviction, persistence, and sidebar rendering match user-created threads.
- An explicit `agent`/`model` override doesn't clobber the panel's
selected agent or the last-used-agent preference — those are snapshotted
and restored around the call.
- The worktree path reuses the existing "Create worktree" machinery
rather than reimplementing it; the agent flow just opens the new
workspace in the background instead of activating it.

A couple of things I left out or want to call out:

- There's no tool to operate on an already-created sibling by session
id. The success payload deliberately omits it, since the session is
populated asynchronously and nothing consumes it yet.
- When a project has multiple worktrees that are linked worktrees of the
*same* underlying repo, they collapse into a single new worktree (they
resolve to the same target path). The tool returns a warning in that
case rather than failing — and this also fixes a latent collision the
manual "Create worktree" flow would hit in the same situation.

Release Notes:

- N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants