cencori 1.16.4 → 1.17.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/dist/agents/index.d.mts +39 -1
- package/dist/agents/index.d.ts +39 -1
- package/dist/agents/index.js +26 -6
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/index.mjs +26 -6
- package/dist/agents/index.mjs.map +1 -1
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/agents/index.mjs
CHANGED
|
@@ -1256,6 +1256,18 @@ function wireTools(agent, resolved = agent.tools) {
|
|
|
1256
1256
|
}
|
|
1257
1257
|
return tools;
|
|
1258
1258
|
}
|
|
1259
|
+
function stepOf(agentName, usage, trace) {
|
|
1260
|
+
const t = trace ?? {};
|
|
1261
|
+
return {
|
|
1262
|
+
agentName,
|
|
1263
|
+
model: typeof t.model === "string" ? t.model : void 0,
|
|
1264
|
+
provider: typeof t.provider === "string" ? t.provider : void 0,
|
|
1265
|
+
usedFallback: t.used_fallback === true,
|
|
1266
|
+
usage: addUsage({ inputTokens: 0, outputTokens: 0, totalTokens: 0 }, usage),
|
|
1267
|
+
costUsd: Number(t.cost_usd) || 0,
|
|
1268
|
+
providerCostUsd: Number(t.provider_cost_usd) || 0
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1259
1271
|
function addUsage(total, usage) {
|
|
1260
1272
|
const u = usage ?? {};
|
|
1261
1273
|
return {
|
|
@@ -1318,10 +1330,10 @@ async function* consumeTurn(response, agentName, sessionId, items) {
|
|
|
1318
1330
|
}
|
|
1319
1331
|
case "turn.paused": {
|
|
1320
1332
|
const actions = Array.isArray(data.actions) ? data.actions : [{ action_id: String(data.action_id), tool: String(data.tool), arguments: JSON.stringify(data.arguments?.[String(data.tool)] ?? {}) }];
|
|
1321
|
-
return { kind: "paused", pause: { actionId: String(data.action_id), actions, text } };
|
|
1333
|
+
return { kind: "paused", pause: { actionId: String(data.action_id), actions, text }, usage: data.usage, trace: data.trace };
|
|
1322
1334
|
}
|
|
1323
1335
|
case "turn.completed":
|
|
1324
|
-
return { kind: "completed", text: completedText(text, data), usage: data.usage };
|
|
1336
|
+
return { kind: "completed", text: completedText(text, data), usage: data.usage, trace: data.trace };
|
|
1325
1337
|
case "owner.handling":
|
|
1326
1338
|
return { kind: "with_human" };
|
|
1327
1339
|
case "turn.failed": {
|
|
@@ -1343,6 +1355,8 @@ async function* runLoop(startAgent, input, options) {
|
|
|
1343
1355
|
const agents = collectAgents(startAgent);
|
|
1344
1356
|
const maxTurns = options.maxTurns ?? DEFAULT_MAX_TURNS;
|
|
1345
1357
|
const items = [];
|
|
1358
|
+
const steps = [];
|
|
1359
|
+
const toolResults = [];
|
|
1346
1360
|
const contextFor = (agent2, sessionId2) => {
|
|
1347
1361
|
const ctx = {
|
|
1348
1362
|
context: options.context,
|
|
@@ -1435,10 +1449,11 @@ async function* runLoop(startAgent, input, options) {
|
|
|
1435
1449
|
response = void 0;
|
|
1436
1450
|
if (outcome.kind === "with_human") {
|
|
1437
1451
|
yield { type: "with_human" };
|
|
1438
|
-
return { finalOutput: void 0, sessionId, lastAgent: agent, interruptions: [], state: void 0, newItems: items, usage, withHuman: true };
|
|
1452
|
+
return { finalOutput: void 0, sessionId, lastAgent: agent, interruptions: [], state: void 0, newItems: items, usage, steps, withHuman: true };
|
|
1439
1453
|
}
|
|
1440
1454
|
if (outcome.kind === "completed") {
|
|
1441
1455
|
usage = addUsage(usage, outcome.usage);
|
|
1456
|
+
steps.push(stepOf(agent.name, outcome.usage, outcome.trace));
|
|
1442
1457
|
let finalOutput = outcome.text;
|
|
1443
1458
|
if (agent.outputType) {
|
|
1444
1459
|
let parsed;
|
|
@@ -1452,11 +1467,13 @@ async function* runLoop(startAgent, input, options) {
|
|
|
1452
1467
|
items.push({ type: "message", agentName: agent.name, text: outcome.text });
|
|
1453
1468
|
const runContext2 = contextFor(agent, sessionId);
|
|
1454
1469
|
for (const guardrail of agent.outputGuardrails) {
|
|
1455
|
-
const verdict = await guardrail.execute({ output: finalOutput, agent, runContext: runContext2 });
|
|
1470
|
+
const verdict = await guardrail.execute({ output: finalOutput, agent, runContext: runContext2, toolResults });
|
|
1456
1471
|
if (verdict.tripwireTriggered) throw new GuardrailTripwireTriggered("output", guardrail.name, verdict.outputInfo);
|
|
1457
1472
|
}
|
|
1458
|
-
return { finalOutput, sessionId, lastAgent: agent, interruptions: [], state: void 0, newItems: items, usage, withHuman: false };
|
|
1473
|
+
return { finalOutput, sessionId, lastAgent: agent, interruptions: [], state: void 0, newItems: items, usage, steps, withHuman: false };
|
|
1459
1474
|
}
|
|
1475
|
+
usage = addUsage(usage, outcome.usage);
|
|
1476
|
+
steps.push(stepOf(agent.name, outcome.usage, outcome.trace));
|
|
1460
1477
|
pending = outcome.pause;
|
|
1461
1478
|
if (outcome.pause.text) items.push({ type: "message", agentName: agent.name, text: outcome.pause.text });
|
|
1462
1479
|
for (const action of outcome.pause.actions) {
|
|
@@ -1493,7 +1510,7 @@ async function* runLoop(startAgent, input, options) {
|
|
|
1493
1510
|
if (interruptions.length > 0) {
|
|
1494
1511
|
const state = new RunState({ sessionId, agentName: agent.name, turnsUsed, usage, pending });
|
|
1495
1512
|
yield { type: "interruption", interruptions };
|
|
1496
|
-
return { finalOutput: void 0, sessionId, lastAgent: agent, interruptions, state, newItems: items, usage, withHuman: false };
|
|
1513
|
+
return { finalOutput: void 0, sessionId, lastAgent: agent, interruptions, state, newItems: items, usage, steps, withHuman: false };
|
|
1497
1514
|
}
|
|
1498
1515
|
if (turnsUsed >= maxTurns) throw new MaxTurnsExceededError(maxTurns, sessionId);
|
|
1499
1516
|
let handoffTo;
|
|
@@ -1525,6 +1542,9 @@ async function* runLoop(startAgent, input, options) {
|
|
|
1525
1542
|
yield { type: "widget", callId: action.action_id, widgetId: shown.widgetId, widget: shown.widget, agentName: agent.name };
|
|
1526
1543
|
}
|
|
1527
1544
|
const output = result.output;
|
|
1545
|
+
const finished = { callId: action.action_id, toolName: action.tool, arguments: action.arguments, output, agentName: agent.name };
|
|
1546
|
+
toolResults.push(finished);
|
|
1547
|
+
if (options.onToolEnd) await options.onToolEnd(finished, runContext);
|
|
1528
1548
|
items.push({ type: "tool_output", agentName: agent.name, callId: action.action_id, toolName: action.tool, output });
|
|
1529
1549
|
yield { type: "tool_output", callId: action.action_id, toolName: action.tool, output, agentName: agent.name };
|
|
1530
1550
|
if (action.tool === HUMAN_HANDOFF_TOOL && !output.startsWith("Error")) {
|