@cogitator-ai/core 0.17.2 → 0.18.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.
- package/README.md +1 -1
- package/dist/agent-tool.d.ts +1 -1
- package/dist/agent-tool.d.ts.map +1 -1
- package/dist/cogitator/tool-executor.js +1 -1
- package/dist/cogitator/tool-executor.js.map +1 -1
- package/dist/cogitator.d.ts +1 -210
- package/dist/cogitator.d.ts.map +1 -1
- package/dist/cogitator.js +1 -585
- package/dist/cogitator.js.map +1 -1
- package/dist/cost-routing/model-selector.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/llm/azure.d.ts.map +1 -1
- package/dist/llm/azure.js +3 -1
- package/dist/llm/azure.js.map +1 -1
- package/dist/llm/bedrock.d.ts.map +1 -1
- package/dist/llm/bedrock.js +8 -5
- package/dist/llm/bedrock.js.map +1 -1
- package/dist/llm/google.d.ts.map +1 -1
- package/dist/llm/google.js +3 -0
- package/dist/llm/google.js.map +1 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +1 -0
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/ollama.d.ts +3 -0
- package/dist/llm/ollama.d.ts.map +1 -1
- package/dist/llm/ollama.js +14 -2
- package/dist/llm/ollama.js.map +1 -1
- package/dist/llm/openai.d.ts.map +1 -1
- package/dist/llm/openai.js +3 -1
- package/dist/llm/openai.js.map +1 -1
- package/dist/reasoning/thought-tree.d.ts +1 -1
- package/dist/reasoning/thought-tree.d.ts.map +1 -1
- package/dist/runtime.d.ts +216 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +593 -0
- package/dist/runtime.js.map +1 -0
- package/dist/time-travel/forker.d.ts +1 -1
- package/dist/time-travel/forker.d.ts.map +1 -1
- package/dist/time-travel/replayer.d.ts +1 -1
- package/dist/time-travel/replayer.d.ts.map +1 -1
- package/dist/time-travel/time-travel.d.ts +1 -1
- package/dist/time-travel/time-travel.d.ts.map +1 -1
- package/dist/tool.d.ts.map +1 -1
- package/dist/tool.js +4 -4
- package/dist/tool.js.map +1 -1
- package/dist/tools/audio-generate.d.ts +2 -2
- package/dist/tools/audio-transcribe.d.ts +1 -1
- package/dist/tools/datetime.d.ts +1 -1
- package/dist/tools/email.d.ts +2 -2
- package/dist/tools/exec.d.ts +1 -1
- package/dist/tools/exec.js +1 -1
- package/dist/tools/exec.js.map +1 -1
- package/dist/tools/github.d.ts +3 -3
- package/dist/tools/hash.d.ts +3 -3
- package/dist/tools/http.d.ts +2 -2
- package/dist/tools/http.d.ts.map +1 -1
- package/dist/tools/http.js +4 -1
- package/dist/tools/http.js.map +1 -1
- package/dist/tools/image-analyze.d.ts +15 -28
- package/dist/tools/image-analyze.d.ts.map +1 -1
- package/dist/tools/image-generate.d.ts +14 -14
- package/dist/tools/image-generate.d.ts.map +1 -1
- package/dist/tools/index.d.ts +19 -19
- package/dist/tools/json.d.ts +1 -1
- package/dist/tools/sql-query.d.ts +1 -1
- package/dist/tools/vector-search.d.ts +3 -3
- package/dist/tools/vector-search.d.ts.map +1 -1
- package/dist/tools/vector-search.js +4 -1
- package/dist/tools/vector-search.js.map +1 -1
- package/dist/tools/web-scrape.d.ts +2 -2
- package/dist/utils/audio-fetch.js +1 -1
- package/dist/utils/audio-fetch.js.map +1 -1
- package/dist/utils/image-fetch.js +1 -1
- package/dist/utils/image-fetch.js.map +1 -1
- package/package.json +26 -26
- package/LICENSE +0 -21
package/dist/cogitator.js
CHANGED
|
@@ -1,586 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { getPrice } from '@cogitator-ai/models';
|
|
3
|
-
import { ToolRegistry } from './registry';
|
|
4
|
-
import { createLLMBackend, parseModel } from './llm/index';
|
|
5
|
-
import { getLogger } from './logger';
|
|
6
|
-
import { initializeMemory, initializeSandbox, initializeReflection, initializeGuardrails, initializeCostRouting, initializeSecurity, initializeContextManager, cleanupState, } from './cogitator/initializers';
|
|
7
|
-
import { CogitatorError, ErrorCode } from '@cogitator-ai/types';
|
|
8
|
-
import { buildInitialMessages, saveEntry, enrichMessagesWithInsights, addContextToMessages, } from './cogitator/message-builder';
|
|
9
|
-
import { createSpan, getTextContent } from './cogitator/span-factory';
|
|
10
|
-
import { executeTool, createToolMessage } from './cogitator/tool-executor';
|
|
11
|
-
import { streamChat } from './cogitator/streaming';
|
|
12
|
-
import { CostEstimator } from './cost-routing/cost-estimator';
|
|
13
|
-
/**
|
|
14
|
-
* Main runtime for executing AI agents.
|
|
15
|
-
*
|
|
16
|
-
* Cogitator orchestrates agent execution with support for:
|
|
17
|
-
* - Multiple LLM providers (OpenAI, Anthropic, Ollama, Google, Azure, etc.)
|
|
18
|
-
* - Memory persistence (Redis, PostgreSQL, in-memory)
|
|
19
|
-
* - Sandboxed tool execution (Docker, WASM)
|
|
20
|
-
* - Reflection and learning from past runs
|
|
21
|
-
* - Constitutional AI guardrails
|
|
22
|
-
* - Cost-aware model routing
|
|
23
|
-
*
|
|
24
|
-
* @example Basic usage
|
|
25
|
-
* ```ts
|
|
26
|
-
* import { Cogitator, Agent } from '@cogitator-ai/core';
|
|
27
|
-
*
|
|
28
|
-
* const cog = new Cogitator({
|
|
29
|
-
* llm: { defaultProvider: 'anthropic' },
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* const agent = new Agent({
|
|
33
|
-
* name: 'assistant',
|
|
34
|
-
* model: 'anthropic/claude-sonnet-4-20250514',
|
|
35
|
-
* instructions: 'You are a helpful assistant.',
|
|
36
|
-
* });
|
|
37
|
-
*
|
|
38
|
-
* const result = await cog.run(agent, { input: 'Hello!' });
|
|
39
|
-
* console.log(result.output);
|
|
40
|
-
*
|
|
41
|
-
* await cog.close();
|
|
42
|
-
* ```
|
|
43
|
-
*
|
|
44
|
-
* @example With memory and streaming
|
|
45
|
-
* ```ts
|
|
46
|
-
* const cog = new Cogitator({
|
|
47
|
-
* memory: {
|
|
48
|
-
* adapter: 'redis',
|
|
49
|
-
* redis: { url: 'redis://localhost:6379' },
|
|
50
|
-
* },
|
|
51
|
-
* });
|
|
52
|
-
*
|
|
53
|
-
* const result = await cog.run(agent, {
|
|
54
|
-
* input: 'Remember my name is Alice',
|
|
55
|
-
* threadId: 'conversation-123',
|
|
56
|
-
* stream: true,
|
|
57
|
-
* onToken: (token) => process.stdout.write(token),
|
|
58
|
-
* });
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
export class Cogitator {
|
|
62
|
-
config;
|
|
63
|
-
backends = new Map();
|
|
64
|
-
/** Global tool registry shared across all runs */
|
|
65
|
-
tools = new ToolRegistry();
|
|
66
|
-
state = {
|
|
67
|
-
memoryInitialized: false,
|
|
68
|
-
sandboxInitialized: false,
|
|
69
|
-
reflectionInitialized: false,
|
|
70
|
-
guardrailsInitialized: false,
|
|
71
|
-
costRoutingInitialized: false,
|
|
72
|
-
securityInitialized: false,
|
|
73
|
-
contextManagerInitialized: false,
|
|
74
|
-
};
|
|
75
|
-
costEstimator;
|
|
76
|
-
/**
|
|
77
|
-
* Create a new Cogitator runtime.
|
|
78
|
-
*
|
|
79
|
-
* @param config - Runtime configuration
|
|
80
|
-
* @param config.llm - LLM provider settings (API keys, base URLs)
|
|
81
|
-
* @param config.memory - Memory adapter configuration
|
|
82
|
-
* @param config.sandbox - Sandbox execution settings
|
|
83
|
-
* @param config.reflection - Reflection engine settings
|
|
84
|
-
* @param config.guardrails - Constitutional AI settings
|
|
85
|
-
* @param config.costRouting - Cost-aware routing settings
|
|
86
|
-
*/
|
|
87
|
-
constructor(config = {}) {
|
|
88
|
-
this.config = config;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Run an agent with the given input.
|
|
92
|
-
*
|
|
93
|
-
* Executes the agent's task, handling LLM calls, tool execution,
|
|
94
|
-
* memory persistence, and observability callbacks.
|
|
95
|
-
*
|
|
96
|
-
* @param agent - Agent to execute
|
|
97
|
-
* @param options - Run configuration
|
|
98
|
-
* @param options.input - User input/prompt for the agent
|
|
99
|
-
* @param options.threadId - Thread ID for memory persistence
|
|
100
|
-
* @param options.context - Additional context to include in system prompt
|
|
101
|
-
* @param options.stream - Enable streaming responses
|
|
102
|
-
* @param options.onToken - Callback for each streamed token
|
|
103
|
-
* @param options.onToolCall - Callback when a tool is called
|
|
104
|
-
* @param options.onToolResult - Callback when a tool returns a result
|
|
105
|
-
* @param options.onSpan - Callback for observability spans
|
|
106
|
-
* @param options.timeout - Override agent timeout
|
|
107
|
-
* @returns Run result with output, usage stats, and trace
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```ts
|
|
111
|
-
* const result = await cog.run(agent, {
|
|
112
|
-
* input: 'Search for TypeScript tutorials',
|
|
113
|
-
* threadId: 'session-123',
|
|
114
|
-
* stream: true,
|
|
115
|
-
* onToken: (token) => process.stdout.write(token),
|
|
116
|
-
* onToolCall: (call) => console.log('Tool:', call.name),
|
|
117
|
-
* });
|
|
118
|
-
*
|
|
119
|
-
* console.log('Output:', result.output);
|
|
120
|
-
* console.log('Tokens:', result.usage.totalTokens);
|
|
121
|
-
* console.log('Cost:', result.usage.cost);
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
async run(agent, options) {
|
|
125
|
-
const runId = `run_${nanoid(12)}`;
|
|
126
|
-
const threadId = options.threadId ?? `thread_${nanoid(12)}`;
|
|
127
|
-
const traceId = `trace_${nanoid(16)}`;
|
|
128
|
-
const startTime = Date.now();
|
|
129
|
-
const spans = [];
|
|
130
|
-
const timeout = options.timeout ?? agent.config?.timeout;
|
|
131
|
-
const abortController = new AbortController();
|
|
132
|
-
let timeoutId;
|
|
133
|
-
if (timeout && timeout > 0) {
|
|
134
|
-
timeoutId = setTimeout(() => {
|
|
135
|
-
abortController.abort(new Error(`Run timed out after ${timeout}ms`));
|
|
136
|
-
}, timeout);
|
|
137
|
-
}
|
|
138
|
-
options.onRunStart?.({ runId, agentId: agent.id, input: options.input, threadId });
|
|
139
|
-
const rootSpanId = `span_${nanoid(12)}`;
|
|
140
|
-
try {
|
|
141
|
-
await this.initializeAll(agent);
|
|
142
|
-
const registry = new ToolRegistry();
|
|
143
|
-
if (agent.tools && agent.tools.length > 0) {
|
|
144
|
-
registry.registerMany(agent.tools);
|
|
145
|
-
}
|
|
146
|
-
let effectiveModel = agent.model;
|
|
147
|
-
if (this.state.costRouter && this.config.costRouting?.autoSelectModel) {
|
|
148
|
-
const recommendation = await this.state.costRouter.recommendModel(options.input);
|
|
149
|
-
effectiveModel = `${recommendation.provider}/${recommendation.modelId}`;
|
|
150
|
-
const budgetCheck = this.state.costRouter.checkBudget(recommendation.estimatedCost);
|
|
151
|
-
if (!budgetCheck.allowed) {
|
|
152
|
-
throw new Error(`Budget exceeded: ${budgetCheck.reason}`);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
const backend = this.getBackend(effectiveModel, agent.config.provider);
|
|
156
|
-
const model = agent.config.provider ? effectiveModel : parseModel(effectiveModel).model;
|
|
157
|
-
const messages = await buildInitialMessages(agent, options, threadId, this.state.memoryAdapter, this.state.contextBuilder);
|
|
158
|
-
if (this.state.injectionDetector) {
|
|
159
|
-
const injectionResult = await this.state.injectionDetector.analyze(options.input);
|
|
160
|
-
if (injectionResult.action === 'blocked') {
|
|
161
|
-
const threatTypes = injectionResult.threats.map((t) => t.type).join(', ');
|
|
162
|
-
throw new CogitatorError({
|
|
163
|
-
message: `Prompt injection detected: ${threatTypes}`,
|
|
164
|
-
code: ErrorCode.PROMPT_INJECTION_DETECTED,
|
|
165
|
-
details: { threats: injectionResult.threats },
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (this.state.constitutionalAI && this.config.guardrails?.filterInput) {
|
|
170
|
-
const inputResult = await this.state.constitutionalAI.filterInput(options.input);
|
|
171
|
-
if (!inputResult.allowed) {
|
|
172
|
-
throw new Error(`Input blocked: ${inputResult.blockedReason ?? 'Policy violation'}`);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
if (options.context) {
|
|
176
|
-
addContextToMessages(messages, options.context);
|
|
177
|
-
}
|
|
178
|
-
if (this.state.memoryAdapter &&
|
|
179
|
-
options.saveHistory !== false &&
|
|
180
|
-
options.useMemory !== false) {
|
|
181
|
-
await saveEntry(threadId, agent.id, { role: 'user', content: options.input }, this.state.memoryAdapter, undefined, undefined, options.onMemoryError);
|
|
182
|
-
}
|
|
183
|
-
const allToolCalls = [];
|
|
184
|
-
let totalInputTokens = 0;
|
|
185
|
-
let totalOutputTokens = 0;
|
|
186
|
-
let iterations = 0;
|
|
187
|
-
const maxIterations = agent.config?.maxIterations ?? 10;
|
|
188
|
-
const allReflections = [];
|
|
189
|
-
const allActions = [];
|
|
190
|
-
const agentContext = {
|
|
191
|
-
agentId: agent.id,
|
|
192
|
-
agentName: agent.name,
|
|
193
|
-
runId,
|
|
194
|
-
threadId,
|
|
195
|
-
goal: options.input,
|
|
196
|
-
iterationIndex: 0,
|
|
197
|
-
previousActions: [],
|
|
198
|
-
availableTools: registry.getNames(),
|
|
199
|
-
};
|
|
200
|
-
if (this.state.reflectionEngine && this.config.reflection?.enabled) {
|
|
201
|
-
await enrichMessagesWithInsights(messages, this.state.reflectionEngine, agentContext);
|
|
202
|
-
}
|
|
203
|
-
while (iterations < maxIterations) {
|
|
204
|
-
if (abortController.signal.aborted) {
|
|
205
|
-
throw abortController.signal.reason ?? new Error('Run aborted');
|
|
206
|
-
}
|
|
207
|
-
if (this.state.contextManager?.shouldCompress(messages, effectiveModel)) {
|
|
208
|
-
const compressionResult = await this.state.contextManager.compress(messages, effectiveModel);
|
|
209
|
-
messages.length = 0;
|
|
210
|
-
messages.push(...compressionResult.messages);
|
|
211
|
-
}
|
|
212
|
-
iterations++;
|
|
213
|
-
agentContext.iterationIndex = iterations - 1;
|
|
214
|
-
agentContext.previousActions = [...allActions];
|
|
215
|
-
const llmSpanStart = Date.now();
|
|
216
|
-
let response;
|
|
217
|
-
if (options.stream && options.onToken) {
|
|
218
|
-
response = await streamChat(backend, model, messages, registry, agent, options.onToken);
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
response = await backend.chat({
|
|
222
|
-
model,
|
|
223
|
-
messages,
|
|
224
|
-
tools: registry.getSchemas(),
|
|
225
|
-
temperature: agent.config.temperature,
|
|
226
|
-
topP: agent.config.topP,
|
|
227
|
-
maxTokens: agent.config.maxTokens,
|
|
228
|
-
stop: agent.config.stopSequences,
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
const llmSpan = createSpan('llm.chat', traceId, rootSpanId, llmSpanStart, Date.now(), {
|
|
232
|
-
'llm.model': model,
|
|
233
|
-
'llm.iteration': iterations,
|
|
234
|
-
'llm.input_tokens': response.usage.inputTokens,
|
|
235
|
-
'llm.output_tokens': response.usage.outputTokens,
|
|
236
|
-
'llm.finish_reason': response.finishReason,
|
|
237
|
-
}, 'ok', 'client', options.onSpan);
|
|
238
|
-
spans.push(llmSpan);
|
|
239
|
-
totalInputTokens += response.usage.inputTokens;
|
|
240
|
-
totalOutputTokens += response.usage.outputTokens;
|
|
241
|
-
let outputContent = response.content;
|
|
242
|
-
if (this.state.constitutionalAI && this.config.guardrails?.filterOutput) {
|
|
243
|
-
const outputResult = await this.state.constitutionalAI.filterOutput(outputContent, messages);
|
|
244
|
-
if (!outputResult.allowed) {
|
|
245
|
-
if (outputResult.suggestedRevision) {
|
|
246
|
-
outputContent = outputResult.suggestedRevision;
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
throw new Error(`Output blocked: ${outputResult.blockedReason ?? 'Policy violation'}`);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
const assistantMessage = {
|
|
254
|
-
role: 'assistant',
|
|
255
|
-
content: outputContent,
|
|
256
|
-
};
|
|
257
|
-
messages.push(assistantMessage);
|
|
258
|
-
if (this.state.memoryAdapter &&
|
|
259
|
-
options.saveHistory !== false &&
|
|
260
|
-
options.useMemory !== false) {
|
|
261
|
-
await saveEntry(threadId, agent.id, assistantMessage, this.state.memoryAdapter, response.toolCalls, undefined, options.onMemoryError);
|
|
262
|
-
}
|
|
263
|
-
if (response.finishReason === 'tool_calls' && response.toolCalls) {
|
|
264
|
-
const toolCalls = response.toolCalls;
|
|
265
|
-
for (const toolCall of toolCalls) {
|
|
266
|
-
allToolCalls.push(toolCall);
|
|
267
|
-
options.onToolCall?.(toolCall);
|
|
268
|
-
}
|
|
269
|
-
const executeToolCall = async (toolCall) => {
|
|
270
|
-
const toolSpanStart = Date.now();
|
|
271
|
-
const result = await executeTool(registry, toolCall, runId, agent.id, this.state.sandboxManager, this.state.constitutionalAI, !!this.config.guardrails?.filterToolCalls, () => initializeSandbox(this.config, this.state), abortController.signal);
|
|
272
|
-
const toolSpanEnd = Date.now();
|
|
273
|
-
return { toolCall, result, toolSpanStart, toolSpanEnd };
|
|
274
|
-
};
|
|
275
|
-
const toolResults = options.parallelToolCalls
|
|
276
|
-
? await Promise.all(toolCalls.map(executeToolCall))
|
|
277
|
-
: await (async () => {
|
|
278
|
-
const results = [];
|
|
279
|
-
for (const toolCall of toolCalls) {
|
|
280
|
-
results.push(await executeToolCall(toolCall));
|
|
281
|
-
}
|
|
282
|
-
return results;
|
|
283
|
-
})();
|
|
284
|
-
for (const { toolCall, result, toolSpanStart, toolSpanEnd } of toolResults) {
|
|
285
|
-
const toolSpan = createSpan(`tool.${toolCall.name}`, traceId, rootSpanId, toolSpanStart, toolSpanEnd, {
|
|
286
|
-
'tool.name': toolCall.name,
|
|
287
|
-
'tool.call_id': toolCall.id,
|
|
288
|
-
'tool.arguments': JSON.stringify(toolCall.arguments),
|
|
289
|
-
'tool.success': !result.error,
|
|
290
|
-
'tool.error': result.error,
|
|
291
|
-
}, result.error ? 'error' : 'ok', 'internal', options.onSpan);
|
|
292
|
-
spans.push(toolSpan);
|
|
293
|
-
options.onToolResult?.(result);
|
|
294
|
-
const toolMessage = createToolMessage(toolCall, result);
|
|
295
|
-
messages.push(toolMessage);
|
|
296
|
-
if (this.state.memoryAdapter &&
|
|
297
|
-
options.saveHistory !== false &&
|
|
298
|
-
options.useMemory !== false) {
|
|
299
|
-
await saveEntry(threadId, agent.id, toolMessage, this.state.memoryAdapter, undefined, [result], options.onMemoryError);
|
|
300
|
-
}
|
|
301
|
-
const action = {
|
|
302
|
-
type: 'tool_call',
|
|
303
|
-
toolName: toolCall.name,
|
|
304
|
-
input: toolCall.arguments,
|
|
305
|
-
output: result.result,
|
|
306
|
-
error: result.error,
|
|
307
|
-
duration: toolSpanEnd - toolSpanStart,
|
|
308
|
-
};
|
|
309
|
-
allActions.push(action);
|
|
310
|
-
if (this.state.reflectionEngine &&
|
|
311
|
-
this.config.reflection?.enabled &&
|
|
312
|
-
this.config.reflection.reflectAfterToolCall) {
|
|
313
|
-
try {
|
|
314
|
-
const reflectionResult = await this.state.reflectionEngine.reflectOnToolCall(action, agentContext);
|
|
315
|
-
allReflections.push(reflectionResult.reflection);
|
|
316
|
-
if (reflectionResult.shouldAdjustStrategy && reflectionResult.suggestedAction) {
|
|
317
|
-
messages.push({
|
|
318
|
-
role: 'system',
|
|
319
|
-
content: `Reflection: ${reflectionResult.reflection.analysis.reasoning}. Consider: ${reflectionResult.suggestedAction}`,
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
catch (reflectionError) {
|
|
324
|
-
getLogger().warn('Reflection failed', {
|
|
325
|
-
error: reflectionError instanceof Error
|
|
326
|
-
? reflectionError.message
|
|
327
|
-
: String(reflectionError),
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
else {
|
|
334
|
-
break;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
const endTime = Date.now();
|
|
338
|
-
const lastAssistantMessage = messages.filter((m) => m.role === 'assistant').pop();
|
|
339
|
-
const finalOutput = lastAssistantMessage ? getTextContent(lastAssistantMessage.content) : '';
|
|
340
|
-
if (this.state.reflectionEngine &&
|
|
341
|
-
this.config.reflection?.enabled &&
|
|
342
|
-
this.config.reflection.reflectAtEnd) {
|
|
343
|
-
try {
|
|
344
|
-
const runReflection = await this.state.reflectionEngine.reflectOnRun(agentContext, allActions, finalOutput, true);
|
|
345
|
-
allReflections.push(runReflection.reflection);
|
|
346
|
-
}
|
|
347
|
-
catch (reflectionError) {
|
|
348
|
-
getLogger().warn('End-of-run reflection failed', {
|
|
349
|
-
error: reflectionError instanceof Error ? reflectionError.message : String(reflectionError),
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
const rootSpan = createSpan('agent.run', traceId, undefined, startTime, endTime, {
|
|
354
|
-
'agent.id': agent.id,
|
|
355
|
-
'agent.name': agent.name,
|
|
356
|
-
'agent.model': agent.model,
|
|
357
|
-
'run.id': runId,
|
|
358
|
-
'run.thread_id': threadId,
|
|
359
|
-
'run.iterations': iterations,
|
|
360
|
-
'run.tool_calls': allToolCalls.length,
|
|
361
|
-
'run.input_tokens': totalInputTokens,
|
|
362
|
-
'run.output_tokens': totalOutputTokens,
|
|
363
|
-
}, 'ok', 'server', options.onSpan);
|
|
364
|
-
spans.unshift(rootSpan);
|
|
365
|
-
const runCost = this.calculateCost(effectiveModel, totalInputTokens, totalOutputTokens);
|
|
366
|
-
if (this.state.costRouter) {
|
|
367
|
-
this.state.costRouter.recordCost({
|
|
368
|
-
runId,
|
|
369
|
-
agentId: agent.id,
|
|
370
|
-
threadId,
|
|
371
|
-
model: effectiveModel,
|
|
372
|
-
inputTokens: totalInputTokens,
|
|
373
|
-
outputTokens: totalOutputTokens,
|
|
374
|
-
cost: runCost,
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
const result = {
|
|
378
|
-
output: finalOutput,
|
|
379
|
-
runId,
|
|
380
|
-
agentId: agent.id,
|
|
381
|
-
threadId,
|
|
382
|
-
modelUsed: this.config.costRouting?.enabled ? effectiveModel : undefined,
|
|
383
|
-
usage: {
|
|
384
|
-
inputTokens: totalInputTokens,
|
|
385
|
-
outputTokens: totalOutputTokens,
|
|
386
|
-
totalTokens: totalInputTokens + totalOutputTokens,
|
|
387
|
-
cost: runCost,
|
|
388
|
-
duration: endTime - startTime,
|
|
389
|
-
},
|
|
390
|
-
toolCalls: allToolCalls,
|
|
391
|
-
messages,
|
|
392
|
-
trace: {
|
|
393
|
-
traceId,
|
|
394
|
-
spans,
|
|
395
|
-
},
|
|
396
|
-
reflections: allReflections.length > 0 ? allReflections : undefined,
|
|
397
|
-
reflectionSummary: this.state.reflectionEngine
|
|
398
|
-
? await this.state.reflectionEngine.getSummary(agent.id)
|
|
399
|
-
: undefined,
|
|
400
|
-
};
|
|
401
|
-
options.onRunComplete?.(result);
|
|
402
|
-
return result;
|
|
403
|
-
}
|
|
404
|
-
catch (error) {
|
|
405
|
-
const endTime = Date.now();
|
|
406
|
-
const errorSpan = createSpan('agent.run', traceId, undefined, startTime, endTime, {
|
|
407
|
-
'agent.id': agent.id,
|
|
408
|
-
'agent.name': agent.name,
|
|
409
|
-
'agent.model': agent.model,
|
|
410
|
-
'run.id': runId,
|
|
411
|
-
error: error instanceof Error ? error.message : String(error),
|
|
412
|
-
}, 'error', 'server', options.onSpan);
|
|
413
|
-
spans.unshift(errorSpan);
|
|
414
|
-
options.onRunError?.(error instanceof Error ? error : new Error(String(error)), runId);
|
|
415
|
-
throw error;
|
|
416
|
-
}
|
|
417
|
-
finally {
|
|
418
|
-
if (timeoutId) {
|
|
419
|
-
clearTimeout(timeoutId);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
async initializeAll(agent) {
|
|
424
|
-
if (this.config.memory?.adapter && !this.state.memoryInitialized) {
|
|
425
|
-
await initializeMemory(this.config, this.state);
|
|
426
|
-
}
|
|
427
|
-
if (this.config.reflection?.enabled && !this.state.reflectionInitialized) {
|
|
428
|
-
await initializeReflection(this.config, this.state, agent, (model) => this.getBackend(model));
|
|
429
|
-
}
|
|
430
|
-
if (this.config.guardrails?.enabled && !this.state.guardrailsInitialized) {
|
|
431
|
-
initializeGuardrails(this.config, this.state, agent, (model) => this.getBackend(model));
|
|
432
|
-
}
|
|
433
|
-
if (this.config.costRouting?.enabled && !this.state.costRoutingInitialized) {
|
|
434
|
-
initializeCostRouting(this.config, this.state);
|
|
435
|
-
}
|
|
436
|
-
if (this.config.security?.promptInjection && !this.state.securityInitialized) {
|
|
437
|
-
initializeSecurity(this.config, this.state, (model) => this.getBackend(model));
|
|
438
|
-
}
|
|
439
|
-
if (this.config.context?.enabled && !this.state.contextManagerInitialized) {
|
|
440
|
-
initializeContextManager(this.config, this.state, (model) => this.getBackend(model));
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
getBackend(modelString, explicitProvider) {
|
|
444
|
-
const { provider: parsedProvider } = parseModel(modelString);
|
|
445
|
-
const actualProvider = (explicitProvider ??
|
|
446
|
-
parsedProvider ??
|
|
447
|
-
this.config.llm?.defaultProvider ??
|
|
448
|
-
'ollama');
|
|
449
|
-
let backend = this.backends.get(actualProvider);
|
|
450
|
-
if (!backend) {
|
|
451
|
-
backend = createLLMBackend(actualProvider, this.config.llm);
|
|
452
|
-
this.backends.set(actualProvider, backend);
|
|
453
|
-
}
|
|
454
|
-
return backend;
|
|
455
|
-
}
|
|
456
|
-
calculateCost(model, inputTokens, outputTokens) {
|
|
457
|
-
const { model: modelName } = parseModel(model);
|
|
458
|
-
const price = getPrice(modelName);
|
|
459
|
-
if (!price) {
|
|
460
|
-
return 0;
|
|
461
|
-
}
|
|
462
|
-
return (inputTokens * price.input + outputTokens * price.output) / 1_000_000;
|
|
463
|
-
}
|
|
464
|
-
/**
|
|
465
|
-
* Get accumulated insights from reflection for an agent.
|
|
466
|
-
*
|
|
467
|
-
* Insights are learnings derived from past runs that can help
|
|
468
|
-
* improve future agent performance.
|
|
469
|
-
*
|
|
470
|
-
* @param agentId - ID of the agent to get insights for
|
|
471
|
-
* @returns Array of insights, empty if reflection is not enabled
|
|
472
|
-
*/
|
|
473
|
-
async getInsights(agentId) {
|
|
474
|
-
if (!this.state.insightStore)
|
|
475
|
-
return [];
|
|
476
|
-
return this.state.insightStore.getAll(agentId);
|
|
477
|
-
}
|
|
478
|
-
/**
|
|
479
|
-
* Get reflection summary for an agent.
|
|
480
|
-
*
|
|
481
|
-
* Summary includes statistics about total runs, successful tool calls,
|
|
482
|
-
* common patterns, and accumulated learnings.
|
|
483
|
-
*
|
|
484
|
-
* @param agentId - ID of the agent to get summary for
|
|
485
|
-
* @returns Reflection summary, null if reflection is not enabled
|
|
486
|
-
*/
|
|
487
|
-
async getReflectionSummary(agentId) {
|
|
488
|
-
if (!this.state.reflectionEngine)
|
|
489
|
-
return null;
|
|
490
|
-
return this.state.reflectionEngine.getSummary(agentId);
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* Get the constitutional AI guardrails instance.
|
|
494
|
-
*
|
|
495
|
-
* @returns ConstitutionalAI instance, undefined if guardrails not enabled
|
|
496
|
-
*/
|
|
497
|
-
getGuardrails() {
|
|
498
|
-
return this.state.constitutionalAI;
|
|
499
|
-
}
|
|
500
|
-
/**
|
|
501
|
-
* Set or update the constitution for guardrails.
|
|
502
|
-
*
|
|
503
|
-
* The constitution defines principles and rules that the agent
|
|
504
|
-
* must follow, filtering both input and output.
|
|
505
|
-
*
|
|
506
|
-
* @param constitution - New constitution to apply
|
|
507
|
-
*/
|
|
508
|
-
setConstitution(constitution) {
|
|
509
|
-
this.state.constitutionalAI?.setConstitution(constitution);
|
|
510
|
-
}
|
|
511
|
-
/**
|
|
512
|
-
* Get cost tracking summary across all runs.
|
|
513
|
-
*
|
|
514
|
-
* @returns Cost summary with total spent, runs count, and per-model breakdown
|
|
515
|
-
*/
|
|
516
|
-
getCostSummary() {
|
|
517
|
-
return this.state.costRouter?.getCostSummary();
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* Get the cost-aware router instance for advanced cost management.
|
|
521
|
-
*
|
|
522
|
-
* @returns CostAwareRouter instance, undefined if cost routing not enabled
|
|
523
|
-
*/
|
|
524
|
-
getCostRouter() {
|
|
525
|
-
return this.state.costRouter;
|
|
526
|
-
}
|
|
527
|
-
/**
|
|
528
|
-
* Estimate the cost of running an agent before execution.
|
|
529
|
-
*
|
|
530
|
-
* Returns min/max/expected cost estimates based on:
|
|
531
|
-
* - Model pricing (from registry)
|
|
532
|
-
* - Task complexity analysis
|
|
533
|
-
* - Tool usage patterns
|
|
534
|
-
* - Estimated iterations
|
|
535
|
-
*
|
|
536
|
-
* @param params - Estimation parameters
|
|
537
|
-
* @param params.agent - Agent to estimate cost for
|
|
538
|
-
* @param params.input - User input/prompt
|
|
539
|
-
* @param params.options - Optional estimation overrides
|
|
540
|
-
* @returns Cost estimate with breakdown and confidence score
|
|
541
|
-
*
|
|
542
|
-
* @example
|
|
543
|
-
* ```ts
|
|
544
|
-
* const estimate = await cog.estimateCost({
|
|
545
|
-
* agent,
|
|
546
|
-
* input: 'Analyze this document and summarize key points',
|
|
547
|
-
* options: { assumeIterations: 3, assumeToolCalls: 5 }
|
|
548
|
-
* });
|
|
549
|
-
*
|
|
550
|
-
* console.log(`Expected cost: $${estimate.expectedCost.toFixed(4)}`);
|
|
551
|
-
* console.log(`Confidence: ${(estimate.confidence * 100).toFixed(0)}%`);
|
|
552
|
-
*
|
|
553
|
-
* if (estimate.expectedCost > 0.10) {
|
|
554
|
-
* console.log('Warning: This may be an expensive operation');
|
|
555
|
-
* }
|
|
556
|
-
* ```
|
|
557
|
-
*/
|
|
558
|
-
async estimateCost(params) {
|
|
559
|
-
if (!this.costEstimator) {
|
|
560
|
-
this.costEstimator = new CostEstimator();
|
|
561
|
-
}
|
|
562
|
-
return this.costEstimator.estimate(params);
|
|
563
|
-
}
|
|
564
|
-
/**
|
|
565
|
-
* Close all connections and release resources.
|
|
566
|
-
*
|
|
567
|
-
* Should be called when done using the Cogitator instance to properly
|
|
568
|
-
* disconnect from memory adapters, shut down sandbox containers, and
|
|
569
|
-
* clean up internal state.
|
|
570
|
-
*
|
|
571
|
-
* @example
|
|
572
|
-
* ```ts
|
|
573
|
-
* const cog = new Cogitator({ ... });
|
|
574
|
-
* try {
|
|
575
|
-
* await cog.run(agent, { input: 'Hello' });
|
|
576
|
-
* } finally {
|
|
577
|
-
* await cog.close();
|
|
578
|
-
* }
|
|
579
|
-
* ```
|
|
580
|
-
*/
|
|
581
|
-
async close() {
|
|
582
|
-
await cleanupState(this.state);
|
|
583
|
-
this.backends.clear();
|
|
584
|
-
}
|
|
585
|
-
}
|
|
1
|
+
export { Cogitator } from './runtime';
|
|
586
2
|
//# sourceMappingURL=cogitator.js.map
|
package/dist/cogitator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cogitator.js","sourceRoot":"","sources":["../src/cogitator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAkBhC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAEL,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,wBAAwB,EACxB,YAAY,GACb,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EACL,oBAAoB,EACpB,SAAS,EACT,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,2BAA2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I,CAAC,KAAK,CAAC,gBAAgB,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC;IAC7D,CAAC;IAED;;;;OAIG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,cAAc,EAAE,CAAC;IACjD,CAAC;IAED;;;;OAIG;IACH,aAAa;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,KAAK,CAAC,YAAY,CAAC,MAIlB;QACC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACxB,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;QAC3C,CAAC;QACD,OAAO,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACF"}
|
|
1
|
+
{"version":3,"file":"cogitator.js","sourceRoot":"","sources":["../src/cogitator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Core runtime for Cogitator AI agents
|
|
5
5
|
*/
|
|
6
|
-
export { Cogitator } from './
|
|
6
|
+
export { Cogitator } from './runtime';
|
|
7
7
|
export { Agent, AgentDeserializationError } from './agent';
|
|
8
8
|
export { tool, toolToSchema } from './tool';
|
|
9
9
|
export { agentAsTool } from './agent-tool';
|
|
@@ -28,7 +28,7 @@ export { ConstitutionalAI, InputFilter, OutputFilter, ToolGuard, CritiqueReviser
|
|
|
28
28
|
export type { ConstitutionalAIOptions, InputFilterOptions, OutputFilterOptions, ToolGuardOptions, CritiqueReviserOptions, } from './constitutional/index';
|
|
29
29
|
export { CostAwareRouter, TaskAnalyzer, ModelSelector, CostTracker, BudgetEnforcer, } from './cost-routing/index';
|
|
30
30
|
export type { CostAwareRouterOptions, CostFilter, BudgetCheckResult } from './cost-routing/index';
|
|
31
|
-
export { BaseLLMBackend, OllamaBackend, OpenAIBackend, AnthropicBackend, createLLMBackend, parseModel, } from './llm/index';
|
|
31
|
+
export { BaseLLMBackend, OllamaBackend, OpenAIBackend, AnthropicBackend, GoogleBackend, AzureOpenAIBackend, BedrockBackend, createLLMBackend, parseModel, } from './llm/index';
|
|
32
32
|
export { withRetry, retryable, CircuitBreaker, CircuitBreakerRegistry, withFallback, withGracefulDegradation, createLLMFallbackExecutor, } from './utils/index';
|
|
33
33
|
export type { RetryOptions, CircuitBreakerOptions, CircuitBreakerStats, CircuitState, FallbackConfig, LLMFallbackConfig, } from './utils/index';
|
|
34
34
|
export { CogitatorError, ErrorCode, ERROR_STATUS_CODES, isRetryableError, getRetryDelay, } from '@cogitator-ai/types';
|