@juspay/neurolink 10.5.3 → 10.6.1
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/CHANGELOG.md +12 -0
- package/dist/agent/agent.js +39 -8
- package/dist/agent/agentNetwork.js +62 -20
- package/dist/agent/agentToolRegistrar.d.ts +48 -0
- package/dist/agent/agentToolRegistrar.js +336 -0
- package/dist/agent/index.d.ts +3 -0
- package/dist/agent/index.js +4 -0
- package/dist/agent/isolatedAgentRunner.d.ts +73 -0
- package/dist/agent/isolatedAgentRunner.js +946 -0
- package/dist/agent/structuredRecovery.d.ts +30 -0
- package/dist/agent/structuredRecovery.js +104 -0
- package/dist/browser/neurolink.min.js +414 -398
- package/dist/cli/loop/optionsSchema.d.ts +1 -1
- package/dist/core/baseProvider.d.ts +8 -0
- package/dist/core/baseProvider.js +40 -19
- package/dist/core/modules/GenerationHandler.d.ts +2 -6
- package/dist/core/modules/GenerationHandler.js +10 -1
- package/dist/core/toolExecutionRecorder.d.ts +76 -0
- package/dist/core/toolExecutionRecorder.js +261 -0
- package/dist/evaluation/contextBuilder.js +6 -6
- package/dist/lib/agent/agent.js +39 -8
- package/dist/lib/agent/agentNetwork.js +62 -20
- package/dist/lib/agent/agentToolRegistrar.d.ts +48 -0
- package/dist/lib/agent/agentToolRegistrar.js +337 -0
- package/dist/lib/agent/index.d.ts +3 -0
- package/dist/lib/agent/index.js +4 -0
- package/dist/lib/agent/isolatedAgentRunner.d.ts +73 -0
- package/dist/lib/agent/isolatedAgentRunner.js +947 -0
- package/dist/lib/agent/structuredRecovery.d.ts +30 -0
- package/dist/lib/agent/structuredRecovery.js +105 -0
- package/dist/lib/core/baseProvider.d.ts +8 -0
- package/dist/lib/core/baseProvider.js +40 -19
- package/dist/lib/core/modules/GenerationHandler.d.ts +2 -6
- package/dist/lib/core/modules/GenerationHandler.js +10 -1
- package/dist/lib/core/toolExecutionRecorder.d.ts +76 -0
- package/dist/lib/core/toolExecutionRecorder.js +262 -0
- package/dist/lib/evaluation/contextBuilder.js +6 -6
- package/dist/lib/models/modelRegistry.d.ts +23 -0
- package/dist/lib/models/modelRegistry.js +62 -1
- package/dist/lib/models/modelResolver.js +1 -0
- package/dist/lib/neurolink.d.ts +80 -1
- package/dist/lib/neurolink.js +199 -37
- package/dist/lib/processors/media/index.js +0 -10
- package/dist/lib/providers/amazonBedrock.js +15 -2
- package/dist/lib/providers/anthropic.js +23 -11
- package/dist/lib/providers/googleAiStudio.js +8 -1
- package/dist/lib/providers/googleNativeGemini3.d.ts +2 -0
- package/dist/lib/providers/googleNativeGemini3.js +8 -1
- package/dist/lib/providers/googleVertex.js +56 -16
- package/dist/lib/providers/openaiChatCompletionsClient.js +18 -5
- package/dist/lib/tasks/autoresearchTaskExecutor.js +7 -6
- package/dist/lib/tasks/taskExecutor.js +2 -5
- package/dist/lib/types/agentNetwork.d.ts +23 -8
- package/dist/lib/types/generate.d.ts +62 -5
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/index.js +1 -0
- package/dist/lib/types/isolatedAgent.d.ts +365 -0
- package/dist/lib/types/isolatedAgent.js +12 -0
- package/dist/lib/types/model.d.ts +8 -0
- package/dist/lib/types/stream.d.ts +3 -1
- package/dist/lib/types/task.d.ts +3 -3
- package/dist/lib/utils/logger.d.ts +12 -3
- package/dist/lib/utils/logger.js +11 -3
- package/dist/lib/utils/transformationUtils.d.ts +14 -0
- package/dist/lib/utils/transformationUtils.js +33 -10
- package/dist/lib/voice/livekit/realtimeVoiceAgent.js +6 -3
- package/dist/models/modelRegistry.d.ts +23 -0
- package/dist/models/modelRegistry.js +62 -1
- package/dist/models/modelResolver.js +1 -0
- package/dist/neurolink.d.ts +80 -1
- package/dist/neurolink.js +199 -37
- package/dist/processors/media/index.js +0 -10
- package/dist/providers/amazonBedrock.js +15 -2
- package/dist/providers/anthropic.js +23 -11
- package/dist/providers/googleAiStudio.js +8 -1
- package/dist/providers/googleNativeGemini3.d.ts +2 -0
- package/dist/providers/googleNativeGemini3.js +8 -1
- package/dist/providers/googleVertex.js +56 -16
- package/dist/providers/openaiChatCompletionsClient.js +18 -5
- package/dist/tasks/autoresearchTaskExecutor.js +7 -6
- package/dist/tasks/taskExecutor.js +2 -5
- package/dist/types/agentNetwork.d.ts +23 -8
- package/dist/types/generate.d.ts +62 -5
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/isolatedAgent.d.ts +365 -0
- package/dist/types/isolatedAgent.js +11 -0
- package/dist/types/model.d.ts +8 -0
- package/dist/types/stream.d.ts +3 -1
- package/dist/types/task.d.ts +3 -3
- package/dist/utils/logger.d.ts +12 -3
- package/dist/utils/logger.js +11 -3
- package/dist/utils/transformationUtils.d.ts +14 -0
- package/dist/utils/transformationUtils.js +33 -10
- package/dist/voice/livekit/realtimeVoiceAgent.js +6 -3
- package/package.json +3 -2
|
@@ -107,6 +107,8 @@ export declare function buildNativeConfig(options: {
|
|
|
107
107
|
temperature?: number;
|
|
108
108
|
maxTokens?: number;
|
|
109
109
|
systemPrompt?: string;
|
|
110
|
+
/** Model id, used for the registry-driven sampling-param strip. */
|
|
111
|
+
model?: string;
|
|
110
112
|
thinkingConfig?: ThinkingConfig;
|
|
111
113
|
/**
|
|
112
114
|
* When true (and `toolsConfig` is undefined), set
|
|
@@ -13,6 +13,7 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
13
13
|
import { extname } from "node:path";
|
|
14
14
|
import { DEFAULT_CONTEXT_GUARD_RATIO, DEFAULT_MAX_STEPS, DEFAULT_TOOL_MAX_RETRIES, DEFAULT_WRAPUP_TIME_LEAD_MS, } from "../core/constants.js";
|
|
15
15
|
import { logger } from "../utils/logger.js";
|
|
16
|
+
import { resolveSamplingParams } from "../models/modelRegistry.js";
|
|
16
17
|
import { convertZodToJsonSchema, ensureNestedSchemaTypes, inlineJsonSchema, isZodSchema, normalizeJsonSchemaObject, } from "../utils/schemaConversion.js";
|
|
17
18
|
import { createNativeThinkingConfig } from "../utils/thinkingConfig.js";
|
|
18
19
|
import { resolveLiveTool } from "../tools/toolDiscovery.js";
|
|
@@ -487,8 +488,14 @@ export function refreshNativeToolDeclarations(liveTools, current) {
|
|
|
487
488
|
* `disableTools: true` whenever JSON/schema output is requested.
|
|
488
489
|
*/
|
|
489
490
|
export function buildNativeConfig(options, toolsConfig) {
|
|
491
|
+
// Registry-driven sampling strip applied for uniformity with every other
|
|
492
|
+
// provider path (inert for current Gemini models).
|
|
493
|
+
const samplingParams = resolveSamplingParams("google-ai", options.model, { temperature: options.temperature ?? 1.0 }, // Gemini 3 requires 1.0 for tool calling
|
|
494
|
+
"googleAiStudio.buildNativeConfig");
|
|
490
495
|
const config = {
|
|
491
|
-
|
|
496
|
+
...(samplingParams.temperature !== undefined && {
|
|
497
|
+
temperature: samplingParams.temperature,
|
|
498
|
+
}),
|
|
492
499
|
maxOutputTokens: options.maxTokens,
|
|
493
500
|
};
|
|
494
501
|
if (toolsConfig) {
|
|
@@ -31,6 +31,8 @@ import { ATTR, LANGFUSE_ATTR, spanJsonAttribute, tracers, withClientSpan, withCl
|
|
|
31
31
|
import { SpanKind, SpanStatusCode, context as otelContext, trace as otelTrace, } from "@opentelemetry/api";
|
|
32
32
|
import { calculateCost } from "../utils/pricing.js";
|
|
33
33
|
import { transformToolExecutions } from "../utils/transformationUtils.js";
|
|
34
|
+
import { resolveToolExecutionRecords } from "../core/toolExecutionRecorder.js";
|
|
35
|
+
import { resolveSamplingParams } from "../models/modelRegistry.js";
|
|
34
36
|
import { sanitizeAnthropicMessagesForTrace } from "../utils/anthropicTraceSanitizer.js";
|
|
35
37
|
import { extractMcpToolErrorMessage, extractToolFailureText, } from "../utils/mcpErrorText.js";
|
|
36
38
|
// Import proper types for multimodal message handling
|
|
@@ -1344,9 +1346,16 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
1344
1346
|
totalTools: existingDeclarations.length,
|
|
1345
1347
|
});
|
|
1346
1348
|
}
|
|
1347
|
-
// Build config
|
|
1348
|
-
|
|
1349
|
+
// Build config. Registry-driven sampling strip applied for uniformity
|
|
1350
|
+
// with every other provider path (inert for current Gemini models).
|
|
1351
|
+
const geminiSampling = resolveSamplingParams(this.providerName, modelName, {
|
|
1349
1352
|
temperature: options.temperature ?? 1.0, // Gemini 3 requires 1.0 for tool calling
|
|
1353
|
+
...(options.topP !== undefined && { topP: options.topP }),
|
|
1354
|
+
}, "vertex.gemini");
|
|
1355
|
+
const config = {
|
|
1356
|
+
...(geminiSampling.temperature !== undefined && {
|
|
1357
|
+
temperature: geminiSampling.temperature,
|
|
1358
|
+
}),
|
|
1350
1359
|
maxOutputTokens: options.maxTokens,
|
|
1351
1360
|
};
|
|
1352
1361
|
// Cap maxOutputTokens for models with restricted output token limits (32768)
|
|
@@ -1363,8 +1372,8 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
1363
1372
|
}
|
|
1364
1373
|
}
|
|
1365
1374
|
// Add topP, topK, stopSequences if provided
|
|
1366
|
-
if (
|
|
1367
|
-
config.topP =
|
|
1375
|
+
if (geminiSampling.topP !== undefined) {
|
|
1376
|
+
config.topP = geminiSampling.topP;
|
|
1368
1377
|
}
|
|
1369
1378
|
if (options.topK !== undefined) {
|
|
1370
1379
|
config.topK = options.topK;
|
|
@@ -2272,9 +2281,16 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
2272
2281
|
totalTools: existingDeclarations.length,
|
|
2273
2282
|
});
|
|
2274
2283
|
}
|
|
2275
|
-
// Build config
|
|
2276
|
-
|
|
2284
|
+
// Build config. Registry-driven sampling strip applied for uniformity
|
|
2285
|
+
// with every other provider path (inert for current Gemini models).
|
|
2286
|
+
const geminiSampling = resolveSamplingParams(this.providerName, modelName, {
|
|
2277
2287
|
temperature: options.temperature ?? 1.0, // Gemini 3 requires 1.0 for tool calling
|
|
2288
|
+
...(options.topP !== undefined && { topP: options.topP }),
|
|
2289
|
+
}, "vertex.gemini");
|
|
2290
|
+
const config = {
|
|
2291
|
+
...(geminiSampling.temperature !== undefined && {
|
|
2292
|
+
temperature: geminiSampling.temperature,
|
|
2293
|
+
}),
|
|
2278
2294
|
maxOutputTokens: options.maxTokens,
|
|
2279
2295
|
};
|
|
2280
2296
|
// Cap maxOutputTokens for models with restricted output token limits (32768)
|
|
@@ -2291,8 +2307,8 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
2291
2307
|
}
|
|
2292
2308
|
}
|
|
2293
2309
|
// Add topP, topK, stopSequences if provided
|
|
2294
|
-
if (
|
|
2295
|
-
config.topP =
|
|
2310
|
+
if (geminiSampling.topP !== undefined) {
|
|
2311
|
+
config.topP = geminiSampling.topP;
|
|
2296
2312
|
}
|
|
2297
2313
|
if (options.topK !== undefined) {
|
|
2298
2314
|
config.topK = options.topK;
|
|
@@ -2954,7 +2970,7 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
2954
2970
|
},
|
|
2955
2971
|
responseTime,
|
|
2956
2972
|
toolsUsed: externalToolCalls.map((tc) => tc.toolName),
|
|
2957
|
-
toolExecutions:
|
|
2973
|
+
toolExecutions: resolveToolExecutionRecords(options, externalToolExecutions),
|
|
2958
2974
|
enhancedWithTools: externalToolCalls.length > 0,
|
|
2959
2975
|
};
|
|
2960
2976
|
// Add structured output if final_result tool was used
|
|
@@ -3301,6 +3317,16 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
3301
3317
|
: schemaSystemPromptSuffix
|
|
3302
3318
|
? schemaSystemPromptSuffix.trim()
|
|
3303
3319
|
: undefined;
|
|
3320
|
+
// Registry-driven strip: Sonnet 5 / Opus 4.7+ / Fable 5 on Vertex reject
|
|
3321
|
+
// sampling params. Applied here so every rebuild that spreads
|
|
3322
|
+
// `...requestParams` (forced finalization, tools-off backstop) inherits
|
|
3323
|
+
// the strip automatically.
|
|
3324
|
+
const streamSampling = resolveSamplingParams(this.providerName, modelName, {
|
|
3325
|
+
...(options.temperature !== undefined && {
|
|
3326
|
+
temperature: options.temperature,
|
|
3327
|
+
}),
|
|
3328
|
+
...(options.topP !== undefined && { topP: options.topP }),
|
|
3329
|
+
}, "vertex.anthropic.stream");
|
|
3304
3330
|
const requestParams = {
|
|
3305
3331
|
model: modelName,
|
|
3306
3332
|
// Default to the model's real output ceiling (e.g. 64K for Sonnet 4.x)
|
|
@@ -3312,10 +3338,12 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
3312
3338
|
...(tools && tools.length > 0 && { tools }),
|
|
3313
3339
|
...(useFinalResultTool && { tool_choice: { type: "any" } }),
|
|
3314
3340
|
...(systemPromptWithSchema && { system: systemPromptWithSchema }),
|
|
3315
|
-
...(
|
|
3316
|
-
temperature:
|
|
3341
|
+
...(streamSampling.temperature !== undefined && {
|
|
3342
|
+
temperature: streamSampling.temperature,
|
|
3343
|
+
}),
|
|
3344
|
+
...(streamSampling.topP !== undefined && {
|
|
3345
|
+
top_p: streamSampling.topP,
|
|
3317
3346
|
}),
|
|
3318
|
-
...(options.topP !== undefined && { top_p: options.topP }),
|
|
3319
3347
|
...(options.stopSequences &&
|
|
3320
3348
|
options.stopSequences.length > 0 && {
|
|
3321
3349
|
stop_sequences: options.stopSequences,
|
|
@@ -4596,6 +4624,16 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
4596
4624
|
: schemaSystemPromptSuffix
|
|
4597
4625
|
? schemaSystemPromptSuffix.trim()
|
|
4598
4626
|
: undefined;
|
|
4627
|
+
// Registry-driven strip: Sonnet 5 / Opus 4.7+ / Fable 5 on Vertex reject
|
|
4628
|
+
// sampling params. Applied at the requestParams build so the forced
|
|
4629
|
+
// finalization and tools-off backstop rebuilds (`...requestParams`)
|
|
4630
|
+
// inherit the strip automatically.
|
|
4631
|
+
const generateSampling = resolveSamplingParams(this.providerName, modelName, {
|
|
4632
|
+
...(options.temperature !== undefined && {
|
|
4633
|
+
temperature: options.temperature,
|
|
4634
|
+
}),
|
|
4635
|
+
...(options.topP !== undefined && { topP: options.topP }),
|
|
4636
|
+
}, "vertex.anthropic.generate");
|
|
4599
4637
|
const requestParams = {
|
|
4600
4638
|
model: modelName,
|
|
4601
4639
|
// Default to the model's real output ceiling (see stream path note).
|
|
@@ -4604,10 +4642,12 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
4604
4642
|
...(tools && tools.length > 0 && { tools }),
|
|
4605
4643
|
...(useFinalResultTool && { tool_choice: { type: "any" } }),
|
|
4606
4644
|
...(systemPromptWithSchema && { system: systemPromptWithSchema }),
|
|
4607
|
-
...(
|
|
4608
|
-
temperature:
|
|
4645
|
+
...(generateSampling.temperature !== undefined && {
|
|
4646
|
+
temperature: generateSampling.temperature,
|
|
4647
|
+
}),
|
|
4648
|
+
...(generateSampling.topP !== undefined && {
|
|
4649
|
+
top_p: generateSampling.topP,
|
|
4609
4650
|
}),
|
|
4610
|
-
...(options.topP !== undefined && { top_p: options.topP }),
|
|
4611
4651
|
...(options.stopSequences &&
|
|
4612
4652
|
options.stopSequences.length > 0 && {
|
|
4613
4653
|
stop_sequences: options.stopSequences,
|
|
@@ -5357,7 +5397,7 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
5357
5397
|
},
|
|
5358
5398
|
responseTime,
|
|
5359
5399
|
toolsUsed: externalToolCalls.map((tc) => tc.toolName),
|
|
5360
|
-
toolExecutions:
|
|
5400
|
+
toolExecutions: resolveToolExecutionRecords(options, externalToolExecutions),
|
|
5361
5401
|
enhancedWithTools: externalToolCalls.length > 0,
|
|
5362
5402
|
};
|
|
5363
5403
|
// Route through enhanceResult so analytics/evaluation/tracing are picked
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { createParser } from "eventsource-parser";
|
|
17
17
|
import { sanitizeToolName } from "../mcp/toolConverter.js";
|
|
18
|
+
import { resolveSamplingParams } from "../models/modelRegistry.js";
|
|
18
19
|
import { convertZodToJsonSchema, normalizeWireToolSchema, } from "../utils/schemaConversion.js";
|
|
19
20
|
import { estimateTokens, TOKENS_PER_MESSAGE, } from "../utils/tokenEstimation.js";
|
|
20
21
|
export const stripTrailingSlash = (s) => s.replace(/\/+$/, "");
|
|
@@ -454,11 +455,23 @@ export const buildBody = (args) => {
|
|
|
454
455
|
if (options.maxTokens !== undefined && options.maxTokens !== null) {
|
|
455
456
|
body.max_tokens = options.maxTokens;
|
|
456
457
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
458
|
+
// Registry-driven strip: models that reject sampling params (Sonnet 5 /
|
|
459
|
+
// Opus 4.7+ / Fable 5 families — e.g. Claude served through litellm)
|
|
460
|
+
// must not receive temperature/top_p. Applied in buildBody so the 400
|
|
461
|
+
// one-shot retries, which reuse the built body, inherit the strip.
|
|
462
|
+
const samplingParams = resolveSamplingParams("openai-compatible", modelId, {
|
|
463
|
+
...(options.temperature !== undefined && options.temperature !== null
|
|
464
|
+
? { temperature: options.temperature }
|
|
465
|
+
: {}),
|
|
466
|
+
...(options.topP !== undefined && options.topP !== null
|
|
467
|
+
? { topP: options.topP }
|
|
468
|
+
: {}),
|
|
469
|
+
}, "openaiCompatible.buildBody");
|
|
470
|
+
if (samplingParams.temperature !== undefined) {
|
|
471
|
+
body.temperature = samplingParams.temperature;
|
|
472
|
+
}
|
|
473
|
+
if (samplingParams.topP !== undefined) {
|
|
474
|
+
body.top_p = samplingParams.topP;
|
|
462
475
|
}
|
|
463
476
|
if (options.presencePenalty !== undefined &&
|
|
464
477
|
options.presencePenalty !== null) {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import { ResearchWorker } from "../autoresearch/worker.js";
|
|
16
16
|
import { withTimeout } from "../utils/errorHandling.js";
|
|
17
17
|
import { logger } from "../utils/logger.js";
|
|
18
|
+
import { toolExecutionRecordsToToolCalls } from "../utils/transformationUtils.js";
|
|
18
19
|
// ── Worker cache ────────────────────────────────────────
|
|
19
20
|
const workerCache = new Map();
|
|
20
21
|
/**
|
|
@@ -252,7 +253,11 @@ export async function executeAutoresearchTick(task, neurolink, emitter) {
|
|
|
252
253
|
const calledTools = (result.toolExecutions ?? [])
|
|
253
254
|
.map((te) => {
|
|
254
255
|
const t = te;
|
|
255
|
-
return typeof t.
|
|
256
|
+
return typeof t.toolName === "string"
|
|
257
|
+
? t.toolName
|
|
258
|
+
: typeof t.name === "string"
|
|
259
|
+
? t.name
|
|
260
|
+
: "";
|
|
256
261
|
})
|
|
257
262
|
.filter(Boolean);
|
|
258
263
|
const currentState = await worker.getState();
|
|
@@ -271,11 +276,7 @@ export async function executeAutoresearchTick(task, neurolink, emitter) {
|
|
|
271
276
|
runId,
|
|
272
277
|
status: "success",
|
|
273
278
|
output: result.content,
|
|
274
|
-
toolCalls: result.toolExecutions
|
|
275
|
-
name: te.name,
|
|
276
|
-
input: te.input,
|
|
277
|
-
output: te.output,
|
|
278
|
-
})),
|
|
279
|
+
toolCalls: toolExecutionRecordsToToolCalls(result.toolExecutions),
|
|
279
280
|
tokensUsed: result.usage
|
|
280
281
|
? { input: result.usage.input ?? 0, output: result.usage.output ?? 0 }
|
|
281
282
|
: undefined,
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { nanoid } from "nanoid";
|
|
11
11
|
import { logger } from "../utils/logger.js";
|
|
12
|
+
import { toolExecutionRecordsToToolCalls } from "../utils/transformationUtils.js";
|
|
12
13
|
import { executeAutoresearchTick } from "./autoresearchTaskExecutor.js";
|
|
13
14
|
/** Errors that are transient and should be retried */
|
|
14
15
|
const TRANSIENT_PATTERNS = [
|
|
@@ -134,11 +135,7 @@ export class TaskExecutor {
|
|
|
134
135
|
runId,
|
|
135
136
|
status: "success",
|
|
136
137
|
output: result.content,
|
|
137
|
-
toolCalls: result.toolExecutions
|
|
138
|
-
name: te.name,
|
|
139
|
-
input: te.input,
|
|
140
|
-
output: te.output,
|
|
141
|
-
})),
|
|
138
|
+
toolCalls: toolExecutionRecordsToToolCalls(result.toolExecutions),
|
|
142
139
|
tokensUsed: result.usage
|
|
143
140
|
? {
|
|
144
141
|
input: result.usage.input ?? 0,
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import type { z } from "zod";
|
|
8
8
|
import type { AIProviderName } from "../constants/enums.js";
|
|
9
9
|
import type { TokenUsage } from "./analytics.js";
|
|
10
|
+
import type { GenerateStopReason, ToolExecutionRecord } from "./generate.js";
|
|
10
11
|
/**
|
|
11
12
|
* Agent definition for creating agents in the network
|
|
12
13
|
*/
|
|
@@ -56,13 +57,16 @@ export type AgentResult = {
|
|
|
56
57
|
usage?: TokenUsage;
|
|
57
58
|
/** Tools used during execution */
|
|
58
59
|
toolsUsed?: string[];
|
|
59
|
-
/**
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Real per-call tool execution records from the underlying generate()
|
|
62
|
+
* turn (params, bounded result text, error flag, timing per call).
|
|
63
|
+
*/
|
|
64
|
+
toolExecutions?: ToolExecutionRecord[];
|
|
65
|
+
/**
|
|
66
|
+
* Why the agentic turn ended (`completed`, `step-cap`, `time-limit`,
|
|
67
|
+
* `stalled`, `aborted`, …) — see {@link GenerateStopReason}.
|
|
68
|
+
*/
|
|
69
|
+
stopReason?: GenerateStopReason;
|
|
66
70
|
/** Execution duration in milliseconds */
|
|
67
71
|
duration: number;
|
|
68
72
|
/** Execution status */
|
|
@@ -84,8 +88,19 @@ export type AgentExecutionOptions = {
|
|
|
84
88
|
traceId?: string;
|
|
85
89
|
/** Parent span ID for nested tracing */
|
|
86
90
|
parentSpanId?: string;
|
|
87
|
-
/**
|
|
91
|
+
/** Per-model-call timeout in milliseconds (see GenerateOptions.timeout) */
|
|
88
92
|
timeout?: number;
|
|
93
|
+
/**
|
|
94
|
+
* Abort signal threaded into every generate() the agent makes. An aborted
|
|
95
|
+
* parent stops the agent — no ghost runs.
|
|
96
|
+
*/
|
|
97
|
+
abortSignal?: AbortSignal;
|
|
98
|
+
/** Wall-clock cap for the whole agentic turn (ms). See GenerateOptions.turnTimeoutMs. */
|
|
99
|
+
turnTimeoutMs?: number;
|
|
100
|
+
/** Remaining-time threshold for the wrap-up nudge (ms). See GenerateOptions.wrapupTimeLeadMs. */
|
|
101
|
+
wrapupTimeLeadMs?: number;
|
|
102
|
+
/** Max time with no progress before the turn ends as "stalled" (ms). See GenerateOptions.stallTimeoutMs. */
|
|
103
|
+
stallTimeoutMs?: number;
|
|
89
104
|
/** Per-execution credentials override */
|
|
90
105
|
credentials?: Record<string, unknown>;
|
|
91
106
|
};
|
package/dist/types/generate.d.ts
CHANGED
|
@@ -363,6 +363,13 @@ export type GenerateOptions = {
|
|
|
363
363
|
toolTimeoutMs?: number;
|
|
364
364
|
/** AbortSignal for external cancellation of the AI call */
|
|
365
365
|
abortSignal?: AbortSignal;
|
|
366
|
+
/**
|
|
367
|
+
* Bounds for the per-call tool execution records surfaced on
|
|
368
|
+
* `GenerateResult.toolExecutions`. Capture is on by default
|
|
369
|
+
* (maxResultChars 8192, maxRecords 500); pass larger caps when the caller
|
|
370
|
+
* needs full result texts.
|
|
371
|
+
*/
|
|
372
|
+
toolExecutionCapture?: ToolExecutionCaptureOptions;
|
|
366
373
|
/** Disable the schema-driven tool call repair mechanism (BZ-665). Default: false (repair enabled). */
|
|
367
374
|
disableToolCallRepair?: boolean;
|
|
368
375
|
/**
|
|
@@ -677,6 +684,52 @@ export type AdditionalMemoryUser = {
|
|
|
677
684
|
/** Max words for this user's condensed memory. Overrides the default maxWords. */
|
|
678
685
|
maxWords?: number;
|
|
679
686
|
};
|
|
687
|
+
/**
|
|
688
|
+
* One real tool invocation captured during an agentic turn.
|
|
689
|
+
*
|
|
690
|
+
* Replaces the historical `{name, input, output}` stub on `GenerateResult`:
|
|
691
|
+
* every record is produced at the actual execution site (AI-SDK loop and the
|
|
692
|
+
* native Gemini/Anthropic loops alike), so `params`, timing, and error status
|
|
693
|
+
* reflect what really ran — consumers no longer need proxy "recorder" tools
|
|
694
|
+
* to observe their own tool traffic.
|
|
695
|
+
*/
|
|
696
|
+
export type ToolExecutionRecord = {
|
|
697
|
+
/** Tool name as the model called it. */
|
|
698
|
+
toolName: string;
|
|
699
|
+
/** Parameters the tool was invoked with, as parsed by the loop. */
|
|
700
|
+
params: unknown;
|
|
701
|
+
/**
|
|
702
|
+
* Serialized tool result (JSON when serializable, else String()), bounded
|
|
703
|
+
* by `toolExecutionCapture.maxResultChars` (default ~8KB). Truncated text
|
|
704
|
+
* ends with a `…[truncated N chars]` marker.
|
|
705
|
+
*/
|
|
706
|
+
resultText: string;
|
|
707
|
+
/** True when the execution threw or returned an error-shaped result. */
|
|
708
|
+
isError: boolean;
|
|
709
|
+
/** Epoch milliseconds when the execution started. */
|
|
710
|
+
startedAt: number;
|
|
711
|
+
/** Wall-clock duration of the execution in milliseconds. */
|
|
712
|
+
durationMs: number;
|
|
713
|
+
};
|
|
714
|
+
/**
|
|
715
|
+
* Bounds for per-call tool execution capture (see `ToolExecutionRecord`).
|
|
716
|
+
* Capture is ON by default with these caps; raise them when a caller needs
|
|
717
|
+
* full result texts (e.g. caller-side evidence verification).
|
|
718
|
+
*/
|
|
719
|
+
export type ToolExecutionCaptureOptions = {
|
|
720
|
+
/** Max serialized result characters kept per record (default 8192). */
|
|
721
|
+
maxResultChars?: number;
|
|
722
|
+
/** Max records kept per turn; oldest are dropped first (default 500). */
|
|
723
|
+
maxRecords?: number;
|
|
724
|
+
/**
|
|
725
|
+
* Fire-and-forget per-record callback, invoked as each tool execution
|
|
726
|
+
* completes. Listener errors — synchronous throws AND async rejections —
|
|
727
|
+
* are swallowed; they never break the turn. Used by supervisors (e.g. the
|
|
728
|
+
* isolated-agent runner's waste detection) and callers that stream
|
|
729
|
+
* evidence as it is gathered.
|
|
730
|
+
*/
|
|
731
|
+
onRecord?: (record: ToolExecutionRecord) => void | Promise<void>;
|
|
732
|
+
};
|
|
680
733
|
/**
|
|
681
734
|
* Why an agentic turn ended — the discriminator consumers should branch on
|
|
682
735
|
* instead of sniffing the provider-shaped `finishReason` (whose values are
|
|
@@ -832,11 +885,13 @@ export type GenerateResult = {
|
|
|
832
885
|
}>;
|
|
833
886
|
toolResults?: unknown[];
|
|
834
887
|
toolsUsed?: string[];
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
888
|
+
/**
|
|
889
|
+
* Real per-call tool execution records captured in the tool loop —
|
|
890
|
+
* params, bounded serialized result, error flag, and timing per call.
|
|
891
|
+
* Populated on the AI-SDK loop and the native agentic loops alike.
|
|
892
|
+
* Bounded by `toolExecutionCapture` (default on, ~8KB per result).
|
|
893
|
+
*/
|
|
894
|
+
toolExecutions?: ToolExecutionRecord[];
|
|
840
895
|
enhancedWithTools?: boolean;
|
|
841
896
|
availableTools?: Array<{
|
|
842
897
|
name: string;
|
|
@@ -1042,6 +1097,8 @@ export type TextGenerationOptions = {
|
|
|
1042
1097
|
toolTimeoutMs?: number;
|
|
1043
1098
|
/** AbortSignal for external cancellation of the AI call */
|
|
1044
1099
|
abortSignal?: AbortSignal;
|
|
1100
|
+
/** Bounds for tool execution capture. See GenerateOptions.toolExecutionCapture. */
|
|
1101
|
+
toolExecutionCapture?: ToolExecutionCaptureOptions;
|
|
1045
1102
|
disableTools?: boolean;
|
|
1046
1103
|
/** Disable the schema-driven tool call repair mechanism (BZ-665). Default: false (repair enabled). */
|
|
1047
1104
|
disableToolCallRepair?: boolean;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export * from "./generate.js";
|
|
|
28
28
|
export * from "./grounding.js";
|
|
29
29
|
export * from "./guardrails.js";
|
|
30
30
|
export * from "./hitl.js";
|
|
31
|
+
export * from "./isolatedAgent.js";
|
|
31
32
|
export * from "./knowledge.js";
|
|
32
33
|
export * from "./livekit.js";
|
|
33
34
|
export * from "./mcp.js";
|
package/dist/types/index.js
CHANGED
|
@@ -29,6 +29,7 @@ export * from "./generate.js";
|
|
|
29
29
|
export * from "./grounding.js";
|
|
30
30
|
export * from "./guardrails.js";
|
|
31
31
|
export * from "./hitl.js";
|
|
32
|
+
export * from "./isolatedAgent.js";
|
|
32
33
|
export * from "./knowledge.js";
|
|
33
34
|
export * from "./livekit.js";
|
|
34
35
|
export * from "./mcp.js";
|