@providerprotocol/agents 0.0.1 → 0.0.3

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 (74) hide show
  1. package/README.md +333 -6
  2. package/dist/checkpoint/index.d.ts +43 -0
  3. package/dist/checkpoint/index.js +64 -0
  4. package/dist/checkpoint/index.js.map +1 -0
  5. package/{src/execution/loop.ts → dist/chunk-4ESYN66B.js} +54 -162
  6. package/dist/chunk-4ESYN66B.js.map +1 -0
  7. package/dist/chunk-EKRXMSDX.js +8 -0
  8. package/dist/chunk-EKRXMSDX.js.map +1 -0
  9. package/dist/chunk-PHI5ULBV.js +427 -0
  10. package/dist/chunk-PHI5ULBV.js.map +1 -0
  11. package/dist/execution/index.d.ts +105 -0
  12. package/dist/execution/index.js +679 -0
  13. package/dist/execution/index.js.map +1 -0
  14. package/dist/index-qsPwbY86.d.ts +65 -0
  15. package/dist/index.d.ts +101 -0
  16. package/dist/index.js +218 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/middleware/index.d.ts +23 -0
  19. package/dist/middleware/index.js +82 -0
  20. package/dist/middleware/index.js.map +1 -0
  21. package/dist/thread-tree/index.d.ts +115 -0
  22. package/dist/thread-tree/index.js +4 -0
  23. package/dist/thread-tree/index.js.map +1 -0
  24. package/dist/types-2Vsthzyu.d.ts +163 -0
  25. package/dist/types-BhX9uD_d.d.ts +91 -0
  26. package/dist/types-DR02gtFv.d.ts +270 -0
  27. package/dist/types-NGQMdnaD.d.ts +65 -0
  28. package/package.json +40 -8
  29. package/.claude/settings.local.json +0 -27
  30. package/AGENTS.md +0 -681
  31. package/CLAUDE.md +0 -681
  32. package/bun.lock +0 -472
  33. package/eslint.config.js +0 -75
  34. package/index.ts +0 -1
  35. package/llms.md +0 -796
  36. package/specs/UAP-1.0.md +0 -2355
  37. package/src/agent/index.ts +0 -384
  38. package/src/agent/types.ts +0 -91
  39. package/src/checkpoint/file.ts +0 -126
  40. package/src/checkpoint/index.ts +0 -40
  41. package/src/checkpoint/types.ts +0 -95
  42. package/src/execution/index.ts +0 -37
  43. package/src/execution/plan.ts +0 -497
  44. package/src/execution/react.ts +0 -340
  45. package/src/execution/tool-ordering.ts +0 -186
  46. package/src/execution/types.ts +0 -315
  47. package/src/index.ts +0 -80
  48. package/src/middleware/index.ts +0 -7
  49. package/src/middleware/logging.ts +0 -123
  50. package/src/middleware/types.ts +0 -69
  51. package/src/state/index.ts +0 -301
  52. package/src/state/types.ts +0 -173
  53. package/src/thread-tree/index.ts +0 -249
  54. package/src/thread-tree/types.ts +0 -29
  55. package/src/utils/uuid.ts +0 -7
  56. package/tests/live/agent-anthropic.test.ts +0 -288
  57. package/tests/live/agent-strategy-hooks.test.ts +0 -268
  58. package/tests/live/checkpoint.test.ts +0 -243
  59. package/tests/live/execution-strategies.test.ts +0 -255
  60. package/tests/live/plan-strategy.test.ts +0 -160
  61. package/tests/live/subagent-events.live.test.ts +0 -249
  62. package/tests/live/thread-tree.test.ts +0 -186
  63. package/tests/unit/agent.test.ts +0 -703
  64. package/tests/unit/checkpoint.test.ts +0 -232
  65. package/tests/unit/execution/equivalence.test.ts +0 -402
  66. package/tests/unit/execution/loop.test.ts +0 -437
  67. package/tests/unit/execution/plan.test.ts +0 -590
  68. package/tests/unit/execution/react.test.ts +0 -604
  69. package/tests/unit/execution/subagent-events.test.ts +0 -235
  70. package/tests/unit/execution/tool-ordering.test.ts +0 -310
  71. package/tests/unit/middleware/logging.test.ts +0 -276
  72. package/tests/unit/state.test.ts +0 -573
  73. package/tests/unit/thread-tree.test.ts +0 -249
  74. package/tsconfig.json +0 -29
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/middleware/logging.ts"],"names":[],"mappings":";AAGA,IAAM,uBAAA,GAAoD;AAAA,EACxD,KAAA,EAAO,MAAA;AAAA,EACP,QAAQ,OAAA,CAAQ,GAAA;AAAA,EAChB,eAAA,EAAiB,KAAA;AAAA,EACjB,aAAA,EAAe;AACjB,CAAA;AAE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AA,CAAO,IAAA,CAAK,QAAA,CAAS,KAAK,SAAA,CAAU,CAAA,EAAG,GAAG,CAAC,CAAA,GAAA,CAAK,CAAA;AAAA,MAC5E;AAEA,MAAA,OAAO,MAAA;AAAA,IACT,CAAA;AAAA,IAEA,MAAM,OAAA,CACJ,OAAA,EACA,KAAA,EACgC;AAChC,MAAA,IAAI,OAAA,GAAU,CAAA,kBAAA,EAAqB,KAAA,CAAM,OAAO,CAAA,CAAA;AAEhD,MAAA,IAAI,KAAK,aAAA,EAAe;AACtB,QAAA,MAAM,SAAA,GAAY,OAAA,CAAQ,QAAA,CAAS,GAAA,CAAI,oBAAoB,CAAA;AAC3D,QAAA,IAAI,SAAA,EAAW;AACb,UAAA,MAAM,QAAA,GAAW,IAAA,CAAK,GAAA,EAAI,GAAI,SAAA;AAC9B,UAAA,OAAA,IAAW,UAAU,QAAQ,CAAA,EAAA,CAAA;AAAA,QAC/B;AAAA,MACF;AAEA,MAAA,OAAA,IAAW,CAAA,EAAA,EAAK,aAAA,CAAc,OAAO,CAAC,CAAA,CAAA;AAEtC,MAAA,GAAA,CAAI,SAAS,OAAO,CAAA;AAGpB,MAAA,OAAO,MAAA;AAAA,IACT;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import type { Middleware, LoggingOptions, MiddlewareContext } from './types.ts';\nimport type { GenerateResult } from '../execution/types.ts';\n\nconst DEFAULT_LOGGING_OPTIONS: Required<LoggingOptions> = {\n level: 'info',\n logger: console.log,\n includeMessages: false,\n includeTiming: true,\n};\n\nconst LOG_LEVELS = {\n debug: 0,\n info: 1,\n warn: 2,\n error: 3,\n} as const;\n\n/**\n * Create a logging middleware.\n *\n * Logs agent execution with configurable detail level:\n * - Execution start/end\n * - Timing information (if enabled)\n * - Message content (if enabled)\n * - Errors\n *\n * @param options - Logging configuration options\n * @returns Middleware\n */\nexport function logging(options: LoggingOptions = {}): Middleware {\n const opts = { ...DEFAULT_LOGGING_OPTIONS, ...options };\n const currentLevel = LOG_LEVELS[opts.level];\n\n function shouldLog(level: keyof typeof LOG_LEVELS): boolean {\n return LOG_LEVELS[level] >= currentLevel;\n }\n\n function log(level: keyof typeof LOG_LEVELS, message: string): void {\n if (shouldLog(level)) {\n const prefix = `[UAP:${level.toUpperCase()}]`;\n opts.logger(`${prefix} ${message}`);\n }\n }\n\n function formatContext(context: MiddlewareContext): string {\n const parts = [`agent=${context.agent.id}`];\n\n if (opts.includeMessages) {\n parts.push(`messages=${context.state.messages.length}`);\n }\n\n return parts.join(' ');\n }\n\n return {\n name: 'logging',\n\n async before(context: MiddlewareContext): Promise<MiddlewareContext | void> {\n log('info', `Execution started: ${formatContext(context)}`);\n\n if (opts.includeTiming) {\n context.metadata.set('_logging_startTime', Date.now());\n }\n\n if (opts.includeMessages && shouldLog('debug')) {\n log('debug', `Input: ${JSON.stringify(context.input)}`);\n }\n\n return context;\n },\n\n async after(\n context: MiddlewareContext,\n result: GenerateResult,\n ): Promise<GenerateResult> {\n let message = 'Execution completed';\n\n if (opts.includeTiming) {\n const startTime = context.metadata.get('_logging_startTime') as number | undefined;\n if (startTime) {\n const duration = Date.now() - startTime;\n message += ` in ${duration}ms`;\n }\n }\n\n message += `: ${formatContext(context)}`;\n\n if (result.turn.usage) {\n message += ` tokens=${result.turn.usage.totalTokens}`;\n }\n\n log('info', message);\n\n if (opts.includeMessages && shouldLog('debug')) {\n log('debug', `Response: ${result.turn.response.text.substring(0, 200)}...`);\n }\n\n return result;\n },\n\n async onError(\n context: MiddlewareContext,\n error: Error,\n ): Promise<GenerateResult | void> {\n let message = `Execution failed: ${error.message}`;\n\n if (opts.includeTiming) {\n const startTime = context.metadata.get('_logging_startTime') as number | undefined;\n if (startTime) {\n const duration = Date.now() - startTime;\n message += ` after ${duration}ms`;\n }\n }\n\n message += `: ${formatContext(context)}`;\n\n log('error', message);\n\n // Let the error propagate\n return undefined;\n },\n };\n}\n"]}
@@ -0,0 +1,115 @@
1
+ import { A as AgentState } from '../index-qsPwbY86.js';
2
+ import { a as AgentStateJSON } from '../types-2Vsthzyu.js';
3
+ import '@providerprotocol/ai';
4
+
5
+ /**
6
+ * Serialized form of a ThreadNode.
7
+ */
8
+ interface ThreadNodeJSON {
9
+ /** Node ID */
10
+ id: string;
11
+ /** Parent node ID (null for root) */
12
+ parentId: string | null;
13
+ /** State snapshot at this node */
14
+ state: AgentStateJSON;
15
+ /** Optional branch name */
16
+ name?: string;
17
+ /** Child node IDs */
18
+ children: string[];
19
+ }
20
+ /**
21
+ * Serialized form of a ThreadTree.
22
+ */
23
+ interface ThreadTreeJSON {
24
+ /** Root node ID */
25
+ rootId: string;
26
+ /** Current (active) node ID */
27
+ currentId: string;
28
+ /** All nodes */
29
+ nodes: ThreadNodeJSON[];
30
+ }
31
+
32
+ /**
33
+ * A node in the thread tree representing a conversation state snapshot.
34
+ */
35
+ declare class ThreadNode {
36
+ /** Node ID (UUIDv4) */
37
+ readonly id: string;
38
+ /** Parent node ID (null for root) */
39
+ readonly parentId: string | null;
40
+ /** State snapshot at this node */
41
+ state: AgentState;
42
+ /** Optional branch name */
43
+ name?: string;
44
+ /** Child node IDs */
45
+ readonly children: string[];
46
+ constructor(id: string, parentId: string | null, state: AgentState, name?: string, children?: string[]);
47
+ /**
48
+ * Serialize to JSON.
49
+ */
50
+ toJSON(): ThreadNodeJSON;
51
+ /**
52
+ * Deserialize from JSON.
53
+ */
54
+ static fromJSON(json: ThreadNodeJSON): ThreadNode;
55
+ }
56
+ /**
57
+ * A tree-structured collection of conversation threads with parent-child relationships.
58
+ * Enables branching conversations and easy switching between alternative paths.
59
+ */
60
+ declare class ThreadTree {
61
+ /** Root node */
62
+ readonly root: ThreadNode;
63
+ /** Currently active node */
64
+ private currentNode;
65
+ /** All nodes by ID */
66
+ readonly nodes: Map<string, ThreadNode>;
67
+ constructor(root?: ThreadNode);
68
+ /**
69
+ * Get the currently active node.
70
+ */
71
+ get current(): ThreadNode;
72
+ /**
73
+ * Create a branch from a node.
74
+ *
75
+ * @param fromId - ID of the node to branch from
76
+ * @param name - Optional name for the branch
77
+ * @returns ID of the new node
78
+ */
79
+ branch(fromId: string, name?: string): string;
80
+ /**
81
+ * Switch to a different node.
82
+ *
83
+ * @param nodeId - ID of the node to switch to
84
+ */
85
+ checkout(nodeId: string): void;
86
+ /**
87
+ * Get the AgentState representing the full history from root to current node.
88
+ * Since nodes store full state snapshots, this returns the current node's state.
89
+ *
90
+ * @returns AgentState with combined history
91
+ */
92
+ history(): AgentState;
93
+ /**
94
+ * Get all leaf nodes (nodes with no children).
95
+ *
96
+ * @returns Array of leaf node IDs
97
+ */
98
+ getLeaves(): string[];
99
+ /**
100
+ * Get all branch names.
101
+ *
102
+ * @returns Map of node IDs to branch names
103
+ */
104
+ getBranches(): Map<string, string | undefined>;
105
+ /**
106
+ * Serialize to JSON.
107
+ */
108
+ toJSON(): ThreadTreeJSON;
109
+ /**
110
+ * Deserialize from JSON.
111
+ */
112
+ static fromJSON(json: ThreadTreeJSON): ThreadTree;
113
+ }
114
+
115
+ export { ThreadNode, type ThreadNodeJSON, ThreadTree, type ThreadTreeJSON };
@@ -0,0 +1,4 @@
1
+ export { ThreadNode, ThreadTree } from '../chunk-PHI5ULBV.js';
2
+ import '../chunk-EKRXMSDX.js';
3
+ //# sourceMappingURL=index.js.map
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,163 @@
1
+ import { Message, TokenUsage, MessageMetadata } from '@providerprotocol/ai';
2
+
3
+ /**
4
+ * Status of a plan step during execution.
5
+ */
6
+ type PlanStepStatus = 'pending' | 'in_progress' | 'completed' | 'failed';
7
+ /**
8
+ * A single tool execution trace from a sub-agent.
9
+ * Per UAP spec Section 8.8.
10
+ */
11
+ interface ToolExecutionTrace {
12
+ /** Name of the tool */
13
+ toolName: string;
14
+ /** Tool call ID */
15
+ toolCallId?: string;
16
+ /** Arguments passed to the tool */
17
+ arguments: Record<string, unknown>;
18
+ /** Tool result */
19
+ result: string;
20
+ /** Whether the tool errored */
21
+ isError?: boolean;
22
+ /** Execution time in milliseconds */
23
+ duration?: number;
24
+ }
25
+ /**
26
+ * Sub-agent execution trace for checkpoint persistence.
27
+ * Per UAP spec Section 8.8.
28
+ */
29
+ interface SubagentExecutionTrace {
30
+ /** Unique ID of the sub-agent instance */
31
+ subagentId: string;
32
+ /** Type/name of the sub-agent */
33
+ subagentType: string;
34
+ /** Tool call ID that spawned this sub-agent */
35
+ parentToolCallId: string;
36
+ /** The task given to the sub-agent */
37
+ prompt: string;
38
+ /** Start timestamp (ms since epoch) */
39
+ startTime: number;
40
+ /** End timestamp (ms since epoch) */
41
+ endTime: number;
42
+ /** Whether execution succeeded */
43
+ success: boolean;
44
+ /** Sub-agent's response (if successful) */
45
+ result?: string;
46
+ /** Error message (if failed) */
47
+ error?: string;
48
+ /** Tools used by sub-agent */
49
+ toolExecutions?: ToolExecutionTrace[];
50
+ /** Token usage for sub-agent */
51
+ usage?: TokenUsage;
52
+ }
53
+ /**
54
+ * Serialized form of SubagentExecutionTrace.
55
+ */
56
+ interface SubagentExecutionTraceJSON {
57
+ subagentId: string;
58
+ subagentType: string;
59
+ parentToolCallId: string;
60
+ prompt: string;
61
+ startTime: number;
62
+ endTime: number;
63
+ success: boolean;
64
+ result?: string;
65
+ error?: string;
66
+ toolExecutions?: ToolExecutionTrace[];
67
+ usage?: TokenUsage;
68
+ }
69
+ /**
70
+ * A single step in an execution plan.
71
+ */
72
+ interface PlanStep {
73
+ /** Unique step identifier */
74
+ id: string;
75
+ /** Description of what this step does */
76
+ description: string;
77
+ /** Tool to use (if applicable) */
78
+ tool?: string;
79
+ /** IDs of steps this depends on */
80
+ dependsOn: string[];
81
+ /** Current status */
82
+ status: PlanStepStatus;
83
+ }
84
+ /**
85
+ * Serialized form of a PlanStep.
86
+ */
87
+ interface PlanStepJSON {
88
+ id: string;
89
+ description: string;
90
+ tool?: string;
91
+ dependsOn: string[];
92
+ status: PlanStepStatus;
93
+ }
94
+ /**
95
+ * Serialized form of AgentState for persistence.
96
+ */
97
+ interface AgentStateJSON {
98
+ /** UAP version */
99
+ version: string;
100
+ /** State snapshot ID */
101
+ id: string;
102
+ /** Serialized messages */
103
+ messages: MessageJSON[];
104
+ /** Current step number */
105
+ step: number;
106
+ /** User-defined metadata */
107
+ metadata: Record<string, unknown>;
108
+ /** Reasoning traces (for ReAct) */
109
+ reasoning: string[];
110
+ /** Execution plan (for Plan strategy) */
111
+ plan?: PlanStepJSON[];
112
+ /** Sub-agent execution traces (per UAP spec Section 8.8) */
113
+ subagentTraces?: SubagentExecutionTraceJSON[];
114
+ }
115
+ /**
116
+ * Serialized form of a Message.
117
+ * This preserves the UPP Message structure for serialization.
118
+ */
119
+ interface MessageJSON {
120
+ role: 'user' | 'assistant' | 'tool_result';
121
+ content: unknown;
122
+ metadata?: MessageMetadata;
123
+ }
124
+ /**
125
+ * Interface for AgentState operations.
126
+ * All operations return new instances (immutable).
127
+ */
128
+ interface AgentStateInterface {
129
+ /** State snapshot ID (UUIDv4) */
130
+ readonly id: string;
131
+ /** Conversation history (UPP Messages) */
132
+ readonly messages: readonly Message[];
133
+ /** Current step number */
134
+ readonly step: number;
135
+ /** User-defined metadata */
136
+ readonly metadata: Readonly<Record<string, unknown>>;
137
+ /** Reasoning traces (for ReAct) */
138
+ readonly reasoning: readonly string[];
139
+ /** Execution plan (for Plan strategy) */
140
+ readonly plan: readonly PlanStep[] | undefined;
141
+ /** Sub-agent execution traces (per UAP spec Section 8.8) */
142
+ readonly subagentTraces: readonly SubagentExecutionTrace[];
143
+ /** Return new state with message added */
144
+ withMessage(message: Message): AgentStateInterface;
145
+ /** Return new state with messages added */
146
+ withMessages(messages: Message[]): AgentStateInterface;
147
+ /** Return new state with context replaced (all messages) */
148
+ withContext(messages: Message[]): AgentStateInterface;
149
+ /** Return new state with updated step */
150
+ withStep(step: number): AgentStateInterface;
151
+ /** Return new state with metadata entry */
152
+ withMetadata(key: string, value: unknown): AgentStateInterface;
153
+ /** Return new state with reasoning added */
154
+ withReasoning(reasoning: string): AgentStateInterface;
155
+ /** Return new state with plan set */
156
+ withPlan(plan: PlanStep[]): AgentStateInterface;
157
+ /** Return new state with sub-agent trace added */
158
+ withSubagentTrace(trace: SubagentExecutionTrace): AgentStateInterface;
159
+ /** Serialize to JSON */
160
+ toJSON(): AgentStateJSON;
161
+ }
162
+
163
+ export type { AgentStateInterface as A, PlanStep as P, SubagentExecutionTrace as S, ToolExecutionTrace as T, AgentStateJSON as a, PlanStepStatus as b, SubagentExecutionTraceJSON as c };
@@ -0,0 +1,91 @@
1
+ import { a as AgentStateJSON } from './types-2Vsthzyu.js';
2
+
3
+ /**
4
+ * Checkpoint Types
5
+ *
6
+ * Type definitions for step-level persistence and session resume.
7
+ *
8
+ * @see UAP-1.0 Spec Section 12.4
9
+ */
10
+
11
+ /**
12
+ * Checkpoint store interface.
13
+ *
14
+ * Implementations handle persistence of agent state at step boundaries
15
+ * for crash recovery and session resume.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const store = fileCheckpoints({ dir: './checkpoints' });
20
+ *
21
+ * // Save checkpoint
22
+ * await store.save('session-123', state.toJSON());
23
+ *
24
+ * // Load checkpoint
25
+ * const saved = await store.load('session-123');
26
+ * if (saved) {
27
+ * const restored = AgentState.fromJSON(saved);
28
+ * }
29
+ * ```
30
+ */
31
+ interface CheckpointStore {
32
+ /**
33
+ * Save a checkpoint at the current state.
34
+ *
35
+ * @param sessionId - Session identifier
36
+ * @param state - Serialized agent state
37
+ */
38
+ save(sessionId: string, state: AgentStateJSON): Promise<void>;
39
+ /**
40
+ * Load the most recent checkpoint for a session.
41
+ *
42
+ * @param sessionId - Session identifier
43
+ * @returns Serialized state or null if not found
44
+ */
45
+ load(sessionId: string): Promise<AgentStateJSON | null>;
46
+ /**
47
+ * Delete all checkpoints for a session.
48
+ *
49
+ * @param sessionId - Session identifier
50
+ */
51
+ delete(sessionId: string): Promise<void>;
52
+ /**
53
+ * List all session IDs with checkpoints.
54
+ *
55
+ * @returns Array of session IDs
56
+ */
57
+ list(): Promise<string[]>;
58
+ }
59
+ /**
60
+ * Options for file-based checkpoint store.
61
+ */
62
+ interface FileCheckpointOptions {
63
+ /** Directory for checkpoint files. Default: ".checkpoints" */
64
+ dir?: string;
65
+ }
66
+ /**
67
+ * Checkpoint metadata stored alongside state.
68
+ */
69
+ interface CheckpointMetadata {
70
+ /** Session identifier */
71
+ sessionId: string;
72
+ /** Unique checkpoint ID */
73
+ checkpointId: string;
74
+ /** ISO 8601 timestamp */
75
+ timestamp: string;
76
+ /** Step number at checkpoint */
77
+ step: number;
78
+ /** Agent instance ID */
79
+ agentId: string;
80
+ }
81
+ /**
82
+ * Full checkpoint data including state and metadata.
83
+ */
84
+ interface CheckpointData {
85
+ /** Checkpoint metadata */
86
+ metadata: CheckpointMetadata;
87
+ /** Serialized agent state */
88
+ state: AgentStateJSON;
89
+ }
90
+
91
+ export type { CheckpointStore as C, FileCheckpointOptions as F, CheckpointMetadata as a, CheckpointData as b };
@@ -0,0 +1,270 @@
1
+ import { LLMInstance, Message, Tool, ToolCall, ToolExecution, Turn, StreamEvent, TokenUsage } from '@providerprotocol/ai';
2
+ import { A as AgentState } from './index-qsPwbY86.js';
3
+ import { C as CheckpointStore } from './types-BhX9uD_d.js';
4
+
5
+ /**
6
+ * Result of agent generation.
7
+ */
8
+ interface GenerateResult {
9
+ /** Standard UPP Turn */
10
+ turn: Turn;
11
+ /** New immutable state */
12
+ state: AgentState;
13
+ }
14
+ /**
15
+ * Agent lifecycle hooks for execution control.
16
+ */
17
+ interface AgentStrategy {
18
+ /** Evaluate if execution should stop */
19
+ stopCondition?: (state: AgentState) => boolean | Promise<boolean>;
20
+ /** Called when step begins */
21
+ onStepStart?: (step: number, state: AgentState) => void;
22
+ /** Called during reasoning phase (ReAct) */
23
+ onReason?: (step: number, reasoning: string) => void;
24
+ /** Called during action phase */
25
+ onAct?: (step: number, actions: ToolCall[]) => void;
26
+ /** Called during observation phase */
27
+ onObserve?: (step: number, observations: ToolExecution[]) => void;
28
+ /** Called when step completes */
29
+ onStepEnd?: (step: number, result: {
30
+ turn: Turn;
31
+ state: AgentState;
32
+ }) => void;
33
+ /** Called when execution completes */
34
+ onComplete?: (result: GenerateResult) => void;
35
+ /** Called on execution error */
36
+ onError?: (error: Error, state: AgentState) => void | GenerateResult;
37
+ }
38
+ /**
39
+ * Forward declaration of Agent for use in ExecutionContext.
40
+ * The actual Agent interface is defined in agent/types.ts.
41
+ */
42
+ interface AgentRef {
43
+ id: string;
44
+ system?: string;
45
+ }
46
+ /**
47
+ * Context passed to execution strategies.
48
+ */
49
+ interface ExecutionContext {
50
+ /** The agent being executed */
51
+ agent: AgentRef;
52
+ /** The bound LLM instance */
53
+ llm: LLMInstance;
54
+ /** The user input message */
55
+ input: Message;
56
+ /** Current immutable state */
57
+ state: AgentState;
58
+ /** Resolved tools */
59
+ tools: Tool[];
60
+ /** Agent lifecycle hooks */
61
+ strategy: AgentStrategy;
62
+ /** Abort signal for cancellation */
63
+ signal?: AbortSignal;
64
+ /** Checkpoint store for persistence (optional) */
65
+ checkpoints?: CheckpointStore;
66
+ /** Session ID for checkpointing */
67
+ sessionId?: string;
68
+ }
69
+ /**
70
+ * Result from execution strategy.
71
+ */
72
+ interface ExecutionResult {
73
+ /** The complete UPP Turn */
74
+ turn: Turn;
75
+ /** New immutable state */
76
+ state: AgentState;
77
+ }
78
+ /**
79
+ * UAP-level event types for streaming.
80
+ */
81
+ type UAPEventType = 'step_start' | 'step_end' | 'reasoning' | 'action' | 'observation' | 'plan_created' | 'plan_step_start' | 'plan_step_end' | 'subagent_start' | 'subagent_event' | 'subagent_end';
82
+ /**
83
+ * Agent stream event - wraps both UAP and UPP events.
84
+ */
85
+ interface AgentStreamEvent {
86
+ /** Event source */
87
+ source: 'uap' | 'upp';
88
+ /** Present when source === 'uap' */
89
+ uap?: {
90
+ type: UAPEventType;
91
+ step: number;
92
+ agentId: string;
93
+ data: Record<string, unknown>;
94
+ };
95
+ /** Present when source === 'upp' */
96
+ upp?: StreamEvent;
97
+ }
98
+ /**
99
+ * Streaming result from agent execution.
100
+ */
101
+ interface AgentStreamResult {
102
+ /** Async iterator for stream events */
103
+ [Symbol.asyncIterator](): AsyncIterator<AgentStreamEvent>;
104
+ /** Resolves to final result after stream completes */
105
+ result: Promise<GenerateResult>;
106
+ /** Abort the stream */
107
+ abort(): void;
108
+ }
109
+ /**
110
+ * Execution strategy interface.
111
+ * Strategies define HOW an agent executes (loop, react, plan).
112
+ */
113
+ interface ExecutionStrategy {
114
+ /** Strategy name */
115
+ name: string;
116
+ /** Execute the strategy */
117
+ execute(context: ExecutionContext): Promise<ExecutionResult>;
118
+ /** Execute with streaming */
119
+ stream(context: ExecutionContext): AgentStreamResult;
120
+ }
121
+ /**
122
+ * Options for loop() strategy.
123
+ */
124
+ interface LoopOptions {
125
+ /** Maximum tool execution rounds. Default: Infinity */
126
+ maxIterations?: number;
127
+ }
128
+ /**
129
+ * Options for react() strategy.
130
+ */
131
+ interface ReactOptions {
132
+ /** Maximum reason-act-observe cycles. Default: Infinity */
133
+ maxSteps?: number;
134
+ /** Prompt suffix for reasoning phase */
135
+ reasoningPrompt?: string;
136
+ }
137
+ /**
138
+ * Options for plan() strategy.
139
+ */
140
+ interface PlanOptions {
141
+ /** Maximum steps in a plan. Default: Infinity */
142
+ maxPlanSteps?: number;
143
+ /** Allow replanning on failure. Default: true */
144
+ allowReplan?: boolean;
145
+ /** Schema for plan structure */
146
+ planSchema?: Record<string, unknown>;
147
+ }
148
+ /**
149
+ * Tool dependency options for execution ordering.
150
+ * These extend the base UPP Tool interface with UAP-specific fields.
151
+ *
152
+ * @see UAP-1.0 Spec Section 8.5
153
+ */
154
+ interface ToolDependencyOptions {
155
+ /**
156
+ * If true, this tool must complete before other tools start.
157
+ * Sequential tools create a barrier in parallel execution.
158
+ */
159
+ sequential?: boolean;
160
+ /**
161
+ * Tool names that must complete before this tool can execute.
162
+ * Used for explicit dependency chains.
163
+ */
164
+ dependsOn?: string[];
165
+ }
166
+ /**
167
+ * Extended Tool interface with UAP dependency options.
168
+ * Use this type when defining tools that need execution ordering.
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * const readTool: ToolWithDependencies = {
173
+ * name: 'read_file',
174
+ * description: 'Read a file',
175
+ * parameters: { ... },
176
+ * sequential: true, // Must complete before other tools
177
+ * run: async (params) => { ... },
178
+ * };
179
+ *
180
+ * const writeTool: ToolWithDependencies = {
181
+ * name: 'write_file',
182
+ * description: 'Write a file',
183
+ * parameters: { ... },
184
+ * dependsOn: ['read_file'], // Waits for read_file to complete
185
+ * run: async (params) => { ... },
186
+ * };
187
+ * ```
188
+ */
189
+ interface ToolWithDependencies extends Tool, ToolDependencyOptions {
190
+ }
191
+ /**
192
+ * Model-driven tool call with optional execution order hint.
193
+ * Models MAY include an `after` field to signal dependencies.
194
+ *
195
+ * @see UAP-1.0 Spec Section 8.6
196
+ */
197
+ interface OrderedToolCall extends ToolCall {
198
+ /** Tool call IDs that must complete before this call executes */
199
+ after?: string[];
200
+ }
201
+ /**
202
+ * Sub-agent event types for hierarchical agent execution.
203
+ *
204
+ * @see UAP-1.0 Spec Section 8.7
205
+ */
206
+ type SubagentEventType = 'subagent_start' | 'subagent_event' | 'subagent_end';
207
+ /**
208
+ * Base fields present in all subagent events.
209
+ */
210
+ interface SubagentEventBase {
211
+ /** Unique ID of the sub-agent instance */
212
+ subagentId: string;
213
+ /** Type/name of the sub-agent (e.g., "explorer", "planner") */
214
+ subagentType: string;
215
+ /** The parent tool call ID that spawned this sub-agent */
216
+ parentToolCallId: string;
217
+ }
218
+ /**
219
+ * Event emitted when a sub-agent starts execution.
220
+ */
221
+ interface SubagentStartEvent extends SubagentEventBase {
222
+ type: 'subagent_start';
223
+ /** The task/prompt given to the sub-agent */
224
+ prompt: string;
225
+ /** Start timestamp in milliseconds */
226
+ timestamp: number;
227
+ }
228
+ /**
229
+ * Event emitted for forwarded events from sub-agent execution.
230
+ */
231
+ interface SubagentInnerEvent extends SubagentEventBase {
232
+ type: 'subagent_event';
233
+ /** The actual event from the sub-agent */
234
+ innerEvent: AgentStreamEvent;
235
+ }
236
+ /**
237
+ * Event emitted when a sub-agent completes execution.
238
+ */
239
+ interface SubagentEndEvent extends SubagentEventBase {
240
+ type: 'subagent_end';
241
+ /** Whether the sub-agent completed successfully */
242
+ success: boolean;
243
+ /** Sub-agent's response text (if successful) */
244
+ result?: string;
245
+ /** Error message (if failed) */
246
+ error?: string;
247
+ /** End timestamp in milliseconds */
248
+ timestamp: number;
249
+ /** Tools used by the sub-agent */
250
+ toolExecutions?: Array<{
251
+ toolName: string;
252
+ arguments: Record<string, unknown>;
253
+ result: string;
254
+ }>;
255
+ /** Token usage for this sub-agent run */
256
+ usage?: TokenUsage;
257
+ }
258
+ /**
259
+ * Union type for all sub-agent events.
260
+ *
261
+ * @see UAP-1.0 Spec Section 8.7
262
+ */
263
+ type SubagentEvent = SubagentStartEvent | SubagentInnerEvent | SubagentEndEvent;
264
+ /**
265
+ * Callback type for receiving sub-agent events.
266
+ * Tools that spawn sub-agents SHOULD accept this callback.
267
+ */
268
+ type OnSubagentEvent = (event: SubagentEvent) => void;
269
+
270
+ export type { AgentStrategy as A, ExecutionStrategy as E, GenerateResult as G, LoopOptions as L, OnSubagentEvent as O, PlanOptions as P, ReactOptions as R, SubagentEventType as S, ToolDependencyOptions as T, UAPEventType as U, AgentStreamResult as a, AgentStreamEvent as b, SubagentEventBase as c, SubagentStartEvent as d, SubagentInnerEvent as e, SubagentEndEvent as f, SubagentEvent as g, ExecutionContext as h, ExecutionResult as i, ToolWithDependencies as j, OrderedToolCall as k };