Skip to content
Website ↗

How the swarm works ​

Codant runs its swarm inside a local daemon. The terminal, SDK, and experimental VS Code extension access it through the same API. The daemon acquires a lock under its data directory and maintains one shared task state. Decentralization describes how agents collaborate. Agents doing different jobs can propose subtasks, leave findings for others, and hand off results. Shared records and scheduling rules determine what can run next.

text
Terminal / SDK / VS Code extension
          │ JSON-RPC
          ▼
      Local daemon
          │ task intake and events
          ▼
Shared board ── cards, leases, signals, evidence
          │
          ├─ Scheduler checks capacity, budgets, write scopes
          ├─ Queen starts, cancels, and reaps agents
          ├─ Scouts investigate, workers execute and hand off
          └─ Soldiers review, nurses maintain memory

Candidate diff → review and checks → approval → delivery

See packages/api/src/daemon.ts:254, packages/api/src/default-swarm.ts:107, and packages/api/src/default-swarm.ts:295.

Why divide the work ​

Investigation, editing, and review need different context and permissions. A scout can locate the implementation and tests, then workers can take changes with a clear scope. A soldier reviews the candidate diff that the workers return, and the report becomes part of the task record. A nurse can preserve useful findings after the task ends.

Parallel work depends on whether the changes can be separated. Consider making UTF‑8 the default. If import and export write to separate files, the scheduler can dispatch separate workers. If both need to edit the same encoding helper, the conflicting write task waits in the queue. A scout can trace the dependency first so the parent task can redefine the scope.

See packages/core/src/ant/delegate.ts:134 for delegation parameters, packages/api/src/scout-subtasks.ts:447 for write-scope checks, and packages/api/src/scout-review.ts:133 for independent review of a candidate diff.

How decentralized coordination works ​

The agent working on a parent task can propose child tasks with goals, acceptance criteria, and file scopes. The daemon puts those cards on the shared board and adds them to the parent's dependencies. When a child finishes, the parent card can receive an outcome record and a trail or doubt signal. Later dispatch reads the parent's effective signals and applies capacity, write-scope, and budget rules. The runtime records whether it dispatched, queued, or rejected the task.

Coordination grows out of the work that different roles propose and the results they return. One local daemon owns task state, leases, and dispatch for a given data directory. Claiming a card creates a lease with a generation, and the runtime checks the current lease before accepting changes to protected execution state. Signals let later work react to new findings. Write scopes, approvals, and checks govern edits and acceptance.

See packages/core/src/bus/bus.ts:459 for child cards, packages/api/src/scout-subtask-finalization.ts:25 and packages/api/src/scout-subtask-finalization.ts:68 for outcome feedback, and packages/api/src/scout-subtasks.ts:430 and packages/api/src/scout-subtasks.ts:464 for dispatch records. See also task cards and leases and execution, validation, and delivery.

What ant colony optimization helps explain ​

Classical ant colony optimization (ACO) offers a way to understand indirect coordination. In Ant System, multiple artificial ants choose their next steps probabilistically, each building a candidate solution. Better solutions reinforce pheromone on the paths they used, and pheromone evaporates over iterations. Those updates influence later searches. Ant System by Dorigo, Maniezzo, and Colorni

Codant's pheromones are typed signals on task cards. A successful subtask can leave trail, which raises the stimulus for a later dispatch. A failed subtask can leave doubt, which lowers it. The runtime sums unexpired, unresolved signals, and each signal drops out of the effective concentration at expiry. The scheduler makes a deterministic decision about each existing child card. It dispatches the card when the stimulus reaches the response threshold for the role and task type and the other constraints allow it.

For example, the raw stimulus starts at 5. Every 10 points of effective trail add 1, up to a bonus of 3. Every 10 points of doubt subtract 1, with a floor of 1. Time spent in the queue can also raise the final stimulus used for dispatch.

See packages/core/src/bus/views.ts:118, packages/core/src/ant/scheduler.ts:159, packages/core/src/ant/scheduler.ts:293, and packages/api/src/scout-subtasks.ts:433. Read how signals inform dispatch

Five built-in roles ​

