# Add create_thread and list_agents_and_models agent tools \(\#57987\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/59f32d2135a9c9816d46e4e98cc55e7103423aa4)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 59f32d2135a9c9816d46e4e98cc55e7103423aa4

Requested commit: 59f32d2135a9c9816d46e4e98cc55e7103423aa4

Commit: 59f32d2135a9c9816d46e4e98cc55e7103423aa4

Tree: a08376c23e02628e05409f51b11072d683d0821b

Author: Eric Holk

Committer: GitHub

## Message

```
Add create_thread and list_agents_and_models agent tools (#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
```

## Parents

- [e4ddcc8bb45b8538884adde7ca82fe48af708919](https://git.cafe/gitcafe/zed/commit/e4ddcc8bb45b8538884adde7ca82fe48af708919?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/59f32d2135a9c9816d46e4e98cc55e7103423aa4?format=markdown)
