Skip to content

Latest commit

 

History

History
170 lines (121 loc) · 3.84 KB

File metadata and controls

170 lines (121 loc) · 3.84 KB

s17: Autonomous Agents

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.

Run

cargo run -p s17_autonomous_agents

Runtime state:

.team/
.team/inbox/
.team/requests/
.tasks/

New Capabilities

  • Teammates can stay alive beyond a single prompt.
  • Add Working / Idle / Shutdown lifecycle states.
  • Add an idle tool.
  • 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.

Autonomous Worker Loop

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.

Code Layout

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

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.

TeammateStatus

Persistent states:

Working
Idle
Shutdown
  • Working: 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 Polling

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.

Identity Context

Long-running teammates must remember who they are. LoopState stores:

  • name
  • role
  • team_name

When a teammate resumes from idle, the identity context is injected again so it continues as the same role.

Task Claim

Tasks become claimable work items. TaskRecord gains:

  • owner
  • claimed_at
  • claim_source
  • claim_role
  • required_role

A task is claimable when:

  • it is pending
  • it has no owner
  • it is not blocked
  • its required role matches the teammate role

Auto Claim

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.

Shutdown and Cleanup

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.

Limits

  • 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.

Next

s18 runs tasks inside git worktree lanes so agents and subagents can work in isolated directories.