CasteResponsibility
QueenRegisters new agents, handles cancellation, and reaps idle agents. Spawning checks caste capacity and lineage depth.
ScoutInvestigates code and tests using read-only tools and returns relevant locations and findings to the parent task.
WorkerExecutes within the granted workspace permissions and can propose subtasks with a defined scope and acceptance criteria.
SoldierReviews diffs in a separate model context and records findings in a structured report.
NurseExtracts and consolidates reusable memory from finished tasks and sessions.

See the caste definitions in packages/core/src/ant/caste.ts:53, the Queen lifecycle in packages/core/src/ant/queen.ts:80, and memory scheduling in packages/api/src/scout-memory.ts:655. See tools and capacity by caste

Army ants and the hunt formation ​

Army ants can use pheromone trails to gather and forage as a group. The website's hunt animation uses that image to show several existing roles working on one task. The runtime uses the five built-in castes listed above. The codant hunt command submits a task to the daemon. Research on army ant mass raiding

The scheduler's raid formation labels describe the cap on concurrent subtasks. When the parent's effective alarm concentration is below 3, the configured cap applies. At 3, the cap narrows to at most two subtasks. At 7, it narrows to one, a single-file formation. At 12, the scheduler can open a five-minute circuit breaker that pauses new dispatches. The same roles can work in parallel when scopes permit and take work one step at a time as alarms rise.

See packages/core/src/ant/scheduler.ts:169 and packages/core/src/ant/scheduler.ts:275 for the formation and thresholds, packages/api/src/scout-subtasks.ts:430 for the parent alarm input, and packages/cli/src/index.ts:376 for the command entry point.

From investigation to delivery ​

Suppose your repository has import and export commands. You want both to default to UTF‑8 while preserving explicit encoding overrides. Open a terminal in the project directory and follow Quickstart to set up the model and local tools. If you have a trusted check configured under the ID import-export-tests, select it to validate the changes. For a first check, follow the JSON example in the hunt guide.

sh
codant hunt --check import-export-tests "Default import and export to UTF-8 and preserve explicit encoding overrides"

1. Investigate and define the scope ​

The daemon records the goal on a root task card and starts the worker responsible for it. That worker can ask a scout to locate the import path, export path, and existing tests, then delegate work that can be done independently. When a parent task with a current lease creates child cards, the runtime adds those cards to its dependencies.

See packages/api/src/scout-task-executor.ts:89, packages/core/src/ant/delegate.ts:134, and packages/core/src/bus/bus.ts:459.

2. Dispatch, claim, and share feedback ​

Suppose import and export have separate implementation files. Two sibling subtasks that write to those separate files can run in parallel when the scheduler allows it. If both declare writes to the same encoding helper, write-scope checks keep them from running together and the conflicting subtask stays queued. The scheduler also checks capacity, model budget, and response thresholds.

Claiming a child card records intent and creates a lease with an owner, generation, and expiry. An earlier generation or an expired lease cannot update protected execution state. A successful child task can leave trail on the parent task, and a failed child task can leave doubt. These signals contribute to the stimulus used for later dispatch decisions.

For scheduling and write scopes, see packages/api/src/scout-subtasks.ts:415 and packages/api/src/scout-subtasks.ts:499. For leases and feedback, see packages/core/src/bus/lease-commands.ts:44, packages/core/src/bus/lease-commands.ts:232, packages/api/src/scout-subtask-finalization.ts:25, and packages/core/src/ant/scheduler.ts:159.

3. Validate the candidate and confirm completion ​

File changes first become a candidate diff. A soldier reviews that diff, and the daemon runs the selected checks against the same candidate and records the review and check evidence. The runtime records a success signal when the review identifies no blocking issue and the checks pass. Before publishing to the workspace, the daemon requests approval for that publication and revalidates the candidate.

The scheduler counts unexpired, unresolved signals in the effective concentration. An expired alarm drops out of that concentration and still blocks task completion until resolved. Completion also requires acceptance for the current generation, completed dependencies, and closed execution and leases. In the TUI, run /ants changes <task ID> to inspect the recorded results.

For review and publication, see packages/api/src/scout-review.ts:133, packages/api/src/scout-review.ts:214, and packages/api/src/scout-publication.ts:156. For signal concentration and completion, see packages/core/src/bus/views.ts:118 and packages/core/src/bus/lease-commands.ts:164.

Explore the design and interfaces ​

Source locations refer to the Codant development version.