feat: Add agent forking with letta fork subcommand #109
+322
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds agent forking capability - agents can clone themselves to spawn subagents for parallel work.
Very speculative, mostly made for experimentation purposes.
Usage
From within an agent (via Bash tool):
How It Works
1. Agent Cloning
--isolatedflag creates new blocks with copied content2. Fork Bomb Prevention
Requires
LETTA_SELF_AGENT_IDenvironment variable:Maximum fork depth: 3 levels
fork-depth:0,fork-depth:1, etc.Tagging:
origin:letta-code-fork- Identifies as forkparent:- Links to parent agentfork-depth:- Tracks recursion depthephemeral:true- Marks for auto-cleanup (unless--keep)3. Ephemeral Agent Cleanup
By default, forks are ephemeral:
--keepflag to persist permanentlyCleanup triggers:
Implementation
Files Added
src/agent/context.ts- Global agent ID context for tool executionsrc/agent/fork.ts- Fork logic with export/import/cleanupFiles Modified
src/cli/App.tsx- Set agent context on session startsrc/headless.ts- Set agent context + cleanup ephemeral agentssrc/index.ts- Add fork subcommand detection + flagsREADME.md- Document fork usageOptions
--isolated- Clone memory blocks instead of sharing--fresh-conversation- Clear conversation history--keep- Persist forked agent (don't auto-delete)-p "prompt"- Execute prompt in forked agentExample Workflow
Testing
✅ Lint passes
✅ Type check passes
✅ Build succeeds
✅ Fork command fails gracefully without
LETTA_SELF_AGENT_IDManual testing needed:
Future Enhancements
letta forks)👾 Generated with Letta Code