# Subagents PR 2: Thread spawning \+ execution \(\#46187\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 756637fef591290c7e4ad6398390709fd181961f

Requested commit: 756637fef591290c7e4ad6398390709fd181961f

Commit: 756637fef591290c7e4ad6398390709fd181961f

Tree: 55febda9667e471e1e9ae5fabd0f37d852959525

Author: Richard Feldman

Committer: GitHub

## Message

```
Subagents PR 2: Thread spawning + execution (#46187)

This PR implements the behind-the-scenes subagent execution logic:

### Core subagent execution
- Add `Thread::new_subagent()` constructor for creating subagent threads
- Implement `SubagentTool::run()` to spawn and manage subagent lifecycle
- Add `SubagentContext` for parent-child thread relationship
- Implement `submit_user_message()`, `interrupt_for_summary()`,
`request_final_summary()`
- Add timeout support and context-low detection (25% threshold)
- Propagate cancellation from parent to child threads

### Thread management
- Add `MAX_SUBAGENT_DEPTH` (4) and `MAX_PARALLEL_SUBAGENTS` (8) limits
- Add `register/unregister_running_subagent()` for tracking
- Add `restrict_tools()` for allowed_tools filtering
- Add `is_subagent()`, `depth()`, `is_turn_complete()` accessors

### Thread changes
- Add `ToolCallContent::SubagentThread` variant
- Add `ToolCallUpdateSubagentThread` for UI updates
- Add `tool_name` field for subagent detection
- Add `is_subagent()` method on `ToolCall`
- Add image support in `ContentBlock`

Release Notes:

- N/A

---------

Co-authored-by: Amp <amp@ampcode.com>
```

## Parents

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

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