orbitx 0.2.9 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/Readme.md +478 -456
  2. package/dist/agents/backend.d.ts +4 -0
  3. package/dist/agents/backend.d.ts.map +1 -0
  4. package/dist/agents/backend.js +54 -0
  5. package/dist/agents/backend.js.map +1 -0
  6. package/dist/agents/frontend.d.ts +4 -0
  7. package/dist/agents/frontend.d.ts.map +1 -0
  8. package/dist/agents/frontend.js +50 -0
  9. package/dist/agents/frontend.js.map +1 -0
  10. package/dist/agents/index.d.ts +10 -0
  11. package/dist/agents/index.d.ts.map +1 -0
  12. package/dist/agents/index.js +22 -0
  13. package/dist/agents/index.js.map +1 -0
  14. package/dist/agents/planner.d.ts +4 -0
  15. package/dist/agents/planner.d.ts.map +1 -0
  16. package/dist/agents/planner.js +86 -0
  17. package/dist/agents/planner.js.map +1 -0
  18. package/dist/agents/protocol.d.ts +5 -0
  19. package/dist/agents/protocol.d.ts.map +1 -0
  20. package/dist/agents/protocol.js +70 -0
  21. package/dist/agents/protocol.js.map +1 -0
  22. package/dist/agents/reasoner.d.ts +5 -0
  23. package/dist/agents/reasoner.d.ts.map +1 -0
  24. package/dist/agents/reasoner.js +96 -0
  25. package/dist/agents/reasoner.js.map +1 -0
  26. package/dist/agents/research.d.ts +4 -0
  27. package/dist/agents/research.d.ts.map +1 -0
  28. package/dist/agents/research.js +28 -0
  29. package/dist/agents/research.js.map +1 -0
  30. package/dist/agents/tester.d.ts +4 -0
  31. package/dist/agents/tester.d.ts.map +1 -0
  32. package/dist/agents/tester.js +70 -0
  33. package/dist/agents/tester.js.map +1 -0
  34. package/dist/core/agent-definition.d.ts +61 -0
  35. package/dist/core/agent-definition.d.ts.map +1 -0
  36. package/dist/core/agent-definition.js +82 -0
  37. package/dist/core/agent-definition.js.map +1 -0
  38. package/dist/core/ai-ask.d.ts +28 -0
  39. package/dist/core/ai-ask.d.ts.map +1 -0
  40. package/dist/core/ai-ask.js +80 -0
  41. package/dist/core/ai-ask.js.map +1 -0
  42. package/dist/core/ai-provider.d.ts +3 -0
  43. package/dist/core/ai-provider.d.ts.map +1 -1
  44. package/dist/core/ai-provider.js.map +1 -1
  45. package/dist/core/anthropic-provider.d.ts +1 -0
  46. package/dist/core/anthropic-provider.d.ts.map +1 -1
  47. package/dist/core/anthropic-provider.js +3 -0
  48. package/dist/core/anthropic-provider.js.map +1 -1
  49. package/dist/core/base-agent.d.ts +51 -28
  50. package/dist/core/base-agent.d.ts.map +1 -1
  51. package/dist/core/base-agent.js +118 -26
  52. package/dist/core/base-agent.js.map +1 -1
  53. package/dist/core/deepseek-provider.d.ts +1 -0
  54. package/dist/core/deepseek-provider.d.ts.map +1 -1
  55. package/dist/core/deepseek-provider.js +3 -0
  56. package/dist/core/deepseek-provider.js.map +1 -1
  57. package/dist/core/mcp-auto-execution-policy.d.ts +22 -0
  58. package/dist/core/mcp-auto-execution-policy.d.ts.map +1 -0
  59. package/dist/core/mcp-auto-execution-policy.js +85 -0
  60. package/dist/core/mcp-auto-execution-policy.js.map +1 -0
  61. package/dist/core/mcp-computer.d.ts +14 -1
  62. package/dist/core/mcp-computer.d.ts.map +1 -1
  63. package/dist/core/mcp-computer.js +352 -71
  64. package/dist/core/mcp-computer.js.map +1 -1
  65. package/dist/core/ollama-provider.d.ts +1 -0
  66. package/dist/core/ollama-provider.d.ts.map +1 -1
  67. package/dist/core/ollama-provider.js +3 -0
  68. package/dist/core/ollama-provider.js.map +1 -1
  69. package/dist/core/openai-provider.d.ts +1 -0
  70. package/dist/core/openai-provider.d.ts.map +1 -1
  71. package/dist/core/openai-provider.js +3 -0
  72. package/dist/core/openai-provider.js.map +1 -1
  73. package/dist/core/stateless-agent.d.ts +30 -0
  74. package/dist/core/stateless-agent.d.ts.map +1 -0
  75. package/dist/core/stateless-agent.js +79 -0
  76. package/dist/core/stateless-agent.js.map +1 -0
  77. package/dist/core/swarm-base.d.ts +88 -0
  78. package/dist/core/swarm-base.d.ts.map +1 -0
  79. package/dist/core/swarm-base.js +427 -0
  80. package/dist/core/swarm-base.js.map +1 -0
  81. package/dist/index.d.ts +13 -5
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +7 -3
  84. package/dist/index.js.map +1 -1
  85. package/dist/tests/agents/default-agents.test.d.ts +2 -0
  86. package/dist/tests/agents/default-agents.test.d.ts.map +1 -0
  87. package/dist/tests/agents/default-agents.test.js +106 -0
  88. package/dist/tests/agents/default-agents.test.js.map +1 -0
  89. package/dist/tests/core/agent-definition.test.d.ts +2 -0
  90. package/dist/tests/core/agent-definition.test.d.ts.map +1 -0
  91. package/dist/tests/core/agent-definition.test.js +99 -0
  92. package/dist/tests/core/agent-definition.test.js.map +1 -0
  93. package/dist/tests/core/ai-ask.test.d.ts +2 -0
  94. package/dist/tests/core/ai-ask.test.d.ts.map +1 -0
  95. package/dist/tests/core/ai-ask.test.js +101 -0
  96. package/dist/tests/core/ai-ask.test.js.map +1 -0
  97. package/dist/tests/core/mcp-auto-execution-policy.test.d.ts +2 -0
  98. package/dist/tests/core/mcp-auto-execution-policy.test.d.ts.map +1 -0
  99. package/dist/tests/core/mcp-auto-execution-policy.test.js +107 -0
  100. package/dist/tests/core/mcp-auto-execution-policy.test.js.map +1 -0
  101. package/dist/tests/core/scripted-provider.d.ts +38 -0
  102. package/dist/tests/core/scripted-provider.d.ts.map +1 -0
  103. package/dist/tests/core/scripted-provider.js +85 -0
  104. package/dist/tests/core/scripted-provider.js.map +1 -0
  105. package/dist/tests/core/stateless-agent.test.d.ts +2 -0
  106. package/dist/tests/core/stateless-agent.test.d.ts.map +1 -0
  107. package/dist/tests/core/stateless-agent.test.js +73 -0
  108. package/dist/tests/core/stateless-agent.test.js.map +1 -0
  109. package/dist/tests/core/swarm-base.test.d.ts +2 -0
  110. package/dist/tests/core/swarm-base.test.d.ts.map +1 -0
  111. package/dist/tests/core/swarm-base.test.js +387 -0
  112. package/dist/tests/core/swarm-base.test.js.map +1 -0
  113. package/dist/tests/index.d.ts +6 -0
  114. package/dist/tests/index.d.ts.map +1 -1
  115. package/dist/tests/index.js +6 -0
  116. package/dist/tests/index.js.map +1 -1
  117. package/dist/tests/tools/agent/agent-tools.test.js +225 -153
  118. package/dist/tests/tools/agent/agent-tools.test.js.map +1 -1
  119. package/dist/tools/agent/active.d.ts +5 -0
  120. package/dist/tools/agent/active.d.ts.map +1 -0
  121. package/dist/tools/agent/active.js +40 -0
  122. package/dist/tools/agent/active.js.map +1 -0
  123. package/dist/tools/agent/fire.d.ts +5 -0
  124. package/dist/tools/agent/fire.d.ts.map +1 -0
  125. package/dist/tools/agent/fire.js +38 -0
  126. package/dist/tools/agent/fire.js.map +1 -0
  127. package/dist/tools/agent/hire.d.ts +2 -2
  128. package/dist/tools/agent/hire.d.ts.map +1 -1
  129. package/dist/tools/agent/hire.js +43 -10
  130. package/dist/tools/agent/hire.js.map +1 -1
  131. package/dist/tools/agent/index.d.ts +22 -19
  132. package/dist/tools/agent/index.d.ts.map +1 -1
  133. package/dist/tools/agent/index.js +29 -21
  134. package/dist/tools/agent/index.js.map +1 -1
  135. package/dist/tools/agent/prompt.d.ts +2 -2
  136. package/dist/tools/agent/prompt.d.ts.map +1 -1
  137. package/dist/tools/agent/prompt.js +19 -53
  138. package/dist/tools/agent/prompt.js.map +1 -1
  139. package/dist/tools/agent/registry.d.ts +74 -24
  140. package/dist/tools/agent/registry.d.ts.map +1 -1
  141. package/dist/tools/agent/registry.js +93 -48
  142. package/dist/tools/agent/registry.js.map +1 -1
  143. package/dist/tools/agent/report-group.d.ts +5 -0
  144. package/dist/tools/agent/report-group.d.ts.map +1 -0
  145. package/dist/tools/agent/report-group.js +50 -0
  146. package/dist/tools/agent/report-group.js.map +1 -0
  147. package/dist/tools/agent/report-parent.d.ts +5 -0
  148. package/dist/tools/agent/report-parent.d.ts.map +1 -0
  149. package/dist/tools/agent/report-parent.js +36 -0
  150. package/dist/tools/agent/report-parent.js.map +1 -0
  151. package/dist/tools/agent/types.d.ts +5 -0
  152. package/dist/tools/agent/types.d.ts.map +1 -0
  153. package/dist/tools/agent/types.js +17 -0
  154. package/dist/tools/agent/types.js.map +1 -0
  155. package/docs/agents.md +249 -228
  156. package/docs/api-reference.md +9 -4
  157. package/docs/getting-started.md +78 -78
  158. package/docs/index.md +24 -23
  159. package/docs/mcp-architecture.md +71 -6
  160. package/docs/providers.md +258 -254
  161. package/docs/skills.md +0 -1
  162. package/docs/streaming.md +133 -133
  163. package/docs/swarm.md +503 -0
  164. package/docs/tools.md +214 -212
  165. package/package.json +1 -1
  166. package/dist/core/image-describer.d.ts +0 -19
  167. package/dist/core/image-describer.d.ts.map +0 -1
  168. package/dist/core/image-describer.js +0 -37
  169. package/dist/core/image-describer.js.map +0 -1
  170. package/dist/core/worker-agent.d.ts +0 -43
  171. package/dist/core/worker-agent.d.ts.map +0 -1
  172. package/dist/core/worker-agent.js +0 -40
  173. package/dist/core/worker-agent.js.map +0 -1
  174. package/dist/skills/shopping.d.ts +0 -4
  175. package/dist/skills/shopping.d.ts.map +0 -1
  176. package/dist/skills/shopping.js +0 -71
  177. package/dist/skills/shopping.js.map +0 -1
  178. package/dist/tools/agent/interaction.d.ts +0 -25
  179. package/dist/tools/agent/interaction.d.ts.map +0 -1
  180. package/dist/tools/agent/interaction.js +0 -14
  181. package/dist/tools/agent/interaction.js.map +0 -1
  182. package/dist/tools/agent/list.d.ts +0 -5
  183. package/dist/tools/agent/list.d.ts.map +0 -1
  184. package/dist/tools/agent/list.js +0 -16
  185. package/dist/tools/agent/list.js.map +0 -1
  186. package/dist/tools/agent/report.d.ts +0 -12
  187. package/dist/tools/agent/report.d.ts.map +0 -1
  188. package/dist/tools/agent/report.js +0 -31
  189. package/dist/tools/agent/report.js.map +0 -1
  190. package/dist/tools/bash/interaction.d.ts +0 -29
  191. package/dist/tools/bash/interaction.d.ts.map +0 -1
  192. package/dist/tools/bash/interaction.js +0 -13
  193. package/dist/tools/bash/interaction.js.map +0 -1
  194. package/dist/tools/browser/interaction.d.ts +0 -49
  195. package/dist/tools/browser/interaction.d.ts.map +0 -1
  196. package/dist/tools/browser/interaction.js +0 -14
  197. package/dist/tools/browser/interaction.js.map +0 -1
  198. package/dist/tools/fs/interaction.d.ts +0 -37
  199. package/dist/tools/fs/interaction.d.ts.map +0 -1
  200. package/dist/tools/fs/interaction.js +0 -13
  201. package/dist/tools/fs/interaction.js.map +0 -1
  202. package/dist/tools/present/interaction.d.ts +0 -17
  203. package/dist/tools/present/interaction.d.ts.map +0 -1
  204. package/dist/tools/present/interaction.js +0 -15
  205. package/dist/tools/present/interaction.js.map +0 -1
  206. package/dist/tools/question-answer/interaction.d.ts +0 -14
  207. package/dist/tools/question-answer/interaction.d.ts.map +0 -1
  208. package/dist/tools/question-answer/interaction.js +0 -13
  209. package/dist/tools/question-answer/interaction.js.map +0 -1
  210. package/dist/tools/todo/interaction.d.ts +0 -30
  211. package/dist/tools/todo/interaction.d.ts.map +0 -1
  212. package/dist/tools/todo/interaction.js +0 -13
  213. package/dist/tools/todo/interaction.js.map +0 -1
