@clinebot/agents 0.0.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 (90) hide show
  1. package/README.md +145 -0
  2. package/dist/agent-input.d.ts +2 -0
  3. package/dist/agent.d.ts +56 -0
  4. package/dist/extensions.d.ts +21 -0
  5. package/dist/hooks/engine.d.ts +42 -0
  6. package/dist/hooks/index.d.ts +2 -0
  7. package/dist/hooks/lifecycle.d.ts +5 -0
  8. package/dist/hooks/node.d.ts +2 -0
  9. package/dist/hooks/subprocess-runner.d.ts +16 -0
  10. package/dist/hooks/subprocess.d.ts +268 -0
  11. package/dist/index.browser.d.ts +1 -0
  12. package/dist/index.browser.js +49 -0
  13. package/dist/index.d.ts +15 -0
  14. package/dist/index.js +49 -0
  15. package/dist/index.node.d.ts +5 -0
  16. package/dist/index.node.js +49 -0
  17. package/dist/mcp/index.d.ts +4 -0
  18. package/dist/mcp/policies.d.ts +14 -0
  19. package/dist/mcp/tools.d.ts +9 -0
  20. package/dist/mcp/types.d.ts +35 -0
  21. package/dist/message-builder.d.ts +31 -0
  22. package/dist/prompts/cline.d.ts +1 -0
  23. package/dist/prompts/index.d.ts +1 -0
  24. package/dist/runtime/agent-runtime-bus.d.ts +13 -0
  25. package/dist/runtime/conversation-store.d.ts +16 -0
  26. package/dist/runtime/lifecycle-orchestrator.d.ts +28 -0
  27. package/dist/runtime/tool-orchestrator.d.ts +39 -0
  28. package/dist/runtime/turn-processor.d.ts +21 -0
  29. package/dist/teams/index.d.ts +3 -0
  30. package/dist/teams/multi-agent.d.ts +566 -0
  31. package/dist/teams/spawn-agent-tool.d.ts +85 -0
  32. package/dist/teams/team-tools.d.ts +51 -0
  33. package/dist/tools/ask-question.d.ts +12 -0
  34. package/dist/tools/create.d.ts +59 -0
  35. package/dist/tools/execution.d.ts +61 -0
  36. package/dist/tools/formatting.d.ts +20 -0
  37. package/dist/tools/index.d.ts +11 -0
  38. package/dist/tools/registry.d.ts +26 -0
  39. package/dist/tools/validation.d.ts +27 -0
  40. package/dist/types.d.ts +826 -0
  41. package/package.json +54 -0
  42. package/src/agent-input.ts +116 -0
  43. package/src/agent.test.ts +931 -0
  44. package/src/agent.ts +1050 -0
  45. package/src/example.test.ts +564 -0
  46. package/src/extensions.ts +337 -0
  47. package/src/hooks/engine.test.ts +163 -0
  48. package/src/hooks/engine.ts +537 -0
  49. package/src/hooks/index.ts +6 -0
  50. package/src/hooks/lifecycle.ts +239 -0
  51. package/src/hooks/node.ts +18 -0
  52. package/src/hooks/subprocess-runner.ts +140 -0
  53. package/src/hooks/subprocess.test.ts +180 -0
  54. package/src/hooks/subprocess.ts +620 -0
  55. package/src/index.browser.ts +1 -0
  56. package/src/index.node.ts +21 -0
  57. package/src/index.ts +133 -0
  58. package/src/mcp/index.ts +17 -0
  59. package/src/mcp/policies.test.ts +51 -0
  60. package/src/mcp/policies.ts +53 -0
  61. package/src/mcp/tools.test.ts +76 -0
  62. package/src/mcp/tools.ts +60 -0
  63. package/src/mcp/types.ts +41 -0
  64. package/src/message-builder.test.ts +175 -0
  65. package/src/message-builder.ts +429 -0
  66. package/src/prompts/cline.ts +49 -0
  67. package/src/prompts/index.ts +1 -0
  68. package/src/runtime/agent-runtime-bus.ts +53 -0
  69. package/src/runtime/conversation-store.ts +61 -0
  70. package/src/runtime/lifecycle-orchestrator.ts +90 -0
  71. package/src/runtime/tool-orchestrator.ts +177 -0
  72. package/src/runtime/turn-processor.ts +250 -0
  73. package/src/streaming.test.ts +197 -0
  74. package/src/streaming.ts +307 -0
  75. package/src/teams/index.ts +63 -0
  76. package/src/teams/multi-agent.lifecycle.test.ts +48 -0
  77. package/src/teams/multi-agent.ts +1866 -0
  78. package/src/teams/spawn-agent-tool.test.ts +172 -0
  79. package/src/teams/spawn-agent-tool.ts +223 -0
  80. package/src/teams/team-tools.test.ts +448 -0
  81. package/src/teams/team-tools.ts +929 -0
  82. package/src/tools/ask-question.ts +78 -0
  83. package/src/tools/create.ts +104 -0
  84. package/src/tools/execution.ts +311 -0
  85. package/src/tools/formatting.ts +73 -0
  86. package/src/tools/index.ts +45 -0
  87. package/src/tools/registry.ts +52 -0
  88. package/src/tools/tools.test.ts +292 -0
  89. package/src/tools/validation.ts +73 -0
  90. package/src/types.ts +966 -0
