s16 adds structured team protocols, but teammates are still mostly driven by the lead. This chapter turns teammates into long-running workers that can work, idle, poll messages, claim tasks, and shut down after being idle.
The main topic is autonomous worker lifecycle.
cargo run -p s17_autonomous_agentsRuntime state:
.team/
.team/inbox/
.team/requests/
.tasks/
- Teammates can stay alive beyond a single prompt.
- Add
Working / Idle / Shutdownlifecycle states. - Add an
idletool. - Idle workers poll inboxes.
- Teammates can auto-claim ready tasks by role.
- Tasks gain owner, claim, and required-role fields.
- Stop signals and runtime cleanup are separated.
The teammate lifecycle becomes:
work phase
-> no more tool calls or explicit idle
-> idle polling phase
-> inbox message or claimed task
-> work phase
-> long idle timeout or stop signal
-> shutdown
This turns teammates from one-shot runners into a minimal worker runtime.
s17_autonomous_agents/
├── src/
│ ├── lib.rs
│ ├── task.rs
│ ├── team/
│ │ ├── cleanup.rs
│ │ ├── message.rs
│ │ ├── requests.rs
│ │ └── teammate.rs
│ └── tool/
│ ├── idle.rs
│ ├── task_claim.rs
│ ├── task_create.rs
│ ├── plan_approval.rs
│ └── ...
└── s17.md
Core logic is in src/lib.rs, src/task.rs, and src/team/cleanup.rs.
LoopState now owns both:
- the normal model/tool loop
- autonomous teammate lifecycle
Important functions:
agent_loop(): run one work phase.run_autonomous_teammate_loop(): long-running worker loop.run_work_phase(): map one work phase to Idle or Shutdown.run_idle_polling_phase(): poll inbox and auto-claim tasks.
Persistent states:
Working
Idle
ShutdownWorking: actively calling the model and tools.Idle: alive but waiting.Shutdown: loop ended and runtime state is cleaned up.
Idle is not dead. It still polls for work.
Idle phase:
sleep
-> check stop signal
-> read inbox
-> if messages exist, resume Working
-> otherwise try auto-claim task
-> if claim succeeds, resume Working
-> if timeout, Shutdown
This avoids model calls while no work is available.
Long-running teammates must remember who they are. LoopState stores:
nameroleteam_name
When a teammate resumes from idle, the identity context is injected again so it continues as the same role.
Tasks become claimable work items. TaskRecord gains:
ownerclaimed_atclaim_sourceclaim_rolerequired_role
A task is claimable when:
- it is
pending - it has no owner
- it is not blocked
- its required role matches the teammate role
SharedTeammateManager::auto_claim_task(...) scans tasks and claims the first ready task matching the worker role.
The claimed task is injected into the teammate context, and the worker resumes its work phase.
The chapter separates:
- shutdown request
- stop signal
- runtime cleanup
The lead requests shutdown. The manager sets a cooperative stop signal. The teammate exits through its own loop. Cleanup happens after the task actually ends.
- Idle polling uses fixed intervals.
- Auto-claim uses a simple first-ready policy.
- No priorities, fairness, leases, or retry recovery.
- Plan approval is still a protocol, not a scheduler policy engine.
- Runtime supervision is minimal.
s18 runs tasks inside git worktree lanes so agents and subagents can work in isolated directories.