@@ -2,26 +2,59 @@ import { MCPTool } from "../../core/mcp.js";
2
2
  export const AgentHireTool = (registry) => {
3
3
  const maxHired = registry.getMaxHired();
4
4
  const limitNote = maxHired !== undefined
5
- ? ` At most ${maxHired} worker agent${maxHired === 1 ? "" : "s"} may be hired at once — hiring beyond that will fail until fewer than ${maxHired} are currently hired, so choose which agent(s) to hire carefully.`
5
+ ? ` At most ${maxHired} agent${maxHired === 1 ? "" : "s"} may be hired across the whole swarm at once — that budget is shared with every other agent that can hire, so check agent-types for remaining slots and fire what you no longer need.`
6
6
  : "";
7
7
  return new MCPTool({
8
8
  name: "agent-hire",
9
- description: `hire a worker agent by name (see agent-list), making it active. Required once per agent before agent-prompt will work on it — hiring the same agent again is a harmless no-op.${limitNote}`,
9
+ description: `hire a new agent of one of the types from agent-types. It starts idle — use agent-prompt to give it work — and reports back only to you.${limitNote}`,
10
10
  inputs: [
11
11
  {
12
- name: "name",
12
+ name: "type",
13
13
  type: "string",
14
- description: "the worker agent's name, exactly as shown by agent-list",
14
+ description: "the agent type to hire, exactly as agent-types spells it",
15
15
  required: true,
16
16
  },
17
+ {
18
+ name: "group",
19
+ type: "string",
20
+ description: "optional group name to put this agent in. Agents in the same group can broadcast to each other with agent-report-group without going through you — useful when several agents work the same area and need to stay in sync.",
21
+ required: false,
22
+ },
23
+ {
24
+ name: "briefing",
25
+ type: "string",
26
+ description: "optional context appended to this agent's standing instruction for its whole lifetime — the project background it should never forget. Per-task work goes in agent-prompt instead.",
27
+ required: false,
28
+ },
17
29
  ],
18
- execute: async (_envID, inputs, _toolCallId, _mcp) => {
19
- const { name } = inputs;
20
- if (!name || typeof name !== "string") {
21
- throw new Error("name must be a non-empty string");
30
+ execute: async (_envID, inputs) => {
31
+ const { type, group, briefing } = inputs;
32
+ if (!type || typeof type !== "string") {
33
+ throw new Error("type must be a non-empty string");
34
+ }
35
+ if (group !== undefined && typeof group !== "string") {
36
+ throw new Error("group must be a string when given");
37
+ }
38
+ if (briefing !== undefined && typeof briefing !== "string") {
39
+ throw new Error("briefing must be a string when given");
40
+ }
41
+ const { controller, agentId } = registry.requireCaller();
42
+ if (!registry.requireAgent(controller, agentId).active) {
43
+ throw new Error("a fired agent cannot hire.");
44
+ }
45
+ const limit = registry.getMaxHired();
46
+ if (limit !== undefined && registry.countHired() >= limit) {
47
+ throw new Error(`cannot hire "${type}" — the swarm's shared limit of ${limit} hired agent(s) is already reached. ` +
48
+ `Fire an agent you no longer need (agent-fire), or use one already working (agent-active).`);
22
49
  }
23
- registry.hire(name);
24
- return { hired: true, name };
50
+ const hired = await registry.request("agent-hire", agentId, { type, group, briefing });
51
+ return {
52
+ hired: true,
53
+ agentId: hired.agentId,
54
+ type: hired.type,
55
+ groups: hired.groups,
56
+ remaining: registry.getRemaining() ?? null,
57
+ };
25
58
  },
26
59
  });
27
60
  };
@@ -1 +1 @@
1
- {"version":3,"file":"hire.js","sourceRoot":"","sources":["../../../src/tools/agent/hire.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAY,MAAM,mBAAmB,CAAC;AAGtD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAAuB,EAAE,EAAE;IACrD,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IACxC,MAAM,SAAS,GAAG,QAAQ,KAAK,SAAS;QACpC,CAAC,CAAC,YAAY,QAAQ,gBAAgB,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,yEAAyE,QAAQ,mEAAmE;QACnN,CAAC,CAAC,EAAE,CAAC;IAET,OAAO,IAAI,OAAO,CAAC;QACf,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,iLAAiL,SAAS,EAAE;QACzM,MAAM,EAAE;YACJ;gBACI,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,yDAAyD;gBACtE,QAAQ,EAAE,IAAI;aACjB;SACJ;QACD,OAAO,EAAE,KAAK,EACV,MAAc,EACd,MAA2B,EAC3B,WAAoB,EACpB,IAAU,EACE,EAAE;YACd,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;YAExB,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACpC,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;YACvD,CAAC;YAED,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEpB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QACjC,CAAC;KACJ,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"hire.js","sourceRoot":"","sources":["../../../src/tools/agent/hire.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAI5C,MAAM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MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;YAC5D,CAAC;YAED,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC,aAAa,EAAE,CAAC;YAEzD,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;gBACrD,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;YAClD,CAAC;YAED,MAAM,KAAK,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;YACrC,IAAI,KAAK,KAAK,SAAS,IAAI,QAAQ,CAAC,UAAU,EAAE,IAAI,KAAK,EAAE,CAAC;gBACxD,MAAM,IAAI,KAAK,CACX,gBAAgB,IAAI,mCAAmC,KAAK,sCAAsC;oBAClG,2FAA2F,CAC9F,CAAC;YACN,CAAC;YAED,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAiB,YAAY,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;YAEvG,OAAO;gBACH,KAAK,EAAE,IAAI;gBACX,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,SAAS,EAAE,QAAQ,CAAC,YAAY,EAAE,IAAI,IAAI;aAC7C,CAAC;QACN,CAAC;KACJ,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -1,25 +1,28 @@
1
- export { AgentListTool } from "./list.js";
1
+ export { AgentTypesTool } from "./types.js";
2
2
  export { AgentHireTool } from "./hire.js";
3
+ export { AgentFireTool } from "./fire.js";
4
+ export { AgentActiveTool } from "./active.js";
3
5
  export { AgentPromptTool } from "./prompt.js";
4
- export { AgentReportTool } from "./report.js";
5
- export { AgentRegistry } from "./registry.js";
6
- export type { AgentInfo } from "./registry.js";
7
- import type WorkerAgent from "../../core/worker-agent.js";
6
+ export { AgentReportParentTool } from "./report-parent.js";
7
+ export { AgentReportGroupTool } from "./report-group.js";
8
+ export { AgentToolsRegistry } from "./registry.js";
9
+ export type { SwarmController, SwarmAgentTypeInfo, SwarmAgentInfo, AgentToolsEvent, AgentToolsAck, AgentToolsListener, } from "./registry.js";
10
+ import type MCPTool from "../../core/mcp.js";
11
+ import { type AgentToolsEvent, type AgentToolsListener, type SwarmController } from "./registry.js";
8
12
  export interface AgentToolsOptions {
9
- /** Cap on how many workers may be hired at once. Omit for no limit. Surfaced dynamically in agent-hire's own description (and in agent-list's output) so the model knows the constraint without being told out of band. */
10
13
  maxHired?: number;
11
14
  }
12
- /**
13
- * EXPERIMENTAL — see the note on WorkerAgent (src/core/worker-agent.ts).
14
- *
15
- * Planner-side tools for a fixed roster of WorkerAgents: list them, hire
16
- * one, and prompt a hired one. Each call builds its own AgentRegistry, so
17
- * separate AgentTools(...) calls (e.g. for two different planners in the
18
- * same process) never share hire state.
19
- *
20
- * Not included here: AgentReportTool — that one goes on each *worker's*
21
- * own tool list instead, not the planner's. Import it separately.
22
- */
23
- export declare const AgentTools: (availableAgents: WorkerAgent[], options?: AgentToolsOptions) => import("../../index.js").MCPTool[];
24
- export default AgentTools;
15
+ export interface AgentToolsHandle {
16
+ readonly tools: MCPTool[];
17
+ readonly id: string;
18
+ getMaxHired(): number | undefined;
19
+ /** Lets the tools read the swarm's roster. SwarmBase calls this. */
20
+ attach(swarm: SwarmController): void;
21
+ /** Subscribe to what the tools ask the swarm to do. SwarmBase calls this, once per event. */
22
+ on(event: AgentToolsEvent, listener: AgentToolsListener): void;
23
+ /** Run an agent's turn labelled with its id, so tools called during it know their caller. SwarmBase wraps every run in this. */
24
+ runAs<T>(agentId: string, fn: () => Promise<T>): Promise<T>;
25
+ }
26
+ export declare const getAgentTools: (options?: AgentToolsOptions) => AgentToolsHandle;
27
+ export default getAgentTools;
25
28
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,YAAY,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,KAAK,WAAW,MAAM,4BAA4B,CAAC;AAM1D,MAAM,WAAW,iBAAiB;IAC9B,2NAA2N;IAC3N,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,GAAI,iBAAiB,WAAW,EAAE,EAAE,UAAS,iBAAsB,uCAOzF,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,YAAY,EACR,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,aAAa,EACb,kBAAkB,GACrB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAC;AAC7C,OAA2B,EAAE,KAAK,eAAe,EAAE,KAAK,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AASxH,MAAM,WAAW,iBAAiB;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,WAAW,IAAI,MAAM,GAAG,SAAS,CAAC;IAClC,oEAAoE;IACpE,MAAM,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAAC;IACrC,6FAA6F;IAC7F,EAAE,CAAC,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAC/D,gIAAgI;IAChI,KAAK,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC/D;AAED,eAAO,MAAM,aAAa,GAAI,UAAS,iBAAsB,KAAG,gBAqB/D,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -1,30 +1,38 @@
1
- export { AgentListTool } from "./list.js";
1
+ export { AgentTypesTool } from "./types.js";
2
2
  export { AgentHireTool } from "./hire.js";
3
+ export { AgentFireTool } from "./fire.js";
4
+ export { AgentActiveTool } from "./active.js";
3
5
  export { AgentPromptTool } from "./prompt.js";
4
- export { AgentReportTool } from "./report.js";
5
- export { AgentRegistry } from "./registry.js";
6
- import { AgentListTool } from "./list.js";
6
+ export { AgentReportParentTool } from "./report-parent.js";
7
+ export { AgentReportGroupTool } from "./report-group.js";
8
+ export { AgentToolsRegistry } from "./registry.js";
9
+ import AgentToolsRegistry, {} from "./registry.js";
10
+ import { AgentTypesTool } from "./types.js";
7
11
  import { AgentHireTool } from "./hire.js";
12
+ import { AgentFireTool } from "./fire.js";
13
+ import { AgentActiveTool } from "./active.js";
8
14
  import { AgentPromptTool } from "./prompt.js";
9
- import { AgentRegistry } from "./registry.js";
10
- /**
11
- * EXPERIMENTAL — see the note on WorkerAgent (src/core/worker-agent.ts).
12
- *
13
- * Planner-side tools for a fixed roster of WorkerAgents: list them, hire
14
- * one, and prompt a hired one. Each call builds its own AgentRegistry, so
15
- * separate AgentTools(...) calls (e.g. for two different planners in the
16
- * same process) never share hire state.
17
- *
18
- * Not included here: AgentReportTool — that one goes on each *worker's*
19
- * own tool list instead, not the planner's. Import it separately.
20
- */
21
- export const AgentTools = (availableAgents, options = {}) => {
22
- const registry = new AgentRegistry(availableAgents, options.maxHired);
23
- return [
24
- AgentListTool(registry),
15
+ import { AgentReportParentTool } from "./report-parent.js";
16
+ import { AgentReportGroupTool } from "./report-group.js";
17
+ export const getAgentTools = (options = {}) => {
18
+ const registry = new AgentToolsRegistry(options.maxHired);
19
+ const tools = [
20
+ AgentTypesTool(registry),
25
21
  AgentHireTool(registry),
22
+ AgentFireTool(registry),
23
+ AgentActiveTool(registry),
26
24
  AgentPromptTool(registry),
25
+ AgentReportParentTool(registry),
26
+ AgentReportGroupTool(registry),
27
27
  ];
28
+ return {
29
+ tools,
30
+ id: registry.id,
31
+ getMaxHired: () => registry.getMaxHired(),
32
+ attach: (swarm) => registry.attach(swarm),
33
+ on: (event, listener) => { registry.on(event, listener); },
34
+ runAs: (agentId, fn) => registry.runAs(agentId, fn),
35
+ };
28
36
  };
29
- export default AgentTools;
37
+ export default getAgentTools;
30
38
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;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1
1
  import { MCPTool } from "../../core/mcp.js";
2
- import type AgentRegistry from "./registry.js";
3
- export declare const AgentPromptTool: (registry: AgentRegistry) => MCPTool;
2
+ import type AgentToolsRegistry from "./registry.js";
3
+ export declare const AgentPromptTool: (registry: AgentToolsRegistry) => MCPTool;
4
4
  export default AgentPromptTool;
5
5
  //# sourceMappingURL=prompt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../src/tools/agent/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAY,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,aAAa,MAAM,eAAe,CAAC;AAE/C,eAAO,MAAM,eAAe,GAAI,UAAU,aAAa,YAqFrD,CAAC;AAEH,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../src/tools/agent/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,kBAAkB,MAAM,eAAe,CAAC;AAEpD,eAAO,MAAM,eAAe,GAAI,UAAU,kBAAkB,YA+C1D,CAAC;AAEH,eAAe,eAAe,CAAC"}
@@ -1,76 +1,42 @@
1
1
  import { MCPTool } from "../../core/mcp.js";
2
2
  export const AgentPromptTool = (registry) => new MCPTool({
3
3
  name: "agent-prompt",
4
- description: "send a prompt to a hired worker agent and wait for its response. The worker runs its own full turn (its own reasoning, its own tools) and either calls agent-report to hand back a result, or just stops on its own — either way this returns once it's done. You can call this again later on the same agent to continue the conversation (it remembers everything from earlier prompts), or move on and never call it again if its report says the work is finished.",
4
+ description: "give a task to an agent you hired. Returns as soon as the task is handed over — the agent works in parallel with you and its answer arrives later as a report message from it, so do not wait or poll for a result. You can prompt several agents in a row to run them at the same time. Prompting an agent that is already mid-task adds your message to its current work rather than starting it over.",
5
5
  inputs: [
6
6
  {
7
- name: "name",
7
+ name: "agentId",
8
8
  type: "string",
9
- description: "the hired worker agent's name, exactly as shown by agent-list",
9
+ description: "id of the agent to task, as returned by agent-hire or shown in agent-active",
10
10
  required: true,
11
11
  },
12
12
  {
13
13
  name: "prompt",
14
14
  type: "string",
15
- description: "the message to send to the worker agent",
15
+ description: "the task, written to stand on its own — the agent cannot see your conversation, only what you send here and the briefing it was hired with",
16
16
  required: true,
17
17
  },
18
18
  ],
19
- execute: async (_envID, inputs, _toolCallId, _mcp) => {
20
- const { name, prompt } = inputs;
21
- if (!name || typeof name !== "string") {
22
- throw new Error("name must be a non-empty string");
19
+ execute: async (_envID, inputs) => {
20
+ const { agentId: target, prompt } = inputs;
21
+ if (!target || typeof target !== "string") {
22
+ throw new Error("agentId must be a non-empty string");
23
23
  }
24
24
  if (!prompt || typeof prompt !== "string") {
25
25
  throw new Error("prompt must be a non-empty string");
26
26
  }
27
- const agent = registry.get(name);
28
- if (!agent) {
29
- throw new Error(`no worker agent named "${name}" — check agent-list for available names.`);
27
+ const { controller, agentId } = registry.requireCaller();
28
+ const info = registry.requireAgent(controller, target);
29
+ if (!info.active) {
30
+ throw new Error(`"${target}" has been fired and can no longer be prompted.`);
30
31
  }
31
- if (!registry.isHired(name)) {
32
- throw new Error(`worker agent "${name}" is not hired yet — call agent-hire first.`);
32
+ if (info.parentId !== agentId) {
33
+ throw new Error(`only ${info.parentId}, the agent that hired "${target}", can prompt it.`);
33
34
  }
34
- // retiredMessages and messagesCompact are disjoint (retiredMessages holds
35
- // only what's already been retired by a compact_memory call) —
36
- // concatenated, in that order, they're the complete chronological
37
- // history. A mid-turn compaction just re-partitions that same sequence
38
- // between the two arrays without changing its order or length, so
39
- // diffing total count across both arrays stays valid even if one happens.
40
- const statesBefore = agent.getCurrentAgentStates();
41
- const beforeLength = statesBefore.retiredMessages.length + statesBefore.messagesCompact.length;
42
- await agent.run(prompt);
43
- // Only look at messages this specific call produced — otherwise a
44
- // worker that answers in plain text (no fresh agent-report) could
45
- // surface a stale report left over from an earlier prompt.
46
- const statesAfter = agent.getCurrentAgentStates();
47
- const newMessages = [...statesAfter.retiredMessages, ...statesAfter.messagesCompact].slice(beforeLength);
48
- let report;
49
- let reported = false;
50
- for (let i = newMessages.length - 1; i >= 0; i--) {
51
- const msg = newMessages[i];
52
- if (msg.role === "tool" && msg.toolName === "agent-report") {
53
- try {
54
- report = JSON.parse(msg.content || "{}").report;
55
- }
56
- catch {
57
- report = msg.content;
58
- }
59
- reported = true;
60
- break;
61
- }
62
- }
63
- if (!reported) {
64
- for (let i = newMessages.length - 1; i >= 0; i--) {
65
- const msg = newMessages[i];
66
- if (msg.role === "assistant" && msg.content) {
67
- report = msg.content;
68
- break;
69
- }
70
- }
71
- }
72
- report ??= "(worker agent produced no output this turn)";
73
- return { report, reported };
35
+ await registry.request("agent-prompt", agentId, {
36
+ to: [target],
37
+ message: `[task from ${agentId}, the agent that hired you]\n${prompt}`,
38
+ });
39
+ return { dispatched: true, agentId: target };
74
40
  },
75
41
  });
76
42
  export default AgentPromptTool;
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../src/tools/agent/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAY,MAAM,mBAAmB,CAAC;AAGtD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAAuB,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC;IACpE,IAAI,EAAE,cAAc;IACpB,WAAW,EAAE,wcAAwc;IACrd,MAAM,EAAE;QACJ;YACI,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,+DAA+D;YAC5E,QAAQ,EAAE,IAAI;SACjB;QACD;YACI,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,yCAAyC;YACtD,QAAQ,EAAE,IAAI;SACjB;KACJ;IACD,OAAO,EAAE,KAAK,EACV,MAAc,EACd,MAA2B,EAC3B,WAAoB,EACpB,IAAU,EACE,EAAE;QACd,MAAM,EA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AM,CAAC;YACZ,OAAO,EAAE,cAAc,OAAO,gCAAgC,MAAM,EAAE;SACzE,CAAC,CAAC;QAEH,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IACjD,CAAC;CACJ,CAAC,CAAC;AAEH,eAAe,eAAe,CAAC"}
@@ -1,33 +1,83 @@
1
- import type WorkerAgent from "../../core/worker-agent.js";
2
- import type { WorkerAgentRating } from "../../core/worker-agent.js";
3
- export interface AgentInfo {
4
- name: string;
1
+ import EventEmitter from "events";
2
+ export interface SwarmAgentTypeInfo {
3
+ type: string;
5
4
  description: string;
6
- rating: WorkerAgentRating;
7
- hired: boolean;
5
+ rating?: Record<string, number>;
6
+ /** How many agents of this type are hired and still active right now. */
7
+ active: number;
8
+ }
9
+ export interface SwarmAgentInfo {
10
+ agentId: string;
11
+ type: string;
12
+ parentId?: string;
13
+ groups: string[];
14
+ active: boolean;
15
+ busy: boolean;
16
+ /**
17
+ * True from the moment its parent tasks it until it reports back.
18
+ *
19
+ * Read together with `busy`, this is what separates the three states that
20
+ * otherwise all look like "not running": `busy` means it is working right
21
+ * now; `awaitingReport` without `busy` means it was given a task, is not
22
+ * running, and has not answered — it has paused mid-task, which in practice
23
+ * means it is blocked on something outside the swarm, such as a question
24
+ * put to the user. Neither flag set means it is idle with nothing owed.
25
+ *
26
+ * Without this a parent cannot tell a paused agent from a dead one, and
27
+ * tends to re-task or fire an agent that was only waiting.
28
+ */
29
+ awaitingReport: boolean;
30
+ }
31
+ /**
32
+ * What a swarm lets the agent tools *read*. Nothing here changes anything — the
33
+ * swarm's job is to know the state of its agents, and every action goes back to
34
+ * it as an event instead (see AgentToolsEvent below).
35
+ */
36
+ export interface SwarmController {
37
+ listTypes(): SwarmAgentTypeInfo[];
38
+ /** Every agent, active or not, in creation order. */
39
+ listAgents(): SwarmAgentInfo[];
40
+ getAgentInfo(agentId: string): SwarmAgentInfo | undefined;
41
+ /** The agent the user talks to — it has no parent and cannot be fired. */
42
+ isEntrypoint(agentId: string): boolean;
8
43
  }
9
44
  /**
10
- * In-memory catalog of WorkerAgents a planner can see/hire/prompt, plus
11
- * which of them are currently "active" (hired). Scoped to one AgentTools()
12
- * call — not a process-wide singleton — so multiple independent planners in
13
- * the same process each get their own roster and hire state.
45
+ * Everything a tool asks the swarm to *do*. The tool has already decided it is
46
+ * allowed (parentage, hire cap, group membership) and has already written the
47
+ * message the receiving agent will see; the swarm only carries it out.
14
48
  *
15
- * WorkerAgent instances are live objects (their own AI provider, message
16
- * history, etc.), not serializable data, so — unlike MCPTool state such as
17
- * TodoTools' lists — this can't live in MCPStorage. The roster itself is
18
- * fixed at construction (only the developer can safely wire up a worker's
19
- * provider/instruction/tools); the model can only hire/prompt from what's
20
- * already here, never create new ones.
49
+ * - `agent-hire` — payload `{ type, group?, briefing? }`, acked with the new `SwarmAgentInfo`
50
+ * - `agent-fire` — payload `{ agentId }`, acked with nothing
51
+ * - `agent-prompt` / `agent-report-parent` / `agent-report-group`
52
+ * — payload `{ to: string[], message: string }`, acked with nothing
21
53
  */
22
- export declare class AgentRegistry {
54
+ export type AgentToolsEvent = "agent-hire" | "agent-fire" | "agent-prompt" | "agent-report-parent" | "agent-report-group";
55
+ /** Called by the swarm once it has carried the request out — `done(error)` to fail the tool call, `done(null, result)` to answer it. */
56
+ export type AgentToolsAck<T = void> = (error?: Error | null, result?: T) => void;
57
+ export type AgentToolsListener = (agentId: string, payload: any, done: AgentToolsAck<any>) => void;
58
+ export declare class AgentToolsRegistry extends EventEmitter {
23
59
  #private;
24
- constructor(agents: WorkerAgent[], maxHired?: number);
60
+ readonly id: string;
61
+ constructor(maxHired?: number);
25
62
  getMaxHired(): number | undefined;
26
- getHiredCount(): number;
27
- list(): AgentInfo[];
28
- hire(name: string): void;
29
- isHired(name: string): boolean;
30
- get(name: string): WorkerAgent | undefined;
63
+ attach(controller: SwarmController): void;
64
+ isAttached(): boolean;
65
+ requireController(): SwarmController;
66
+ /** Run an agent's turn labelled with its id. SwarmBase wraps every `BaseAgent.run()` in this. */
67
+ runAs<T>(agentId: string, fn: () => Promise<T>): Promise<T>;
68
+ currentAgentId(): string | undefined;
69
+ /** The caller and the swarm, or a tool error saying which of the two is missing. */
70
+ requireCaller(): {
71
+ controller: SwarmController;
72
+ agentId: string;
73
+ };
74
+ /** Ask the swarm to carry something out, and wait for its ack. */
75
+ request<T = void>(event: AgentToolsEvent, agentId: string, payload: Record<string, any>): Promise<T>;
76
+ /** Hired agents still active — the entrypoint agent is not one of them. */
77
+ countHired(): number;
78
+ getRemaining(): number | undefined;
79
+ /** Look an agent up the way a tool needs it: with an error the model can act on. */
80
+ requireAgent(controller: SwarmController, agentId: string): SwarmAgentInfo;
31
81
  }
32
- export default AgentRegistry;
82
+ export default AgentToolsRegistry;
33
83
  //# sourceMappingURL=registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/tools/agent/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,aAAa;;gBAKV,MAAM,EAAE,WAAW,EAAE,EAAE,QAAQ,CAAC,EAAE,MAAM;IAepD,WAAW,IAAI,MAAM,GAAG,SAAS;IAIjC,aAAa,IAAI,MAAM;IAIvB,IAAI,IAAI,SAAS,EAAE;IASnB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAkBxB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI9B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;CAG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