@@ -0,0 +1,826 @@
1
+ /**
2
+ * Types and Zod Schemas for the Agent Package
3
+ *
4
+ * This module defines all TypeScript types and Zod validation schemas
5
+ * for agent configuration, tools, events, and results.
6
+ */
7
+ import type { providers as LlmsProviders } from "@clinebot/llms";
8
+ import { type BasicLogger, type Tool, type ToolApprovalRequest, type ToolApprovalResult, type ToolCallRecord, type ToolPolicy } from "@clinebot/shared";
9
+ import { z } from "zod";
10
+ export type { BasicLogger, Tool, ToolApprovalRequest, ToolApprovalResult, ToolCallRecord, ToolContext, ToolPolicy, } from "@clinebot/shared";
11
+ export { ToolCallRecordSchema, ToolContextSchema } from "@clinebot/shared";
12
+ /**
13
+ * Events emitted during agent execution
14
+ */
15
+ export type AgentEvent = AgentContentStartEvent | AgentContentEndEvent | AgentIterationStartEvent | AgentIterationEndEvent | AgentUsageEvent | AgentDoneEvent | AgentErrorEvent;
16
+ export type AgentContentType = "text" | "reasoning" | "tool";
17
+ export interface AgentContentStartEvent {
18
+ type: "content_start";
19
+ contentType: AgentContentType;
20
+ /** The text chunk received from the model */
21
+ text?: string;
22
+ /** Accumulated text so far in this turn */
23
+ accumulated?: string;
24
+ /** The reasoning/thinking text from the model */
25
+ reasoning?: string;
26
+ /** Whether this is redacted reasoning */
27
+ redacted?: boolean;
28
+ /** Name of the tool being called */
29
+ toolName?: string;
30
+ /** Unique identifier for this tool call */
31
+ toolCallId?: string;
32
+ /** Input being passed to the tool */
33
+ input?: unknown;
34
+ }
35
+ export interface AgentContentEndEvent {
36
+ type: "content_end";
37
+ contentType: AgentContentType;
38
+ /** Final text generated for this turn */
39
+ text?: string;
40
+ /** Final reasoning/thinking text generated for this turn */
41
+ reasoning?: string;
42
+ /** Name of the tool that completed */
43
+ toolName?: string;
44
+ /** Unique identifier for this tool call */
45
+ toolCallId?: string;
46
+ /** Output from the tool */
47
+ output?: unknown;
48
+ /** Error message if the tool failed */
49
+ error?: string;
50
+ /** Time taken in milliseconds for tool content */
51
+ durationMs?: number;
52
+ }
53
+ export interface AgentIterationStartEvent {
54
+ type: "iteration_start";
55
+ /** The iteration number (1-based) */
56
+ iteration: number;
57
+ }
58
+ export interface AgentIterationEndEvent {
59
+ type: "iteration_end";
60
+ /** The iteration number that just completed */
61
+ iteration: number;
62
+ /** Whether this iteration had any tool calls */
63
+ hadToolCalls: boolean;
64
+ /** Number of tool calls in this iteration */
65
+ toolCallCount: number;
66
+ }
67
+ export interface AgentUsageEvent {
68
+ type: "usage";
69
+ /** Number of input tokens for this turn */
70
+ inputTokens: number;
71
+ /** Number of output tokens for this turn */
72
+ outputTokens: number;
73
+ /** Tokens read from cache */
74
+ cacheReadTokens?: number;
75
+ /** Tokens written to cache */
76
+ cacheWriteTokens?: number;
77
+ /** Cost for this turn */
78
+ cost?: number;
79
+ /** Accumulated totals */
80
+ totalInputTokens: number;
81
+ totalOutputTokens: number;
82
+ totalCost?: number;
83
+ }
84
+ export interface AgentDoneEvent {
85
+ type: "done";
86
+ /** The reason the agent stopped */
87
+ reason: AgentFinishReason;
88
+ /** Final text output */
89
+ text: string;
90
+ /** Total number of iterations */
91
+ iterations: number;
92
+ }
93
+ export interface AgentErrorEvent {
94
+ type: "error";
95
+ /** The error that occurred */
96
+ error: Error;
97
+ /** Whether the error is recoverable */
98
+ recoverable: boolean;
99
+ /** Current iteration when error occurred */
100
+ iteration: number;
101
+ }
102
+ /**
103
+ * Hook error handling behavior.
104
+ * - "ignore": swallow hook errors and continue agent execution
105
+ * - "throw": fail agent execution when a hook throws
106
+ */
107
+ export type HookErrorMode = "ignore" | "throw";
108
+ /**
109
+ * Common controls supported by lifecycle hooks.
110
+ */
111
+ export interface AgentHookControl {
112
+ /**
113
+ * Cancel the active run after this hook.
114
+ * When true, finishReason becomes "aborted".
115
+ */
116
+ cancel?: boolean;
117
+ /**
118
+ * Request explicit approval before executing the active tool call.
119
+ * Only applied for `onToolCallStart`.
120
+ */
121
+ review?: boolean;
122
+ /**
123
+ * Optional context appended to the conversation as a user text block.
124
+ */
125
+ context?: string;
126
+ /**
127
+ * Optional replacement input for the active tool call.
128
+ * Only applied for `onToolCallStart`.
129
+ */
130
+ overrideInput?: unknown;
131
+ /**
132
+ * Optional replacement system prompt.
133
+ * Primarily used by before-agent-start hook stages.
134
+ */
135
+ systemPrompt?: string;
136
+ /**
137
+ * Optional messages to append before model turn execution.
138
+ * Primarily used by before-agent-start hook stages.
139
+ */
140
+ appendMessages?: LlmsProviders.Message[];
141
+ }
142
+ export interface AgentHookRunStartContext {
143
+ agentId: string;
144
+ conversationId: string;
145
+ parentAgentId: string | null;
146
+ userMessage: string;
147
+ }
148
+ export interface AgentHookScheduleContext {
149
+ scheduleId: string;
150
+ executionId?: string;
151
+ trigger: "scheduled" | "manual";
152
+ triggeredAt?: string;
153
+ }
154
+ export interface AgentHookSessionStartContext {
155
+ agentId: string;
156
+ conversationId: string;
157
+ parentAgentId: string | null;
158
+ schedule?: AgentHookScheduleContext;
159
+ }
160
+ export interface AgentHookRunEndContext {
161
+ agentId: string;
162
+ conversationId: string;
163
+ parentAgentId: string | null;
164
+ result: AgentResult;
165
+ }
166
+ export interface AgentHookIterationStartContext {
167
+ agentId: string;
168
+ conversationId: string;
169
+ parentAgentId: string | null;
170
+ iteration: number;
171
+ }
172
+ export interface AgentHookIterationEndContext {
173
+ agentId: string;
174
+ conversationId: string;
175
+ parentAgentId: string | null;
176
+ iteration: number;
177
+ hadToolCalls: boolean;
178
+ toolCallCount: number;
179
+ }
180
+ export interface AgentHookTurnStartContext {
181
+ agentId: string;
182
+ conversationId: string;
183
+ parentAgentId: string | null;
184
+ iteration: number;
185
+ messages: LlmsProviders.Message[];
186
+ }
187
+ export interface AgentHookTurnEndContext {
188
+ agentId: string;
189
+ conversationId: string;
190
+ parentAgentId: string | null;
191
+ iteration: number;
192
+ turn: ProcessedTurn;
193
+ }
194
+ export interface AgentHookToolCallStartContext {
195
+ agentId: string;
196
+ conversationId: string;
197
+ parentAgentId: string | null;
198
+ iteration: number;
199
+ call: PendingToolCall;
200
+ }
201
+ export interface AgentHookToolCallEndContext {
202
+ agentId: string;
203
+ conversationId: string;
204
+ parentAgentId: string | null;
205
+ iteration: number;
206
+ record: ToolCallRecord;
207
+ }
208
+ export interface AgentHookErrorContext {
209
+ agentId: string;
210
+ conversationId: string;
211
+ parentAgentId: string | null;
212
+ iteration: number;
213
+ error: Error;
214
+ }
215
+ export interface AgentHookSessionShutdownContext {
216
+ agentId: string;
217
+ conversationId: string;
218
+ parentAgentId: string | null;
219
+ /**
220
+ * Optional reason for shutdown (e.g. "ctrl_d", "process_exit")
221
+ */
222
+ reason?: string;
223
+ }
224
+ export type HookStage = "input" | "runtime_event" | "session_start" | "run_start" | "iteration_start" | "turn_start" | "before_agent_start" | "tool_call_before" | "tool_call_after" | "turn_end" | "iteration_end" | "run_end" | "session_shutdown" | "error";
225
+ export type HookMode = "blocking" | "async";
226
+ export type HookFailureMode = "fail_open" | "fail_closed";
227
+ export interface HookStagePolicy {
228
+ mode: HookMode;
229
+ timeoutMs: number;
230
+ retries: number;
231
+ retryDelayMs: number;
232
+ failureMode: HookFailureMode;
233
+ maxConcurrency: number;
234
+ queueLimit: number;
235
+ }
236
+ export type HookStagePolicyInput = Partial<HookStagePolicy>;
237
+ export interface HookPolicies {
238
+ defaultPolicy?: HookStagePolicyInput;
239
+ stages?: Partial<Record<HookStage, HookStagePolicyInput>>;
240
+ handlers?: Record<string, HookStagePolicyInput>;
241
+ }
242
+ export interface HookEventEnvelope<TPayload = unknown> {
243
+ eventId: string;
244
+ stage: HookStage;
245
+ createdAt: Date;
246
+ sequence: number;
247
+ runId: string;
248
+ agentId: string;
249
+ conversationId: string;
250
+ parentAgentId: string | null;
251
+ iteration?: number;
252
+ parentEventId?: string;
253
+ payload: TPayload;
254
+ }
255
+ export type HookAttemptStatus = "ok" | "timeout" | "error" | "skipped";
256
+ export interface HookHandlerResult {
257
+ handlerName: string;
258
+ stage: HookStage;
259
+ status: HookAttemptStatus;
260
+ attempts: number;
261
+ durationMs: number;
262
+ error?: Error;
263
+ control?: AgentHookControl;
264
+ }
265
+ export interface HookDispatchResult {
266
+ event: HookEventEnvelope;
267
+ queued: boolean;
268
+ dropped: boolean;
269
+ control?: AgentHookControl;
270
+ results: HookHandlerResult[];
271
+ }
272
+ export interface AgentExtensionCommand {
273
+ name: string;
274
+ description?: string;
275
+ handler?: (input: string) => Promise<string> | string;
276
+ }
277
+ export interface AgentExtensionShortcut {
278
+ name: string;
279
+ value: string;
280
+ description?: string;
281
+ }
282
+ export interface AgentExtensionFlag {
283
+ name: string;
284
+ description?: string;
285
+ defaultValue?: boolean | string | number;
286
+ }
287
+ export interface AgentExtensionMessageRenderer {
288
+ name: string;
289
+ render: (message: LlmsProviders.Message) => string;
290
+ }
291
+ export interface AgentExtensionProvider {
292
+ name: string;
293
+ description?: string;
294
+ metadata?: Record<string, unknown>;
295
+ }
296
+ export interface AgentExtensionRuntimeEventContext {
297
+ agentId: string;
298
+ conversationId: string;
299
+ parentAgentId: string | null;
300
+ event: AgentEvent;
301
+ }
302
+ export interface AgentExtensionSessionStartContext {
303
+ agentId: string;
304
+ conversationId: string;
305
+ parentAgentId: string | null;
306
+ schedule?: AgentHookScheduleContext;
307
+ }
308
+ export interface AgentExtensionSessionShutdownContext {
309
+ agentId: string;
310
+ conversationId: string;
311
+ parentAgentId: string | null;
312
+ reason?: string;
313
+ }
314
+ export interface AgentExtensionInputContext {
315
+ agentId: string;
316
+ conversationId: string;
317
+ parentAgentId: string | null;
318
+ mode: "run" | "continue";
319
+ input: string;
320
+ }
321
+ export interface AgentExtensionBeforeAgentStartContext {
322
+ agentId: string;
323
+ conversationId: string;
324
+ parentAgentId: string | null;
325
+ iteration: number;
326
+ systemPrompt: string;
327
+ messages: LlmsProviders.Message[];
328
+ }
329
+ export interface AgentExtensionBeforeAgentStartControl extends AgentHookControl {
330
+ systemPrompt?: string;
331
+ appendMessages?: LlmsProviders.Message[];
332
+ }
333
+ export interface AgentExtensionApi {
334
+ registerTool: (tool: Tool) => void;
335
+ registerCommand: (command: AgentExtensionCommand) => void;
336
+ registerShortcut: (shortcut: AgentExtensionShortcut) => void;
337
+ registerFlag: (flag: AgentExtensionFlag) => void;
338
+ registerMessageRenderer: (renderer: AgentExtensionMessageRenderer) => void;
339
+ registerProvider: (provider: AgentExtensionProvider) => void;
340
+ }
341
+ export type AgentExtensionCapability = "hooks" | "tools" | "commands" | "shortcuts" | "flags" | "message_renderers" | "providers";
342
+ export type AgentExtensionHookStage = "input" | "runtime_event" | "session_start" | "run_start" | "iteration_start" | "turn_start" | "before_agent_start" | "tool_call_before" | "tool_call_after" | "turn_end" | "iteration_end" | "run_end" | "session_shutdown" | "error";
343
+ export interface PluginManifest {
344
+ capabilities: AgentExtensionCapability[];
345
+ hookStages?: AgentExtensionHookStage[];
346
+ }
347
+ export interface AgentExtension {
348
+ name: string;
349
+ manifest: PluginManifest;
350
+ setup?: (api: AgentExtensionApi) => void | Promise<void>;
351
+ onSessionStart?: (ctx: AgentExtensionSessionStartContext) => undefined | AgentHookControl | Promise<undefined | AgentHookControl>;
352
+ onRunStart?: (ctx: AgentHookRunStartContext) => undefined | AgentHookControl | Promise<undefined | AgentHookControl>;
353
+ onIterationStart?: (ctx: AgentHookIterationStartContext) => undefined | AgentHookControl | Promise<undefined | AgentHookControl>;
354
+ onTurnStart?: (ctx: AgentHookTurnStartContext) => undefined | AgentHookControl | Promise<undefined | AgentHookControl>;
355
+ onInput?: (ctx: AgentExtensionInputContext) => undefined | AgentHookControl | Promise<undefined | AgentHookControl>;
356
+ onBeforeAgentStart?: (ctx: AgentExtensionBeforeAgentStartContext) => undefined | AgentExtensionBeforeAgentStartControl | Promise<undefined | AgentExtensionBeforeAgentStartControl>;
357
+ onToolCall?: (ctx: AgentHookToolCallStartContext) => undefined | AgentHookControl | Promise<undefined | AgentHookControl>;
358
+ onToolResult?: (ctx: AgentHookToolCallEndContext) => undefined | AgentHookControl | Promise<undefined | AgentHookControl>;
359
+ onAgentEnd?: (ctx: AgentHookTurnEndContext) => undefined | AgentHookControl | Promise<undefined | AgentHookControl>;
360
+ onIterationEnd?: (ctx: AgentHookIterationEndContext) => void | Promise<void>;
361
+ onRunEnd?: (ctx: AgentHookRunEndContext) => void | Promise<void>;
362
+ onSessionShutdown?: (ctx: AgentExtensionSessionShutdownContext) => undefined | AgentHookControl | Promise<undefined | AgentHookControl>;
363
+ onRuntimeEvent?: (ctx: AgentExtensionRuntimeEventContext) => void | Promise<void>;
364
+ onError?: (ctx: AgentHookErrorContext) => void | Promise<void>;
365
+ }
366
+ export interface AgentExtensionRegistry {
367
+ tools: Tool[];
368
+ commands: AgentExtensionCommand[];
369
+ shortcuts: AgentExtensionShortcut[];
370
+ flags: AgentExtensionFlag[];
371
+ messageRenderers: AgentExtensionMessageRenderer[];
372
+ providers: AgentExtensionProvider[];
373
+ }
374
+ /**
375
+ * Lifecycle hooks for observing or influencing agent execution.
376
+ */
377
+ export interface AgentHooks {
378
+ onSessionStart?: (ctx: AgentHookSessionStartContext) => undefined | AgentHookControl | Promise<undefined | AgentHookControl>;
379
+ onRunStart?: (ctx: AgentHookRunStartContext) => undefined | AgentHookControl | Promise<undefined | AgentHookControl>;
380
+ onRunEnd?: (ctx: AgentHookRunEndContext) => void | Promise<void>;
381
+ onIterationStart?: (ctx: AgentHookIterationStartContext) => undefined | AgentHookControl | Promise<undefined | AgentHookControl>;
382
+ onIterationEnd?: (ctx: AgentHookIterationEndContext) => void | Promise<void>;
383
+ onTurnStart?: (ctx: AgentHookTurnStartContext) => undefined | AgentHookControl | Promise<undefined | AgentHookControl>;
384
+ onTurnEnd?: (ctx: AgentHookTurnEndContext) => undefined | AgentHookControl | Promise<undefined | AgentHookControl>;
385
+ onToolCallStart?: (ctx: AgentHookToolCallStartContext) => undefined | AgentHookControl | Promise<undefined | AgentHookControl>;
386
+ onToolCallEnd?: (ctx: AgentHookToolCallEndContext) => undefined | AgentHookControl | Promise<undefined | AgentHookControl>;
387
+ onSessionShutdown?: (ctx: AgentHookSessionShutdownContext) => undefined | AgentHookControl | Promise<undefined | AgentHookControl>;
388
+ onError?: (ctx: AgentHookErrorContext) => void | Promise<void>;
389
+ }
390
+ /**
391
+ * Reasons why the agent stopped executing
392
+ */
393
+ export type AgentFinishReason = "completed" | "max_iterations" | "aborted" | "error";
394
+ export declare const AgentFinishReasonSchema: z.ZodEnum<{
395
+ completed: "completed";
396
+ max_iterations: "max_iterations";
397
+ aborted: "aborted";
398
+ error: "error";
399
+ }>;
400
+ /**
401
+ * Aggregated token usage and cost information
402
+ */
403
+ export interface AgentUsage {
404
+ /** Total input tokens across all iterations */
405
+ inputTokens: number;
406
+ /** Total output tokens across all iterations */
407
+ outputTokens: number;
408
+ /** Total tokens read from cache */
409
+ cacheReadTokens?: number;
410
+ /** Total tokens written to cache */
411
+ cacheWriteTokens?: number;
412
+ /** Total cost in dollars */
413
+ totalCost?: number;
414
+ }
415
+ export declare const AgentUsageSchema: z.ZodObject<{
416
+ inputTokens: z.ZodNumber;
417
+ outputTokens: z.ZodNumber;
418
+ cacheReadTokens: z.ZodOptional<z.ZodNumber>;
419
+ cacheWriteTokens: z.ZodOptional<z.ZodNumber>;
420
+ totalCost: z.ZodOptional<z.ZodNumber>;
421
+ }, z.core.$strip>;
422
+ /**
423
+ * Result returned from Agent.run()
424
+ */
425
+ export interface AgentResult {
426
+ /** Final text output from the agent */
427
+ text: string;
428
+ /** Aggregated token usage and cost */
429
+ usage: AgentUsage;
430
+ /** Full conversation history */
431
+ messages: LlmsProviders.Message[];
432
+ /** All tool calls made during execution */
433
+ toolCalls: ToolCallRecord[];
434
+ /** Number of loop iterations */
435
+ iterations: number;
436
+ /** Why the agent stopped */
437
+ finishReason: AgentFinishReason;
438
+ /** Model information used */
439
+ model: {
440
+ id: string;
441
+ provider: string;
442
+ info?: LlmsProviders.ModelInfo;
443
+ };
444
+ /** Start time of the run */
445
+ startedAt: Date;
446
+ /** End time of the run */
447
+ endedAt: Date;
448
+ /** Total duration in milliseconds */
449
+ durationMs: number;
450
+ }
451
+ export declare const AgentResultSchema: z.ZodObject<{
452
+ text: z.ZodString;
453
+ usage: z.ZodObject<{
454
+ inputTokens: z.ZodNumber;
455
+ outputTokens: z.ZodNumber;
456
+ cacheReadTokens: z.ZodOptional<z.ZodNumber>;
457
+ cacheWriteTokens: z.ZodOptional<z.ZodNumber>;
458
+ totalCost: z.ZodOptional<z.ZodNumber>;
459
+ }, z.core.$strip>;
460
+ messages: z.ZodArray<z.ZodCustom<LlmsProviders.Message, LlmsProviders.Message>>;
461
+ toolCalls: z.ZodArray<z.ZodObject<{
462
+ id: z.ZodString;
463
+ name: z.ZodString;
464
+ input: z.ZodUnknown;
465
+ output: z.ZodUnknown;
466
+ error: z.ZodOptional<z.ZodString>;
467
+ durationMs: z.ZodNumber;
468
+ startedAt: z.ZodDate;
469
+ endedAt: z.ZodDate;
470
+ }, z.core.$strip>>;
471
+ iterations: z.ZodNumber;
472
+ finishReason: z.ZodEnum<{
473
+ completed: "completed";
474
+ max_iterations: "max_iterations";
475
+ aborted: "aborted";
476
+ error: "error";
477
+ }>;
478
+ model: z.ZodObject<{
479
+ id: z.ZodString;
480
+ provider: z.ZodString;
481
+ info: z.ZodOptional<z.ZodCustom<{
482
+ id: string;
483
+ name?: string | undefined;
484
+ description?: string | undefined;
485
+ maxTokens?: number | undefined;
486
+ contextWindow?: number | undefined;
487
+ capabilities?: ("reasoning" | "tools" | "temperature" | "images" | "streaming" | "prompt-cache" | "reasoning-effort" | "computer-use" | "global-endpoint" | "structured_output" | "files")[] | undefined;
488
+ apiFormat?: "default" | "openai-responses" | "r1" | undefined;
489
+ systemRole?: "system" | "developer" | undefined;
490
+ temperature?: number | undefined;
491
+ pricing?: {
492
+ input?: number | undefined;
493
+ output?: number | undefined;
494
+ cacheWrite?: number | undefined;
495
+ cacheRead?: number | undefined;
496
+ } | undefined;
497
+ thinkingConfig?: {
498
+ maxBudget?: number | undefined;
499
+ outputPrice?: number | undefined;
500
+ thinkingLevel?: "low" | "high" | undefined;
501
+ } | undefined;
502
+ status?: "active" | "preview" | "deprecated" | "legacy" | undefined;
503
+ deprecationNotice?: string | undefined;
504
+ replacedBy?: string | undefined;
505
+ releaseDate?: string | undefined;
506
+ deprecationDate?: string | undefined;
507
+ }, {
508
+ id: string;
509
+ name?: string | undefined;
510
+ description?: string | undefined;
511
+ maxTokens?: number | undefined;
512
+ contextWindow?: number | undefined;
513
+ capabilities?: ("reasoning" | "tools" | "temperature" | "images" | "streaming" | "prompt-cache" | "reasoning-effort" | "computer-use" | "global-endpoint" | "structured_output" | "files")[] | undefined;
514
+ apiFormat?: "default" | "openai-responses" | "r1" | undefined;
515
+ systemRole?: "system" | "developer" | undefined;
516
+ temperature?: number | undefined;
517
+ pricing?: {
518
+ input?: number | undefined;
519
+ output?: number | undefined;
520
+ cacheWrite?: number | undefined;
521
+ cacheRead?: number | undefined;
522
+ } | undefined;
523
+ thinkingConfig?: {
524
+ maxBudget?: number | undefined;
525
+ outputPrice?: number | undefined;
526
+ thinkingLevel?: "low" | "high" | undefined;
527
+ } | undefined;
528
+ status?: "active" | "preview" | "deprecated" | "legacy" | undefined;
529
+ deprecationNotice?: string | undefined;
530
+ replacedBy?: string | undefined;
531
+ releaseDate?: string | undefined;
532
+ deprecationDate?: string | undefined;
533
+ }>>;
534
+ }, z.core.$strip>;
535
+ startedAt: z.ZodDate;
536
+ endedAt: z.ZodDate;
537
+ durationMs: z.ZodNumber;
538
+ }, z.core.$strip>;
539
+ /**
540
+ * Reasoning effort level for capable models
541
+ */
542
+ export type ReasoningEffort = "low" | "medium" | "high";
543
+ export declare const ReasoningEffortSchema: z.ZodEnum<{
544
+ low: "low";
545
+ high: "high";
546
+ medium: "medium";
547
+ }>;
548
+ /**
549
+ * Configuration for creating an Agent
550
+ */
551
+ export interface AgentConfig {
552
+ /** Provider ID (e.g., "anthropic", "openai", "gemini") */
553
+ providerId: string;
554
+ /** Model ID to use */
555
+ modelId: string;
556
+ /** API key for the provider */
557
+ apiKey?: string;
558
+ /** Custom base URL for the API */
559
+ baseUrl?: string;
560
+ /** Additional headers for API requests */
561
+ headers?: Record<string, string>;
562
+ /** Optional provider model catalog overrides */
563
+ knownModels?: Record<string, LlmsProviders.ModelInfo>;
564
+ /** Optional pre-resolved provider configuration (includes provider-specific fields like aws/gcp). */
565
+ providerConfig?: LlmsProviders.ProviderConfig;
566
+ /**
567
+ * Optional preloaded conversation history for resume flows.
568
+ * When provided, start by calling continue() to preserve history.
569
+ */
570
+ initialMessages?: LlmsProviders.Message[];
571
+ /** System prompt for the agent */
572
+ systemPrompt: string;
573
+ /** Tools available to the agent */
574
+ tools: Tool[];
575
+ /**
576
+ * Maximum number of loop iterations
577
+ * If undefined, no iteration cap is enforced.
578
+ */
579
+ maxIterations?: number;
580
+ /**
581
+ * Maximum number of tool calls to execute concurrently in a single iteration.
582
+ * @default 8
583
+ */
584
+ maxParallelToolCalls?: number;
585
+ /**
586
+ * Maximum output tokens per API call
587
+ */
588
+ maxTokensPerTurn?: number;
589
+ /**
590
+ * After this many consecutive iterations with tool calls,
591
+ * inject a reminder text block asking the agent to answer if it has enough info.
592
+ * Set to 0 to disable.
593
+ * @default 6
594
+ */
595
+ reminderAfterIterations?: number;
596
+ /**
597
+ * Custom reminder text to inject after reminderAfterIterations.
598
+ * @default "REMINDER: If you have gathered enough information to answer the user's question, please provide your final answer now without using any more tools."
599
+ */
600
+ reminderText?: string;
601
+ /**
602
+ * Timeout for each API call in milliseconds
603
+ * @default 120000 (2 minutes)
604
+ */
605
+ apiTimeoutMs?: number;
606
+ /**
607
+ * Optional runtime file-content loader used when user files are attached.
608
+ * When omitted, attached files will be represented as loader errors.
609
+ */
610
+ userFileContentLoader?: (path: string) => Promise<string>;
611
+ /**
612
+ * Reasoning effort level
613
+ */
614
+ reasoningEffort?: ReasoningEffort;
615
+ /**
616
+ * Maximum tokens for thinking/reasoning
617
+ */
618
+ thinkingBudgetTokens?: number;
619
+ /**
620
+ * Enable default thinking/reasoning behavior for supported models.
621
+ */
622
+ thinking?: boolean;
623
+ /**
624
+ * Callback for agent events (streaming, progress, etc.)
625
+ */
626
+ onEvent?: (event: AgentEvent) => void;
627
+ /**
628
+ * Lifecycle hooks for observing or influencing agent execution.
629
+ */
630
+ hooks?: AgentHooks;
631
+ /**
632
+ * Optional parent agent ID for spawned/delegated runs.
633
+ * Root agents should leave this undefined.
634
+ */
635
+ parentAgentId?: string;
636
+ /**
637
+ * Extension modules that can intercept lifecycle events and register tools/commands.
638
+ */
639
+ extensions?: AgentExtension[];
640
+ /**
641
+ * How hook errors should be handled.
642
+ * @default "ignore"
643
+ */
644
+ hookErrorMode?: HookErrorMode;
645
+ /**
646
+ * Optional deterministic hook execution policies.
647
+ */
648
+ hookPolicies?: HookPolicies;
649
+ /**
650
+ * Optional schedule metadata for runs initiated by scheduler services.
651
+ * Used by session_start lifecycle hooks.
652
+ */
653
+ schedule?: AgentHookScheduleContext;
654
+ /**
655
+ * Per-tool execution policy. Tool names not listed here default to enabled + autoApprove.
656
+ */
657
+ toolPolicies?: Record<string, ToolPolicy>;
658
+ /**
659
+ * Optional callback to request client approval when a tool policy disables auto-approval.
660
+ */
661
+ requestToolApproval?: (request: ToolApprovalRequest) => Promise<ToolApprovalResult> | ToolApprovalResult;
662
+ /**
663
+ * Optional logger for tracing agent loop lifecycle and recoverable failures.
664
+ */
665
+ logger?: BasicLogger;
666
+ /**
667
+ * Optional guard that runs when the model returns no tool calls.
668
+ * If it returns a non-empty string, that string is injected as a
669
+ * system-level nudge and the loop continues instead of completing.
670
+ * Use this to prevent premature exit when the agent has unfinished
671
+ * obligations (e.g. in-progress team tasks).
672
+ */
673
+ completionGuard?: () => string | undefined;
674
+ /**
675
+ * Abort signal for cancellation
676
+ */
677
+ abortSignal?: AbortSignal;
678
+ }
679
+ export declare const AgentConfigSchema: z.ZodObject<{
680
+ providerId: z.ZodString;
681
+ modelId: z.ZodString;
682
+ apiKey: z.ZodOptional<z.ZodString>;
683
+ baseUrl: z.ZodOptional<z.ZodString>;
684
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
685
+ knownModels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodCustom<{
686
+ id: string;
687
+ name?: string | undefined;
688
+ description?: string | undefined;
689
+ maxTokens?: number | undefined;
690
+ contextWindow?: number | undefined;
691
+ capabilities?: ("reasoning" | "tools" | "temperature" | "images" | "streaming" | "prompt-cache" | "reasoning-effort" | "computer-use" | "global-endpoint" | "structured_output" | "files")[] | undefined;
692
+ apiFormat?: "default" | "openai-responses" | "r1" | undefined;
693
+ systemRole?: "system" | "developer" | undefined;
694
+ temperature?: number | undefined;
695
+ pricing?: {
696
+ input?: number | undefined;
697
+ output?: number | undefined;
698
+ cacheWrite?: number | undefined;
699
+ cacheRead?: number | undefined;
700
+ } | undefined;
701
+ thinkingConfig?: {
702
+ maxBudget?: number | undefined;
703
+ outputPrice?: number | undefined;
704
+ thinkingLevel?: "low" | "high" | undefined;
705
+ } | undefined;
706
+ status?: "active" | "preview" | "deprecated" | "legacy" | undefined;
707
+ deprecationNotice?: string | undefined;
708
+ replacedBy?: string | undefined;
709
+ releaseDate?: string | undefined;
710
+ deprecationDate?: string | undefined;
711
+ }, {
712
+ id: string;
713
+ name?: string | undefined;
714
+ description?: string | undefined;
715
+ maxTokens?: number | undefined;
716
+ contextWindow?: number | undefined;
717
+ capabilities?: ("reasoning" | "tools" | "temperature" | "images" | "streaming" | "prompt-cache" | "reasoning-effort" | "computer-use" | "global-endpoint" | "structured_output" | "files")[] | undefined;
718
+ apiFormat?: "default" | "openai-responses" | "r1" | undefined;
719
+ systemRole?: "system" | "developer" | undefined;
720
+ temperature?: number | undefined;
721
+ pricing?: {
722
+ input?: number | undefined;
723
+ output?: number | undefined;
724
+ cacheWrite?: number | undefined;
725
+ cacheRead?: number | undefined;
726
+ } | undefined;
727
+ thinkingConfig?: {
728
+ maxBudget?: number | undefined;
729
+ outputPrice?: number | undefined;
730
+ thinkingLevel?: "low" | "high" | undefined;
731
+ } | undefined;
732
+ status?: "active" | "preview" | "deprecated" | "legacy" | undefined;
733
+ deprecationNotice?: string | undefined;
734
+ replacedBy?: string | undefined;
735
+ releaseDate?: string | undefined;
736
+ deprecationDate?: string | undefined;
737
+ }>>>;
738
+ providerConfig: z.ZodOptional<z.ZodCustom<LlmsProviders.ProviderConfig, LlmsProviders.ProviderConfig>>;
739
+ initialMessages: z.ZodOptional<z.ZodArray<z.ZodCustom<LlmsProviders.Message, LlmsProviders.Message>>>;
740
+ systemPrompt: z.ZodString;
741
+ tools: z.ZodArray<z.ZodCustom<Tool<unknown, unknown>, Tool<unknown, unknown>>>;
742
+ maxIterations: z.ZodOptional<z.ZodNumber>;
743
+ maxParallelToolCalls: z.ZodDefault<z.ZodNumber>;
744
+ maxTokensPerTurn: z.ZodOptional<z.ZodNumber>;
745
+ apiTimeoutMs: z.ZodDefault<z.ZodNumber>;
746
+ userFileContentLoader: z.ZodOptional<z.ZodFunction<z.core.$ZodTuple<readonly [z.ZodString], z.core.$ZodFunctionOut>, z.ZodPromise<z.ZodString>>>;
747
+ reminderAfterIterations: z.ZodDefault<z.ZodNumber>;
748
+ reminderText: z.ZodOptional<z.ZodString>;
749
+ reasoningEffort: z.ZodOptional<z.ZodEnum<{
750
+ low: "low";
751
+ high: "high";
752
+ medium: "medium";
753
+ }>>;
754
+ thinkingBudgetTokens: z.ZodOptional<z.ZodNumber>;
755
+ thinking: z.ZodOptional<z.ZodBoolean>;
756
+ onEvent: z.ZodOptional<z.ZodFunction<z.core.$ZodTuple<readonly [z.ZodCustom<AgentEvent, AgentEvent>], z.core.$ZodFunctionOut>, z.ZodVoid>>;
757
+ hooks: z.ZodOptional<z.ZodCustom<AgentHooks, AgentHooks>>;
758
+ parentAgentId: z.ZodOptional<z.ZodString>;
759
+ extensions: z.ZodOptional<z.ZodArray<z.ZodCustom<AgentExtension, AgentExtension>>>;
760
+ hookErrorMode: z.ZodDefault<z.ZodEnum<{
761
+ ignore: "ignore";
762
+ throw: "throw";
763
+ }>>;
764
+ hookPolicies: z.ZodOptional<z.ZodCustom<HookPolicies, HookPolicies>>;
765
+ toolPolicies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
766
+ enabled: z.ZodOptional<z.ZodBoolean>;
767
+ autoApprove: z.ZodOptional<z.ZodBoolean>;
768
+ }, z.core.$strip>>>;
769
+ requestToolApproval: z.ZodOptional<z.ZodFunction<z.core.$ZodTuple<readonly [z.ZodObject<{
770
+ agentId: z.ZodString;
771
+ conversationId: z.ZodString;
772
+ iteration: z.ZodNumber;
773
+ toolCallId: z.ZodString;
774
+ toolName: z.ZodString;
775
+ input: z.ZodUnknown;
776
+ policy: z.ZodDefault<z.ZodObject<{
777
+ enabled: z.ZodOptional<z.ZodBoolean>;
778
+ autoApprove: z.ZodOptional<z.ZodBoolean>;
779
+ }, z.core.$strip>>;
780
+ }, z.core.$strip>], z.core.$ZodFunctionOut>, z.ZodUnion<readonly [z.ZodObject<{
781
+ approved: z.ZodBoolean;
782
+ reason: z.ZodOptional<z.ZodString>;
783
+ }, z.core.$strip>, z.ZodPromise<z.ZodObject<{
784
+ approved: z.ZodBoolean;
785
+ reason: z.ZodOptional<z.ZodString>;
786
+ }, z.core.$strip>>]>>>;
787
+ logger: z.ZodOptional<z.ZodCustom<BasicLogger, BasicLogger>>;
788
+ abortSignal: z.ZodOptional<z.ZodCustom<AbortSignal, AbortSignal>>;
789
+ }, z.core.$strip>;
790
+ /**
791
+ * Pending tool call from the model
792
+ */
793
+ export interface PendingToolCall {
794
+ id: string;
795
+ name: string;
796
+ input: unknown;
797
+ signature?: string;
798
+ review?: boolean;
799
+ }
800
+ /**
801
+ * Processed response from one turn of the loop
802
+ */
803
+ export interface ProcessedTurn {
804
+ /** Text output from the model */
805
+ text: string;
806
+ /** Reasoning/thinking content */
807
+ reasoning?: string;
808
+ /** Tool calls requested by the model */
809
+ toolCalls: PendingToolCall[];
810
+ /** Token usage for this turn */
811
+ usage: {
812
+ inputTokens: number;
813
+ outputTokens: number;
814
+ cacheReadTokens?: number;
815
+ cacheWriteTokens?: number;
816
+ cost?: number;
817
+ };
818
+ /** Whether the response was truncated */
819
+ truncated: boolean;
820
+ /** Response ID from the API */
821
+ responseId?: string;
822
+ }
823
+ export type ContentBlock = LlmsProviders.ContentBlock;
824
+ export type Message = LlmsProviders.Message;
825
+ export type ModelInfo = LlmsProviders.ModelInfo;
826
+ export type ToolDefinition = LlmsProviders.ToolDefinition;