Coverage for app / services / swarms / __init__.py: 100%

0 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-10-31 11:21 +0000

1""" 

2Swarms — a team of the workspace's agents, in a shape, sent on one long task 

3under a budget and a time cap. 

4 

5A **swarm** (``models.Swarm``) is a saved team: a *shape* — one registered 

6class in :mod:`.topologies`, saying who leads, who works and how the work 

7flows between them — and a *roster* of the workspace's agents playing its 

8parts (:mod:`.roster`). Dispatching it on a task starts a **run** 

9(``models.SwarmRun``), which the team works through as a tree of **tasks** 

10(``models.SwarmTask``): the lead plans, workers do the pieces in parallel, 

11the lead reviews them against what each was for, and writes the answer. 

12 

13Every task is a real turn of a real agent — its own model, knowledge, tools 

14and skill graph — through the governed path evaluations and dashboard tiles 

15already use (``evaluation.targets.AgentTarget``): the agent's rules run on 

16it, its spend is on the ledger as it happens (``UsageEnum.Source.swarm``), 

17and it carries its own ``invocation_id``. Nothing about the team is a 

18stand-in, which is why the simulation runner's agent clusters are not the 

19base for it. 

20 

21What the design rests on (``docs/guides/swarms.md`` gives the literature): 

22 

23* **Every result goes through a reviewing parent.** Agents working 

24 independently amplify each other's errors far more than ones whose work 

25 an orchestrator checks; the shapes never merge unreviewed work. 

26* **The plan may say one agent should do it.** Splitting sequential work 

27 makes it worse, so a lead may plan a single task, which runs alone. 

28* **Each piece is briefed in full** (:class:`.schemas.TaskBrief`): what it is 

29 for, what to hand back, where to look, what is not its business, and how 

30 it will be judged done — the gaps most multi-agent failures come from. 

31* **The team shares one ledger** (:mod:`.ledger`): the goal, the plan and 

32 what the work has established reach every agent, not just its subtask. 

33* **Work is passed by reference.** A reviewer receives the pieces as 

34 attached documents, read and searched on demand, rather than pasted. 

35* **Budget is the lever.** Each task gets a share of the run's budget and 

36 svc-ai stops a call past it (:mod:`.budget`); the answer has a reserve, so 

37 a run that reaches a cap still writes one, marked partial. 

38 

39The run's rows are the truth: a finished task is committed before anything 

40is decided from it, so a coordinator lost to a restart is resumed by the 

41scheduler's watchdog from the last finished task (:mod:`.engine`). 

42"""