@open-multi-agent/core 1.4.0

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 (207) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +373 -0
  3. package/dist/agent/agent.d.ts +153 -0
  4. package/dist/agent/agent.d.ts.map +1 -0
  5. package/dist/agent/agent.js +559 -0
  6. package/dist/agent/agent.js.map +1 -0
  7. package/dist/agent/loop-detector.d.ts +39 -0
  8. package/dist/agent/loop-detector.d.ts.map +1 -0
  9. package/dist/agent/loop-detector.js +122 -0
  10. package/dist/agent/loop-detector.js.map +1 -0
  11. package/dist/agent/pool.d.ts +158 -0
  12. package/dist/agent/pool.d.ts.map +1 -0
  13. package/dist/agent/pool.js +320 -0
  14. package/dist/agent/pool.js.map +1 -0
  15. package/dist/agent/runner.d.ts +242 -0
  16. package/dist/agent/runner.d.ts.map +1 -0
  17. package/dist/agent/runner.js +943 -0
  18. package/dist/agent/runner.js.map +1 -0
  19. package/dist/agent/structured-output.d.ts +33 -0
  20. package/dist/agent/structured-output.d.ts.map +1 -0
  21. package/dist/agent/structured-output.js +116 -0
  22. package/dist/agent/structured-output.js.map +1 -0
  23. package/dist/cli/oma.d.ts +30 -0
  24. package/dist/cli/oma.d.ts.map +1 -0
  25. package/dist/cli/oma.js +433 -0
  26. package/dist/cli/oma.js.map +1 -0
  27. package/dist/dashboard/layout-tasks.d.ts +23 -0
  28. package/dist/dashboard/layout-tasks.d.ts.map +1 -0
  29. package/dist/dashboard/layout-tasks.js +79 -0
  30. package/dist/dashboard/layout-tasks.js.map +1 -0
  31. package/dist/dashboard/render-team-run-dashboard.d.ts +11 -0
  32. package/dist/dashboard/render-team-run-dashboard.d.ts.map +1 -0
  33. package/dist/dashboard/render-team-run-dashboard.js +456 -0
  34. package/dist/dashboard/render-team-run-dashboard.js.map +1 -0
  35. package/dist/errors.d.ts +14 -0
  36. package/dist/errors.d.ts.map +1 -0
  37. package/dist/errors.js +20 -0
  38. package/dist/errors.js.map +1 -0
  39. package/dist/index.d.ts +79 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +92 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/llm/adapter.d.ts +54 -0
  44. package/dist/llm/adapter.d.ts.map +1 -0
  45. package/dist/llm/adapter.js +101 -0
  46. package/dist/llm/adapter.js.map +1 -0
  47. package/dist/llm/anthropic.d.ts +57 -0
  48. package/dist/llm/anthropic.d.ts.map +1 -0
  49. package/dist/llm/anthropic.js +432 -0
  50. package/dist/llm/anthropic.js.map +1 -0
  51. package/dist/llm/azure-openai.d.ts +74 -0
  52. package/dist/llm/azure-openai.d.ts.map +1 -0
  53. package/dist/llm/azure-openai.js +267 -0
  54. package/dist/llm/azure-openai.js.map +1 -0
  55. package/dist/llm/bedrock.d.ts +41 -0
  56. package/dist/llm/bedrock.d.ts.map +1 -0
  57. package/dist/llm/bedrock.js +345 -0
  58. package/dist/llm/bedrock.js.map +1 -0
  59. package/dist/llm/copilot.d.ts +92 -0
  60. package/dist/llm/copilot.d.ts.map +1 -0
  61. package/dist/llm/copilot.js +433 -0
  62. package/dist/llm/copilot.js.map +1 -0
  63. package/dist/llm/deepseek.d.ts +21 -0
  64. package/dist/llm/deepseek.d.ts.map +1 -0
  65. package/dist/llm/deepseek.js +24 -0
  66. package/dist/llm/deepseek.js.map +1 -0
  67. package/dist/llm/gemini.d.ts +65 -0
  68. package/dist/llm/gemini.d.ts.map +1 -0
  69. package/dist/llm/gemini.js +427 -0
  70. package/dist/llm/gemini.js.map +1 -0
  71. package/dist/llm/grok.d.ts +21 -0
  72. package/dist/llm/grok.d.ts.map +1 -0
  73. package/dist/llm/grok.js +24 -0
  74. package/dist/llm/grok.js.map +1 -0
  75. package/dist/llm/minimax.d.ts +21 -0
  76. package/dist/llm/minimax.d.ts.map +1 -0
  77. package/dist/llm/minimax.js +24 -0
  78. package/dist/llm/minimax.js.map +1 -0
  79. package/dist/llm/openai-common.d.ts +65 -0
  80. package/dist/llm/openai-common.d.ts.map +1 -0
  81. package/dist/llm/openai-common.js +286 -0
  82. package/dist/llm/openai-common.js.map +1 -0
  83. package/dist/llm/openai.d.ts +63 -0
  84. package/dist/llm/openai.d.ts.map +1 -0
  85. package/dist/llm/openai.js +256 -0
  86. package/dist/llm/openai.js.map +1 -0
  87. package/dist/llm/qiniu.d.ts +21 -0
  88. package/dist/llm/qiniu.d.ts.map +1 -0
  89. package/dist/llm/qiniu.js +24 -0
  90. package/dist/llm/qiniu.js.map +1 -0
  91. package/dist/mcp.d.ts +3 -0
  92. package/dist/mcp.d.ts.map +1 -0
  93. package/dist/mcp.js +2 -0
  94. package/dist/mcp.js.map +1 -0
  95. package/dist/memory/shared.d.ts +162 -0
  96. package/dist/memory/shared.d.ts.map +1 -0
  97. package/dist/memory/shared.js +294 -0
  98. package/dist/memory/shared.js.map +1 -0
  99. package/dist/memory/store.d.ts +72 -0
  100. package/dist/memory/store.d.ts.map +1 -0
  101. package/dist/memory/store.js +121 -0
  102. package/dist/memory/store.js.map +1 -0
  103. package/dist/orchestrator/orchestrator.d.ts +245 -0
  104. package/dist/orchestrator/orchestrator.d.ts.map +1 -0
  105. package/dist/orchestrator/orchestrator.js +1400 -0
  106. package/dist/orchestrator/orchestrator.js.map +1 -0
  107. package/dist/orchestrator/scheduler.d.ts +112 -0
  108. package/dist/orchestrator/scheduler.d.ts.map +1 -0
  109. package/dist/orchestrator/scheduler.js +256 -0
  110. package/dist/orchestrator/scheduler.js.map +1 -0
  111. package/dist/task/queue.d.ts +191 -0
  112. package/dist/task/queue.d.ts.map +1 -0
  113. package/dist/task/queue.js +408 -0
  114. package/dist/task/queue.js.map +1 -0
  115. package/dist/task/task.d.ts +90 -0
  116. package/dist/task/task.d.ts.map +1 -0
  117. package/dist/task/task.js +206 -0
  118. package/dist/task/task.js.map +1 -0
  119. package/dist/team/messaging.d.ts +106 -0
  120. package/dist/team/messaging.d.ts.map +1 -0
  121. package/dist/team/messaging.js +183 -0
  122. package/dist/team/messaging.js.map +1 -0
  123. package/dist/team/team.d.ts +141 -0
  124. package/dist/team/team.d.ts.map +1 -0
  125. package/dist/team/team.js +293 -0
  126. package/dist/team/team.js.map +1 -0
  127. package/dist/tool/built-in/bash.d.ts +12 -0
  128. package/dist/tool/built-in/bash.d.ts.map +1 -0
  129. package/dist/tool/built-in/bash.js +133 -0
  130. package/dist/tool/built-in/bash.js.map +1 -0
  131. package/dist/tool/built-in/delegate.d.ts +29 -0
  132. package/dist/tool/built-in/delegate.d.ts.map +1 -0
  133. package/dist/tool/built-in/delegate.js +92 -0
  134. package/dist/tool/built-in/delegate.js.map +1 -0
  135. package/dist/tool/built-in/file-edit.d.ts +14 -0
  136. package/dist/tool/built-in/file-edit.d.ts.map +1 -0
  137. package/dist/tool/built-in/file-edit.js +130 -0
  138. package/dist/tool/built-in/file-edit.js.map +1 -0
  139. package/dist/tool/built-in/file-read.d.ts +12 -0
  140. package/dist/tool/built-in/file-read.d.ts.map +1 -0
  141. package/dist/tool/built-in/file-read.js +82 -0
  142. package/dist/tool/built-in/file-read.js.map +1 -0
  143. package/dist/tool/built-in/file-write.d.ts +11 -0
  144. package/dist/tool/built-in/file-write.d.ts.map +1 -0
  145. package/dist/tool/built-in/file-write.js +70 -0
  146. package/dist/tool/built-in/file-write.js.map +1 -0
  147. package/dist/tool/built-in/fs-walk.d.ts +23 -0
  148. package/dist/tool/built-in/fs-walk.d.ts.map +1 -0
  149. package/dist/tool/built-in/fs-walk.js +78 -0
  150. package/dist/tool/built-in/fs-walk.js.map +1 -0
  151. package/dist/tool/built-in/glob.d.ts +12 -0
  152. package/dist/tool/built-in/glob.d.ts.map +1 -0
  153. package/dist/tool/built-in/glob.js +82 -0
  154. package/dist/tool/built-in/glob.js.map +1 -0
  155. package/dist/tool/built-in/grep.d.ts +15 -0
  156. package/dist/tool/built-in/grep.d.ts.map +1 -0
  157. package/dist/tool/built-in/grep.js +218 -0
  158. package/dist/tool/built-in/grep.js.map +1 -0
  159. package/dist/tool/built-in/index.d.ts +48 -0
  160. package/dist/tool/built-in/index.d.ts.map +1 -0
  161. package/dist/tool/built-in/index.js +56 -0
  162. package/dist/tool/built-in/index.js.map +1 -0
  163. package/dist/tool/executor.d.ts +100 -0
  164. package/dist/tool/executor.d.ts.map +1 -0
  165. package/dist/tool/executor.js +184 -0
  166. package/dist/tool/executor.js.map +1 -0
  167. package/dist/tool/framework.d.ts +167 -0
  168. package/dist/tool/framework.d.ts.map +1 -0
  169. package/dist/tool/framework.js +402 -0
  170. package/dist/tool/framework.js.map +1 -0
  171. package/dist/tool/mcp.d.ts +31 -0
  172. package/dist/tool/mcp.d.ts.map +1 -0
  173. package/dist/tool/mcp.js +175 -0
  174. package/dist/tool/mcp.js.map +1 -0
  175. package/dist/tool/text-tool-extractor.d.ts +32 -0
  176. package/dist/tool/text-tool-extractor.d.ts.map +1 -0
  177. package/dist/tool/text-tool-extractor.js +195 -0
  178. package/dist/tool/text-tool-extractor.js.map +1 -0
  179. package/dist/types.d.ts +916 -0
  180. package/dist/types.d.ts.map +1 -0
  181. package/dist/types.js +8 -0
  182. package/dist/types.js.map +1 -0
  183. package/dist/utils/keywords.d.ts +18 -0
  184. package/dist/utils/keywords.d.ts.map +1 -0
  185. package/dist/utils/keywords.js +32 -0
  186. package/dist/utils/keywords.js.map +1 -0
  187. package/dist/utils/semaphore.d.ts +49 -0
  188. package/dist/utils/semaphore.d.ts.map +1 -0
  189. package/dist/utils/semaphore.js +89 -0
  190. package/dist/utils/semaphore.js.map +1 -0
  191. package/dist/utils/tokens.d.ts +7 -0
  192. package/dist/utils/tokens.d.ts.map +1 -0
  193. package/dist/utils/tokens.js +30 -0
  194. package/dist/utils/tokens.js.map +1 -0
  195. package/dist/utils/trace.d.ts +12 -0
  196. package/dist/utils/trace.d.ts.map +1 -0
  197. package/dist/utils/trace.js +30 -0
  198. package/dist/utils/trace.js.map +1 -0
  199. package/docs/DECISIONS.md +49 -0
  200. package/docs/cli.md +265 -0
  201. package/docs/context-management.md +24 -0
  202. package/docs/featured-partner.md +28 -0
  203. package/docs/observability.md +56 -0
  204. package/docs/providers.md +78 -0
  205. package/docs/shared-memory.md +27 -0
  206. package/docs/tool-configuration.md +152 -0
  207. package/package.json +96 -0
