@vibe-agent-toolkit/agent-runtime 0.1.2-rc.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.
- package/README.md +295 -0
- package/dist/adapter-types.d.ts +48 -0
- package/dist/adapter-types.d.ts.map +1 -0
- package/dist/adapter-types.js +24 -0
- package/dist/adapter-types.js.map +1 -0
- package/dist/agent-helpers.d.ts +128 -0
- package/dist/agent-helpers.d.ts.map +1 -0
- package/dist/agent-helpers.js +291 -0
- package/dist/agent-helpers.js.map +1 -0
- package/dist/agentic-researcher.d.ts +63 -0
- package/dist/agentic-researcher.d.ts.map +1 -0
- package/dist/agentic-researcher.js +60 -0
- package/dist/agentic-researcher.js.map +1 -0
- package/dist/conversational-assistant.d.ts +57 -0
- package/dist/conversational-assistant.d.ts.map +1 -0
- package/dist/conversational-assistant.js +48 -0
- package/dist/conversational-assistant.js.map +1 -0
- package/dist/conversational-helpers.d.ts +26 -0
- package/dist/conversational-helpers.d.ts.map +1 -0
- package/dist/conversational-helpers.js +34 -0
- package/dist/conversational-helpers.js.map +1 -0
- package/dist/execute-wrapper.d.ts +59 -0
- package/dist/execute-wrapper.d.ts.map +1 -0
- package/dist/execute-wrapper.js +98 -0
- package/dist/execute-wrapper.js.map +1 -0
- package/dist/external-event-integrator.d.ts +66 -0
- package/dist/external-event-integrator.d.ts.map +1 -0
- package/dist/external-event-integrator.js +62 -0
- package/dist/external-event-integrator.js.map +1 -0
- package/dist/function-event-consumer.d.ts +60 -0
- package/dist/function-event-consumer.d.ts.map +1 -0
- package/dist/function-event-consumer.js +52 -0
- package/dist/function-event-consumer.js.map +1 -0
- package/dist/function-orchestrator.d.ts +45 -0
- package/dist/function-orchestrator.d.ts.map +1 -0
- package/dist/function-orchestrator.js +51 -0
- package/dist/function-orchestrator.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/llm-analyzer.d.ts +58 -0
- package/dist/llm-analyzer.d.ts.map +1 -0
- package/dist/llm-analyzer.js +53 -0
- package/dist/llm-analyzer.js.map +1 -0
- package/dist/llm-coordinator.d.ts +62 -0
- package/dist/llm-coordinator.d.ts.map +1 -0
- package/dist/llm-coordinator.js +60 -0
- package/dist/llm-coordinator.js.map +1 -0
- package/dist/llm-event-handler.d.ts +67 -0
- package/dist/llm-event-handler.d.ts.map +1 -0
- package/dist/llm-event-handler.js +65 -0
- package/dist/llm-event-handler.js.map +1 -0
- package/dist/pure-function.d.ts +34 -0
- package/dist/pure-function.d.ts.map +1 -0
- package/dist/pure-function.js +40 -0
- package/dist/pure-function.js.map +1 -0
- package/dist/result-helpers.d.ts +80 -0
- package/dist/result-helpers.d.ts.map +1 -0
- package/dist/result-helpers.js +232 -0
- package/dist/result-helpers.js.map +1 -0
- package/dist/session/errors.d.ts +11 -0
- package/dist/session/errors.d.ts.map +1 -0
- package/dist/session/errors.js +15 -0
- package/dist/session/errors.js.map +1 -0
- package/dist/session/file-session-store.d.ts +46 -0
- package/dist/session/file-session-store.d.ts.map +1 -0
- package/dist/session/file-session-store.js +149 -0
- package/dist/session/file-session-store.js.map +1 -0
- package/dist/session/index.d.ts +12 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +13 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/memory-session-store.d.ts +35 -0
- package/dist/session/memory-session-store.d.ts.map +1 -0
- package/dist/session/memory-session-store.js +76 -0
- package/dist/session/memory-session-store.js.map +1 -0
- package/dist/session/session-store-helpers.d.ts +26 -0
- package/dist/session/session-store-helpers.d.ts.map +1 -0
- package/dist/session/session-store-helpers.js +54 -0
- package/dist/session/session-store-helpers.js.map +1 -0
- package/dist/session/test-helpers/index.d.ts +61 -0
- package/dist/session/test-helpers/index.d.ts.map +1 -0
- package/dist/session/test-helpers/index.js +167 -0
- package/dist/session/test-helpers/index.js.map +1 -0
- package/dist/session/types.d.ts +86 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +8 -0
- package/dist/session/types.js.map +1 -0
- package/dist/shared-validation.d.ts +21 -0
- package/dist/shared-validation.d.ts.map +1 -0
- package/dist/shared-validation.js +45 -0
- package/dist/shared-validation.js.map +1 -0
- package/dist/test-helpers.d.ts +50 -0
- package/dist/test-helpers.d.ts.map +1 -0
- package/dist/test-helpers.js +47 -0
- package/dist/test-helpers.js.map +1 -0
- package/dist/two-phase-conversational.d.ts +173 -0
- package/dist/two-phase-conversational.d.ts.map +1 -0
- package/dist/two-phase-conversational.js +205 -0
- package/dist/two-phase-conversational.js.map +1 -0
- package/dist/types.d.ts +194 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions for creating agents.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Default LLM error for unknown failures.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
const LLM_UNAVAILABLE_ERROR = 'llm-unavailable';
|
|
9
|
+
/**
|
|
10
|
+
* Validate agent input against a Zod schema.
|
|
11
|
+
*
|
|
12
|
+
* Returns parsed data on success, or OneShotAgentOutput error envelope on failure.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // For LLM agents
|
|
16
|
+
* const validatedOrError = validateAgentInput<MyInput, MyOutput, LLMError>(input, InputSchema, 'llm-invalid-output');
|
|
17
|
+
* if ('result' in validatedOrError) {
|
|
18
|
+
* return validatedOrError; // Validation error
|
|
19
|
+
* }
|
|
20
|
+
* const { characteristics, mockable } = validatedOrError;
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // For external event agents
|
|
24
|
+
* const validatedOrError = validateAgentInput<MyInput, MyOutput, ExternalEventError>(
|
|
25
|
+
* input,
|
|
26
|
+
* InputSchema,
|
|
27
|
+
* 'event-invalid-response'
|
|
28
|
+
* );
|
|
29
|
+
*/
|
|
30
|
+
// eslint-disable-next-line sonarjs/function-return-type -- Intentional discriminated union pattern
|
|
31
|
+
export function validateAgentInput(input, schema, invalidInputError = 'llm-invalid-output') {
|
|
32
|
+
const parsed = schema.safeParse(input);
|
|
33
|
+
if (!parsed.success) {
|
|
34
|
+
return {
|
|
35
|
+
result: { status: 'error', error: invalidInputError },
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return parsed.data;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Wrap LLM calls to catch expected failures and map to result errors.
|
|
42
|
+
*
|
|
43
|
+
* Handles common LLM failure modes:
|
|
44
|
+
* - API timeouts → 'llm-timeout'
|
|
45
|
+
* - Rate limits → 'llm-rate-limit'
|
|
46
|
+
* - Content policy → 'llm-refusal'
|
|
47
|
+
* - Invalid output → 'llm-invalid-output'
|
|
48
|
+
* - Service errors → 'llm-unavailable'
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const llmResult = await executeLLMCall(
|
|
52
|
+
* () => llm.chat.completions.create({...}),
|
|
53
|
+
* {
|
|
54
|
+
* parseOutput: (raw) => CatCharacteristicsSchema.parse(raw),
|
|
55
|
+
* timeoutMs: 30000,
|
|
56
|
+
* }
|
|
57
|
+
* );
|
|
58
|
+
*/
|
|
59
|
+
export async function executeLLMCall(fn, options) {
|
|
60
|
+
try {
|
|
61
|
+
const result = await fn();
|
|
62
|
+
// Optionally parse/validate output
|
|
63
|
+
if (options?.parseOutput) {
|
|
64
|
+
try {
|
|
65
|
+
const parsed = options.parseOutput(result);
|
|
66
|
+
return { status: 'success', data: parsed };
|
|
67
|
+
}
|
|
68
|
+
catch (error_) {
|
|
69
|
+
// Convert parse errors to llm-invalid-output
|
|
70
|
+
// Log the error for debugging but don't expose details in result
|
|
71
|
+
if (error_ instanceof Error) {
|
|
72
|
+
console.warn('LLM output parse error:', error_.message);
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
status: 'error',
|
|
76
|
+
error: 'llm-invalid-output',
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return { status: 'success', data: result };
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
// Map known LLM exceptions to error codes
|
|
84
|
+
const error = mapLLMException(err);
|
|
85
|
+
return { status: 'error', error };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Execute an LLM analyzer agent with mock/real mode support.
|
|
90
|
+
*
|
|
91
|
+
* Eliminates boilerplate for LLM analyzer agents by handling:
|
|
92
|
+
* - Mock vs real mode switching
|
|
93
|
+
* - Metadata generation
|
|
94
|
+
* - Error handling with llm-unavailable fallback
|
|
95
|
+
* - Consistent return envelope structure
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* // With real implementation
|
|
99
|
+
* execute: async (input) => {
|
|
100
|
+
* return executeLLMAnalyzer({
|
|
101
|
+
* mockable: input.mockable ?? true,
|
|
102
|
+
* mockFn: () => mockParseDescription(input.description),
|
|
103
|
+
* realFn: async () => callLLM(...),
|
|
104
|
+
* parseOutput: (raw) => CatCharacteristicsSchema.parse(JSON.parse(raw)),
|
|
105
|
+
* errorContext: 'Description parsing',
|
|
106
|
+
* });
|
|
107
|
+
* }
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* // Mock-only (no real implementation)
|
|
111
|
+
* execute: async (input) => {
|
|
112
|
+
* return executeLLMAnalyzer({
|
|
113
|
+
* mockable: input.mockable ?? true,
|
|
114
|
+
* mockFn: () => mockGenerateName(input.characteristics),
|
|
115
|
+
* notImplementedMessage: 'Real LLM name generation requires runtime adapter',
|
|
116
|
+
* });
|
|
117
|
+
* }
|
|
118
|
+
*/
|
|
119
|
+
export async function executeLLMAnalyzer(config) {
|
|
120
|
+
try {
|
|
121
|
+
// Mock mode: return mock data immediately
|
|
122
|
+
if (config.mockable) {
|
|
123
|
+
const data = config.mockFn();
|
|
124
|
+
return {
|
|
125
|
+
result: { status: 'success', data },
|
|
126
|
+
metadata: {
|
|
127
|
+
mode: 'mock',
|
|
128
|
+
executedAt: new Date().toISOString(),
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
// Real mode: check if implemented
|
|
133
|
+
if (!config.realFn) {
|
|
134
|
+
// Not implemented: return error with custom message
|
|
135
|
+
return {
|
|
136
|
+
result: {
|
|
137
|
+
status: 'error',
|
|
138
|
+
error: LLM_UNAVAILABLE_ERROR,
|
|
139
|
+
},
|
|
140
|
+
metadata: {
|
|
141
|
+
mode: 'real',
|
|
142
|
+
message: config.notImplementedMessage ?? 'Real LLM implementation not available',
|
|
143
|
+
executedAt: new Date().toISOString(),
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
// Real mode: use LLM
|
|
148
|
+
const result = await executeLLMCall(config.realFn, config.parseOutput ? { parseOutput: config.parseOutput } : undefined);
|
|
149
|
+
return {
|
|
150
|
+
result,
|
|
151
|
+
metadata: {
|
|
152
|
+
mode: 'real',
|
|
153
|
+
executedAt: new Date().toISOString(),
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
// Unexpected errors
|
|
159
|
+
if (err instanceof Error && config.errorContext) {
|
|
160
|
+
console.warn(`${config.errorContext} error:`, err.message);
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
result: { status: 'error', error: LLM_UNAVAILABLE_ERROR },
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Execute an external event integrator agent (HITL, webhook, etc).
|
|
169
|
+
*
|
|
170
|
+
* Handles common external event failure modes:
|
|
171
|
+
* - Timeouts waiting for response
|
|
172
|
+
* - System unavailable
|
|
173
|
+
* - Explicit rejection
|
|
174
|
+
* - Invalid responses
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* // With auto-response (testing)
|
|
178
|
+
* execute: async (input) => {
|
|
179
|
+
* return executeExternalEvent({
|
|
180
|
+
* autoResponse: input.autoResponse,
|
|
181
|
+
* handler: async () => requestApproval(input.prompt, input.context),
|
|
182
|
+
* timeoutMs: 60000,
|
|
183
|
+
* });
|
|
184
|
+
* }
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* // Production mode (waits for real human/external system)
|
|
188
|
+
* execute: async (input) => {
|
|
189
|
+
* return executeExternalEvent({
|
|
190
|
+
* handler: async () => requestApproval(input.prompt, input.context),
|
|
191
|
+
* timeoutMs: input.timeoutMs ?? 60000,
|
|
192
|
+
* });
|
|
193
|
+
* }
|
|
194
|
+
*/
|
|
195
|
+
export async function executeExternalEvent(config) {
|
|
196
|
+
try {
|
|
197
|
+
// Auto-response mode (testing)
|
|
198
|
+
if (config.autoResponse !== undefined) {
|
|
199
|
+
return {
|
|
200
|
+
result: { status: 'success', data: config.autoResponse },
|
|
201
|
+
metadata: {
|
|
202
|
+
mode: 'auto',
|
|
203
|
+
executedAt: new Date().toISOString(),
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
// Real mode: execute handler
|
|
208
|
+
const data = await config.handler();
|
|
209
|
+
return {
|
|
210
|
+
result: { status: 'success', data },
|
|
211
|
+
metadata: {
|
|
212
|
+
mode: 'real',
|
|
213
|
+
executedAt: new Date().toISOString(),
|
|
214
|
+
...(config.timeoutMs !== undefined && { timeoutMs: config.timeoutMs }),
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
// Map exceptions to external event errors
|
|
220
|
+
const error = mapExternalEventException(err, config.errorContext);
|
|
221
|
+
return {
|
|
222
|
+
result: { status: 'error', error },
|
|
223
|
+
metadata: {
|
|
224
|
+
mode: 'real',
|
|
225
|
+
executedAt: new Date().toISOString(),
|
|
226
|
+
...(err instanceof Error && { errorMessage: err.message }),
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Map common external event exceptions to standard error codes.
|
|
233
|
+
*
|
|
234
|
+
* @internal
|
|
235
|
+
*/
|
|
236
|
+
function mapExternalEventException(err, context) {
|
|
237
|
+
if (err instanceof Error) {
|
|
238
|
+
const message = err.message.toLowerCase();
|
|
239
|
+
// Timeouts
|
|
240
|
+
if (message.includes('timeout') || message.includes('timed out') || message.includes('etimedout')) {
|
|
241
|
+
return 'event-timeout';
|
|
242
|
+
}
|
|
243
|
+
// Rejected
|
|
244
|
+
if (message.includes('reject') || message.includes('denied') || message.includes('refused')) {
|
|
245
|
+
return 'event-rejected';
|
|
246
|
+
}
|
|
247
|
+
// Invalid response
|
|
248
|
+
if (message.includes('invalid') || message.includes('malformed') || message.includes('parse')) {
|
|
249
|
+
return 'event-invalid-response';
|
|
250
|
+
}
|
|
251
|
+
// Log unexpected errors for debugging
|
|
252
|
+
if (context) {
|
|
253
|
+
console.warn(`${context} error:`, err.message);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// Default to unavailable for unknown errors
|
|
257
|
+
return 'event-unavailable';
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Map common LLM SDK exceptions to standard error codes.
|
|
261
|
+
*
|
|
262
|
+
* @internal
|
|
263
|
+
*/
|
|
264
|
+
function mapLLMException(err) {
|
|
265
|
+
if (err instanceof Error) {
|
|
266
|
+
const message = err.message.toLowerCase();
|
|
267
|
+
// Content policy violations
|
|
268
|
+
if (message.includes('content_policy') || message.includes('content filter') || message.includes('content policy')) {
|
|
269
|
+
return 'llm-refusal';
|
|
270
|
+
}
|
|
271
|
+
// Rate limiting
|
|
272
|
+
if (message.includes('rate limit') || message.includes('429')) {
|
|
273
|
+
return 'llm-rate-limit';
|
|
274
|
+
}
|
|
275
|
+
// Timeouts
|
|
276
|
+
if (message.includes('timeout') || message.includes('etimedout')) {
|
|
277
|
+
return 'llm-timeout';
|
|
278
|
+
}
|
|
279
|
+
// Token limits
|
|
280
|
+
if (message.includes('token') && message.includes('limit')) {
|
|
281
|
+
return 'llm-token-limit';
|
|
282
|
+
}
|
|
283
|
+
// Service unavailable
|
|
284
|
+
if (message.includes('503') || message.includes('502')) {
|
|
285
|
+
return LLM_UNAVAILABLE_ERROR;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// Default to unavailable for unknown errors
|
|
289
|
+
return LLM_UNAVAILABLE_ERROR;
|
|
290
|
+
}
|
|
291
|
+
//# sourceMappingURL=agent-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-helpers.js","sourceRoot":"","sources":["../src/agent-helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH;;;GAGG;AACH,MAAM,qBAAqB,GAAa,iBAAiB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,mGAAmG;AACnG,MAAM,UAAU,kBAAkB,CAChC,KAAc,EACd,MAA6E,EAC7E,oBAA4B,oBAA8B;IAE1D,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACvC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO;YACL,MAAM,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE;SACjB,CAAC;IACzC,CAAC;IACD,OAAO,MAAM,CAAC,IAAc,CAAC;AAC/B,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,EAAoB,EACpB,OAGC;IAED,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,EAAE,EAAE,CAAC;QAE1B,mCAAmC;QACnC,IAAI,OAAO,EAAE,WAAW,EAAE,CAAC;YACzB,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;gBAC3C,O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,aAAa,CAAC;QACvB,CAAC;QAED,eAAe;QACf,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3D,OAAO,iBAAiB,CAAC;QAC3B,CAAC;QAED,sBAAsB;QACtB,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACvD,OAAO,qBAAqB,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,4CAA4C;IAC5C,OAAO,qBAAqB,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type z } from 'zod';
|
|
2
|
+
import type { Agent, ResearcherContext } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for defining an agentic researcher agent
|
|
5
|
+
*/
|
|
6
|
+
export interface AgenticResearcherConfig<TInput, TOutput> {
|
|
7
|
+
/** Unique name for the agent */
|
|
8
|
+
name: string;
|
|
9
|
+
/** Human-readable description of what the agent does */
|
|
10
|
+
description: string;
|
|
11
|
+
/** Semantic version (e.g., "1.0.0") */
|
|
12
|
+
version: string;
|
|
13
|
+
/** Zod schema for input validation */
|
|
14
|
+
inputSchema: z.ZodType<TInput>;
|
|
15
|
+
/** Zod schema for output validation */
|
|
16
|
+
outputSchema: z.ZodType<TOutput>;
|
|
17
|
+
/** List of tool names this agent can use (optional) */
|
|
18
|
+
tools?: string[];
|
|
19
|
+
/** Maximum number of iterations (default: 10) */
|
|
20
|
+
maxIterations?: number;
|
|
21
|
+
/** Whether this agent can be mocked in tests (default: true) */
|
|
22
|
+
mockable?: boolean;
|
|
23
|
+
/** Additional metadata */
|
|
24
|
+
metadata?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Defines an agentic researcher agent that iteratively uses tools and LLM
|
|
28
|
+
* reasoning to accomplish complex research tasks.
|
|
29
|
+
*
|
|
30
|
+
* The agent validates inputs and outputs using Zod schemas, provides
|
|
31
|
+
* access to tools and LLM context, and tracks iteration count.
|
|
32
|
+
*
|
|
33
|
+
* @param config - Agent configuration including schemas and tools
|
|
34
|
+
* @param handler - Async function that uses research context
|
|
35
|
+
* @returns Agent with validated execute function and manifest
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const researchAgent = defineAgenticResearcher(
|
|
40
|
+
* {
|
|
41
|
+
* name: 'web-researcher',
|
|
42
|
+
* description: 'Researches topics using web search',
|
|
43
|
+
* version: '1.0.0',
|
|
44
|
+
* inputSchema: z.object({ topic: z.string() }),
|
|
45
|
+
* outputSchema: z.object({ findings: z.string() }),
|
|
46
|
+
* tools: ['search', 'scrape'],
|
|
47
|
+
* maxIterations: 5,
|
|
48
|
+
* },
|
|
49
|
+
* async (input, ctx) => {
|
|
50
|
+
* let findings = '';
|
|
51
|
+
* while (ctx.iterationCount < ctx.maxIterations) {
|
|
52
|
+
* const query = await ctx.callLLM(`What should I search next for: ${input.topic}`);
|
|
53
|
+
* const results = await ctx.callTool('search', { query });
|
|
54
|
+
* findings += results;
|
|
55
|
+
* ctx.iterationCount++;
|
|
56
|
+
* }
|
|
57
|
+
* return { findings };
|
|
58
|
+
* }
|
|
59
|
+
* );
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function defineAgenticResearcher<TInput, TOutput>(config: AgenticResearcherConfig<TInput, TOutput>, handler: (input: TInput, ctx: ResearcherContext) => Promise<TOutput>): Agent<TInput, TOutput>;
|
|
63
|
+
//# sourceMappingURL=agentic-researcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentic-researcher.d.ts","sourceRoot":"","sources":["../src/agentic-researcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC;AAG7B,OAAO,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,uBAAuB,CAAC,MAAM,EAAE,OAAO;IACtD,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IAEb,wDAAwD;IACxD,WAAW,EAAE,MAAM,CAAC;IAEpB,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAEhB,sCAAsC;IACtC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAE/B,uCAAuC;IACvC,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEjC,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IAEjB,iDAAiD;IACjD,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,gEAAgE;IAChE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,OAAO,EACrD,MAAM,EAAE,uBAAuB,CAAC,MAAM,EAAE,OAAO,CAAC,EAChD,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,iBAAiB,KAAK,OAAO,CAAC,OAAO,CAAC,GACnE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CA2BxB"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { buildManifest, createAsyncExecuteWrapperWithContext } from './execute-wrapper.js';
|
|
2
|
+
/**
|
|
3
|
+
* Defines an agentic researcher agent that iteratively uses tools and LLM
|
|
4
|
+
* reasoning to accomplish complex research tasks.
|
|
5
|
+
*
|
|
6
|
+
* The agent validates inputs and outputs using Zod schemas, provides
|
|
7
|
+
* access to tools and LLM context, and tracks iteration count.
|
|
8
|
+
*
|
|
9
|
+
* @param config - Agent configuration including schemas and tools
|
|
10
|
+
* @param handler - Async function that uses research context
|
|
11
|
+
* @returns Agent with validated execute function and manifest
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const researchAgent = defineAgenticResearcher(
|
|
16
|
+
* {
|
|
17
|
+
* name: 'web-researcher',
|
|
18
|
+
* description: 'Researches topics using web search',
|
|
19
|
+
* version: '1.0.0',
|
|
20
|
+
* inputSchema: z.object({ topic: z.string() }),
|
|
21
|
+
* outputSchema: z.object({ findings: z.string() }),
|
|
22
|
+
* tools: ['search', 'scrape'],
|
|
23
|
+
* maxIterations: 5,
|
|
24
|
+
* },
|
|
25
|
+
* async (input, ctx) => {
|
|
26
|
+
* let findings = '';
|
|
27
|
+
* while (ctx.iterationCount < ctx.maxIterations) {
|
|
28
|
+
* const query = await ctx.callLLM(`What should I search next for: ${input.topic}`);
|
|
29
|
+
* const results = await ctx.callTool('search', { query });
|
|
30
|
+
* findings += results;
|
|
31
|
+
* ctx.iterationCount++;
|
|
32
|
+
* }
|
|
33
|
+
* return { findings };
|
|
34
|
+
* }
|
|
35
|
+
* );
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export function defineAgenticResearcher(config, handler) {
|
|
39
|
+
// Build manifest
|
|
40
|
+
const manifest = buildManifest(config, 'agentic-researcher', {
|
|
41
|
+
mockable: config.mockable ?? true,
|
|
42
|
+
maxIterations: config.maxIterations ?? 10,
|
|
43
|
+
...(config.tools && { tools: config.tools }),
|
|
44
|
+
});
|
|
45
|
+
// Create validated execute function
|
|
46
|
+
const execute = createAsyncExecuteWrapperWithContext(config, handler, (ctx) => ({
|
|
47
|
+
mockable: config.mockable ?? true,
|
|
48
|
+
tools: ctx.tools,
|
|
49
|
+
callLLM: ctx.callLLM,
|
|
50
|
+
callTool: ctx.callTool,
|
|
51
|
+
iterationCount: 0,
|
|
52
|
+
maxIterations: config.maxIterations ?? 10,
|
|
53
|
+
}));
|
|
54
|
+
return {
|
|
55
|
+
name: config.name,
|
|
56
|
+
execute,
|
|
57
|
+
manifest,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=agentic-researcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentic-researcher.js","sourceRoot":"","sources":["../src/agentic-researcher.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,oCAAoC,EAAE,MAAM,sBAAsB,CAAC;AAmC3F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAAgD,EAChD,OAAoE;IAEpE,iBAAiB;IACjB,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,EAAE,oBAAoB,EAAE;QAC3D,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,IAAI;QACjC,aAAa,EAAE,MAAM,CAAC,aAAa,IAAI,EAAE;QACzC,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;KAC7C,CAAC,CAAC;IAEH,oCAAoC;IACpC,MAAM,OAAO,GAAG,oCAAoC,CAClD,MAAM,EACN,OAAO,EACP,CAAC,GAAsB,EAAqB,EAAE,CAAC,CAAC;QAC9C,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,IAAI;QACjC,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,cAAc,EAAE,CAAC;QACjB,aAAa,EAAE,MAAM,CAAC,aAAa,IAAI,EAAE;KAC1C,CAAC,CACH,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,OAAO;QACP,QAAQ;KACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type z } from 'zod';
|
|
2
|
+
import type { Agent, ConversationalContext } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for defining a conversational assistant agent
|
|
5
|
+
*/
|
|
6
|
+
export interface ConversationalAssistantConfig<TInput, TOutput> {
|
|
7
|
+
/** Unique name for the agent */
|
|
8
|
+
name: string;
|
|
9
|
+
/** Human-readable description of what the agent does */
|
|
10
|
+
description: string;
|
|
11
|
+
/** Semantic version (e.g., "1.0.0") */
|
|
12
|
+
version: string;
|
|
13
|
+
/** Zod schema for input validation */
|
|
14
|
+
inputSchema: z.ZodType<TInput>;
|
|
15
|
+
/** Zod schema for output validation */
|
|
16
|
+
outputSchema: z.ZodType<TOutput>;
|
|
17
|
+
/** System prompt for the assistant (optional) */
|
|
18
|
+
systemPrompt?: string;
|
|
19
|
+
/** Whether this agent can be mocked in tests (default: true) */
|
|
20
|
+
mockable?: boolean;
|
|
21
|
+
/** Additional metadata */
|
|
22
|
+
metadata?: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Defines a conversational assistant agent that maintains context across
|
|
26
|
+
* multiple interactions using conversation history.
|
|
27
|
+
*
|
|
28
|
+
* The agent validates inputs and outputs using Zod schemas, provides
|
|
29
|
+
* conversation context to the handler, and generates a manifest describing
|
|
30
|
+
* its interface.
|
|
31
|
+
*
|
|
32
|
+
* @param config - Agent configuration including schemas and system prompt
|
|
33
|
+
* @param handler - Async function that uses conversation context
|
|
34
|
+
* @returns Agent with validated execute function and manifest
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const chatAgent = defineConversationalAssistant(
|
|
39
|
+
* {
|
|
40
|
+
* name: 'helpful-assistant',
|
|
41
|
+
* description: 'A helpful conversational assistant',
|
|
42
|
+
* version: '1.0.0',
|
|
43
|
+
* inputSchema: z.object({ message: z.string() }),
|
|
44
|
+
* outputSchema: z.object({ reply: z.string() }),
|
|
45
|
+
* systemPrompt: 'You are a helpful assistant.',
|
|
46
|
+
* },
|
|
47
|
+
* async (input, ctx) => {
|
|
48
|
+
* ctx.addToHistory('user', input.message);
|
|
49
|
+
* const response = await ctx.callLLM(ctx.history);
|
|
50
|
+
* ctx.addToHistory('assistant', response);
|
|
51
|
+
* return { reply: response };
|
|
52
|
+
* }
|
|
53
|
+
* );
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function defineConversationalAssistant<TInput, TOutput>(config: ConversationalAssistantConfig<TInput, TOutput>, handler: (input: TInput, ctx: ConversationalContext) => Promise<TOutput>): Agent<TInput, TOutput>;
|
|
57
|
+
//# sourceMappingURL=conversational-assistant.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversational-assistant.d.ts","sourceRoot":"","sources":["../src/conversational-assistant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC;AAO7B,OAAO,KAAK,EAAE,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,6BAA6B,CAAC,MAAM,EAAE,OAAO;IAC5D,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IAEb,wDAAwD;IACxD,WAAW,EAAE,MAAM,CAAC;IAEpB,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAEhB,sCAAsC;IACtC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAE/B,uCAAuC;IACvC,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEjC,iDAAiD;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,gEAAgE;IAChE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,OAAO,EAC3D,MAAM,EAAE,6BAA6B,CAAC,MAAM,EAAE,OAAO,CAAC,EACtD,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,qBAAqB,KAAK,OAAO,CAAC,OAAO,CAAC,GACvE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAmBxB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { buildManifest, createAsyncExecuteWrapperWithContext, createConversationalContextMapper, } from './execute-wrapper.js';
|
|
2
|
+
/**
|
|
3
|
+
* Defines a conversational assistant agent that maintains context across
|
|
4
|
+
* multiple interactions using conversation history.
|
|
5
|
+
*
|
|
6
|
+
* The agent validates inputs and outputs using Zod schemas, provides
|
|
7
|
+
* conversation context to the handler, and generates a manifest describing
|
|
8
|
+
* its interface.
|
|
9
|
+
*
|
|
10
|
+
* @param config - Agent configuration including schemas and system prompt
|
|
11
|
+
* @param handler - Async function that uses conversation context
|
|
12
|
+
* @returns Agent with validated execute function and manifest
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const chatAgent = defineConversationalAssistant(
|
|
17
|
+
* {
|
|
18
|
+
* name: 'helpful-assistant',
|
|
19
|
+
* description: 'A helpful conversational assistant',
|
|
20
|
+
* version: '1.0.0',
|
|
21
|
+
* inputSchema: z.object({ message: z.string() }),
|
|
22
|
+
* outputSchema: z.object({ reply: z.string() }),
|
|
23
|
+
* systemPrompt: 'You are a helpful assistant.',
|
|
24
|
+
* },
|
|
25
|
+
* async (input, ctx) => {
|
|
26
|
+
* ctx.addToHistory('user', input.message);
|
|
27
|
+
* const response = await ctx.callLLM(ctx.history);
|
|
28
|
+
* ctx.addToHistory('assistant', response);
|
|
29
|
+
* return { reply: response };
|
|
30
|
+
* }
|
|
31
|
+
* );
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function defineConversationalAssistant(config, handler) {
|
|
35
|
+
// Build manifest
|
|
36
|
+
const manifest = buildManifest(config, 'conversational-assistant', {
|
|
37
|
+
mockable: config.mockable ?? true,
|
|
38
|
+
...(config.systemPrompt && { systemPrompt: config.systemPrompt }),
|
|
39
|
+
});
|
|
40
|
+
// Create validated execute function
|
|
41
|
+
const execute = createAsyncExecuteWrapperWithContext(config, handler, createConversationalContextMapper(config.mockable ?? true));
|
|
42
|
+
return {
|
|
43
|
+
name: config.name,
|
|
44
|
+
execute,
|
|
45
|
+
manifest,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=conversational-assistant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversational-assistant.js","sourceRoot":"","sources":["../src/conversational-assistant.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,EACb,oCAAoC,EACpC,iCAAiC,GAClC,MAAM,sBAAsB,CAAC;AAgC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,6BAA6B,CAC3C,MAAsD,EACtD,OAAwE;IAExE,iBAAiB;IACjB,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,EAAE,0BAA0B,EAAE;QACjE,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,IAAI;QACjC,GAAG,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE,CAAC;KAClE,CAAC,CAAC;IAEH,oCAAoC;IACpC,MAAM,OAAO,GAAG,oCAAoC,CAClD,MAAM,EACN,OAAO,EACP,iCAAiC,CAAC,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,CAC3D,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,OAAO;QACP,QAAQ;KACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper utilities for building conversational agent contexts
|
|
3
|
+
*/
|
|
4
|
+
import type { ConversationalContext, Message } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a conversational context with the given LLM function and history
|
|
7
|
+
* Reduces duplication between adapters and examples
|
|
8
|
+
*
|
|
9
|
+
* @param history - Conversation history array (will be mutated by addToHistory)
|
|
10
|
+
* @param callLLM - Function to call the LLM with messages
|
|
11
|
+
* @returns ConversationalContext object
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const session = { history: [] };
|
|
16
|
+
* const context = createConversationalContext(
|
|
17
|
+
* session.history,
|
|
18
|
+
* async (messages) => {
|
|
19
|
+
* // Call your LLM here
|
|
20
|
+
* return "response";
|
|
21
|
+
* }
|
|
22
|
+
* );
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function createConversationalContext(history: Message[], callLLM: (messages: Message[]) => Promise<string>): ConversationalContext;
|
|
26
|
+
//# sourceMappingURL=conversational-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversational-helpers.d.ts","sourceRoot":"","sources":["../src/conversational-helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,OAAO,EAAE,EAClB,OAAO,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,MAAM,CAAC,GAChD,qBAAqB,CASvB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper utilities for building conversational agent contexts
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Creates a conversational context with the given LLM function and history
|
|
6
|
+
* Reduces duplication between adapters and examples
|
|
7
|
+
*
|
|
8
|
+
* @param history - Conversation history array (will be mutated by addToHistory)
|
|
9
|
+
* @param callLLM - Function to call the LLM with messages
|
|
10
|
+
* @returns ConversationalContext object
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const session = { history: [] };
|
|
15
|
+
* const context = createConversationalContext(
|
|
16
|
+
* session.history,
|
|
17
|
+
* async (messages) => {
|
|
18
|
+
* // Call your LLM here
|
|
19
|
+
* return "response";
|
|
20
|
+
* }
|
|
21
|
+
* );
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function createConversationalContext(history, callLLM) {
|
|
25
|
+
return {
|
|
26
|
+
mockable: false,
|
|
27
|
+
history,
|
|
28
|
+
addToHistory: (role, content) => {
|
|
29
|
+
history.push({ role, content });
|
|
30
|
+
},
|
|
31
|
+
callLLM,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=conversational-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversational-helpers.js","sourceRoot":"","sources":["../src/conversational-helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,2BAA2B,CACzC,OAAkB,EAClB,OAAiD;IAEjD,OAAO;QACL,QAAQ,EAAE,KAAK;QACf,OAAO;QACP,YAAY,EAAE,CAAC,IAAqC,EAAE,OAAe,EAAE,EAAE;YACvE,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;QAClC,CAAC;QACD,OAAO;KACR,CAAC;AACJ,CAAC"}
|