feat(subagent): comprehensive sub-agent system with persistence#34
Open
lalyeah wants to merge 1 commit intoXSpoonAi:masterfrom
Open
feat(subagent): comprehensive sub-agent system with persistence#34lalyeah wants to merge 1 commit intoXSpoonAi:masterfrom
lalyeah wants to merge 1 commit intoXSpoonAi:masterfrom
Conversation
…ence
Implement a full sub-agent system allowing agents to spawn child agents
that run concurrently, with push-based result delivery, lifecycle events,
and file-based persistence across process restarts.
Core sub-agent system (spoon_bot/subagent/):
- SubagentManager: orchestration engine with spawn/cancel/steer/info
- SubagentRegistry: thread-safe lifecycle tracking with state machine
- SubagentTool: LLM-facing tool with spawn/status/cancel/kill/steer/info actions
- Models: SubagentConfig, SubagentRecord, SubagentResult, TokenUsage, SubagentState
Key features:
- Push-based wake continuation: results auto-injected into parent session via MessageBus
- Cascade kill: cancelling a sub-agent recursively cancels all descendants
- Steer operation: redirect a running sub-agent to a new task mid-execution
- Pending descendants tracking: prevents false completion signals
- Per-sub-agent token usage tracking
- Extended thinking support (thinking_level config)
- Per-task run timeout (asyncio.wait_for)
- Announce retry with exponential backoff (3 retries, 1s/2s/4s)
- Lifecycle events (SubagentEvent) on the message bus
- Max spawn depth raised to 8
Persistence (spoon_bot/subagent/persistence.py):
- JSON file persistence ({workspace}/subagents/runs.json)
- Atomic writes (write-to-tmp + replace) for crash safety
- Startup restoration with orphan reconciliation (PENDING/RUNNING -> FAILED)
- Background SubagentSweeper archives terminal records after configurable interval
- Schema versioning (v1) with forward compatibility and migration hooks
- Corrupt file quarantine (.corrupt.json) with graceful fallback
Channel integrations:
- Telegram: /subagents command with list/spawn/cancel/kill/steer/info/help
- spawn supports --model and --thinking flags
- Enhanced list with active/recent separation, model names, pending descendants
- Discord: lifecycle event listener logging spawn/complete/fail/cancel events
Configuration:
- SubagentLimitsConfig: persist_runs, persist_file, archive_after_minutes,
sweeper_interval_seconds, max_depth (le=8), thinking_level, timeout_seconds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Implement a full sub-agent system that allows agents to spawn concurrent child agents with automatic result delivery, lifecycle management, and crash-safe persistence.
Core System (
spoon_bot/subagent/)spawn/status/cancel/kill/steer/infoactionsSubagentConfig,SubagentRecord,SubagentResult,TokenUsage,SubagentStateKey Features
thinking_levelconfig)asyncio.wait_forSubagentEvent) emitted on the message busPersistence (
persistence.py){workspace}/subagents/runs.json(schema version 1).tmp+replace()) for crash safety.corrupt.json, graceful fallback to empty registryChannel Integrations
/subagentscommand —list/spawn/cancel/kill/steer/info/helpspawnsupports--modeland--thinkingflagsConfiguration
New fields in
SubagentLimitsConfig:persist_runs(default: true),persist_file,archive_after_minutes,sweeper_interval_secondsthinking_level,timeout_secondsinSubagentConfigTest Plan
count_pending_descendants()BFS works with parent-child hierarchiesSubagentRunsFilesave/load roundtrip preserves all fields.corrupt.json, return empty dict)restore_subagent_runs()marks orphaned PENDING/RUNNING as FAILED/subagents spawn/list/cancel/steer/infocommandsruns.jsonrestored and orphans reconciled