@@ -0,0 +1,559 @@
1
+ /**
2
+ * @fileoverview High-level Agent class for open-multi-agent.
3
+ *
4
+ * {@link Agent} is the primary interface most consumers interact with.
5
+ * It wraps {@link AgentRunner} with:
6
+ * - Persistent conversation history (`prompt()`)
7
+ * - Fresh-conversation semantics (`run()`)
8
+ * - Streaming support (`stream()`)
9
+ * - Dynamic tool registration at runtime
10
+ * - Full lifecycle state tracking (`idle → running → completed | error`)
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { Agent, ToolRegistry, ToolExecutor, registerBuiltInTools } from '@open-multi-agent/core'
15
+ *
16
+ * const registry = new ToolRegistry()
17
+ * registerBuiltInTools(registry)
18
+ * const executor = new ToolExecutor(registry)
19
+ *
20
+ * const agent = new Agent(
21
+ * {
22
+ * name: 'researcher',
23
+ * model: 'claude-sonnet-4-6',
24
+ * systemPrompt: 'You are a rigorous research assistant.',
25
+ * tools: ['file_read', 'grep'],
26
+ * },
27
+ * registry,
28
+ * executor,
29
+ * )
30
+ *
31
+ * const result = await agent.run('Summarise the project README.')
32
+ * console.log(result.output)
33
+ *
34
+ * // For one-shot runs without managing the Agent instance, use
35
+ * // `new OpenMultiAgent().runAgent(config, prompt)` instead.
36
+ * ```
37
+ */
38
+ import { emitTrace, generateRunId } from '../utils/trace.js';
39
+ import { createAdapter } from '../llm/adapter.js';
40
+ import { AgentRunner } from './runner.js';
41
+ import { buildStructuredOutputInstruction, extractJSON, validateOutput, } from './structured-output.js';
42
+ // ---------------------------------------------------------------------------
43
+ // Internal helpers
44
+ // ---------------------------------------------------------------------------
45
+ const ZERO_USAGE = { input_tokens: 0, output_tokens: 0 };
46
+ /**
47
+ * Combine two {@link AbortSignal}s so that aborting either one cancels the
48
+ * returned signal. Works on Node 18+ (no `AbortSignal.any` required).
49
+ */
50
+ function mergeAbortSignals(a, b) {
51
+ const controller = new AbortController();
52
+ if (a.aborted || b.aborted) {
53
+ controller.abort();
54
+ return controller.signal;
55
+ }
56
+ const abort = () => controller.abort();
57
+ a.addEventListener('abort', abort, { once: true });
58
+ b.addEventListener('abort', abort, { once: true });
59
+ return controller.signal;
60
+ }
61
+ function addUsage(a, b) {
62
+ return {
63
+ input_tokens: a.input_tokens + b.input_tokens,
64
+ output_tokens: a.output_tokens + b.output_tokens,
65
+ };
66
+ }
67
+ // ---------------------------------------------------------------------------
68
+ // Agent
69
+ // ---------------------------------------------------------------------------
70
+ /**
71
+ * High-level wrapper around {@link AgentRunner} that manages conversation
72
+ * history, state transitions, and tool lifecycle.
73
+ */
74
+ export class Agent {
75
+ name;
76
+ config;
77
+ runner = null;
78
+ state;
79
+ _toolRegistry;
80
+ _toolExecutor;
81
+ messageHistory = [];
82
+ /**
83
+ * @param config - Static configuration for this agent.
84
+ * @param toolRegistry - Registry used to resolve and manage tools.
85
+ * @param toolExecutor - Executor that dispatches tool calls.
86
+ *
87
+ * `toolRegistry` and `toolExecutor` are injected rather than instantiated
88
+ * internally so that teams of agents can share a single registry.
89
+ */
90
+ constructor(config, toolRegistry, toolExecutor) {
91
+ this.name = config.name;
92
+ this.config = config;
93
+ this._toolRegistry = toolRegistry;
94
+ this._toolExecutor = toolExecutor;
95
+ this.state = {
96
+ status: 'idle',
97
+ messages: [],
98
+ tokenUsage: ZERO_USAGE,
99
+ };
100
+ }
101
+ // -------------------------------------------------------------------------
102
+ // Initialisation (async, called lazily)
103
+ // -------------------------------------------------------------------------
104
+ /**
105
+ * Lazily create the {@link AgentRunner}.
106
+ *
107
+ * The adapter is created asynchronously (it may lazy-import provider SDKs),
108
+ * so we defer construction until the first `run` / `prompt` / `stream` call.
109
+ */
110
+ async getRunner() {
111
+ if (this.runner !== null) {
112
+ return this.runner;
113
+ }
114
+ const provider = this.config.provider ?? 'anthropic';
115
+ const adapter = await createAdapter(provider, this.config.apiKey, this.config.baseURL, this.config.region);
116
+ // Append structured-output instructions when an outputSchema is configured.
117
+ let effectiveSystemPrompt = this.config.systemPrompt;
118
+ if (this.config.outputSchema) {
119
+ const instruction = buildStructuredOutputInstruction(this.config.outputSchema);
120
+ effectiveSystemPrompt = effectiveSystemPrompt
121
+ ? effectiveSystemPrompt + '\n' + instruction
122
+ : instruction;
123
+ }
124
+ const runnerOptions = {
125
+ model: this.config.model,
126
+ systemPrompt: effectiveSystemPrompt,
127
+ maxTurns: this.config.maxTurns,
128
+ maxTokens: this.config.maxTokens,
129
+ temperature: this.config.temperature,
130
+ topP: this.config.topP,
131
+ topK: this.config.topK,
132
+ minP: this.config.minP,
133
+ parallelToolCalls: this.config.parallelToolCalls,
134
+ frequencyPenalty: this.config.frequencyPenalty,
135
+ presencePenalty: this.config.presencePenalty,
136
+ extraBody: this.config.extraBody,
137
+ thinking: this.config.thinking,
138
+ toolPreset: this.config.toolPreset,
139
+ allowedTools: this.config.tools,
140
+ disallowedTools: this.config.disallowedTools,
141
+ agentName: this.name,
142
+ agentRole: this.config.systemPrompt?.slice(0, 50) ?? 'assistant',
143
+ loopDetection: this.config.loopDetection,
144
+ maxTokenBudget: this.config.maxTokenBudget,
145
+ contextStrategy: this.config.contextStrategy,
146
+ compressToolResults: this.config.compressToolResults,
147
+ };
148
+ this.runner = new AgentRunner(adapter, this._toolRegistry, this._toolExecutor, runnerOptions);
149
+ return this.runner;
150
+ }
151
+ // -------------------------------------------------------------------------
152
+ // Primary execution methods
153
+ // -------------------------------------------------------------------------
154
+ /**
155
+ * Run `prompt` in a fresh conversation (history is NOT used).
156
+ *
157
+ * Equivalent to constructing a brand-new messages array `[{ role:'user', … }]`
158
+ * and calling the runner once. The agent's persistent history is not modified.
159
+ *
160
+ * Use this for one-shot queries where past context is irrelevant.
161
+ */
162
+ async run(prompt, runOptions) {
163
+ const messages = [
164
+ { role: 'user', content: [{ type: 'text', text: prompt }] },
165
+ ];
166
+ return this.executeRun(messages, runOptions);
167
+ }
168
+ /**
169
+ * Run `prompt` as part of the ongoing conversation.
170
+ *
171
+ * Appends the user message to the persistent history, runs the agent, then
172
+ * appends the resulting messages to the history for the next call.
173
+ *
174
+ * Use this for multi-turn interactions.
175
+ */
176
+ // TODO(#18): accept optional RunOptions to forward trace context
177
+ async prompt(message) {
178
+ const userMessage = {
179
+ role: 'user',
180
+ content: [{ type: 'text', text: message }],
181
+ };
182
+ this.messageHistory.push(userMessage);
183
+ const result = await this.executeRun([...this.messageHistory]);
184
+ // Persist the new messages into history so the next `prompt` sees them.
185
+ for (const msg of result.messages) {
186
+ this.messageHistory.push(msg);
187
+ }
188
+ return result;
189
+ }
190
+ /**
191
+ * Stream a fresh-conversation response, yielding {@link StreamEvent}s.
192
+ *
193
+ * Like {@link run}, this does not use or update the persistent history.
194
+ */
195
+ async *stream(prompt, runOptions) {
196
+ const messages = [
197
+ { role: 'user', content: [{ type: 'text', text: prompt }] },
198
+ ];
199
+ yield* this.executeStream(messages, runOptions);
200
+ }
201
+ // -------------------------------------------------------------------------
202
+ // State management
203
+ // -------------------------------------------------------------------------
204
+ /** Return a snapshot of the current agent state (does not clone nested objects). */
205
+ getState() {
206
+ return { ...this.state, messages: [...this.state.messages] };
207
+ }
208
+ /** Return a copy of the persistent message history. */
209
+ getHistory() {
210
+ return [...this.messageHistory];
211
+ }
212
+ /**
213
+ * Clear the persistent conversation history and reset state to `idle`.
214
+ * Does NOT discard the runner instance — the adapter connection is reused.
215
+ */
216
+ reset() {
217
+ this.messageHistory = [];
218
+ this.state = {
219
+ status: 'idle',
220
+ messages: [],
221
+ tokenUsage: ZERO_USAGE,
222
+ };
223
+ }
224
+ // -------------------------------------------------------------------------
225
+ // Dynamic tool management
226
+ // -------------------------------------------------------------------------
227
+ /**
228
+ * Register a new tool with this agent's tool registry at runtime.
229
+ *
230
+ * The tool becomes available to the next LLM call — no restart required.
231
+ */
232
+ addTool(tool) {
233
+ this._toolRegistry.register(tool, { runtimeAdded: true });
234
+ }
235
+ /**
236
+ * Deregister a tool by name.
237
+ * If the tool is not registered this is a no-op (no error is thrown).
238
+ */
239
+ removeTool(name) {
240
+ this._toolRegistry.deregister(name);
241
+ }
242
+ /** Return the names of all currently registered tools. */
243
+ getTools() {
244
+ return this._toolRegistry.list().map((t) => t.name);
245
+ }
246
+ // -------------------------------------------------------------------------
247
+ // Private execution core
248
+ // -------------------------------------------------------------------------
249
+ /**
250
+ * Shared execution path used by both `run` and `prompt`.
251
+ * Handles state transitions and error wrapping.
252
+ */
253
+ async executeRun(messages, callerOptions) {
254
+ this.transitionTo('running');
255
+ const agentStartMs = Date.now();
256
+ try {
257
+ // --- beforeRun hook ---
258
+ if (this.config.beforeRun) {
259
+ const hookCtx = this.buildBeforeRunHookContext(messages);
260
+ const modified = await this.config.beforeRun(hookCtx);
261
+ this.applyHookContext(messages, modified, hookCtx.prompt);
262
+ }
263
+ const runner = await this.getRunner();
264
+ const internalOnMessage = (msg) => {
265
+ this.state.messages.push(msg);
266
+ callerOptions?.onMessage?.(msg);
267
+ };
268
+ // Auto-generate runId when onTrace is provided but runId is missing
269
+ const needsRunId = callerOptions?.onTrace && !callerOptions.runId;
270
+ // Create a fresh timeout signal per run (not per runner) so that
271
+ // each run() / prompt() call gets its own timeout window.
272
+ const timeoutSignal = this.config.timeoutMs !== undefined && this.config.timeoutMs > 0
273
+ ? AbortSignal.timeout(this.config.timeoutMs)
274
+ : undefined;
275
+ // Merge caller-provided abortSignal with the timeout signal so that
276
+ // either cancellation source is respected.
277
+ const callerAbort = callerOptions?.abortSignal;
278
+ const effectiveAbort = timeoutSignal && callerAbort
279
+ ? mergeAbortSignals(timeoutSignal, callerAbort)
280
+ : timeoutSignal ?? callerAbort;
281
+ const runOptions = {
282
+ ...callerOptions,
283
+ onMessage: internalOnMessage,
284
+ ...(needsRunId ? { runId: generateRunId() } : undefined),
285
+ ...(effectiveAbort ? { abortSignal: effectiveAbort } : undefined),
286
+ };
287
+ const result = await runner.run(messages, runOptions);
288
+ this.state.tokenUsage = addUsage(this.state.tokenUsage, result.tokenUsage);
289
+ if (result.budgetExceeded) {
290
+ let budgetResult = this.toAgentRunResult(result, false);
291
+ if (this.config.afterRun) {
292
+ budgetResult = await this.config.afterRun(budgetResult);
293
+ }
294
+ this.transitionTo('completed');
295
+ this.emitAgentTrace(callerOptions, agentStartMs, budgetResult);
296
+ return budgetResult;
297
+ }
298
+ // --- Structured output validation ---
299
+ if (this.config.outputSchema) {
300
+ let validated = await this.validateStructuredOutput(messages, result, runner, runOptions);
301
+ // --- afterRun hook ---
302
+ if (this.config.afterRun) {
303
+ validated = await this.config.afterRun(validated);
304
+ }
305
+ this.emitAgentTrace(callerOptions, agentStartMs, validated);
306
+ return validated;
307
+ }
308
+ let agentResult = this.toAgentRunResult(result, true);
309
+ // --- afterRun hook ---
310
+ if (this.config.afterRun) {
311
+ agentResult = await this.config.afterRun(agentResult);
312
+ }
313
+ this.transitionTo('completed');
314
+ this.emitAgentTrace(callerOptions, agentStartMs, agentResult);
315
+ return agentResult;
316
+ }
317
+ catch (err) {
318
+ const error = err instanceof Error ? err : new Error(String(err));
319
+ this.transitionToError(error);
320
+ const errorResult = {
321
+ success: false,
322
+ output: error.message,
323
+ messages: [],
324
+ tokenUsage: ZERO_USAGE,
325
+ toolCalls: [],
326
+ structured: undefined,
327
+ };
328
+ this.emitAgentTrace(callerOptions, agentStartMs, errorResult);
329
+ return errorResult;
330
+ }
331
+ }
332
+ /** Emit an `agent` trace event if `onTrace` is provided. */
333
+ emitAgentTrace(options, startMs, result) {
334
+ if (!options?.onTrace)
335
+ return;
336
+ const endMs = Date.now();
337
+ emitTrace(options.onTrace, {
338
+ type: 'agent',
339
+ runId: options.runId ?? '',
340
+ taskId: options.taskId,
341
+ agent: options.traceAgent ?? this.name,
342
+ turns: result.messages.filter(m => m.role === 'assistant').length,
343
+ tokens: result.tokenUsage,
344
+ toolCalls: result.toolCalls.length,
345
+ startMs,
346
+ endMs,
347
+ durationMs: endMs - startMs,
348
+ });
349
+ }
350
+ /**
351
+ * Validate agent output against the configured `outputSchema`.
352
+ * On first validation failure, retry once with error feedback.
353
+ */
354
+ async validateStructuredOutput(originalMessages, result, runner, runOptions) {
355
+ const schema = this.config.outputSchema;
356
+ // First attempt
357
+ let firstAttemptError;
358
+ try {
359
+ const parsed = extractJSON(result.output);
360
+ const validated = validateOutput(schema, parsed);
361
+ this.transitionTo('completed');
362
+ return this.toAgentRunResult(result, true, validated);
363
+ }
364
+ catch (e) {
365
+ firstAttemptError = e;
366
+ }
367
+ // Retry: send full context + error feedback
368
+ const errorMsg = firstAttemptError instanceof Error
369
+ ? firstAttemptError.message
370
+ : String(firstAttemptError);
371
+ const errorFeedbackMessage = {
372
+ role: 'user',
373
+ content: [{
374
+ type: 'text',
375
+ text: [
376
+ 'Your previous response did not produce valid JSON matching the required schema.',
377
+ '',
378
+ `Error: ${errorMsg}`,
379
+ '',
380
+ 'Please try again. Respond with ONLY valid JSON, no other text.',
381
+ ].join('\n'),
382
+ }],
383
+ };
384
+ const retryMessages = [
385
+ ...originalMessages,
386
+ ...result.messages,
387
+ errorFeedbackMessage,
388
+ ];
389
+ const retryResult = await runner.run(retryMessages, runOptions);
390
+ this.state.tokenUsage = addUsage(this.state.tokenUsage, retryResult.tokenUsage);
391
+ const mergedTokenUsage = addUsage(result.tokenUsage, retryResult.tokenUsage);
392
+ // Include the error feedback turn to maintain alternating user/assistant roles,
393
+ // which is required by Anthropic's API for subsequent prompt() calls.
394
+ const mergedMessages = [...result.messages, errorFeedbackMessage, ...retryResult.messages];
395
+ const mergedToolCalls = [...result.toolCalls, ...retryResult.toolCalls];
396
+ try {
397
+ const parsed = extractJSON(retryResult.output);
398
+ const validated = validateOutput(schema, parsed);
399
+ this.transitionTo('completed');
400
+ return {
401
+ success: true,
402
+ output: retryResult.output,
403
+ messages: mergedMessages,
404
+ tokenUsage: mergedTokenUsage,
405
+ toolCalls: mergedToolCalls,
406
+ structured: validated,
407
+ ...(retryResult.budgetExceeded ? { budgetExceeded: true } : {}),
408
+ };
409
+ }
410
+ catch {
411
+ // Retry also failed
412
+ this.transitionTo('completed');
413
+ return {
414
+ success: false,
415
+ output: retryResult.output,
416
+ messages: mergedMessages,
417
+ tokenUsage: mergedTokenUsage,
418
+ toolCalls: mergedToolCalls,
419
+ structured: undefined,
420
+ ...(retryResult.budgetExceeded ? { budgetExceeded: true } : {}),
421
+ };
422
+ }
423
+ }
424
+ /**
425
+ * Shared streaming path used by `stream`.
426
+ * Handles state transitions and error wrapping.
427
+ */
428
+ async *executeStream(messages, callerOptions) {
429
+ this.transitionTo('running');
430
+ try {
431
+ // --- beforeRun hook ---
432
+ if (this.config.beforeRun) {
433
+ const hookCtx = this.buildBeforeRunHookContext(messages);
434
+ const modified = await this.config.beforeRun(hookCtx);
435
+ this.applyHookContext(messages, modified, hookCtx.prompt);
436
+ }
437
+ const runner = await this.getRunner();
438
+ // Fresh timeout per stream call, same as executeRun.
439
+ const timeoutSignal = this.config.timeoutMs !== undefined && this.config.timeoutMs > 0
440
+ ? AbortSignal.timeout(this.config.timeoutMs)
441
+ : undefined;
442
+ const callerAbort = callerOptions?.abortSignal;
443
+ const effectiveAbort = timeoutSignal && callerAbort
444
+ ? mergeAbortSignals(timeoutSignal, callerAbort)
445
+ : timeoutSignal ?? callerAbort;
446
+ for await (const event of runner.stream(messages, {
447
+ ...callerOptions,
448
+ ...(effectiveAbort ? { abortSignal: effectiveAbort } : {}),
449
+ })) {
450
+ if (event.type === 'done') {
451
+ const result = event.data;
452
+ this.state.tokenUsage = addUsage(this.state.tokenUsage, result.tokenUsage);
453
+ let agentResult = this.toAgentRunResult(result, !result.budgetExceeded);
454
+ if (this.config.afterRun) {
455
+ agentResult = await this.config.afterRun(agentResult);
456
+ }
457
+ this.transitionTo('completed');
458
+ yield { type: 'done', data: agentResult };
459
+ continue;
460
+ }
461
+ else if (event.type === 'error') {
462
+ const error = event.data instanceof Error
463
+ ? event.data
464
+ : new Error(String(event.data));
465
+ this.transitionToError(error);
466
+ }
467
+ yield event;
468
+ }
469
+ }
470
+ catch (err) {
471
+ const error = err instanceof Error ? err : new Error(String(err));
472
+ this.transitionToError(error);
473
+ yield { type: 'error', data: error };
474
+ }
475
+ }
476
+ // -------------------------------------------------------------------------
477
+ // Hook helpers
478
+ // -------------------------------------------------------------------------
479
+ /** Extract the prompt text from the last user message to build hook context. */
480
+ buildBeforeRunHookContext(messages) {
481
+ let prompt = '';
482
+ for (let i = messages.length - 1; i >= 0; i--) {
483
+ if (messages[i].role === 'user') {
484
+ prompt = messages[i].content
485
+ .filter((b) => b.type === 'text')
486
+ .map(b => b.text)
487
+ .join('');
488
+ break;
489
+ }
490
+ }
491
+ // Strip hook functions to avoid circular self-references in the context
492
+ const { beforeRun, afterRun, ...agentInfo } = this.config;
493
+ return { prompt, agent: agentInfo };
494
+ }
495
+ /**
496
+ * Apply a (possibly modified) hook context back to the messages array.
497
+ *
498
+ * Only text blocks in the last user message are replaced; non-text content
499
+ * (images, tool results) is preserved. The array element is replaced (not
500
+ * mutated in place) so that shallow copies of the original array (e.g. from
501
+ * `prompt()`) are not affected.
502
+ */
503
+ applyHookContext(messages, ctx, originalPrompt) {
504
+ if (ctx.prompt === originalPrompt)
505
+ return;
506
+ for (let i = messages.length - 1; i >= 0; i--) {
507
+ if (messages[i].role === 'user') {
508
+ const nonTextBlocks = messages[i].content.filter(b => b.type !== 'text');
509
+ messages[i] = {
510
+ role: 'user',
511
+ content: [{ type: 'text', text: ctx.prompt }, ...nonTextBlocks],
512
+ };
513
+ break;
514
+ }
515
+ }
516
+ }
517
+ // -------------------------------------------------------------------------
518
+ // State transition helpers
519
+ // -------------------------------------------------------------------------
520
+ transitionTo(status) {
521
+ this.state = { ...this.state, status };
522
+ }
523
+ transitionToError(error) {
524
+ this.state = { ...this.state, status: 'error', error };
525
+ }
526
+ // -------------------------------------------------------------------------
527
+ // Result mapping
528
+ // -------------------------------------------------------------------------
529
+ toAgentRunResult(result, success, structured) {
530
+ return {
531
+ success,
532
+ output: result.output,
533
+ messages: result.messages,
534
+ tokenUsage: result.tokenUsage,
535
+ toolCalls: result.toolCalls,
536
+ structured,
537
+ ...(result.loopDetected ? { loopDetected: true } : {}),
538
+ ...(result.budgetExceeded ? { budgetExceeded: true } : {}),
539
+ };
540
+ }
541
+ // -------------------------------------------------------------------------
542
+ // ToolUseContext builder (for direct use by subclasses or advanced callers)
543
+ // -------------------------------------------------------------------------
544
+ /**
545
+ * Build a {@link ToolUseContext} that identifies this agent.
546
+ * Exposed so team orchestrators can inject richer context (e.g. `TeamInfo`).
547
+ */
548
+ buildToolContext(abortSignal) {
549
+ return {
550
+ agent: {
551
+ name: this.name,
552
+ role: this.config.systemPrompt?.slice(0, 60) ?? 'assistant',
553
+ model: this.config.model,
554
+ },
555
+ abortSignal,
556
+ };
557
+ }
558
+ }
559
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/agent/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAYH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAG5D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAuD,MAAM,aAAa,CAAA;AAC9F,OAAO,EACL,gCAAgC,EAChC,WAAW,EACX,cAAc,GACf,MAAM,wBAAwB,CAAA;AAE/B,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E,MAAM,UAAU,GAAe,EAAE,YAAY,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,CAAA;AAEpE;;;GAGG;AACH,SAAS,iBAAiB,CAAC,CAAc,EAAE,CAAc;IACvD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAA;IACxC,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;QAAC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,4EAA4E;IAC5E,4EAA4E;IAE5E;;;OAGG;IACH,gBAAgB,CAAC,WAAyB;QACxC,OAAO;YACL,KAAK,EAAE;gBACL,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,WAAW;gBAC3D,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK;aACzB;YACD,WAAW;SACZ,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @fileoverview Sliding-window loop detector for the agent conversation loop.
3
+ *
4
+ * Tracks tool-call signatures and text outputs across turns to detect when an
5
+ * agent is stuck repeating the same actions. Used by {@link AgentRunner} when
6
+ * {@link LoopDetectionConfig} is provided.
7
+ */
8
+ import type { LoopDetectionConfig, LoopDetectionInfo } from '../types.js';
9
+ export declare class LoopDetector {
10
+ private readonly maxRepeats;
11
+ private readonly windowSize;
12
+ private readonly toolSignatures;
13
+ private readonly textOutputs;
14
+ constructor(config?: LoopDetectionConfig);
15
+ /**
16
+ * Record a turn's tool calls. Returns detection info when a loop is found.
17
+ */
18
+ recordToolCalls(blocks: ReadonlyArray<{
19
+ name: string;
20
+ input: Record<string, unknown>;
21
+ }>): LoopDetectionInfo | null;
22
+ /**
23
+ * Record a turn's text output. Returns detection info when a loop is found.
24
+ */
25
+ recordText(text: string): LoopDetectionInfo | null;
26
+ /**
27
+ * Deterministic JSON signature for a set of tool calls.
28
+ * Sorts calls by name (for multi-tool turns) and keys within each input.
29
+ */
30
+ private computeToolSignature;
31
+ /** Push an entry and trim the buffer to `windowSize`. */
32
+ private push;
33
+ /**
34
+ * Count how many consecutive identical entries exist at the tail of `buffer`.
35
+ * Returns 1 when the last entry is unique.
36
+ */
37
+ private consecutiveRepeats;
38
+ }
39
+ //# sourceMappingURL=loop-detector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loop-detector.d.ts","sourceRoot":"","sources":["../../src/agent/loop-detector.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAwBzE,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;IAEnC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAe;IAC9C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;gBAE/B,MAAM,GAAE,mBAAwB;IAO5C;;OAEG;IACH,eAAe,CACb,MAAM,EAAE,aAAa,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,GACtE,iBAAiB,GAAG,IAAI;IAoB3B;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI;IAuBlD;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAa5B,yDAAyD;IACzD,OAAO,CAAC,IAAI;IAOZ;;;OAGG;IACH,OAAO,CAAC,kBAAkB;CAU3B"}