@librechat/agents 3.6.8 → 3.6.10
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/cjs/agents/AgentContext.cjs +46 -39
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/agents/projection.cjs +2 -2
- package/dist/cjs/agents/projection.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +28 -18
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +87 -16
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +10 -0
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +14 -0
- package/dist/cjs/messages/alternation.cjs +125 -20
- package/dist/cjs/messages/alternation.cjs.map +1 -1
- package/dist/cjs/messages/core.cjs +195 -18
- package/dist/cjs/messages/core.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +488 -118
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/messages/handoffCue.cjs +3 -2
- package/dist/cjs/messages/handoffCue.cjs.map +1 -1
- package/dist/cjs/messages/index.cjs +1 -0
- package/dist/cjs/messages/injected.cjs +5 -2
- package/dist/cjs/messages/injected.cjs.map +1 -1
- package/dist/cjs/messages/provenance.cjs +411 -0
- package/dist/cjs/messages/provenance.cjs.map +1 -0
- package/dist/cjs/messages/prune.cjs +18 -13
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/cjs/messages/toolResultTypes.cjs +663 -0
- package/dist/cjs/messages/toolResultTypes.cjs.map +1 -0
- package/dist/cjs/run.cjs +7 -4
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +21 -4
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/CallerCapabilities.cjs +48 -0
- package/dist/cjs/tools/CallerCapabilities.cjs.map +1 -0
- package/dist/cjs/tools/ProgrammaticCallerPolicy.cjs +34 -0
- package/dist/cjs/tools/ProgrammaticCallerPolicy.cjs.map +1 -0
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +21 -4
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +25 -24
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareProgrammaticToolCalling.cjs +12 -4
- package/dist/cjs/tools/cloudflare/CloudflareProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +13 -4
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs +47 -11
- package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs.map +1 -1
- package/dist/cjs/tools/ptcTimeout.cjs.map +1 -1
- package/dist/cjs/tools/search/search.cjs +19 -9
- package/dist/cjs/tools/search/search.cjs.map +1 -1
- package/dist/cjs/tools/search/tool.cjs +2 -1
- package/dist/cjs/tools/search/tool.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/utils/toolContent.cjs +2 -2
- package/dist/cjs/utils/toolContent.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +46 -39
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/agents/projection.mjs +2 -2
- package/dist/esm/agents/projection.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +30 -20
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +87 -16
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +10 -0
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/main.mjs +4 -3
- package/dist/esm/messages/alternation.mjs +125 -20
- package/dist/esm/messages/alternation.mjs.map +1 -1
- package/dist/esm/messages/core.mjs +196 -19
- package/dist/esm/messages/core.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +488 -119
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/messages/handoffCue.mjs +3 -2
- package/dist/esm/messages/handoffCue.mjs.map +1 -1
- package/dist/esm/messages/index.mjs +1 -0
- package/dist/esm/messages/injected.mjs +5 -2
- package/dist/esm/messages/injected.mjs.map +1 -1
- package/dist/esm/messages/provenance.mjs +401 -0
- package/dist/esm/messages/provenance.mjs.map +1 -0
- package/dist/esm/messages/prune.mjs +18 -13
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/messages/toolResultTypes.mjs +657 -0
- package/dist/esm/messages/toolResultTypes.mjs.map +1 -0
- package/dist/esm/run.mjs +7 -4
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +21 -4
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/CallerCapabilities.mjs +45 -0
- package/dist/esm/tools/CallerCapabilities.mjs.map +1 -0
- package/dist/esm/tools/ProgrammaticCallerPolicy.mjs +32 -0
- package/dist/esm/tools/ProgrammaticCallerPolicy.mjs.map +1 -0
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +21 -4
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +25 -24
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareProgrammaticToolCalling.mjs +14 -6
- package/dist/esm/tools/cloudflare/CloudflareProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +15 -6
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/local/resolveLocalExecutionTools.mjs +47 -12
- package/dist/esm/tools/local/resolveLocalExecutionTools.mjs.map +1 -1
- package/dist/esm/tools/ptcTimeout.mjs.map +1 -1
- package/dist/esm/tools/search/search.mjs +19 -9
- package/dist/esm/tools/search/search.mjs.map +1 -1
- package/dist/esm/tools/search/tool.mjs +2 -1
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/utils/toolContent.mjs +2 -2
- package/dist/esm/utils/toolContent.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +8 -13
- package/dist/types/agents/projection.d.ts +3 -1
- package/dist/types/graphs/Graph.d.ts +1 -1
- package/dist/types/llm/openai/index.d.ts +20 -0
- package/dist/types/messages/format.d.ts +5 -0
- package/dist/types/messages/index.d.ts +1 -0
- package/dist/types/messages/provenance.d.ts +85 -0
- package/dist/types/messages/toolResultTypes.d.ts +33 -0
- package/dist/types/tools/CallerCapabilities.d.ts +12 -0
- package/dist/types/tools/ProgrammaticCallerPolicy.d.ts +20 -0
- package/dist/types/tools/ToolNode.d.ts +4 -7
- package/dist/types/tools/local/resolveLocalExecutionTools.d.ts +4 -0
- package/dist/types/tools/ptcTimeout.d.ts +8 -0
- package/dist/types/tools/search/types.d.ts +15 -0
- package/dist/types/types/graph.d.ts +3 -1
- package/dist/types/types/tools.d.ts +13 -2
- package/package.json +1 -1
- package/src/agents/AgentContext.ts +109 -67
- package/src/agents/projection.ts +9 -1
- package/src/graphs/Graph.ts +56 -23
- package/src/graphs/MultiAgentGraph.ts +175 -33
- package/src/llm/openai/index.ts +43 -0
- package/src/messages/alternation.ts +217 -34
- package/src/messages/core.ts +358 -38
- package/src/messages/format.ts +958 -137
- package/src/messages/handoffCue.ts +7 -4
- package/src/messages/index.ts +1 -0
- package/src/messages/injected.ts +9 -6
- package/src/messages/provenance.ts +897 -0
- package/src/messages/prune.ts +28 -10
- package/src/messages/toolResultTypes.ts +1174 -0
- package/src/run.ts +9 -4
- package/src/tools/BashProgrammaticToolCalling.ts +46 -12
- package/src/tools/CallerCapabilities.ts +78 -0
- package/src/tools/ProgrammaticCallerPolicy.ts +97 -0
- package/src/tools/ProgrammaticToolCalling.ts +41 -7
- package/src/tools/ToolNode.ts +70 -52
- package/src/tools/cloudflare/CloudflareProgrammaticToolCalling.ts +24 -26
- package/src/tools/local/LocalProgrammaticToolCalling.ts +28 -23
- package/src/tools/local/resolveLocalExecutionTools.ts +132 -13
- package/src/tools/ptcTimeout.ts +6 -0
- package/src/tools/search/search.ts +25 -8
- package/src/tools/search/tool.ts +2 -0
- package/src/tools/search/types.ts +16 -0
- package/src/tools/subagent/SubagentExecutor.ts +8 -4
- package/src/types/graph.ts +3 -0
- package/src/types/tools.ts +14 -3
- package/src/utils/toolContent.ts +2 -2
|
@@ -32,6 +32,16 @@ import {
|
|
|
32
32
|
Constants,
|
|
33
33
|
Providers,
|
|
34
34
|
} from '@/common';
|
|
35
|
+
import {
|
|
36
|
+
isProgrammaticRunnerAutoBound,
|
|
37
|
+
resolveLocalToolRegistry,
|
|
38
|
+
} from '@/tools/local/resolveLocalExecutionTools';
|
|
39
|
+
import {
|
|
40
|
+
allowsToolCaller,
|
|
41
|
+
isToolDefinitionActive,
|
|
42
|
+
isProgrammaticControlTool,
|
|
43
|
+
resolveCallerCapabilityProjection,
|
|
44
|
+
} from '@/tools/CallerCapabilities';
|
|
35
45
|
import { createSchemaOnlyTools } from '@/tools/schema';
|
|
36
46
|
import { apportionTokenCounts } from '@/utils/tokens';
|
|
37
47
|
import { isThinkingEnabled } from '@/llm/request';
|
|
@@ -59,7 +69,8 @@ export class AgentContext {
|
|
|
59
69
|
static fromConfig(
|
|
60
70
|
agentConfig: t.AgentInputs,
|
|
61
71
|
tokenCounter?: t.TokenCounter,
|
|
62
|
-
indexTokenCountMap?: Record<string, number
|
|
72
|
+
indexTokenCountMap?: Record<string, number>,
|
|
73
|
+
toolExecution?: t.ToolExecutionConfig
|
|
63
74
|
): AgentContext {
|
|
64
75
|
const {
|
|
65
76
|
agentId,
|
|
@@ -103,6 +114,7 @@ export class AgentContext {
|
|
|
103
114
|
tools,
|
|
104
115
|
toolMap,
|
|
105
116
|
toolRegistry,
|
|
117
|
+
toolExecution,
|
|
106
118
|
toolDefinitions,
|
|
107
119
|
instructions,
|
|
108
120
|
additionalInstructions: additional_instructions,
|
|
@@ -269,6 +281,8 @@ export class AgentContext {
|
|
|
269
281
|
* Used for tool search and programmatic tool calling.
|
|
270
282
|
*/
|
|
271
283
|
toolRegistry?: t.LCToolRegistry;
|
|
284
|
+
/** Run-scoped backend used to identify auto-bound programmatic runners. */
|
|
285
|
+
private toolExecution?: t.ToolExecutionConfig;
|
|
272
286
|
/**
|
|
273
287
|
* Serializable tool definitions for event-driven execution.
|
|
274
288
|
* When provided, ToolNode operates in event-driven mode.
|
|
@@ -385,6 +399,7 @@ export class AgentContext {
|
|
|
385
399
|
tools,
|
|
386
400
|
toolMap,
|
|
387
401
|
toolRegistry,
|
|
402
|
+
toolExecution,
|
|
388
403
|
toolDefinitions,
|
|
389
404
|
instructions,
|
|
390
405
|
additionalInstructions,
|
|
@@ -410,6 +425,7 @@ export class AgentContext {
|
|
|
410
425
|
tools?: t.GraphTools;
|
|
411
426
|
toolMap?: t.ToolMap;
|
|
412
427
|
toolRegistry?: t.LCToolRegistry;
|
|
428
|
+
toolExecution?: t.ToolExecutionConfig;
|
|
413
429
|
toolDefinitions?: t.LCTool[];
|
|
414
430
|
instructions?: string;
|
|
415
431
|
additionalInstructions?: string;
|
|
@@ -434,7 +450,11 @@ export class AgentContext {
|
|
|
434
450
|
this.tokenCounter = tokenCounter;
|
|
435
451
|
this.tools = tools;
|
|
436
452
|
this.toolMap = toolMap;
|
|
437
|
-
this.toolRegistry =
|
|
453
|
+
this.toolRegistry = resolveLocalToolRegistry({
|
|
454
|
+
toolRegistry,
|
|
455
|
+
toolExecution,
|
|
456
|
+
});
|
|
457
|
+
this.toolExecution = toolExecution;
|
|
438
458
|
this.toolDefinitions = toolDefinitions;
|
|
439
459
|
this.instructions = instructions;
|
|
440
460
|
this.additionalInstructions = additionalInstructions;
|
|
@@ -461,37 +481,46 @@ export class AgentContext {
|
|
|
461
481
|
}
|
|
462
482
|
}
|
|
463
483
|
|
|
464
|
-
/**
|
|
465
|
-
* Builds instructions text for tools that are ONLY callable via programmatic code execution.
|
|
466
|
-
* These tools cannot be called directly by the LLM but are available through the
|
|
467
|
-
* configured programmatic tool.
|
|
468
|
-
*
|
|
469
|
-
* Includes:
|
|
470
|
-
* - Code_execution-only tools that are NOT deferred
|
|
471
|
-
* - Code_execution-only tools that ARE deferred but have been discovered via tool search
|
|
472
|
-
*/
|
|
484
|
+
/** Builds the caller boundary and schemas for programmatic-only tools. */
|
|
473
485
|
private buildProgrammaticOnlyToolsInstructions(): string {
|
|
474
486
|
if (!this.toolRegistry) return '';
|
|
475
487
|
|
|
476
|
-
const
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
488
|
+
const capabilities = resolveCallerCapabilityProjection(
|
|
489
|
+
this.toolRegistry.values(),
|
|
490
|
+
(toolDef) => isToolDefinitionActive(toolDef, this.discoveredToolNames)
|
|
491
|
+
);
|
|
492
|
+
const programmaticOnlyTools = capabilities.codeExecutionOnlyTools;
|
|
493
|
+
const programmaticToolNames = capabilities.codeExecutionTools.map(
|
|
494
|
+
(toolDef) => toolDef.name
|
|
495
|
+
);
|
|
496
|
+
const directOnlyToolNames = capabilities.directOnlyTools
|
|
497
|
+
.map((toolDef) => toolDef.name)
|
|
498
|
+
.filter((name) => !isProgrammaticControlTool(name));
|
|
499
|
+
|
|
500
|
+
const programmaticTools = this.getProgrammaticToolInstructionTargets();
|
|
501
|
+
if (programmaticTools.length === 0) return '';
|
|
502
|
+
const programmaticRunnerNames = programmaticTools
|
|
503
|
+
.map((tool) => `\`${tool.name}\``)
|
|
504
|
+
.join(' or ');
|
|
505
|
+
const quotedProgrammaticNames =
|
|
506
|
+
programmaticToolNames.length > 0
|
|
507
|
+
? programmaticToolNames.map((name) => `\`${name}\``).join(', ')
|
|
508
|
+
: 'none';
|
|
509
|
+
const directOnlyBoundary =
|
|
510
|
+
directOnlyToolNames.length > 0
|
|
511
|
+
? `\nCall these tools directly; never list them in the \`tool_manifest\` or reference them inside ${programmaticRunnerNames}: ${directOnlyToolNames
|
|
512
|
+
.map((name) => `\`${name}\``)
|
|
513
|
+
.join(', ')}. Every ${programmaticRunnerNames} call must include a \`tool_manifest\` containing the exact registered names used by its code; the manifest is validated before execution starts.`
|
|
514
|
+
: '';
|
|
515
|
+
const boundary =
|
|
516
|
+
'\n\n## Programmatic Tool Calling\n\n' +
|
|
517
|
+
`Only these tools may be invoked inside ${programmaticRunnerNames}: ${quotedProgrammaticNames}.` +
|
|
518
|
+
directOnlyBoundary;
|
|
519
|
+
|
|
520
|
+
if (programmaticOnlyTools.length === 0) {
|
|
521
|
+
return boundary;
|
|
490
522
|
}
|
|
491
523
|
|
|
492
|
-
if (programmaticOnlyTools.length === 0) return '';
|
|
493
|
-
|
|
494
|
-
const programmaticTool = this.getProgrammaticToolInstructionTarget();
|
|
495
524
|
const toolDescriptions = programmaticOnlyTools
|
|
496
525
|
.map((tool) => {
|
|
497
526
|
let desc = `- **${tool.name}**`;
|
|
@@ -506,41 +535,64 @@ export class AgentContext {
|
|
|
506
535
|
.join('\n\n');
|
|
507
536
|
|
|
508
537
|
return (
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
`
|
|
538
|
+
boundary +
|
|
539
|
+
'\n\n### Programmatic-Only Tools\n\n' +
|
|
540
|
+
`The following tools are available exclusively through ${programmaticRunnerNames}. ` +
|
|
541
|
+
`You cannot call these tools directly; instead, ${programmaticTools
|
|
542
|
+
.map(
|
|
543
|
+
(tool) =>
|
|
544
|
+
`use \`${tool.name}\` with ${tool.codeGuidance} that invokes them`
|
|
545
|
+
)
|
|
546
|
+
.join(', or ')}.\n\n` +
|
|
512
547
|
toolDescriptions
|
|
513
548
|
);
|
|
514
549
|
}
|
|
515
550
|
|
|
516
|
-
private
|
|
551
|
+
private getProgrammaticToolInstructionTargets(): Array<{
|
|
517
552
|
name: string;
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
553
|
+
codeGuidance: string;
|
|
554
|
+
}> {
|
|
555
|
+
const targets: Array<{ name: string; codeGuidance: string }> = [];
|
|
556
|
+
if (
|
|
557
|
+
this.hasBoundTool(Constants.BASH_PROGRAMMATIC_TOOL_CALLING) ||
|
|
558
|
+
isProgrammaticRunnerAutoBound(
|
|
559
|
+
Constants.BASH_PROGRAMMATIC_TOOL_CALLING,
|
|
560
|
+
this.toolExecution
|
|
561
|
+
)
|
|
562
|
+
) {
|
|
563
|
+
targets.push({
|
|
522
564
|
name: Constants.BASH_PROGRAMMATIC_TOOL_CALLING,
|
|
523
|
-
|
|
524
|
-
};
|
|
565
|
+
codeGuidance: 'Bash code',
|
|
566
|
+
});
|
|
525
567
|
}
|
|
526
568
|
|
|
527
|
-
if (
|
|
528
|
-
|
|
569
|
+
if (
|
|
570
|
+
this.hasBoundTool(Constants.PROGRAMMATIC_TOOL_CALLING) ||
|
|
571
|
+
isProgrammaticRunnerAutoBound(
|
|
572
|
+
Constants.PROGRAMMATIC_TOOL_CALLING,
|
|
573
|
+
this.toolExecution
|
|
574
|
+
)
|
|
575
|
+
) {
|
|
576
|
+
const localDefault =
|
|
577
|
+
this.toolExecution?.engine === 'local' ||
|
|
578
|
+
this.toolExecution?.engine === 'cloudflare-sandbox';
|
|
579
|
+
targets.push({
|
|
580
|
+
name: Constants.PROGRAMMATIC_TOOL_CALLING,
|
|
581
|
+
codeGuidance: localDefault
|
|
582
|
+
? 'Bash code by default, or set `lang: "py"` to use Python code'
|
|
583
|
+
: 'Python code',
|
|
584
|
+
});
|
|
529
585
|
}
|
|
530
586
|
|
|
531
|
-
return
|
|
587
|
+
return targets;
|
|
532
588
|
}
|
|
533
589
|
|
|
534
|
-
private
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
)
|
|
540
|
-
return true;
|
|
541
|
-
}
|
|
542
|
-
if (this.toolMap?.has(name) === true) return true;
|
|
543
|
-
return this.toolRegistry?.has(name) === true;
|
|
590
|
+
private hasBoundTool(name: string): boolean {
|
|
591
|
+
return (
|
|
592
|
+
this.getToolsForBinding()?.some(
|
|
593
|
+
(tool) => 'name' in tool && tool.name === name
|
|
594
|
+
) === true
|
|
595
|
+
);
|
|
544
596
|
}
|
|
545
597
|
|
|
546
598
|
/**
|
|
@@ -1083,15 +1135,10 @@ export class AgentContext {
|
|
|
1083
1135
|
* alone left programmatic-only definitions counted in
|
|
1084
1136
|
* `toolSchemaTokens` even though they were never bound.
|
|
1085
1137
|
*/
|
|
1086
|
-
return
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
}
|
|
1091
|
-
return (
|
|
1092
|
-
def.defer_loading !== true || this.discoveredToolNames.has(def.name)
|
|
1093
|
-
);
|
|
1094
|
-
});
|
|
1138
|
+
return resolveCallerCapabilityProjection(
|
|
1139
|
+
this.toolDefinitions,
|
|
1140
|
+
(toolDef) => isToolDefinitionActive(toolDef, this.discoveredToolNames)
|
|
1141
|
+
).directTools;
|
|
1095
1142
|
}
|
|
1096
1143
|
|
|
1097
1144
|
/**
|
|
@@ -1807,14 +1854,9 @@ export class AgentContext {
|
|
|
1807
1854
|
return true;
|
|
1808
1855
|
}
|
|
1809
1856
|
|
|
1810
|
-
if (this.discoveredToolNames.has(tool.name)) {
|
|
1811
|
-
const allowedCallers = toolDef.allowed_callers ?? ['direct'];
|
|
1812
|
-
return allowedCallers.includes('direct');
|
|
1813
|
-
}
|
|
1814
|
-
|
|
1815
|
-
const allowedCallers = toolDef.allowed_callers ?? ['direct'];
|
|
1816
1857
|
return (
|
|
1817
|
-
|
|
1858
|
+
allowsToolCaller(toolDef, 'direct') &&
|
|
1859
|
+
isToolDefinitionActive(toolDef, this.discoveredToolNames)
|
|
1818
1860
|
);
|
|
1819
1861
|
});
|
|
1820
1862
|
}
|
package/src/agents/projection.ts
CHANGED
|
@@ -13,6 +13,8 @@ export interface ProjectAgentContextUsageParams {
|
|
|
13
13
|
indexTokenCountMap?: Record<string, number>;
|
|
14
14
|
/** Provider-calibrated ratio from a prior snapshot, applied as a static seed. */
|
|
15
15
|
calibrationRatio?: number;
|
|
16
|
+
/** Execution backend used to synthesize the live effective tool registry. */
|
|
17
|
+
toolExecution?: t.ToolExecutionConfig;
|
|
16
18
|
runId?: string;
|
|
17
19
|
agentId?: string;
|
|
18
20
|
}
|
|
@@ -32,10 +34,16 @@ export async function projectAgentContextUsage({
|
|
|
32
34
|
tokenCounter,
|
|
33
35
|
indexTokenCountMap,
|
|
34
36
|
calibrationRatio,
|
|
37
|
+
toolExecution,
|
|
35
38
|
runId,
|
|
36
39
|
agentId,
|
|
37
40
|
}: ProjectAgentContextUsageParams): Promise<t.ContextUsageEvent | null> {
|
|
38
|
-
const context = AgentContext.fromConfig(
|
|
41
|
+
const context = AgentContext.fromConfig(
|
|
42
|
+
agent,
|
|
43
|
+
tokenCounter,
|
|
44
|
+
indexTokenCountMap,
|
|
45
|
+
toolExecution
|
|
46
|
+
);
|
|
39
47
|
await context.tokenCalculationPromise;
|
|
40
48
|
return context.projectContextUsage(messages, {
|
|
41
49
|
runId,
|
package/src/graphs/Graph.ts
CHANGED
|
@@ -34,6 +34,7 @@ import type {
|
|
|
34
34
|
import type {
|
|
35
35
|
GraphFactory,
|
|
36
36
|
GraphFactoryDependencies,
|
|
37
|
+
GraphFactoryRequest,
|
|
37
38
|
} from '@/graphs/graphFactory';
|
|
38
39
|
import type { OverflowRecoveryPlan } from '@/llm/contextOverflowRecovery';
|
|
39
40
|
import type { FallbackErrorContext } from '@/llm/invoke';
|
|
@@ -61,6 +62,7 @@ import {
|
|
|
61
62
|
resolveBedrockPromptCacheTtl,
|
|
62
63
|
supportsBedrockToolCache,
|
|
63
64
|
isSyntheticProviderContextMessage,
|
|
65
|
+
compactSyntheticProviderContextMessage,
|
|
64
66
|
getMessageId,
|
|
65
67
|
getMessageCreationContentMetadata,
|
|
66
68
|
splitAssistantTextContentByPhase,
|
|
@@ -73,6 +75,7 @@ import {
|
|
|
73
75
|
strictAlternationProviders,
|
|
74
76
|
appendPredecessorHandoffCue,
|
|
75
77
|
removePredecessorHandoffCue,
|
|
78
|
+
stampSyntheticProviderMessage,
|
|
76
79
|
} from '@/messages';
|
|
77
80
|
import {
|
|
78
81
|
Constants,
|
|
@@ -133,11 +136,6 @@ import {
|
|
|
133
136
|
resolveLangfuseConfig,
|
|
134
137
|
resolveToolOutputTracingConfig,
|
|
135
138
|
} from '@/langfuseConfig';
|
|
136
|
-
import {
|
|
137
|
-
compactToolContent,
|
|
138
|
-
getToolContentCharLength,
|
|
139
|
-
serializeToolContentBounded,
|
|
140
|
-
} from '@/utils/toolContent';
|
|
141
139
|
import {
|
|
142
140
|
annotateMessagesForLLM,
|
|
143
141
|
ToolOutputReferenceRegistry,
|
|
@@ -146,6 +144,10 @@ import {
|
|
|
146
144
|
resolveLangfuseRuntimeScope,
|
|
147
145
|
withLangfuseRuntimeScope,
|
|
148
146
|
} from '@/langfuseRuntimeScope';
|
|
147
|
+
import {
|
|
148
|
+
getToolContentCharLength,
|
|
149
|
+
serializeToolContentBounded,
|
|
150
|
+
} from '@/utils/toolContent';
|
|
149
151
|
import {
|
|
150
152
|
appendCallbacks,
|
|
151
153
|
findCallback,
|
|
@@ -412,7 +414,9 @@ function getCurrentStepIds({
|
|
|
412
414
|
if (stepKey !== baseStepKey && !stepKey.startsWith(`${baseStepKey}_`)) {
|
|
413
415
|
continue;
|
|
414
416
|
}
|
|
415
|
-
|
|
417
|
+
for (const stepId of stepIds) {
|
|
418
|
+
currentStepIds.push(stepId);
|
|
419
|
+
}
|
|
416
420
|
}
|
|
417
421
|
return currentStepIds;
|
|
418
422
|
}
|
|
@@ -1457,6 +1461,7 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
1457
1461
|
subagentExecutionContext,
|
|
1458
1462
|
preemption,
|
|
1459
1463
|
streamLimits,
|
|
1464
|
+
toolExecution,
|
|
1460
1465
|
}: t.StandardGraphInput,
|
|
1461
1466
|
dependencies?: GraphFactoryDependencies
|
|
1462
1467
|
) {
|
|
@@ -1482,6 +1487,7 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
1482
1487
|
this.subagentExecutionContext = subagentExecutionContext;
|
|
1483
1488
|
this.preemption = preemption;
|
|
1484
1489
|
this.streamLimits = resolveStreamLimits(streamLimits);
|
|
1490
|
+
this.toolExecution = toolExecution;
|
|
1485
1491
|
|
|
1486
1492
|
if (agents.length === 0) {
|
|
1487
1493
|
throw new Error('At least one agent configuration is required');
|
|
@@ -1491,7 +1497,8 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
1491
1497
|
const agentContext = AgentContext.fromConfig(
|
|
1492
1498
|
agentConfig,
|
|
1493
1499
|
tokenCounter,
|
|
1494
|
-
indexTokenCountMap
|
|
1500
|
+
indexTokenCountMap,
|
|
1501
|
+
toolExecution
|
|
1495
1502
|
);
|
|
1496
1503
|
if (calibrationRatio != null && calibrationRatio > 0) {
|
|
1497
1504
|
agentContext.calibrationRatio = calibrationRatio;
|
|
@@ -2557,6 +2564,8 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
2557
2564
|
executingAgentId: agentContext?.agentId,
|
|
2558
2565
|
toolCallStepIds: this.toolCallStepIds,
|
|
2559
2566
|
toolRegistry: agentContext?.toolRegistry,
|
|
2567
|
+
getDiscoveredToolNames: (): readonly string[] =>
|
|
2568
|
+
agentContext?.getDiscoveredTools() ?? [],
|
|
2560
2569
|
hookRegistry: this.hookRegistry,
|
|
2561
2570
|
humanInTheLoop: this.humanInTheLoop,
|
|
2562
2571
|
eagerEventToolExecution: this.eagerEventToolExecution,
|
|
@@ -2634,6 +2643,8 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
2634
2643
|
errorHandler: (data, metadata): Promise<boolean> =>
|
|
2635
2644
|
StandardGraph.handleToolCallErrorStatic(this, data, metadata),
|
|
2636
2645
|
toolRegistry: agentContext?.toolRegistry,
|
|
2646
|
+
getDiscoveredToolNames: (): readonly string[] =>
|
|
2647
|
+
agentContext?.getDiscoveredTools() ?? [],
|
|
2637
2648
|
sessions: this.sessions,
|
|
2638
2649
|
codeSessionKey: agentContext?.codeSessionKey,
|
|
2639
2650
|
toolExecution: this.toolExecution,
|
|
@@ -2839,6 +2850,8 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
2839
2850
|
const rawToolsForBinding = resolveLocalToolsForBinding({
|
|
2840
2851
|
tools: agentContext.getToolsForBinding(),
|
|
2841
2852
|
toolExecution: this.toolExecution,
|
|
2853
|
+
toolRegistry: agentContext.toolRegistry,
|
|
2854
|
+
discoveredToolNames: new Set(agentContext.getDiscoveredTools()),
|
|
2842
2855
|
});
|
|
2843
2856
|
|
|
2844
2857
|
/**
|
|
@@ -3553,17 +3566,10 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
3553
3566
|
const buildCandidate = (scale: number): BaseMessage[] => {
|
|
3554
3567
|
const compacted = [...candidate];
|
|
3555
3568
|
for (const { index, message, chars } of synthetic) {
|
|
3556
|
-
|
|
3557
|
-
message
|
|
3569
|
+
compacted[index] = compactSyntheticProviderContextMessage(
|
|
3570
|
+
message,
|
|
3558
3571
|
Math.floor(chars * scale)
|
|
3559
|
-
)
|
|
3560
|
-
compacted[index] = new HumanMessage({
|
|
3561
|
-
content,
|
|
3562
|
-
id: message.id,
|
|
3563
|
-
name: message.name,
|
|
3564
|
-
additional_kwargs: message.additional_kwargs,
|
|
3565
|
-
response_metadata: message.response_metadata,
|
|
3566
|
-
});
|
|
3572
|
+
);
|
|
3567
3573
|
}
|
|
3568
3574
|
return compacted;
|
|
3569
3575
|
};
|
|
@@ -4725,15 +4731,26 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
4725
4731
|
);
|
|
4726
4732
|
if (contexts.length > 0) {
|
|
4727
4733
|
injected.push(
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4734
|
+
stampSyntheticProviderMessage(
|
|
4735
|
+
new HumanMessage({
|
|
4736
|
+
content: contexts.join('\n\n'),
|
|
4737
|
+
additional_kwargs: {
|
|
4738
|
+
role: 'system',
|
|
4739
|
+
isMeta: true,
|
|
4740
|
+
source: 'hook',
|
|
4741
|
+
},
|
|
4742
|
+
})
|
|
4743
|
+
)
|
|
4732
4744
|
);
|
|
4733
4745
|
}
|
|
4734
4746
|
if (result.injectedMessages.length > 0) {
|
|
4735
4747
|
try {
|
|
4736
|
-
|
|
4748
|
+
const convertedMessages = convertInjectedMessages(
|
|
4749
|
+
result.injectedMessages
|
|
4750
|
+
);
|
|
4751
|
+
for (const convertedMessage of convertedMessages) {
|
|
4752
|
+
injected.push(convertedMessage);
|
|
4753
|
+
}
|
|
4737
4754
|
} catch (e) {
|
|
4738
4755
|
console.warn(
|
|
4739
4756
|
'[StandardGraph] Failed to convert PreemptBoundary injectedMessages:',
|
|
@@ -4805,7 +4822,23 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
4805
4822
|
};
|
|
4806
4823
|
const checkpointer = this.compileOptions?.checkpointer;
|
|
4807
4824
|
return (request): StandardGraph => {
|
|
4808
|
-
const
|
|
4825
|
+
const configuredRequest: GraphFactoryRequest =
|
|
4826
|
+
request.kind === 'multi-agent'
|
|
4827
|
+
? {
|
|
4828
|
+
kind: 'multi-agent',
|
|
4829
|
+
input: {
|
|
4830
|
+
...request.input,
|
|
4831
|
+
toolExecution: runtimeConfig.toolExecution,
|
|
4832
|
+
},
|
|
4833
|
+
}
|
|
4834
|
+
: {
|
|
4835
|
+
kind: 'standard',
|
|
4836
|
+
input: {
|
|
4837
|
+
...request.input,
|
|
4838
|
+
toolExecution: runtimeConfig.toolExecution,
|
|
4839
|
+
},
|
|
4840
|
+
};
|
|
4841
|
+
const childGraph = graphFactory(configuredRequest);
|
|
4809
4842
|
if (subagentModelOverride != null) {
|
|
4810
4843
|
childGraph.overrideModel = subagentModelOverride;
|
|
4811
4844
|
childGraph.setSubagentModelOverride(subagentModelOverride);
|