@librechat/agents 3.4.7 → 3.5.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/dist/cjs/agents/AgentContext.cjs +0 -356
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/agents/projection.cjs +0 -9
- package/dist/cjs/agents/projection.cjs.map +1 -1
- package/dist/cjs/common/constants.cjs +0 -26
- package/dist/cjs/common/constants.cjs.map +1 -1
- package/dist/cjs/common/enum.cjs +0 -85
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/events.cjs +0 -14
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +1 -909
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +7 -272
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/graphs/applyGraphRuntimeConfig.cjs.map +1 -1
- package/dist/cjs/graphs/createGraph.cjs.map +1 -1
- package/dist/cjs/hitl/askUserQuestion.cjs +0 -53
- package/dist/cjs/hitl/askUserQuestion.cjs.map +1 -1
- package/dist/cjs/hitl/askUserQuestions.cjs +0 -20
- package/dist/cjs/hitl/askUserQuestions.cjs.map +1 -1
- package/dist/cjs/hitl/askUserQuestionsInterrupt.cjs +0 -6
- package/dist/cjs/hitl/askUserQuestionsInterrupt.cjs.map +1 -1
- package/dist/cjs/hooks/HookRegistry.cjs +0 -127
- package/dist/cjs/hooks/HookRegistry.cjs.map +1 -1
- package/dist/cjs/hooks/createToolPolicyHook.cjs +0 -38
- package/dist/cjs/hooks/createToolPolicyHook.cjs.map +1 -1
- package/dist/cjs/hooks/createWorkspacePolicyHook.cjs +0 -77
- package/dist/cjs/hooks/createWorkspacePolicyHook.cjs.map +1 -1
- package/dist/cjs/hooks/executeHooks.cjs +0 -79
- package/dist/cjs/hooks/executeHooks.cjs.map +1 -1
- package/dist/cjs/hooks/index.cjs +0 -16
- package/dist/cjs/hooks/index.cjs.map +1 -1
- package/dist/cjs/hooks/matchers.cjs +0 -104
- package/dist/cjs/hooks/matchers.cjs.map +1 -1
- package/dist/cjs/hooks/types.cjs +0 -8
- package/dist/cjs/hooks/types.cjs.map +1 -1
- package/dist/cjs/instrumentation.cjs +0 -14
- package/dist/cjs/instrumentation.cjs.map +1 -1
- package/dist/cjs/langfuse.cjs +0 -75
- package/dist/cjs/langfuse.cjs.map +1 -1
- package/dist/cjs/langfuseConfig.cjs.map +1 -1
- package/dist/cjs/langfuseRuntimeContext.cjs +0 -13
- package/dist/cjs/langfuseRuntimeContext.cjs.map +1 -1
- package/dist/cjs/langfuseRuntimeScope.cjs +0 -4
- package/dist/cjs/langfuseRuntimeScope.cjs.map +1 -1
- package/dist/cjs/langfuseSpanRegistry.cjs +0 -28
- package/dist/cjs/langfuseSpanRegistry.cjs.map +1 -1
- package/dist/cjs/langfuseToolOutputTracing.cjs +0 -3
- package/dist/cjs/langfuseToolOutputTracing.cjs.map +1 -1
- package/dist/cjs/langfuseTraceShaping.cjs +0 -74
- package/dist/cjs/langfuseTraceShaping.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/index.cjs +0 -3
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/types.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +1 -111
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +0 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/stream_events.cjs +0 -8
- package/dist/cjs/llm/anthropic/utils/stream_events.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/tools.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/cachePoints.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +1 -95
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/toolCache.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +0 -78
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/message_outputs.cjs +0 -24
- package/dist/cjs/llm/bedrock/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/contextOverflowRecovery.cjs +0 -62
- package/dist/cjs/llm/contextOverflowRecovery.cjs.map +1 -1
- package/dist/cjs/llm/fake.cjs.map +1 -1
- package/dist/cjs/llm/google/index.cjs +2 -21
- package/dist/cjs/llm/google/index.cjs.map +1 -1
- package/dist/cjs/llm/google/utils/common.cjs +0 -35
- package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
- package/dist/cjs/llm/init.cjs +0 -9
- package/dist/cjs/llm/init.cjs.map +1 -1
- package/dist/cjs/llm/invoke.cjs +1 -270
- package/dist/cjs/llm/invoke.cjs.map +1 -1
- package/dist/cjs/llm/mistral/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +0 -99
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/streamMetadata.cjs +0 -21
- package/dist/cjs/llm/openai/streamMetadata.cjs.map +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
- package/dist/cjs/llm/openrouter/index.cjs +0 -1
- package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
- package/dist/cjs/llm/openrouter/toolCache.cjs +0 -6
- package/dist/cjs/llm/openrouter/toolCache.cjs.map +1 -1
- package/dist/cjs/llm/preempt.cjs +0 -75
- package/dist/cjs/llm/preempt.cjs.map +1 -1
- package/dist/cjs/llm/providers.cjs.map +1 -1
- package/dist/cjs/llm/request.cjs +0 -10
- package/dist/cjs/llm/request.cjs.map +1 -1
- package/dist/cjs/llm/stream/chunkAdapters.cjs +0 -62
- package/dist/cjs/llm/stream/chunkAdapters.cjs.map +1 -1
- package/dist/cjs/llm/stream/smoother.cjs +0 -58
- package/dist/cjs/llm/stream/smoother.cjs.map +1 -1
- package/dist/cjs/llm/streamLimits.cjs +4 -293
- package/dist/cjs/llm/streamLimits.cjs.map +1 -1
- package/dist/cjs/llm/truncation.cjs +0 -36
- package/dist/cjs/llm/truncation.cjs.map +1 -1
- package/dist/cjs/llm/vertexai/index.cjs +0 -330
- package/dist/cjs/llm/vertexai/index.cjs.map +1 -1
- package/dist/cjs/messages/alternation.cjs +0 -43
- package/dist/cjs/messages/alternation.cjs.map +1 -1
- package/dist/cjs/messages/anthropicToolCache.cjs +0 -45
- package/dist/cjs/messages/anthropicToolCache.cjs.map +1 -1
- package/dist/cjs/messages/assistantPhase.cjs +0 -12
- package/dist/cjs/messages/assistantPhase.cjs.map +1 -1
- package/dist/cjs/messages/budget.cjs +0 -9
- package/dist/cjs/messages/budget.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +0 -172
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/content.cjs +0 -9
- package/dist/cjs/messages/content.cjs.map +1 -1
- package/dist/cjs/messages/contextPruning.cjs +0 -15
- package/dist/cjs/messages/contextPruning.cjs.map +1 -1
- package/dist/cjs/messages/contextPruningSettings.cjs +0 -3
- package/dist/cjs/messages/contextPruningSettings.cjs.map +1 -1
- package/dist/cjs/messages/core.cjs +0 -48
- package/dist/cjs/messages/core.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +1 -345
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/messages/handoffCue.cjs +0 -36
- package/dist/cjs/messages/handoffCue.cjs.map +1 -1
- package/dist/cjs/messages/ids.cjs.map +1 -1
- package/dist/cjs/messages/injected.cjs +0 -33
- package/dist/cjs/messages/injected.cjs.map +1 -1
- package/dist/cjs/messages/langchain.cjs +0 -14
- package/dist/cjs/messages/langchain.cjs.map +1 -1
- package/dist/cjs/messages/prune.cjs +1 -184
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/cjs/messages/recency.cjs +0 -32
- package/dist/cjs/messages/recency.cjs.map +1 -1
- package/dist/cjs/messages/reducer.cjs +0 -30
- package/dist/cjs/messages/reducer.cjs.map +1 -1
- package/dist/cjs/messages/tools.cjs +0 -14
- package/dist/cjs/messages/tools.cjs.map +1 -1
- package/dist/cjs/openai/index.cjs.map +1 -1
- package/dist/cjs/prompts/activityLabel.cjs +9 -79
- package/dist/cjs/prompts/activityLabel.cjs.map +1 -1
- package/dist/cjs/responses/index.cjs.map +1 -1
- package/dist/cjs/run.cjs +2 -538
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/session/AgentSession.cjs +1 -17
- package/dist/cjs/session/AgentSession.cjs.map +1 -1
- package/dist/cjs/session/JsonlSessionStore.cjs.map +1 -1
- package/dist/cjs/session/handlers.cjs +0 -7
- package/dist/cjs/session/handlers.cjs.map +1 -1
- package/dist/cjs/session/ids.cjs.map +1 -1
- package/dist/cjs/session/messageSerialization.cjs +0 -4
- package/dist/cjs/session/messageSerialization.cjs.map +1 -1
- package/dist/cjs/stream.cjs +1 -93
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/index.cjs +0 -27
- package/dist/cjs/summarization/index.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +0 -273
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +0 -35
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +0 -24
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/Calculator.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +0 -13
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/CodeSessionFileSummary.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +0 -101
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ReadFile.cjs.map +1 -1
- package/dist/cjs/tools/SkillTool.cjs +0 -5
- package/dist/cjs/tools/SkillTool.cjs.map +1 -1
- package/dist/cjs/tools/SubagentTool.cjs +0 -10
- package/dist/cjs/tools/SubagentTool.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +6 -1038
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/ToolSearch.cjs +0 -179
- package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareBridgeRuntime.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs +0 -39
- package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareSandboxTools.cjs.map +1 -1
- package/dist/cjs/tools/eagerEventExecution.cjs +0 -6
- package/dist/cjs/tools/eagerEventExecution.cjs.map +1 -1
- package/dist/cjs/tools/handlers.cjs +1 -41
- package/dist/cjs/tools/handlers.cjs.map +1 -1
- package/dist/cjs/tools/intentArg.cjs +1 -132
- package/dist/cjs/tools/intentArg.cjs.map +1 -1
- package/dist/cjs/tools/local/CompileCheckTool.cjs +0 -25
- package/dist/cjs/tools/local/CompileCheckTool.cjs.map +1 -1
- package/dist/cjs/tools/local/FileCheckpointer.cjs +0 -23
- package/dist/cjs/tools/local/FileCheckpointer.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalCodingTools.cjs +0 -80
- package/dist/cjs/tools/local/LocalCodingTools.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs +0 -126
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalExecutionTools.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +0 -12
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/local/attachments.cjs +0 -44
- package/dist/cjs/tools/local/attachments.cjs.map +1 -1
- package/dist/cjs/tools/local/bashAst.cjs +0 -16
- package/dist/cjs/tools/local/bashAst.cjs.map +1 -1
- package/dist/cjs/tools/local/editStrategies.cjs +0 -14
- package/dist/cjs/tools/local/editStrategies.cjs.map +1 -1
- package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs.map +1 -1
- package/dist/cjs/tools/local/syntaxCheck.cjs +0 -31
- package/dist/cjs/tools/local/syntaxCheck.cjs.map +1 -1
- package/dist/cjs/tools/local/textEncoding.cjs +0 -11
- package/dist/cjs/tools/local/textEncoding.cjs.map +1 -1
- package/dist/cjs/tools/local/workspaceFS.cjs +0 -33
- package/dist/cjs/tools/local/workspaceFS.cjs.map +1 -1
- package/dist/cjs/tools/ptcTimeout.cjs.map +1 -1
- package/dist/cjs/tools/schema.cjs +0 -8
- package/dist/cjs/tools/schema.cjs.map +1 -1
- package/dist/cjs/tools/search/anthropic.cjs +0 -9
- package/dist/cjs/tools/search/anthropic.cjs.map +1 -1
- package/dist/cjs/tools/search/content.cjs.map +1 -1
- package/dist/cjs/tools/search/crw-scraper.cjs +0 -33
- package/dist/cjs/tools/search/crw-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/crw-search.cjs +0 -2
- package/dist/cjs/tools/search/crw-search.cjs.map +1 -1
- package/dist/cjs/tools/search/firecrawl.cjs +0 -25
- package/dist/cjs/tools/search/firecrawl.cjs.map +1 -1
- package/dist/cjs/tools/search/format.cjs +0 -30
- package/dist/cjs/tools/search/format.cjs.map +1 -1
- package/dist/cjs/tools/search/highlights.cjs +0 -16
- package/dist/cjs/tools/search/highlights.cjs.map +1 -1
- package/dist/cjs/tools/search/keenable-scraper.cjs +0 -8
- package/dist/cjs/tools/search/keenable-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/keenable-search.cjs +0 -7
- package/dist/cjs/tools/search/keenable-search.cjs.map +1 -1
- package/dist/cjs/tools/search/rerankers.cjs +0 -35
- package/dist/cjs/tools/search/rerankers.cjs.map +1 -1
- package/dist/cjs/tools/search/schema.cjs +0 -1
- package/dist/cjs/tools/search/schema.cjs.map +1 -1
- package/dist/cjs/tools/search/search.cjs +1 -14
- package/dist/cjs/tools/search/search.cjs.map +1 -1
- package/dist/cjs/tools/search/serper-scraper.cjs +0 -46
- package/dist/cjs/tools/search/serper-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/tavily-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/tavily-search.cjs.map +1 -1
- package/dist/cjs/tools/search/tool.cjs +0 -25
- package/dist/cjs/tools/search/tool.cjs.map +1 -1
- package/dist/cjs/tools/search/utils.cjs +0 -8
- package/dist/cjs/tools/search/utils.cjs.map +1 -1
- package/dist/cjs/tools/skillCatalog.cjs +0 -6
- package/dist/cjs/tools/skillCatalog.cjs.map +1 -1
- package/dist/cjs/tools/streamedToolCallSeals.cjs +0 -6
- package/dist/cjs/tools/streamedToolCallSeals.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs +0 -2
- package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +3 -213
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentReplay.cjs.map +1 -1
- package/dist/cjs/tools/subagent/childGraphConfig.cjs +0 -4
- package/dist/cjs/tools/subagent/childGraphConfig.cjs.map +1 -1
- package/dist/cjs/tools/subagent/runtimeLimits.cjs.map +1 -1
- package/dist/cjs/tools/toolOutputReferences.cjs +1 -322
- package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -1
- package/dist/cjs/types/hitl.cjs +0 -5
- package/dist/cjs/types/hitl.cjs.map +1 -1
- package/dist/cjs/utils/callbacks.cjs.map +1 -1
- package/dist/cjs/utils/errors.cjs +14 -165
- package/dist/cjs/utils/errors.cjs.map +1 -1
- package/dist/cjs/utils/events.cjs +0 -10
- package/dist/cjs/utils/events.cjs.map +1 -1
- package/dist/cjs/utils/graph.cjs.map +1 -1
- package/dist/cjs/utils/handlers.cjs +0 -3
- package/dist/cjs/utils/handlers.cjs.map +1 -1
- package/dist/cjs/utils/llm.cjs +0 -1
- package/dist/cjs/utils/llm.cjs.map +1 -1
- package/dist/cjs/utils/misc.cjs +0 -16
- package/dist/cjs/utils/misc.cjs.map +1 -1
- package/dist/cjs/utils/proxy.cjs +0 -26
- package/dist/cjs/utils/proxy.cjs.map +1 -1
- package/dist/cjs/utils/run.cjs +0 -6
- package/dist/cjs/utils/run.cjs.map +1 -1
- package/dist/cjs/utils/schema.cjs +0 -5
- package/dist/cjs/utils/schema.cjs.map +1 -1
- package/dist/cjs/utils/title.cjs +0 -6
- package/dist/cjs/utils/title.cjs.map +1 -1
- package/dist/cjs/utils/tokens.cjs +0 -113
- package/dist/cjs/utils/tokens.cjs.map +1 -1
- package/dist/cjs/utils/toolContent.cjs +0 -41
- package/dist/cjs/utils/toolContent.cjs.map +1 -1
- package/dist/cjs/utils/truncation.cjs +0 -61
- package/dist/cjs/utils/truncation.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +0 -356
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/agents/projection.mjs +0 -9
- package/dist/esm/agents/projection.mjs.map +1 -1
- package/dist/esm/common/constants.mjs +0 -26
- package/dist/esm/common/constants.mjs.map +1 -1
- package/dist/esm/common/enum.mjs +0 -85
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/events.mjs +0 -14
- package/dist/esm/events.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +1 -909
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +7 -272
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/graphs/applyGraphRuntimeConfig.mjs.map +1 -1
- package/dist/esm/graphs/createGraph.mjs.map +1 -1
- package/dist/esm/hitl/askUserQuestion.mjs +0 -53
- package/dist/esm/hitl/askUserQuestion.mjs.map +1 -1
- package/dist/esm/hitl/askUserQuestions.mjs +0 -20
- package/dist/esm/hitl/askUserQuestions.mjs.map +1 -1
- package/dist/esm/hitl/askUserQuestionsInterrupt.mjs +0 -6
- package/dist/esm/hitl/askUserQuestionsInterrupt.mjs.map +1 -1
- package/dist/esm/hooks/HookRegistry.mjs +0 -127
- package/dist/esm/hooks/HookRegistry.mjs.map +1 -1
- package/dist/esm/hooks/createToolPolicyHook.mjs +0 -38
- package/dist/esm/hooks/createToolPolicyHook.mjs.map +1 -1
- package/dist/esm/hooks/createWorkspacePolicyHook.mjs +0 -77
- package/dist/esm/hooks/createWorkspacePolicyHook.mjs.map +1 -1
- package/dist/esm/hooks/executeHooks.mjs +0 -79
- package/dist/esm/hooks/executeHooks.mjs.map +1 -1
- package/dist/esm/hooks/index.mjs +0 -16
- package/dist/esm/hooks/index.mjs.map +1 -1
- package/dist/esm/hooks/matchers.mjs +0 -104
- package/dist/esm/hooks/matchers.mjs.map +1 -1
- package/dist/esm/hooks/types.mjs +0 -8
- package/dist/esm/hooks/types.mjs.map +1 -1
- package/dist/esm/instrumentation.mjs +0 -14
- package/dist/esm/instrumentation.mjs.map +1 -1
- package/dist/esm/langfuse.mjs +0 -75
- package/dist/esm/langfuse.mjs.map +1 -1
- package/dist/esm/langfuseConfig.mjs.map +1 -1
- package/dist/esm/langfuseRuntimeContext.mjs +0 -13
- package/dist/esm/langfuseRuntimeContext.mjs.map +1 -1
- package/dist/esm/langfuseRuntimeScope.mjs +0 -4
- package/dist/esm/langfuseRuntimeScope.mjs.map +1 -1
- package/dist/esm/langfuseSpanRegistry.mjs +0 -28
- package/dist/esm/langfuseSpanRegistry.mjs.map +1 -1
- package/dist/esm/langfuseToolOutputTracing.mjs +0 -3
- package/dist/esm/langfuseToolOutputTracing.mjs.map +1 -1
- package/dist/esm/langfuseTraceShaping.mjs +0 -74
- package/dist/esm/langfuseTraceShaping.mjs.map +1 -1
- package/dist/esm/llm/anthropic/index.mjs +0 -3
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/anthropic/types.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +1 -111
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +0 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/stream_events.mjs +0 -8
- package/dist/esm/llm/anthropic/utils/stream_events.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/tools.mjs.map +1 -1
- package/dist/esm/llm/bedrock/cachePoints.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +1 -95
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/llm/bedrock/toolCache.mjs.map +1 -1
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs +0 -78
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/bedrock/utils/message_outputs.mjs +0 -24
- package/dist/esm/llm/bedrock/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/contextOverflowRecovery.mjs +0 -62
- package/dist/esm/llm/contextOverflowRecovery.mjs.map +1 -1
- package/dist/esm/llm/fake.mjs.map +1 -1
- package/dist/esm/llm/google/index.mjs +2 -21
- package/dist/esm/llm/google/index.mjs.map +1 -1
- package/dist/esm/llm/google/utils/common.mjs +0 -35
- package/dist/esm/llm/google/utils/common.mjs.map +1 -1
- package/dist/esm/llm/init.mjs +0 -9
- package/dist/esm/llm/init.mjs.map +1 -1
- package/dist/esm/llm/invoke.mjs +1 -270
- package/dist/esm/llm/invoke.mjs.map +1 -1
- package/dist/esm/llm/mistral/index.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +0 -99
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/streamMetadata.mjs +0 -21
- package/dist/esm/llm/openai/streamMetadata.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/index.mjs +0 -1
- package/dist/esm/llm/openrouter/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/toolCache.mjs +0 -6
- package/dist/esm/llm/openrouter/toolCache.mjs.map +1 -1
- package/dist/esm/llm/preempt.mjs +0 -75
- package/dist/esm/llm/preempt.mjs.map +1 -1
- package/dist/esm/llm/providers.mjs.map +1 -1
- package/dist/esm/llm/request.mjs +0 -10
- package/dist/esm/llm/request.mjs.map +1 -1
- package/dist/esm/llm/stream/chunkAdapters.mjs +0 -62
- package/dist/esm/llm/stream/chunkAdapters.mjs.map +1 -1
- package/dist/esm/llm/stream/smoother.mjs +0 -58
- package/dist/esm/llm/stream/smoother.mjs.map +1 -1
- package/dist/esm/llm/streamLimits.mjs +4 -293
- package/dist/esm/llm/streamLimits.mjs.map +1 -1
- package/dist/esm/llm/truncation.mjs +0 -36
- package/dist/esm/llm/truncation.mjs.map +1 -1
- package/dist/esm/llm/vertexai/index.mjs +0 -330
- package/dist/esm/llm/vertexai/index.mjs.map +1 -1
- package/dist/esm/messages/alternation.mjs +0 -43
- package/dist/esm/messages/alternation.mjs.map +1 -1
- package/dist/esm/messages/anthropicToolCache.mjs +0 -45
- package/dist/esm/messages/anthropicToolCache.mjs.map +1 -1
- package/dist/esm/messages/assistantPhase.mjs +0 -12
- package/dist/esm/messages/assistantPhase.mjs.map +1 -1
- package/dist/esm/messages/budget.mjs +0 -9
- package/dist/esm/messages/budget.mjs.map +1 -1
- package/dist/esm/messages/cache.mjs +0 -172
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/content.mjs +0 -9
- package/dist/esm/messages/content.mjs.map +1 -1
- package/dist/esm/messages/contextPruning.mjs +0 -15
- package/dist/esm/messages/contextPruning.mjs.map +1 -1
- package/dist/esm/messages/contextPruningSettings.mjs +0 -3
- package/dist/esm/messages/contextPruningSettings.mjs.map +1 -1
- package/dist/esm/messages/core.mjs +0 -48
- package/dist/esm/messages/core.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +1 -345
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/messages/handoffCue.mjs +0 -36
- package/dist/esm/messages/handoffCue.mjs.map +1 -1
- package/dist/esm/messages/ids.mjs.map +1 -1
- package/dist/esm/messages/injected.mjs +0 -33
- package/dist/esm/messages/injected.mjs.map +1 -1
- package/dist/esm/messages/langchain.mjs +0 -14
- package/dist/esm/messages/langchain.mjs.map +1 -1
- package/dist/esm/messages/prune.mjs +1 -184
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/messages/recency.mjs +0 -32
- package/dist/esm/messages/recency.mjs.map +1 -1
- package/dist/esm/messages/reducer.mjs +0 -30
- package/dist/esm/messages/reducer.mjs.map +1 -1
- package/dist/esm/messages/tools.mjs +0 -14
- package/dist/esm/messages/tools.mjs.map +1 -1
- package/dist/esm/openai/index.mjs.map +1 -1
- package/dist/esm/prompts/activityLabel.mjs +9 -79
- package/dist/esm/prompts/activityLabel.mjs.map +1 -1
- package/dist/esm/responses/index.mjs.map +1 -1
- package/dist/esm/run.mjs +2 -538
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/session/AgentSession.mjs +1 -17
- package/dist/esm/session/AgentSession.mjs.map +1 -1
- package/dist/esm/session/JsonlSessionStore.mjs.map +1 -1
- package/dist/esm/session/handlers.mjs +0 -7
- package/dist/esm/session/handlers.mjs.map +1 -1
- package/dist/esm/session/ids.mjs.map +1 -1
- package/dist/esm/session/messageSerialization.mjs +0 -4
- package/dist/esm/session/messageSerialization.mjs.map +1 -1
- package/dist/esm/stream.mjs +1 -93
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/index.mjs +0 -27
- package/dist/esm/summarization/index.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +0 -273
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +0 -35
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +0 -24
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/Calculator.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +0 -13
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/CodeSessionFileSummary.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +0 -101
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ReadFile.mjs.map +1 -1
- package/dist/esm/tools/SkillTool.mjs +0 -5
- package/dist/esm/tools/SkillTool.mjs.map +1 -1
- package/dist/esm/tools/SubagentTool.mjs +0 -10
- package/dist/esm/tools/SubagentTool.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +6 -1038
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/ToolSearch.mjs +0 -179
- package/dist/esm/tools/ToolSearch.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareBridgeRuntime.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs +0 -39
- package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareSandboxTools.mjs.map +1 -1
- package/dist/esm/tools/eagerEventExecution.mjs +0 -6
- package/dist/esm/tools/eagerEventExecution.mjs.map +1 -1
- package/dist/esm/tools/handlers.mjs +1 -41
- package/dist/esm/tools/handlers.mjs.map +1 -1
- package/dist/esm/tools/intentArg.mjs +1 -132
- package/dist/esm/tools/intentArg.mjs.map +1 -1
- package/dist/esm/tools/local/CompileCheckTool.mjs +0 -25
- package/dist/esm/tools/local/CompileCheckTool.mjs.map +1 -1
- package/dist/esm/tools/local/FileCheckpointer.mjs +0 -23
- package/dist/esm/tools/local/FileCheckpointer.mjs.map +1 -1
- package/dist/esm/tools/local/LocalCodingTools.mjs +0 -80
- package/dist/esm/tools/local/LocalCodingTools.mjs.map +1 -1
- package/dist/esm/tools/local/LocalExecutionEngine.mjs +0 -126
- package/dist/esm/tools/local/LocalExecutionEngine.mjs.map +1 -1
- package/dist/esm/tools/local/LocalExecutionTools.mjs.map +1 -1
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +0 -12
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/local/attachments.mjs +0 -44
- package/dist/esm/tools/local/attachments.mjs.map +1 -1
- package/dist/esm/tools/local/bashAst.mjs +0 -16
- package/dist/esm/tools/local/bashAst.mjs.map +1 -1
- package/dist/esm/tools/local/editStrategies.mjs +0 -14
- package/dist/esm/tools/local/editStrategies.mjs.map +1 -1
- package/dist/esm/tools/local/resolveLocalExecutionTools.mjs.map +1 -1
- package/dist/esm/tools/local/syntaxCheck.mjs +0 -31
- package/dist/esm/tools/local/syntaxCheck.mjs.map +1 -1
- package/dist/esm/tools/local/textEncoding.mjs +0 -11
- package/dist/esm/tools/local/textEncoding.mjs.map +1 -1
- package/dist/esm/tools/local/workspaceFS.mjs +0 -33
- package/dist/esm/tools/local/workspaceFS.mjs.map +1 -1
- package/dist/esm/tools/ptcTimeout.mjs.map +1 -1
- package/dist/esm/tools/schema.mjs +0 -8
- package/dist/esm/tools/schema.mjs.map +1 -1
- package/dist/esm/tools/search/anthropic.mjs +0 -9
- package/dist/esm/tools/search/anthropic.mjs.map +1 -1
- package/dist/esm/tools/search/content.mjs.map +1 -1
- package/dist/esm/tools/search/crw-scraper.mjs +0 -33
- package/dist/esm/tools/search/crw-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/crw-search.mjs +0 -2
- package/dist/esm/tools/search/crw-search.mjs.map +1 -1
- package/dist/esm/tools/search/firecrawl.mjs +0 -25
- package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
- package/dist/esm/tools/search/format.mjs +0 -30
- package/dist/esm/tools/search/format.mjs.map +1 -1
- package/dist/esm/tools/search/highlights.mjs +0 -16
- package/dist/esm/tools/search/highlights.mjs.map +1 -1
- package/dist/esm/tools/search/keenable-scraper.mjs +0 -8
- package/dist/esm/tools/search/keenable-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/keenable-search.mjs +0 -7
- package/dist/esm/tools/search/keenable-search.mjs.map +1 -1
- package/dist/esm/tools/search/rerankers.mjs +0 -35
- package/dist/esm/tools/search/rerankers.mjs.map +1 -1
- package/dist/esm/tools/search/schema.mjs +0 -1
- package/dist/esm/tools/search/schema.mjs.map +1 -1
- package/dist/esm/tools/search/search.mjs +1 -14
- package/dist/esm/tools/search/search.mjs.map +1 -1
- package/dist/esm/tools/search/serper-scraper.mjs +0 -46
- package/dist/esm/tools/search/serper-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/tavily-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/tavily-search.mjs.map +1 -1
- package/dist/esm/tools/search/tool.mjs +0 -25
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/esm/tools/search/utils.mjs +0 -8
- package/dist/esm/tools/search/utils.mjs.map +1 -1
- package/dist/esm/tools/skillCatalog.mjs +0 -6
- package/dist/esm/tools/skillCatalog.mjs.map +1 -1
- package/dist/esm/tools/streamedToolCallSeals.mjs +0 -6
- package/dist/esm/tools/streamedToolCallSeals.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs +0 -2
- package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +3 -213
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentReplay.mjs.map +1 -1
- package/dist/esm/tools/subagent/childGraphConfig.mjs +0 -4
- package/dist/esm/tools/subagent/childGraphConfig.mjs.map +1 -1
- package/dist/esm/tools/subagent/runtimeLimits.mjs.map +1 -1
- package/dist/esm/tools/toolOutputReferences.mjs +1 -322
- package/dist/esm/tools/toolOutputReferences.mjs.map +1 -1
- package/dist/esm/types/hitl.mjs +0 -5
- package/dist/esm/types/hitl.mjs.map +1 -1
- package/dist/esm/utils/callbacks.mjs.map +1 -1
- package/dist/esm/utils/errors.mjs +14 -165
- package/dist/esm/utils/errors.mjs.map +1 -1
- package/dist/esm/utils/events.mjs +0 -10
- package/dist/esm/utils/events.mjs.map +1 -1
- package/dist/esm/utils/graph.mjs.map +1 -1
- package/dist/esm/utils/handlers.mjs +0 -3
- package/dist/esm/utils/handlers.mjs.map +1 -1
- package/dist/esm/utils/llm.mjs +0 -1
- package/dist/esm/utils/llm.mjs.map +1 -1
- package/dist/esm/utils/misc.mjs +0 -16
- package/dist/esm/utils/misc.mjs.map +1 -1
- package/dist/esm/utils/proxy.mjs +0 -26
- package/dist/esm/utils/proxy.mjs.map +1 -1
- package/dist/esm/utils/run.mjs +0 -6
- package/dist/esm/utils/run.mjs.map +1 -1
- package/dist/esm/utils/schema.mjs +0 -5
- package/dist/esm/utils/schema.mjs.map +1 -1
- package/dist/esm/utils/title.mjs +0 -6
- package/dist/esm/utils/title.mjs.map +1 -1
- package/dist/esm/utils/tokens.mjs +0 -113
- package/dist/esm/utils/tokens.mjs.map +1 -1
- package/dist/esm/utils/toolContent.mjs +0 -41
- package/dist/esm/utils/toolContent.mjs.map +1 -1
- package/dist/esm/utils/truncation.mjs +0 -61
- package/dist/esm/utils/truncation.mjs.map +1 -1
- package/package.json +35 -32
- package/dist/types/agents/__tests__/promptCacheLiveHelpers.d.ts +0 -52
- package/dist/types/test/mockTools.d.ts +0 -28
- package/dist/types/utils/__tests__/fixtures/contextOverflowSignatures.d.ts +0 -40
- package/src/__tests__/stream.eagerArgsDivergence.test.ts +0 -911
- package/src/__tests__/stream.eagerEventExecution.test.ts +0 -5046
- package/src/__tests__/stream.streamLimits.test.ts +0 -1982
- package/src/agents/__tests__/AgentContext.anthropic.live.test.ts +0 -448
- package/src/agents/__tests__/AgentContext.bedrock.live.test.ts +0 -655
- package/src/agents/__tests__/AgentContext.openrouter.live.test.ts +0 -128
- package/src/agents/__tests__/AgentContext.overflow.test.ts +0 -205
- package/src/agents/__tests__/AgentContext.test.ts +0 -2425
- package/src/agents/__tests__/projection.test.ts +0 -73
- package/src/agents/__tests__/promptCacheLiveHelpers.ts +0 -175
- package/src/aggregator.test.ts +0 -1214
- package/src/graphs/__tests__/Graph.breakerLifecycle.test.ts +0 -273
- package/src/graphs/__tests__/Graph.closeRunStep.test.ts +0 -385
- package/src/graphs/__tests__/Graph.contextOverflow.test.ts +0 -1766
- package/src/graphs/__tests__/Graph.preemptSignal.test.ts +0 -126
- package/src/graphs/__tests__/Graph.reasoning.test.ts +0 -1717
- package/src/graphs/__tests__/Graph.subagentResumeState.test.ts +0 -80
- package/src/graphs/__tests__/MultiAgentGraph.test.ts +0 -177
- package/src/graphs/__tests__/composition.smoke.test.ts +0 -509
- package/src/graphs/__tests__/createGraph.test.ts +0 -206
- package/src/hooks/__tests__/HookRegistry.test.ts +0 -334
- package/src/hooks/__tests__/compactHooks.test.ts +0 -250
- package/src/hooks/__tests__/createToolPolicyHook.test.ts +0 -268
- package/src/hooks/__tests__/createWorkspacePolicyHook.test.ts +0 -405
- package/src/hooks/__tests__/executeHooks.test.ts +0 -1294
- package/src/hooks/__tests__/integration.test.ts +0 -337
- package/src/hooks/__tests__/matchers.test.ts +0 -238
- package/src/hooks/__tests__/preemptBoundary.test.ts +0 -152
- package/src/hooks/__tests__/toolHooks.test.ts +0 -669
- package/src/llm/__tests__/contextOverflowRecovery.test.ts +0 -401
- package/src/llm/__tests__/fallbackOverflow.test.ts +0 -287
- package/src/llm/anthropic/Jacob_Lee_Resume_2023.pdf +0 -0
- package/src/llm/anthropic/inherited-content-utils.spec.ts +0 -249
- package/src/llm/anthropic/inherited-stream-events.spec.ts +0 -1259
- package/src/llm/anthropic/inherited-strict.spec.ts +0 -302
- package/src/llm/anthropic/llm.spec.ts +0 -3394
- package/src/llm/anthropic/utils/cross-provider-reasoning.test.ts +0 -383
- package/src/llm/anthropic/utils/cross-provider-server-tools.test.ts +0 -110
- package/src/llm/anthropic/utils/server-tool-inputs.test.ts +0 -508
- package/src/llm/anthropic/utils/streaming-tool-input.test.ts +0 -361
- package/src/llm/anthropic/utils/stripPrefillCache.test.ts +0 -111
- package/src/llm/anthropic/utils/tool-id-normalization.test.ts +0 -287
- package/src/llm/bedrock/inherited-cache.spec.ts +0 -144
- package/src/llm/bedrock/inherited.spec.ts +0 -724
- package/src/llm/bedrock/llm.spec.ts +0 -1533
- package/src/llm/bedrock/streamSealDispatch.test.ts +0 -331
- package/src/llm/bedrock/toolCache.test.ts +0 -194
- package/src/llm/bedrock/utils/cross-provider-reasoning.test.ts +0 -131
- package/src/llm/bedrock/utils/cross-provider-server-tools.test.ts +0 -122
- package/src/llm/bedrock/utils/message_inputs.test.ts +0 -650
- package/src/llm/bedrock/utils/message_outputs.test.ts +0 -85
- package/src/llm/bedrock/utils/toolResultCachePoint.test.ts +0 -118
- package/src/llm/custom-chat-models.smoke.test.ts +0 -1966
- package/src/llm/google/data/gettysburg10.wav +0 -0
- package/src/llm/google/data/hotdog.jpg +0 -0
- package/src/llm/google/inherited-stream-events.spec.ts +0 -350
- package/src/llm/google/llm.spec.ts +0 -1388
- package/src/llm/google/streamSmoothing.test.ts +0 -121
- package/src/llm/google/utils/common.test.ts +0 -196
- package/src/llm/invoke.alternation.test.ts +0 -87
- package/src/llm/invoke.handoffCue.test.ts +0 -112
- package/src/llm/invoke.streamLimits.test.ts +0 -142
- package/src/llm/invoke.test.ts +0 -1198
- package/src/llm/mistral/streamSmoothing.test.ts +0 -97
- package/src/llm/openai/cacheWriteTokens.test.ts +0 -112
- package/src/llm/openai/contentBlocks.test.ts +0 -381
- package/src/llm/openai/deepseek.test.ts +0 -747
- package/src/llm/openai/inherited-deepseek.spec.ts +0 -347
- package/src/llm/openai/inherited-xai.spec.ts +0 -416
- package/src/llm/openai/llm.spec.ts +0 -1774
- package/src/llm/openai/managedRequests.test.ts +0 -182
- package/src/llm/openai/sequentialToolCallSeals.test.ts +0 -199
- package/src/llm/openai/streamMetadata.spec.ts +0 -86
- package/src/llm/openai/streamMetadataDedup.spec.ts +0 -166
- package/src/llm/openai/utils/isReasoningModel.test.ts +0 -90
- package/src/llm/openai/utils/messages.test.ts +0 -488
- package/src/llm/openrouter/reasoning.test.ts +0 -561
- package/src/llm/openrouter/toolCache.test.ts +0 -134
- package/src/llm/preempt.test.ts +0 -323
- package/src/llm/stream/chunkAdapters.test.ts +0 -202
- package/src/llm/stream/reassembly.test.ts +0 -241
- package/src/llm/stream/smoother.bench.test.ts +0 -155
- package/src/llm/stream/smoother.test.ts +0 -519
- package/src/llm/streamLimits.test.ts +0 -450
- package/src/llm/truncation.test.ts +0 -242
- package/src/llm/vertexai/fixThoughtSignatures.test.ts +0 -154
- package/src/llm/vertexai/inherited-stream-events.spec.ts +0 -271
- package/src/llm/vertexai/llm.spec.ts +0 -159
- package/src/llm/vertexai/repairUsageMetadata.test.ts +0 -54
- package/src/llm/vertexai/sealStreamedToolCalls.test.ts +0 -88
- package/src/llm/vertexai/streamSealDispatch.test.ts +0 -148
- package/src/llm/vertexai/streamSmoothing.test.ts +0 -109
- package/src/messages/__tests__/anthropicToolCache.test.ts +0 -339
- package/src/messages/__tests__/observationMasking.test.ts +0 -312
- package/src/messages/__tests__/recency.test.ts +0 -267
- package/src/messages/__tests__/tools.test.ts +0 -473
- package/src/messages/alternation.test.ts +0 -212
- package/src/messages/assistantPhase.test.ts +0 -75
- package/src/messages/cache.tail.test.ts +0 -533
- package/src/messages/cache.test.ts +0 -2166
- package/src/messages/content.test.ts +0 -362
- package/src/messages/contextPruning.test.ts +0 -184
- package/src/messages/ensureThinkingBlock.test.ts +0 -1427
- package/src/messages/foldToollessToolBlocks.test.ts +0 -596
- package/src/messages/formatAgentMessages.reducer.test.ts +0 -162
- package/src/messages/formatAgentMessages.skills.test.ts +0 -513
- package/src/messages/formatAgentMessages.steer.test.ts +0 -598
- package/src/messages/formatAgentMessages.test.ts +0 -8111
- package/src/messages/formatAgentMessages.tools.test.ts +0 -522
- package/src/messages/formatMessage.test.ts +0 -693
- package/src/messages/handoffCue.test.ts +0 -96
- package/src/messages/injected.test.ts +0 -107
- package/src/messages/labelContentByAgent.test.ts +0 -962
- package/src/messages/reducer.spec.ts +0 -32
- package/src/messages/shiftIndexTokenCountMap.test.ts +0 -81
- package/src/messages/tailCacheConversion.test.ts +0 -161
- package/src/openai/__tests__/openai.test.ts +0 -337
- package/src/responses/__tests__/responses.test.ts +0 -652
- package/src/scripts/abort.ts +0 -157
- package/src/scripts/activity-labels/captured.json +0 -56
- package/src/scripts/activity-labels/checks.cjs +0 -205
- package/src/scripts/activity-labels/corpus.cjs +0 -473
- package/src/scripts/activity-labels/report.cjs +0 -203
- package/src/scripts/activity-labels/rescore.cjs +0 -102
- package/src/scripts/activity-labels/run.ts +0 -705
- package/src/scripts/activity-labels/variants.ts +0 -71
- package/src/scripts/ant_web_search.ts +0 -159
- package/src/scripts/ant_web_search_edge_case.ts +0 -163
- package/src/scripts/ant_web_search_error_edge_case.ts +0 -149
- package/src/scripts/args.ts +0 -48
- package/src/scripts/bedrock-cache-debug.ts +0 -250
- package/src/scripts/bedrock-content-aggregation-test.ts +0 -266
- package/src/scripts/bedrock-merge-test.ts +0 -107
- package/src/scripts/bedrock-parallel-tools-test.ts +0 -204
- package/src/scripts/bench-prompt-cache.ts +0 -479
- package/src/scripts/caching.ts +0 -132
- package/src/scripts/cli.ts +0 -172
- package/src/scripts/cli2.ts +0 -133
- package/src/scripts/cli3.ts +0 -184
- package/src/scripts/cli4.ts +0 -191
- package/src/scripts/cli5.ts +0 -191
- package/src/scripts/code_exec.ts +0 -214
- package/src/scripts/code_exec_files.ts +0 -237
- package/src/scripts/code_exec_multi_session.ts +0 -237
- package/src/scripts/code_exec_ptc.ts +0 -335
- package/src/scripts/code_exec_session.ts +0 -283
- package/src/scripts/code_exec_simple.ts +0 -148
- package/src/scripts/compare_pi_vs_ours.ts +0 -1259
- package/src/scripts/content.ts +0 -139
- package/src/scripts/context-overflow-probe.ts +0 -997
- package/src/scripts/empty_input.ts +0 -137
- package/src/scripts/handoff-test.ts +0 -134
- package/src/scripts/local_engine.ts +0 -166
- package/src/scripts/local_engine_checkpointer.ts +0 -205
- package/src/scripts/local_engine_compile.ts +0 -263
- package/src/scripts/local_engine_hooks.ts +0 -226
- package/src/scripts/local_engine_image.ts +0 -201
- package/src/scripts/local_engine_ptc.ts +0 -151
- package/src/scripts/local_engine_workspace.ts +0 -258
- package/src/scripts/memory.ts +0 -107
- package/src/scripts/multi-agent-chain.ts +0 -332
- package/src/scripts/multi-agent-conditional.ts +0 -222
- package/src/scripts/multi-agent-document-review-chain.ts +0 -198
- package/src/scripts/multi-agent-hybrid-flow.ts +0 -311
- package/src/scripts/multi-agent-parallel-start.ts +0 -265
- package/src/scripts/multi-agent-parallel.ts +0 -395
- package/src/scripts/multi-agent-sequence.ts +0 -217
- package/src/scripts/multi-agent-subagent.ts +0 -246
- package/src/scripts/multi-agent-supervisor.ts +0 -366
- package/src/scripts/multi-agent-test.ts +0 -187
- package/src/scripts/openrouter_prompt_cache_live.ts +0 -310
- package/src/scripts/parallel-asymmetric-tools-test.ts +0 -275
- package/src/scripts/parallel-full-metadata-test.ts +0 -241
- package/src/scripts/parallel-tools-test.ts +0 -341
- package/src/scripts/preempt-probe.ts +0 -330
- package/src/scripts/preempt-scenarios.ts +0 -388
- package/src/scripts/programmatic_exec.ts +0 -387
- package/src/scripts/programmatic_exec_agent.ts +0 -232
- package/src/scripts/search.ts +0 -147
- package/src/scripts/sequential-full-metadata-test.ts +0 -198
- package/src/scripts/session_live.ts +0 -548
- package/src/scripts/simple.ts +0 -226
- package/src/scripts/single-agent-metadata-test.ts +0 -196
- package/src/scripts/stream.ts +0 -141
- package/src/scripts/subagent-configurable-inheritance.ts +0 -252
- package/src/scripts/subagent-event-driven-debug.ts +0 -190
- package/src/scripts/subagent-tools-debug.ts +0 -160
- package/src/scripts/subagent-usage-sink.ts +0 -176
- package/src/scripts/summarization-recency.ts +0 -462
- package/src/scripts/test-custom-prompt-key.ts +0 -145
- package/src/scripts/test-handoff-input.ts +0 -170
- package/src/scripts/test-handoff-preamble.ts +0 -278
- package/src/scripts/test-handoff-steering.ts +0 -430
- package/src/scripts/test-multi-agent-list-handoff.ts +0 -418
- package/src/scripts/test-parallel-agent-labeling.ts +0 -327
- package/src/scripts/test-parallel-handoffs.ts +0 -292
- package/src/scripts/test-thinking-handoff-bedrock.ts +0 -154
- package/src/scripts/test-thinking-handoff.ts +0 -156
- package/src/scripts/test-thinking-to-thinking-handoff-bedrock.ts +0 -166
- package/src/scripts/test-tool-before-handoff-role-order.ts +0 -276
- package/src/scripts/test-tools-before-handoff.ts +0 -222
- package/src/scripts/test_code_api.ts +0 -354
- package/src/scripts/thinking-bedrock.ts +0 -160
- package/src/scripts/thinking-vertexai.ts +0 -168
- package/src/scripts/thinking.ts +0 -172
- package/src/scripts/tool_search.ts +0 -153
- package/src/scripts/tools.ts +0 -163
- package/src/session/__tests__/JsonlSessionStore.test.ts +0 -1463
- package/src/session/__tests__/handlers.test.ts +0 -161
- package/src/specs/activity-label-observability.live.test.ts +0 -262
- package/src/specs/activity-label-observability.test.ts +0 -167
- package/src/specs/activity-label-prompt.test.ts +0 -359
- package/src/specs/activity-label-trace-seed.test.ts +0 -47
- package/src/specs/activity-phase-label.test.ts +0 -306
- package/src/specs/agent-handoffs.live.test.ts +0 -140
- package/src/specs/agent-handoffs.test.ts +0 -2465
- package/src/specs/anthropic.simple.test.ts +0 -453
- package/src/specs/ask-user-question-batch.test.ts +0 -289
- package/src/specs/ask-user-questions.live.test.ts +0 -185
- package/src/specs/ask-user-questions.test.ts +0 -293
- package/src/specs/azure.simple.test.ts +0 -502
- package/src/specs/bedrock-toolless.live.test.ts +0 -123
- package/src/specs/bedrock-truncation.live.test.ts +0 -191
- package/src/specs/cache.simple.test.ts +0 -416
- package/src/specs/context-accuracy.live.test.ts +0 -409
- package/src/specs/context-overflow-recovery.live.test.ts +0 -213
- package/src/specs/context-usage-event.test.ts +0 -117
- package/src/specs/context-usage.live.test.ts +0 -297
- package/src/specs/custom-event-await.test.ts +0 -304
- package/src/specs/deepseek.simple.test.ts +0 -290
- package/src/specs/deterministic-trace-id.test.ts +0 -43
- package/src/specs/discovered-tools.test.ts +0 -217
- package/src/specs/durability-checkpoint.integration.test.ts +0 -243
- package/src/specs/graph-subagent.live.test.ts +0 -242
- package/src/specs/graph-subagent.test.ts +0 -322
- package/src/specs/handoffCue.test.ts +0 -165
- package/src/specs/langfuse-callbacks.test.ts +0 -1578
- package/src/specs/langfuse-config.test.ts +0 -247
- package/src/specs/langfuse-instrumentation.test.ts +0 -393
- package/src/specs/langfuse-metadata.test.ts +0 -245
- package/src/specs/langfuse-routing.integration.test.ts +0 -844
- package/src/specs/langfuse-runtime-context.test.ts +0 -92
- package/src/specs/langfuse-span-registry.test.ts +0 -87
- package/src/specs/langfuse-tool-output-tracing.test.ts +0 -1858
- package/src/specs/langfuse-trace-shaping.test.ts +0 -591
- package/src/specs/moonshot.simple.test.ts +0 -367
- package/src/specs/multi-agent-summarization.test.ts +0 -396
- package/src/specs/openai.simple.test.ts +0 -315
- package/src/specs/openrouter.simple.test.ts +0 -275
- package/src/specs/preemptSeal.test.ts +0 -678
- package/src/specs/prune.test.ts +0 -3741
- package/src/specs/reasoning.test.ts +0 -201
- package/src/specs/run-step-timestamps.test.ts +0 -414
- package/src/specs/spec.utils.ts +0 -15
- package/src/specs/subagent.test.ts +0 -864
- package/src/specs/summarization-unit.test.ts +0 -973
- package/src/specs/summarization.test.ts +0 -3823
- package/src/specs/summarize-prune.test.ts +0 -376
- package/src/specs/thinking-handoff.test.ts +0 -621
- package/src/specs/thinking-prune.test.ts +0 -827
- package/src/specs/token-accounting-e2e.test.ts +0 -1034
- package/src/specs/token-accounting-pipeline.test.ts +0 -1008
- package/src/specs/token-distribution-edge-case.test.ts +0 -315
- package/src/specs/token-memoization.test.ts +0 -40
- package/src/specs/tokens.test.ts +0 -1000
- package/src/specs/tool-error-resume.test.ts +0 -194
- package/src/specs/tool-error.test.ts +0 -198
- package/src/specs/vllm-reasoning-toolcalls.test.ts +0 -340
- package/src/stream.dispatch.test.ts +0 -63
- package/src/stream.test.ts +0 -144
- package/src/summarization/__tests__/aggregator.test.ts +0 -236
- package/src/summarization/__tests__/node.test.ts +0 -1996
- package/src/summarization/__tests__/trigger.test.ts +0 -149
- package/src/summarization/chunkHandler.test.ts +0 -196
- package/src/test/mockTools.ts +0 -386
- package/src/tools/Calculator.test.ts +0 -278
- package/src/tools/__tests__/BashExecutor.test.ts +0 -108
- package/src/tools/__tests__/CloudflareSandboxExecution.test.ts +0 -939
- package/src/tools/__tests__/CodeApiAuthHeaders.test.ts +0 -858
- package/src/tools/__tests__/CodeExecutor.stateful.test.ts +0 -124
- package/src/tools/__tests__/LocalExecutionRoots.test.ts +0 -8
- package/src/tools/__tests__/LocalExecutionTools.test.ts +0 -2733
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.ts +0 -318
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +0 -1557
- package/src/tools/__tests__/ReadFile.test.ts +0 -44
- package/src/tools/__tests__/SkillTool.test.ts +0 -442
- package/src/tools/__tests__/SubagentExecutor.test.ts +0 -3728
- package/src/tools/__tests__/SubagentReplay.test.ts +0 -329
- package/src/tools/__tests__/SubagentTool.test.ts +0 -149
- package/src/tools/__tests__/ToolNode.breakerSignal.test.ts +0 -595
- package/src/tools/__tests__/ToolNode.eagerEventExecution.test.ts +0 -1191
- package/src/tools/__tests__/ToolNode.invalidToolCalls.test.ts +0 -757
- package/src/tools/__tests__/ToolNode.langfuse.test.ts +0 -57
- package/src/tools/__tests__/ToolNode.onResultCompletion.test.ts +0 -736
- package/src/tools/__tests__/ToolNode.outputReferences.test.ts +0 -1710
- package/src/tools/__tests__/ToolNode.runtimeState.test.ts +0 -120
- package/src/tools/__tests__/ToolNode.session.test.ts +0 -1352
- package/src/tools/__tests__/ToolNode.streamLimits.test.ts +0 -69
- package/src/tools/__tests__/ToolSearch.integration.test.ts +0 -161
- package/src/tools/__tests__/ToolSearch.test.ts +0 -1227
- package/src/tools/__tests__/annotateMessagesForLLM.test.ts +0 -561
- package/src/tools/__tests__/directToolHITLResumeScope.test.ts +0 -980
- package/src/tools/__tests__/directToolHooks.test.ts +0 -700
- package/src/tools/__tests__/eagerEventExecution.session.test.ts +0 -92
- package/src/tools/__tests__/handlers.test.ts +0 -997
- package/src/tools/__tests__/hitl.test.ts +0 -4663
- package/src/tools/__tests__/intentArg.test.ts +0 -357
- package/src/tools/__tests__/intentCoverage.test.ts +0 -139
- package/src/tools/__tests__/localToolNames.test.ts +0 -75
- package/src/tools/__tests__/skillCatalog.test.ts +0 -161
- package/src/tools/__tests__/subagentHooks.test.ts +0 -1651
- package/src/tools/__tests__/toolOutputReferences.test.ts +0 -515
- package/src/tools/__tests__/workspaceSeam.test.ts +0 -147
- package/src/tools/local/__tests__/FileCheckpointer.test.ts +0 -162
- package/src/tools/local/__tests__/editStrategies.test.ts +0 -134
- package/src/tools/search/content.test.ts +0 -173
- package/src/tools/search/crw.test.ts +0 -836
- package/src/tools/search/format.test.ts +0 -242
- package/src/tools/search/http-agent.test.ts +0 -133
- package/src/tools/search/jina-reranker.test.ts +0 -306
- package/src/tools/search/keenable-scraper.test.ts +0 -153
- package/src/tools/search/keenable.test.ts +0 -183
- package/src/tools/search/outcome.test.ts +0 -90
- package/src/tools/search/output.md +0 -2775
- package/src/tools/search/rag-api-reranker.test.ts +0 -891
- package/src/tools/search/source-processing.test.ts +0 -516
- package/src/tools/search/tavily.test.ts +0 -965
- package/src/tools/search/test.html +0 -884
- package/src/tools/search/test.md +0 -643
- package/src/tools/subagent/__tests__/SubagentExecutionRegistry.test.ts +0 -637
- package/src/tools/subagent/__tests__/SubagentExecutor.lazy.test.ts +0 -3054
- package/src/tools/subagent/__tests__/childGraphConfig.test.ts +0 -521
- package/src/utils/__tests__/apportion.test.ts +0 -32
- package/src/utils/__tests__/errors.test.ts +0 -270
- package/src/utils/__tests__/fixtures/contextOverflowSignatures.ts +0 -336
- package/src/utils/__tests__/redactSecrets.test.ts +0 -56
- package/src/utils/__tests__/truncation.test.ts +0 -66
- package/src/utils/llm.test.ts +0 -18
- package/src/utils/proxy.test.ts +0 -176
- package/src/utils/toolContent.test.ts +0 -1432
|
@@ -74,7 +74,6 @@ const EMPTY_PREEMPT_BOUNDARY = {
|
|
|
74
74
|
messages: [],
|
|
75
75
|
preventContinuation: false
|
|
76
76
|
};
|
|
77
|
-
/** Minimum relative variance before calibrated toolSchemaTokens overrides current value. */
|
|
78
77
|
const CALIBRATION_VARIANCE_THRESHOLD = .15;
|
|
79
78
|
function createChildHandlerRegistry(source) {
|
|
80
79
|
const toolHandler = source?.getHandler("on_tool_execute");
|
|
@@ -173,21 +172,10 @@ function clearCurrentDeltaStepMarkers({ graph, metadata }) {
|
|
|
173
172
|
graph.reasoningStepHasDeltas.delete(stepId);
|
|
174
173
|
}
|
|
175
174
|
}
|
|
176
|
-
/**
|
|
177
|
-
* The completion allowance the caller configured, under whichever key the
|
|
178
|
-
* provider's client uses. Providers count it against the same ceiling as the
|
|
179
|
-
* prompt, so overflow recovery has to reserve it when the error did not
|
|
180
|
-
* itemize the total.
|
|
181
|
-
*/
|
|
182
175
|
function getConfiguredCompletionTokens(clientOptions) {
|
|
183
176
|
const options = clientOptions;
|
|
184
177
|
for (const value of [options?.maxTokens, options?.maxOutputTokens]) if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;
|
|
185
178
|
}
|
|
186
|
-
/**
|
|
187
|
-
* Our own estimate of the prompt that was actually sent, derived from the
|
|
188
|
-
* pre-invoke usage snapshot. Used to corroborate ambiguous provider errors
|
|
189
|
-
* and to measure how far our token accounting sits from the provider's.
|
|
190
|
-
*/
|
|
191
179
|
function getEstimatedPromptTokens(contextUsage) {
|
|
192
180
|
const budget = contextUsage?.contextBudget;
|
|
193
181
|
const remaining = contextUsage?.remainingContextTokens;
|
|
@@ -281,7 +269,6 @@ function getDispatchableFinalReasoningContent({ agentContext, responseReasoningC
|
|
|
281
269
|
}
|
|
282
270
|
var Graph = class {
|
|
283
271
|
restoreCheckpointMessages(_messages, _pendingMessages) {}
|
|
284
|
-
/** Returns a snapshot of deferred tools discovered by this graph. */
|
|
285
272
|
getDiscoveredTools(_agentId) {
|
|
286
273
|
return [];
|
|
287
274
|
}
|
|
@@ -294,122 +281,33 @@ var Graph = class {
|
|
|
294
281
|
stepKeyIds = /* @__PURE__ */ new Map();
|
|
295
282
|
contentIndexMap = /* @__PURE__ */ new Map();
|
|
296
283
|
toolCallStepIds = /* @__PURE__ */ new Map();
|
|
297
|
-
/** Step ID -> tool call IDs whose completions have not yet arrived. */
|
|
298
284
|
pendingToolCallsByStep = /* @__PURE__ */ new Map();
|
|
299
|
-
/**
|
|
300
|
-
* Step ID -> latest producer completion time seen for that step. Parallel
|
|
301
|
-
* calls sharing a step can settle out of producer order when their host
|
|
302
|
-
* handlers differ in latency, so the call that happens to drain the set is
|
|
303
|
-
* not necessarily the one that finished last.
|
|
304
|
-
*/
|
|
305
285
|
latestCompletionByStep = /* @__PURE__ */ new Map();
|
|
306
|
-
/** Agent key ('' for single-agent) -> currently open MESSAGE_CREATION step ID. */
|
|
307
286
|
openMessageStepByAgent = /* @__PURE__ */ new Map();
|
|
308
|
-
/**
|
|
309
|
-
* Step IDs dispatched through the handler registry during this run.
|
|
310
|
-
* Event echo suppression is tracked separately so repeated deltas for
|
|
311
|
-
* the same step are scoped to the active custom event dispatch.
|
|
312
|
-
*/
|
|
313
287
|
handlerDispatchedStepIds = /* @__PURE__ */ new Set();
|
|
314
288
|
reasoningStepHasDeltas = /* @__PURE__ */ new Set();
|
|
315
289
|
handlerDispatchedEventCounts = /* @__PURE__ */ new Map();
|
|
316
290
|
signal;
|
|
317
|
-
/**
|
|
318
|
-
* The abort signal the CALLER handed to the current `processStream` call,
|
|
319
|
-
* assigned unconditionally — including back to `undefined` — on every call.
|
|
320
|
-
*
|
|
321
|
-
* Kept separate from {@link signal} on purpose. That field is construction
|
|
322
|
-
* state with its own consumers (model-call config, subagent parentSignal),
|
|
323
|
-
* so adopting a per-call signal into it would leak one call's controller
|
|
324
|
-
* into the next — `clearHeavyState()` is skipped on HITL interrupts, so a
|
|
325
|
-
* host that aborts a finished request's controller would poison the resumed
|
|
326
|
-
* run's model calls and boundary drains with an already-aborted signal.
|
|
327
|
-
* Boundary dispatch composes the two instead; see
|
|
328
|
-
* `StandardGraph.dispatchPreemptBoundary`.
|
|
329
|
-
*/
|
|
330
291
|
callerSignal;
|
|
331
|
-
/** Set of invoked tool call IDs from non-message run steps completed mid-run, if any */
|
|
332
292
|
invokedToolIds;
|
|
333
293
|
handlerRegistry;
|
|
334
|
-
/** Host registry retained only for forwarding tools from nested child graphs. */
|
|
335
294
|
parentToolHandlerRegistry;
|
|
336
|
-
/**
|
|
337
|
-
* True when event-driven tool execution can be routed through callbacks even
|
|
338
|
-
* though this graph intentionally does not own the full handler registry.
|
|
339
|
-
* Self-spawned subagent graphs use this shape: their callback forwarder sends
|
|
340
|
-
* `ON_TOOL_EXECUTE` to the parent's handler, while child run-step events stay
|
|
341
|
-
* wrapped as `ON_SUBAGENT_UPDATE` instead of leaking as parent events.
|
|
342
|
-
*/
|
|
343
295
|
eventToolExecutionAvailable = false;
|
|
344
296
|
hookRegistry;
|
|
345
|
-
/**
|
|
346
|
-
* Run-scoped HITL configuration. When `humanInTheLoop?.enabled` is
|
|
347
|
-
* `true`, `ToolNode` raises a real `interrupt()` for `PreToolUse`
|
|
348
|
-
* `ask` decisions instead of treating them as a synchronous deny.
|
|
349
|
-
* Threaded from `RunConfig.humanInTheLoop`.
|
|
350
|
-
*/
|
|
351
297
|
humanInTheLoop;
|
|
352
|
-
/**
|
|
353
|
-
* Run-scoped config for the tool output reference registry. Threaded
|
|
354
|
-
* from `RunConfig.toolOutputReferences` down into every ToolNode this
|
|
355
|
-
* graph compiles.
|
|
356
|
-
*/
|
|
357
298
|
toolOutputReferences;
|
|
358
|
-
/**
|
|
359
|
-
* Run-scoped Langfuse defaults. Per-agent config wins when present.
|
|
360
|
-
*/
|
|
361
299
|
langfuse;
|
|
362
|
-
/**
|
|
363
|
-
* Run-scoped opt-in for eager event-driven tool execution. The stream
|
|
364
|
-
* handler may prestart eligible event-driven tools; ToolNode later
|
|
365
|
-
* consumes the settled promises while preserving final ToolMessage order.
|
|
366
|
-
*/
|
|
367
300
|
eagerEventToolExecution;
|
|
368
301
|
codeSessionToolNames;
|
|
369
|
-
/**
|
|
370
|
-
* Run-scoped names of tools whose in-process body may raise a LangGraph
|
|
371
|
-
* `interrupt()` (e.g. `ask_user_question`). Threaded from
|
|
372
|
-
* `RunConfig.interruptingToolNames` into every ToolNode this graph
|
|
373
|
-
* compiles so a mid-batch interrupt cannot double-execute non-idempotent
|
|
374
|
-
* siblings on resume. See {@link t.ToolNodeOptions.interruptingToolNames}.
|
|
375
|
-
*/
|
|
376
302
|
interruptingToolNames;
|
|
377
303
|
eagerEventToolExecutions = /* @__PURE__ */ new Map();
|
|
378
304
|
eagerEventToolUsageCount = /* @__PURE__ */ new Map();
|
|
379
305
|
eagerEventToolUsageCountsByAgentId = /* @__PURE__ */ new Map();
|
|
380
306
|
eagerEventToolCallChunks = /* @__PURE__ */ new Map();
|
|
381
|
-
/**
|
|
382
|
-
* Per-run eager prestart circuit breaker, shared by reference with every
|
|
383
|
-
* ToolNode this graph compiles. When a prestarted execution's args turn
|
|
384
|
-
* out to differ from the final request, ToolNode records the tool name
|
|
385
|
-
* here and the stream handler stops prestarting that tool for the rest of
|
|
386
|
-
* the run — the retry then executes normally instead of re-diverging in a
|
|
387
|
-
* loop (LibreChat#14371).
|
|
388
|
-
*/
|
|
389
307
|
eagerEventToolSuppressions = /* @__PURE__ */ new Set();
|
|
390
|
-
/**
|
|
391
|
-
* Run-scoped execution backend for built-in code tools. Defaults to the
|
|
392
|
-
* remote Code API sandbox when unset.
|
|
393
|
-
*/
|
|
394
308
|
toolExecution;
|
|
395
|
-
/**
|
|
396
|
-
* Shared registry instance used by every ToolNode compiled from this
|
|
397
|
-
* graph. Lazily constructed on first access so multi-agent graphs
|
|
398
|
-
* produce one registry per run (not one per agent), letting cross-
|
|
399
|
-
* agent `{{tool<i>turn<n>}}` substitutions resolve.
|
|
400
|
-
*/
|
|
401
309
|
_toolOutputRegistry;
|
|
402
|
-
/**
|
|
403
|
-
* Tool session contexts for automatic state persistence across tool invocations.
|
|
404
|
-
* Keyed by tool name (e.g., Constants.EXECUTE_CODE).
|
|
405
|
-
* Currently supports code execution session tracking (session_id, files).
|
|
406
|
-
*/
|
|
407
310
|
sessions = /* @__PURE__ */ new Map();
|
|
408
|
-
/**
|
|
409
|
-
* Clears heavy references to allow GC to reclaim memory held by
|
|
410
|
-
* LangGraph's internal config / AsyncLocalStorage RunTree chain.
|
|
411
|
-
* Call after a run completes and content has been extracted.
|
|
412
|
-
*/
|
|
413
311
|
clearHeavyState() {
|
|
414
312
|
this.config = void 0;
|
|
415
313
|
this.signal = void 0;
|
|
@@ -441,14 +339,6 @@ var Graph = class {
|
|
|
441
339
|
this.eagerEventToolSuppressions.clear();
|
|
442
340
|
this.toolExecution = void 0;
|
|
443
341
|
this.handlerDispatchedEventCounts.clear();
|
|
444
|
-
/**
|
|
445
|
-
* ToolNodes compiled from this graph captured the registry
|
|
446
|
-
* instance at construction time, so simply dropping the Graph's
|
|
447
|
-
* own reference would leave their captured reference — and every
|
|
448
|
-
* stored `tool<i>turn<n>` entry, plus up to `maxTotalSize` of raw
|
|
449
|
-
* output — alive across subsequent `processStream()` calls. Wipe
|
|
450
|
-
* the registry's contents first so subsequent runs start fresh.
|
|
451
|
-
*/
|
|
452
342
|
this._toolOutputRegistry?.clear();
|
|
453
343
|
this._toolOutputRegistry = void 0;
|
|
454
344
|
for (const node of this._compiledToolNodes) node.clearDirectPathTurns();
|
|
@@ -468,18 +358,10 @@ var Graph = class {
|
|
|
468
358
|
this.eagerEventToolUsageCount.clear();
|
|
469
359
|
for (const usageCount of this.eagerEventToolUsageCountsByAgentId.values()) usageCount.clear();
|
|
470
360
|
}
|
|
471
|
-
/**
|
|
472
|
-
* Tracks a tool call whose completion must arrive before its step can be
|
|
473
|
-
* considered finished. Registered wherever `toolCallStepIds` gains entries,
|
|
474
|
-
* except cross-process subagent resume restoration, where pending state
|
|
475
|
-
* cannot be faithfully rebuilt and closes fall back to completions/sweep.
|
|
476
|
-
*/
|
|
477
361
|
registerPendingToolCall(toolCallId, stepId) {
|
|
478
362
|
if (!toolCallId || !stepId) return;
|
|
479
363
|
this.getPendingToolCallSet(stepId).add(toolCallId);
|
|
480
364
|
}
|
|
481
|
-
/** Lazily creates a step's pending-completions set; callers registering a
|
|
482
|
-
* batch hoist this lookup out of their per-call loop. */
|
|
483
365
|
getPendingToolCallSet(stepId) {
|
|
484
366
|
let pending = this.pendingToolCallsByStep.get(stepId);
|
|
485
367
|
if (!pending) {
|
|
@@ -504,12 +386,6 @@ var Graph = class {
|
|
|
504
386
|
const key = getHandlerDispatchedEventKey(eventName, stepId);
|
|
505
387
|
return (this.handlerDispatchedEventCounts.get(key) ?? 0) > 0;
|
|
506
388
|
}
|
|
507
|
-
/**
|
|
508
|
-
* Subclass hook to register a freshly compiled ToolNode so
|
|
509
|
-
* `clearHeavyState` can flush its per-Run direct-path turn cache
|
|
510
|
-
* at end-of-Run. Internal — called from `initializeTools` in the
|
|
511
|
-
* concrete graph subclasses.
|
|
512
|
-
*/
|
|
513
389
|
registerCompiledToolNode(node) {
|
|
514
390
|
this._compiledToolNodes.add(node);
|
|
515
391
|
}
|
|
@@ -580,19 +456,6 @@ var Graph = class {
|
|
|
580
456
|
for (const toolName of state.eagerToolSuppressions) this.eagerEventToolSuppressions.add(toolName);
|
|
581
457
|
if (state.toolOutputReferences != null && registry != null) registry.restoreState(runId, state.toolOutputReferences);
|
|
582
458
|
}
|
|
583
|
-
/**
|
|
584
|
-
* Returns the shared `ToolOutputReferenceRegistry` for this run,
|
|
585
|
-
* constructing it on first access. Returns `undefined` when the
|
|
586
|
-
* feature is disabled. All ToolNodes compiled from this graph share
|
|
587
|
-
* this single instance so cross-agent `{{…}}` references resolve.
|
|
588
|
-
*
|
|
589
|
-
* @internal Public so `attemptInvoke` can read it through the typed
|
|
590
|
-
* `InvokeContext` and project ToolMessages into LLM-facing annotated
|
|
591
|
-
* copies right before each provider call (see
|
|
592
|
-
* `annotateMessagesForLLM`). Host code should not call this directly
|
|
593
|
-
* — registry mutations outside the ToolNode lifecycle break the
|
|
594
|
-
* partitioning, eviction, and turn-counter invariants.
|
|
595
|
-
*/
|
|
596
459
|
getOrCreateToolOutputRegistry() {
|
|
597
460
|
if (this.toolOutputReferences?.enabled !== true) return;
|
|
598
461
|
if (this._toolOutputRegistry == null) this._toolOutputRegistry = new require_toolOutputReferences.ToolOutputReferenceRegistry({
|
|
@@ -601,25 +464,7 @@ var Graph = class {
|
|
|
601
464
|
});
|
|
602
465
|
return this._toolOutputRegistry;
|
|
603
466
|
}
|
|
604
|
-
/**
|
|
605
|
-
* Single per-Run file checkpointer shared across every ToolNode the
|
|
606
|
-
* graph compiles. Lazily constructed when
|
|
607
|
-
* `toolExecution.local.fileCheckpointing === true` or
|
|
608
|
-
* `toolExecution.cloudflare.fileCheckpointing === true` so
|
|
609
|
-
* multi-agent graphs see ONE snapshot store, not one-per-agent.
|
|
610
|
-
* Returns undefined when checkpointing is disabled or a supported
|
|
611
|
-
* coding-tool engine isn't selected. Exposed via
|
|
612
|
-
* `Run.getFileCheckpointer()` / `Run.rewindFiles()`.
|
|
613
|
-
*/
|
|
614
467
|
_fileCheckpointer;
|
|
615
|
-
/**
|
|
616
|
-
* ToolNodes compiled into this Graph's workflow. Tracked so
|
|
617
|
-
* `clearHeavyState()` can flush their per-Run direct-path turn
|
|
618
|
-
* cache (`directPathTurns`) at end-of-Run — that map intentionally
|
|
619
|
-
* survives `run()` re-entry (resume-stable per Codex P2 #30) but
|
|
620
|
-
* would otherwise grow linearly with tool calls and could collide
|
|
621
|
-
* across Runs if a provider reuses call ids (Codex P2 #33).
|
|
622
|
-
*/
|
|
623
468
|
_compiledToolNodes = /* @__PURE__ */ new Set();
|
|
624
469
|
_subagentExecutors = /* @__PURE__ */ new Set();
|
|
625
470
|
getOrCreateFileCheckpointer() {
|
|
@@ -641,158 +486,45 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
641
486
|
subagentModelOverride;
|
|
642
487
|
graphFactory;
|
|
643
488
|
supportsMultiAgentChildren;
|
|
644
|
-
/** Optional compile options passed into workflow.compile() */
|
|
645
489
|
compileOptions;
|
|
646
|
-
/** Whether the workflow was actually compiled with a checkpointer. */
|
|
647
490
|
hasCompiledCheckpointer = false;
|
|
648
491
|
messages = [];
|
|
649
|
-
/** Whether a rebuilt resume seeded the message baseline from its checkpoint. */
|
|
650
492
|
hasRestoredCheckpointMessages = false;
|
|
651
|
-
/** Cached run messages preserved before clearHeavyState() so getRunMessages() works after cleanup. */
|
|
652
493
|
cachedRunMessages;
|
|
653
|
-
/** Per-agent discovery snapshots preserved before contexts are reset on cleanup. */
|
|
654
494
|
cachedDiscoveredTools;
|
|
655
|
-
/** Ids of AI turns the agent node returned THIS run; see isRunProducedMessage. */
|
|
656
495
|
runProducedAiMessageIds = /* @__PURE__ */ new Set();
|
|
657
|
-
/** Checkpoint scope whose messages match index-keyed tool snapshots. */
|
|
658
496
|
originalToolContentCheckpointScope;
|
|
659
497
|
runId;
|
|
660
|
-
/**
|
|
661
|
-
* Identity used to stamp Langfuse runtime scopes and handlers (see
|
|
662
|
-
* `LangfuseRuntimeContext.runId`). Carries an opaque per-instance
|
|
663
|
-
* component: public run ids are unrestricted and may repeat across
|
|
664
|
-
* concurrently executing runs (retries, duplicate submissions,
|
|
665
|
-
* tenant-local message ids), and equal stamps would let those runs adopt
|
|
666
|
-
* each other's scopes. One graph instance = one execution's stamp, shared
|
|
667
|
-
* by the stream handler and every graph-level scope of that execution.
|
|
668
|
-
*/
|
|
669
498
|
langfuseScopeRunId;
|
|
670
|
-
/**
|
|
671
|
-
* Boundary between historical messages (loaded from conversation state)
|
|
672
|
-
* and messages produced during the current run. Set once in the state
|
|
673
|
-
* reducer when messages first arrive. Used by `getRunMessages()` and
|
|
674
|
-
* multi-agent message filtering — NOT for pruner token counting (the
|
|
675
|
-
* pruner maintains its own `lastTurnStartIndex` in its closure).
|
|
676
|
-
*/
|
|
677
499
|
startIndex = 0;
|
|
678
500
|
signal;
|
|
679
|
-
/** Map of agent contexts by agent ID */
|
|
680
501
|
agentContexts = /* @__PURE__ */ new Map();
|
|
681
|
-
/** Default agent ID to use */
|
|
682
502
|
defaultAgentId;
|
|
683
|
-
/**
|
|
684
|
-
* Host sink for model usage emitted inside subagent child runs. Threaded
|
|
685
|
-
* into each `SubagentExecutor` this graph creates (and from there into
|
|
686
|
-
* child graphs, so nested subagents report too). See
|
|
687
|
-
* {@link t.StandardGraphInput.subagentUsageSink}.
|
|
688
|
-
*/
|
|
689
503
|
subagentUsageSink;
|
|
690
|
-
/** See {@link t.StandardGraphInput.subagentScope}. */
|
|
691
504
|
subagentScope;
|
|
692
|
-
/** See {@link t.StandardGraphInput.subagentExecutionContext}. */
|
|
693
505
|
subagentExecutionContext;
|
|
694
|
-
/** See {@link t.StandardGraphInput.preemption}. */
|
|
695
506
|
preemption;
|
|
696
|
-
/**
|
|
697
|
-
* Stream circuit breakers, resolved once from
|
|
698
|
-
* {@link t.StandardGraphInput.streamLimits}. The stream handler enforces
|
|
699
|
-
* these on every streamed chunk event.
|
|
700
|
-
*/
|
|
701
507
|
streamLimits;
|
|
702
|
-
/**
|
|
703
|
-
* Cumulative streamed argument bytes per in-flight tool call, keyed by
|
|
704
|
-
* generation key + chunk index (see `resolveGenerationKey`). Per-run
|
|
705
|
-
* accumulation state, cleared by both reset paths.
|
|
706
|
-
*/
|
|
707
508
|
streamedToolCallArgTallies = /* @__PURE__ */ new Map();
|
|
708
|
-
/** Streamed chunk events per model generation, keyed by generation key. */
|
|
709
509
|
streamDeltaEventCounts = /* @__PURE__ */ new Map();
|
|
710
|
-
/** Per-chunk-object, per-generation charge balances (lazily created; see
|
|
711
|
-
* `StreamLimitState`). Reinitialized by both reset paths: a model may
|
|
712
|
-
* retain and re-yield one mutable chunk object, whose nested map would
|
|
713
|
-
* otherwise grow by one attempt-stamped entry per model call for the
|
|
714
|
-
* graph's lifetime. */
|
|
715
510
|
streamLimitChargeCredits;
|
|
716
|
-
/** Run-scoped breaker abort: composed into every model invocation and
|
|
717
|
-
* every SubagentExecutor child signal, and tripped when a stream circuit
|
|
718
|
-
* breaker fires anywhere in the run, so parallel agent nodes' in-flight
|
|
719
|
-
* provider calls and subagents stop consuming quota while the rejection
|
|
720
|
-
* propagates. Recreated by both reset paths — the abort is one-way within
|
|
721
|
-
* a run, and a reused graph must start its next run unaborted. */
|
|
722
511
|
breakerAbort = new AbortController();
|
|
723
|
-
/** Incremented whenever `breakerAbort` is replaced. Stamped into each
|
|
724
|
-
* model attempt's metadata ({@link STREAM_LIMIT_EPOCH_KEY}) so the stream
|
|
725
|
-
* handler's consumer-side trip binds to the run that produced the event
|
|
726
|
-
* rather than whichever controller is live when a straggling chunk is
|
|
727
|
-
* finally handled. */
|
|
728
512
|
breakerEpoch = 0;
|
|
729
|
-
/** Immutable snapshot of the run's breaker identity (epoch + controller),
|
|
730
|
-
* replaced as ONE object whenever `resetValues` installs a fresh
|
|
731
|
-
* controller. Sites that pause across awaits capture it at entry and
|
|
732
|
-
* revalidate by REFERENCE afterwards — a single identity comparison
|
|
733
|
-
* proves no reset happened while suspended, where separate epoch and
|
|
734
|
-
* controller reads could interleave with one. */
|
|
735
513
|
runScope = Object.freeze({
|
|
736
514
|
epoch: 0,
|
|
737
515
|
controller: this.breakerAbort
|
|
738
516
|
});
|
|
739
|
-
/** Generation keys of model attempts still in flight (see
|
|
740
|
-
* `StreamLimitState.activeStreamLimitGenerations`). Lazily created by the
|
|
741
|
-
* attempt lease; spans resets on purpose. */
|
|
742
517
|
activeStreamLimitGenerations;
|
|
743
|
-
/** The stream-limit error behind an already-fired breaker, whether this
|
|
744
|
-
* graph's own controller tripped or a parent run's breaker arrived through
|
|
745
|
-
* the composed constructor signal (child graphs own separate controllers).
|
|
746
|
-
* Providers can translate either abort into a generic error, and recovery
|
|
747
|
-
* paths must not run in that state. */
|
|
748
518
|
resolveTrippedBreakerReason(breakerSignal = this.breakerAbort.signal) {
|
|
749
519
|
if (breakerSignal.aborted && breakerSignal.reason instanceof require_streamLimits.StreamLimitExceededError) return breakerSignal.reason;
|
|
750
520
|
if (this.signal?.aborted === true && this.signal.reason instanceof require_streamLimits.StreamLimitExceededError) return this.signal.reason;
|
|
751
521
|
}
|
|
752
|
-
/**
|
|
753
|
-
* Seals charged against `preemption.maxSeals`. Per-turn: cleared by both
|
|
754
|
-
* reset paths so a fresh turn gets a fresh budget, while a HITL resume —
|
|
755
|
-
* which skips `resetValues` — keeps what it had left.
|
|
756
|
-
*/
|
|
757
522
|
preemptSealBudgetUsed = 0;
|
|
758
|
-
/**
|
|
759
|
-
* Seals honored over the graph's lifetime. Reported by
|
|
760
|
-
* {@link getPreemptStats}, so it deliberately SURVIVES `clearHeavyState()`
|
|
761
|
-
* — a host reads it after `processStream` returns, which is strictly after
|
|
762
|
-
* cleanup runs.
|
|
763
|
-
*/
|
|
764
523
|
preemptSealCount = 0;
|
|
765
|
-
/** Boundaries that produced nothing to inject, so the turn stopped early. */
|
|
766
524
|
preemptEmptyBoundaries = 0;
|
|
767
|
-
/**
|
|
768
|
-
* Set between claiming a seal and resolving its boundary. `MultiAgentGraph`
|
|
769
|
-
* fans parallel agents through this one instance against a single host
|
|
770
|
-
* request, so without a one-at-a-time gate several streams would each seal
|
|
771
|
-
* for the same queued message and every loser would take the
|
|
772
|
-
* nothing-to-inject path and cut its answer short.
|
|
773
|
-
*/
|
|
774
525
|
preemptSealInFlight = false;
|
|
775
|
-
/**
|
|
776
|
-
* True when a seal ended the turn without a resume. The assistant turn is
|
|
777
|
-
* real and kept, but it is not the answer the model intended to finish —
|
|
778
|
-
* hosts persist it as unfinished rather than complete.
|
|
779
|
-
*/
|
|
780
526
|
preemptIncomplete = false;
|
|
781
|
-
/**
|
|
782
|
-
* `stopReason` from a `PreemptBoundary` hook that halted the turn.
|
|
783
|
-
*
|
|
784
|
-
* Clearing the registry halt is what keeps the sealed turn alive, but the
|
|
785
|
-
* registry held the only copy of the reason — so it is captured here first.
|
|
786
|
-
* Without it `getHaltReason()` returns undefined and a host records a
|
|
787
|
-
* hook-halted turn as an ordinary completion.
|
|
788
|
-
*/
|
|
789
527
|
preemptHaltReason;
|
|
790
|
-
/**
|
|
791
|
-
* Agent IDs whose next superstep must return to the agent node. Keyed by
|
|
792
|
-
* agent because `MultiAgentGraph` routes every parallel agent through this
|
|
793
|
-
* same instance, and a single field would let one agent's boundary resume
|
|
794
|
-
* another's turn.
|
|
795
|
-
*/
|
|
796
528
|
pendingPreemptReturn = /* @__PURE__ */ new Set();
|
|
797
529
|
constructor({ runId, signal, agents, langfuse, tokenCounter, indexTokenCountMap, calibrationRatio, subagentUsageSink, subagentScope, subagentExecutionContext, preemption, streamLimits }, dependencies) {
|
|
798
530
|
super();
|
|
@@ -830,12 +562,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
830
562
|
this.contentIndexMap = require_graph.resetIfNotEmpty(this.contentIndexMap, /* @__PURE__ */ new Map());
|
|
831
563
|
}
|
|
832
564
|
this.stepKeyIds = require_graph.resetIfNotEmpty(this.stepKeyIds, /* @__PURE__ */ new Map());
|
|
833
|
-
/**
|
|
834
|
-
* Clear in-place instead of replacing with a new Map to preserve the
|
|
835
|
-
* shared reference held by ToolNode (passed at construction time).
|
|
836
|
-
* Using resetIfNotEmpty would create a new Map, leaving ToolNode with
|
|
837
|
-
* a stale reference on 2nd+ processStream calls.
|
|
838
|
-
*/
|
|
839
565
|
this.toolCallStepIds.clear();
|
|
840
566
|
this.pendingToolCallsByStep.clear();
|
|
841
567
|
this.latestCompletionByStep.clear();
|
|
@@ -845,22 +571,9 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
845
571
|
this.clearEagerEventToolUsageCounts();
|
|
846
572
|
this.eagerEventToolCallChunks.clear();
|
|
847
573
|
this.eagerEventToolSuppressions.clear();
|
|
848
|
-
/** Grace sweep instead of a clear: producer loops of straggling
|
|
849
|
-
* attempts use these maps directly and sit outside the consumer-only
|
|
850
|
-
* epoch gate — clearing would hand a cancellation-ignoring provider a
|
|
851
|
-
* fresh allowance at every run start. Entries from the epoch that is
|
|
852
|
-
* ending survive exactly one reset so those stragglers stay on their
|
|
853
|
-
* original budgets; older entries are removed. */
|
|
854
574
|
require_streamLimits.sweepStaleStreamLimitEntries(this.streamedToolCallArgTallies, this.breakerEpoch, this.activeStreamLimitGenerations);
|
|
855
575
|
require_streamLimits.sweepStaleStreamLimitEntries(this.streamDeltaEventCounts, this.breakerEpoch, this.activeStreamLimitGenerations);
|
|
856
576
|
this.streamLimitChargeCredits = void 0;
|
|
857
|
-
/** Run-start is the only safe replacement point for the breaker:
|
|
858
|
-
* end-of-run cleanup must leave it in place so straggling parallel
|
|
859
|
-
* children from the failed run cannot start on a fresh signal.
|
|
860
|
-
* Replaced UNCONDITIONALLY here — a run that failed on an ordinary
|
|
861
|
-
* error leaves the controller un-aborted, and stragglers still settling
|
|
862
|
-
* hold their entry-time capture of it; a late stream-limit trip on that
|
|
863
|
-
* old controller must not cancel the run starting now. */
|
|
864
577
|
this.breakerAbort = new AbortController();
|
|
865
578
|
this.breakerEpoch += 1;
|
|
866
579
|
this.runScope = Object.freeze({
|
|
@@ -882,7 +595,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
882
595
|
for (const context of this.agentContexts.values()) context.reset({ preserveOriginalToolContent });
|
|
883
596
|
this.originalToolContentCheckpointScope = hasScopedCheckpoint ? checkpointScope : void 0;
|
|
884
597
|
}
|
|
885
|
-
/** Seeds the sidecar message view that checkpoint restoration bypasses. */
|
|
886
598
|
restoreCheckpointMessages(messages, pendingMessages) {
|
|
887
599
|
if (this.messages.length > 0) return;
|
|
888
600
|
this.messages = pendingMessages == null ? [...messages] : require_reducer.messagesStateReducer(messages, pendingMessages);
|
|
@@ -897,96 +609,28 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
897
609
|
this.messages = [];
|
|
898
610
|
this.overrideModel = void 0;
|
|
899
611
|
this.subagentModelOverride = void 0;
|
|
900
|
-
/** Stream-limit accounting (argument tallies, event counts, charge
|
|
901
|
-
* credits) deliberately SURVIVES cleanup: this runs in `processStream`'s
|
|
902
|
-
* finally, which an ordinary parallel-branch failure reaches while
|
|
903
|
-
* sibling attempts are still unwinding on the retained breaker — a
|
|
904
|
-
* cancellation-ignoring provider's late chunks would otherwise recreate
|
|
905
|
-
* their budgets from zero and stream another full allowance. The maps
|
|
906
|
-
* are bounded by in-flight call sizes and `resetValues` clears them at
|
|
907
|
-
* the next run start, where the epoch bump already drops stamped
|
|
908
|
-
* straggler events before accounting. */
|
|
909
|
-
/** Deliberately NOT recreating a tripped breakerAbort here: this runs in
|
|
910
|
-
* `processStream`'s cleanup, which a rejected parallel batch reaches
|
|
911
|
-
* while sibling subagents can still be pre-invoke — a fresh controller
|
|
912
|
-
* would hand them an un-aborted signal and let provider requests start
|
|
913
|
-
* after the run already failed. `resetValues` recreates it when the next
|
|
914
|
-
* run begins. */
|
|
915
|
-
/**
|
|
916
|
-
* Turn state only. The reported totals must outlive cleanup — this runs
|
|
917
|
-
* in `processStream`'s `finally`, and the host reads `getPreemptStats()`
|
|
918
|
-
* after that returns.
|
|
919
|
-
*/
|
|
920
612
|
this.resetPreemptTurnState();
|
|
921
613
|
const preserveOriginalToolContent = this.hasCompiledCheckpointer && this.originalToolContentCheckpointScope != null;
|
|
922
614
|
for (const context of this.agentContexts.values()) context.reset({ preserveOriginalToolContent });
|
|
923
615
|
}
|
|
924
|
-
/**
|
|
925
|
-
* Per-turn seal budget and routing markers. Cleared by both reset paths so
|
|
926
|
-
* a new turn starts with a full budget and no stale resume marker.
|
|
927
|
-
*
|
|
928
|
-
* The REPORTED counters are deliberately not touched here — see
|
|
929
|
-
* {@link resetPreemptTotals}.
|
|
930
|
-
*/
|
|
931
616
|
resetPreemptTurnState() {
|
|
932
617
|
this.preemptSealBudgetUsed = 0;
|
|
933
618
|
this.preemptSealInFlight = false;
|
|
934
619
|
this.pendingPreemptReturn.clear();
|
|
935
620
|
}
|
|
936
|
-
/**
|
|
937
|
-
* Lifetime seal totals, cleared only when a genuinely new run starts.
|
|
938
|
-
* `clearHeavyState()` must NOT call this: it runs in `processStream`'s
|
|
939
|
-
* `finally`, so zeroing here would make {@link getPreemptStats} and
|
|
940
|
-
* `preemptIncomplete` unreadable for every caller of the method that just
|
|
941
|
-
* produced them.
|
|
942
|
-
*/
|
|
943
621
|
resetPreemptTotals() {
|
|
944
622
|
this.preemptSealCount = 0;
|
|
945
623
|
this.preemptEmptyBoundaries = 0;
|
|
946
624
|
this.preemptIncomplete = false;
|
|
947
625
|
this.preemptHaltReason = void 0;
|
|
948
626
|
}
|
|
949
|
-
/**
|
|
950
|
-
* True when the host has requested a cooperative seal AND this graph may
|
|
951
|
-
* honor it. Read once per streamed chunk, so it stays property reads plus
|
|
952
|
-
* one host callback — no I/O, no allocation.
|
|
953
|
-
*
|
|
954
|
-
* Non-mutating: a true result only means a seal is worth evaluating. The
|
|
955
|
-
* budget is taken by {@link claimPreemptSeal} once the accumulated chunk is
|
|
956
|
-
* known to be safe, so a chunk that cannot seal never spends budget.
|
|
957
|
-
*
|
|
958
|
-
* Subagent scopes never seal: a steer targets the top-level conversation,
|
|
959
|
-
* and a child run must finish so its parent sees a complete result.
|
|
960
|
-
*/
|
|
961
|
-
/** Internal seal preconditions only — no host callback, no side effects. */
|
|
962
627
|
canClaimPreemptSeal() {
|
|
963
|
-
/**
|
|
964
|
-
* Resolved and required here with the same rule `dispatchPreemptBoundary`
|
|
965
|
-
* uses. Without it a direct `StandardGraph` consumer that supplies no
|
|
966
|
-
* `runId` could claim a seal on the strength of a global matcher, then hit
|
|
967
|
-
* the boundary's own null-runId guard and get nothing back — truncating
|
|
968
|
-
* the answer for a drain that provably could not run.
|
|
969
|
-
*/
|
|
970
628
|
const runId = this.config?.configurable?.run_id ?? this.runId;
|
|
971
629
|
return !this.subagentScope && this.preemption != null && !this.preemptSealInFlight && this.preemptSealBudgetUsed < require_preempt.resolveMaxSeals(this.preemption.maxSeals) && runId != null && this.hookRegistry?.hasDispatchableHookFor("PreemptBoundary", runId) === true;
|
|
972
630
|
}
|
|
973
631
|
shouldPreemptStream() {
|
|
974
632
|
return this.canClaimPreemptSeal() && this.preemption?.shouldPreempt() === true;
|
|
975
633
|
}
|
|
976
|
-
/**
|
|
977
|
-
* Takes the seal slot, or returns false if another stream already holds it.
|
|
978
|
-
*
|
|
979
|
-
* Assumes the caller already polled `shouldPreemptStream()` for THIS chunk,
|
|
980
|
-
* and deliberately does not poll the host again — `StreamPreemption`
|
|
981
|
-
* documents `shouldPreempt` as once per chunk, and a host that consumes a
|
|
982
|
-
* pending flag on read would lose the request to a second call.
|
|
983
|
-
*
|
|
984
|
-
* The guard and both mutations remain one synchronous body, which is what
|
|
985
|
-
* makes this safe under a parallel `MultiAgentGraph`: several agents share
|
|
986
|
-
* one graph and can each see the poll as true, but no `await` can split the
|
|
987
|
-
* claim, so only one takes the slot. The loser keeps streaming normally
|
|
988
|
-
* rather than sealing for a message it would never receive.
|
|
989
|
-
*/
|
|
990
634
|
claimPreemptSeal() {
|
|
991
635
|
if (!this.canClaimPreemptSeal()) return false;
|
|
992
636
|
this.preemptSealInFlight = true;
|
|
@@ -994,7 +638,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
994
638
|
this.preemptSealCount += 1;
|
|
995
639
|
return true;
|
|
996
640
|
}
|
|
997
|
-
/** Releases the seal slot once its boundary has resolved, win or lose. */
|
|
998
641
|
releasePreemptSeal() {
|
|
999
642
|
this.preemptSealInFlight = false;
|
|
1000
643
|
}
|
|
@@ -1008,13 +651,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1008
651
|
const index = this.contentIndexMap.get(stepId);
|
|
1009
652
|
if (index !== void 0) return this.contentData[index];
|
|
1010
653
|
}
|
|
1011
|
-
/**
|
|
1012
|
-
* Derives the same lane key `dispatchRunStep` stamps as `runStep.agentId`.
|
|
1013
|
-
* The multi-agent check gates the lookup because `getAgentContext` signals
|
|
1014
|
-
* a miss by throwing: single-agent graphs key every step under `''`, so
|
|
1015
|
-
* resolving the context could only ever produce a thrown-and-discarded
|
|
1016
|
-
* Error on a per-model-call path.
|
|
1017
|
-
*/
|
|
1018
654
|
getStepAgentKey(metadata) {
|
|
1019
655
|
if (!metadata || !this.isMultiAgentGraph()) return "";
|
|
1020
656
|
try {
|
|
@@ -1023,72 +659,25 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1023
659
|
} catch (_e) {}
|
|
1024
660
|
return "";
|
|
1025
661
|
}
|
|
1026
|
-
/**
|
|
1027
|
-
* O(1) reverse lookup: both dispatch funnels key the open-message map by
|
|
1028
|
-
* `runStep.agentId ?? ''`, so the entry is addressable without scanning.
|
|
1029
|
-
*/
|
|
1030
662
|
untrackRunStep(runStep) {
|
|
1031
663
|
this.pendingToolCallsByStep.delete(runStep.id);
|
|
1032
664
|
this.latestCompletionByStep.delete(runStep.id);
|
|
1033
665
|
const agentKey = runStep.agentId ?? "";
|
|
1034
666
|
if (this.openMessageStepByAgent.get(agentKey) === runStep.id) this.openMessageStepByAgent.delete(agentKey);
|
|
1035
667
|
}
|
|
1036
|
-
/**
|
|
1037
|
-
* Shared step accounting for both dispatch funnels: a successor step in
|
|
1038
|
-
* the same agent lane marks the previous message step as finished — its
|
|
1039
|
-
* CLOSED event must precede the successor's ON_RUN_STEP so hosts observe
|
|
1040
|
-
* a consistent open-step timeline — then the step is registered in the
|
|
1041
|
-
* content maps and tracked as the lane's open message step when
|
|
1042
|
-
* applicable.
|
|
1043
|
-
*/
|
|
1044
668
|
async trackDispatchedRunStep(runStep, metadata, trackAsOpenMessageStep = true) {
|
|
1045
669
|
const agentKey = runStep.agentId ?? "";
|
|
1046
670
|
const openMessageStepId = this.openMessageStepByAgent.get(agentKey);
|
|
1047
|
-
/**
|
|
1048
|
-
* Reserve the content index and register the step SYNCHRONOUSLY, before
|
|
1049
|
-
* awaiting the predecessor's closure. Parallel agent lanes dispatch
|
|
1050
|
-
* successors concurrently: if both yielded here first, they would push
|
|
1051
|
-
* with the same `contentData.length` and `contentIndexMap` would resolve
|
|
1052
|
-
* one step id to the other lane's entry, so later deltas and completions
|
|
1053
|
-
* would mutate the wrong agent's step. Assigning the index at push time
|
|
1054
|
-
* also supersedes whatever the caller computed before this await point.
|
|
1055
|
-
*/
|
|
1056
671
|
runStep.index = this.contentData.length;
|
|
1057
672
|
this.contentData.push(runStep);
|
|
1058
673
|
this.contentIndexMap.set(runStep.id, runStep.index);
|
|
1059
674
|
if (trackAsOpenMessageStep && runStep.type === "message_creation") this.openMessageStepByAgent.set(agentKey, runStep.id);
|
|
1060
675
|
else this.openMessageStepByAgent.delete(agentKey);
|
|
1061
|
-
|
|
1062
|
-
* Awaited after registration but before the caller dispatches this step's
|
|
1063
|
-
* ON_RUN_STEP, so the predecessor's CLOSED event still precedes the
|
|
1064
|
-
* successor's start event.
|
|
1065
|
-
*/
|
|
1066
|
-
if (openMessageStepId != null && openMessageStepId !== runStep.id)
|
|
1067
|
-
/**
|
|
1068
|
-
* Isolated: this step is already registered in `contentData`, so a
|
|
1069
|
-
* predecessor delivery failure rejecting here would abort the caller
|
|
1070
|
-
* before it publishes this step's ON_RUN_STEP — leaving the sweep to
|
|
1071
|
-
* emit a terminal event for a step that never announced a start.
|
|
1072
|
-
*/
|
|
1073
|
-
try {
|
|
676
|
+
if (openMessageStepId != null && openMessageStepId !== runStep.id) try {
|
|
1074
677
|
await this.closeRunStep(openMessageStepId, "completed", { metadata });
|
|
1075
678
|
} catch (_e) {}
|
|
1076
|
-
/**
|
|
1077
|
-
* Stamped last, after the predecessor's closure has been delivered and
|
|
1078
|
-
* immediately before the caller publishes this step's ON_RUN_STEP.
|
|
1079
|
-
* `created_at` documents when the step was dispatched, so it must not
|
|
1080
|
-
* absorb the latency of an arbitrarily slow predecessor handler.
|
|
1081
|
-
*/
|
|
1082
679
|
runStep.created_at = Date.now();
|
|
1083
680
|
}
|
|
1084
|
-
/**
|
|
1085
|
-
* Closes a run step: stamps its terminal status + timestamp on the stored
|
|
1086
|
-
* `RunStep` and emits `ON_RUN_STEP_CLOSED`. First close wins — later calls
|
|
1087
|
-
* are no-ops — except a `restamp` close, which lets a `completed`
|
|
1088
|
-
* TOOL_CALLS step refresh `completed_at` when a late-registered parallel
|
|
1089
|
-
* tool call finishes after the step already closed (the eager-execution
|
|
1090
|
-
* race). `cancelled`/`failed` are immutable once stamped.
|
|
1091
|
-
*/
|
|
1092
681
|
async closeRunStep(stepId, status, options) {
|
|
1093
682
|
if (!stepId) return false;
|
|
1094
683
|
const runStep = this.getRunStep(stepId);
|
|
@@ -1128,12 +717,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1128
717
|
}
|
|
1129
718
|
return true;
|
|
1130
719
|
}
|
|
1131
|
-
/**
|
|
1132
|
-
* Observes one `ON_RUN_STEP_COMPLETED` for a step and closes the step when
|
|
1133
|
-
* no registered tool calls remain pending. Steps without pending tracking
|
|
1134
|
-
* (summaries, cross-process resume) close on their first completion; the
|
|
1135
|
-
* terminal-status guard in `closeRunStep` absorbs duplicate echoes.
|
|
1136
|
-
*/
|
|
1137
720
|
async recordStepCompletion(stepId, options) {
|
|
1138
721
|
if (!stepId) return;
|
|
1139
722
|
const { toolCallId, metadata, at } = options ?? {};
|
|
@@ -1157,12 +740,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1157
740
|
at: closeAt
|
|
1158
741
|
});
|
|
1159
742
|
}
|
|
1160
|
-
/**
|
|
1161
|
-
* Closes the tracked open MESSAGE_CREATION step for the event's agent lane.
|
|
1162
|
-
* Fires on every model end, so the empty-map check short-circuits ahead of
|
|
1163
|
-
* resolving the lane key — a turn whose message step already closed through
|
|
1164
|
-
* successor-close does no work here.
|
|
1165
|
-
*/
|
|
1166
743
|
async closeOpenMessageStep(metadata, at) {
|
|
1167
744
|
if (this.openMessageStepByAgent.size === 0) return;
|
|
1168
745
|
const agentKey = this.getStepAgentKey(metadata);
|
|
@@ -1173,23 +750,10 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1173
750
|
at
|
|
1174
751
|
});
|
|
1175
752
|
}
|
|
1176
|
-
/**
|
|
1177
|
-
* End-of-run sweep: closes every step that never reached a terminal
|
|
1178
|
-
* status. Dual-dispatches like any other close — the custom-event channel
|
|
1179
|
-
* is usually already torn down here and `safeDispatchCustomEvent` reports
|
|
1180
|
-
* that quietly, but callback-only subscribers still receive the terminal
|
|
1181
|
-
* signal whenever it is alive.
|
|
1182
|
-
*/
|
|
1183
753
|
async closeUnfinishedRunSteps(status, at) {
|
|
1184
754
|
const closedAt = at ?? Date.now();
|
|
1185
755
|
for (const runStep of this.contentData) {
|
|
1186
756
|
if (runStep.status != null && runStep.status !== "in_progress") continue;
|
|
1187
|
-
/**
|
|
1188
|
-
* Isolated per step: one host handler throwing must not strand the
|
|
1189
|
-
* remaining steps `in_progress` with no terminal event. The step is
|
|
1190
|
-
* stamped before dispatch either way, so a thrown handler still leaves
|
|
1191
|
-
* consistent state behind.
|
|
1192
|
-
*/
|
|
1193
757
|
try {
|
|
1194
758
|
await this.closeRunStep(runStep.id, status, { at: closedAt });
|
|
1195
759
|
} catch (_e) {}
|
|
@@ -1273,9 +837,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1273
837
|
return keyList.some((key) => key === void 0);
|
|
1274
838
|
}
|
|
1275
839
|
getRunMessages() {
|
|
1276
|
-
/** Runtime-honest widening: a disposed-but-cached graph (HITL
|
|
1277
|
-
* resume/reconnect through a WeakRef cache) can carry null here despite
|
|
1278
|
-
* the field type. */
|
|
1279
840
|
const messages = this.messages;
|
|
1280
841
|
if (messages == null) return this.cachedRunMessages;
|
|
1281
842
|
if (messages.length === 0 && this.cachedRunMessages != null) return this.cachedRunMessages;
|
|
@@ -1292,16 +853,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1292
853
|
if (discoveredTools.size === 0 && this.cachedDiscoveredTools != null) for (const snapshot of this.cachedDiscoveredTools.values()) for (const toolName of snapshot) discoveredTools.add(toolName);
|
|
1293
854
|
return Array.from(discoveredTools);
|
|
1294
855
|
}
|
|
1295
|
-
/**
|
|
1296
|
-
* True when THIS RUN produced `message` — the provenance the handoff cue
|
|
1297
|
-
* gate needs. Tracked as an id set rather than inferred from `startIndex`
|
|
1298
|
-
* arithmetic: summarization's remove-all compaction rewrites the live
|
|
1299
|
-
* array and leaves `startIndex` stale, so index-based run/host
|
|
1300
|
-
* discrimination silently breaks right after a mid-run summarize. Ids
|
|
1301
|
-
* survive compaction (retained messages keep theirs), host-supplied
|
|
1302
|
-
* prefill messages are never in the set, and membership is O(1) per
|
|
1303
|
-
* model call.
|
|
1304
|
-
*/
|
|
1305
856
|
isRunProducedMessage(message) {
|
|
1306
857
|
const id = message.id;
|
|
1307
858
|
return typeof id === "string" && id !== "" && this.runProducedAiMessageIds.has(id);
|
|
@@ -1321,18 +872,12 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1321
872
|
const context = this.agentContexts.get(this.defaultAgentId);
|
|
1322
873
|
return (context?.tools?.length ?? 0) + (context?.toolDefinitions?.length ?? 0) + (context?.graphTools?.length ?? 0);
|
|
1323
874
|
}
|
|
1324
|
-
/**
|
|
1325
|
-
* Get all run steps, optionally filtered by agent ID
|
|
1326
|
-
*/
|
|
1327
875
|
getRunSteps(agentId) {
|
|
1328
876
|
const contentData = this.contentData;
|
|
1329
877
|
if (contentData == null) return [];
|
|
1330
878
|
if (agentId == null || agentId === "") return [...contentData];
|
|
1331
879
|
return contentData.filter((step) => step.agentId === agentId);
|
|
1332
880
|
}
|
|
1333
|
-
/**
|
|
1334
|
-
* Get run steps grouped by agent ID
|
|
1335
|
-
*/
|
|
1336
881
|
getRunStepsByAgent() {
|
|
1337
882
|
const stepsByAgent = /* @__PURE__ */ new Map();
|
|
1338
883
|
for (const step of this.contentData) {
|
|
@@ -1343,18 +888,11 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1343
888
|
}
|
|
1344
889
|
return stepsByAgent;
|
|
1345
890
|
}
|
|
1346
|
-
/**
|
|
1347
|
-
* Get agent IDs that participated in this run
|
|
1348
|
-
*/
|
|
1349
891
|
getActiveAgentIds() {
|
|
1350
892
|
const agentIds = /* @__PURE__ */ new Set();
|
|
1351
893
|
for (const step of this.contentData) if (step.agentId != null && step.agentId !== "") agentIds.add(step.agentId);
|
|
1352
894
|
return Array.from(agentIds);
|
|
1353
895
|
}
|
|
1354
|
-
/**
|
|
1355
|
-
* Maps contentPart indices to agent IDs for post-run analysis
|
|
1356
|
-
* Returns a map where key is the contentPart index and value is the agentId
|
|
1357
|
-
*/
|
|
1358
896
|
getContentPartAgentMap() {
|
|
1359
897
|
const contentPartAgentMap = /* @__PURE__ */ new Map();
|
|
1360
898
|
for (const step of this.contentData) if (step.agentId != null && step.agentId !== "" && Number.isFinite(step.index)) contentPartAgentMap.set(step.index, step.agentId);
|
|
@@ -1454,7 +992,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1454
992
|
toolCalls
|
|
1455
993
|
});
|
|
1456
994
|
}
|
|
1457
|
-
/** Explicitly overrides the model used by isolated descendant subagent graphs. */
|
|
1458
995
|
setSubagentModelOverride(model) {
|
|
1459
996
|
this.subagentModelOverride = model;
|
|
1460
997
|
}
|
|
@@ -1470,23 +1007,8 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1470
1007
|
this.signal.removeEventListener("abort", client.abortHandler);
|
|
1471
1008
|
client.abortHandler = void 0;
|
|
1472
1009
|
}
|
|
1473
|
-
/**
|
|
1474
|
-
* Applies a context-overflow recovery plan and hands control to the
|
|
1475
|
-
* summarize node, which compacts and then routes straight back here for a
|
|
1476
|
-
* retry against the corrected budget.
|
|
1477
|
-
*
|
|
1478
|
-
* Returning the detour rather than rethrowing is the whole point: the
|
|
1479
|
-
* caller never sees the provider's rejection, only a slightly longer turn.
|
|
1480
|
-
*/
|
|
1481
1010
|
beginOverflowRecovery({ recovery, agentContext, agentId, config, originalToolContent, estimatedPromptTokens }) {
|
|
1482
1011
|
const previousBudget = agentContext.maxContextTokens;
|
|
1483
|
-
/**
|
|
1484
|
-
* Deterministic compaction first. Re-pruning against the corrected budget
|
|
1485
|
-
* raises context pressure, which is what drives the pruner's tool-output
|
|
1486
|
-
* truncation and observation masking — no model call, no cost, and no
|
|
1487
|
-
* message content lost. A summarization call is held back until that has
|
|
1488
|
-
* been tried and the provider rejected the prompt again.
|
|
1489
|
-
*/
|
|
1490
1012
|
const allowSummarization = agentContext.shouldSummarizeOverflow();
|
|
1491
1013
|
agentContext.preserveOriginalToolContent(originalToolContent);
|
|
1492
1014
|
agentContext.applyContextBudgetCorrection(recovery.budgetTokens, estimatedPromptTokens);
|
|
@@ -1515,37 +1037,13 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1515
1037
|
}
|
|
1516
1038
|
createCallModel(agentId = "default") {
|
|
1517
1039
|
return async (state, config) => {
|
|
1518
|
-
/** Captured at node ENTRY, before any host-facing await (context-usage
|
|
1519
|
-
* dispatch, hooks): a sibling's trip can fail the run and a prompt
|
|
1520
|
-
* next run can reset the controller while this node is paused in one
|
|
1521
|
-
* of those awaits, and a later capture would bind this attempt to the
|
|
1522
|
-
* fresh controller. Trips and reason reads below stay on this
|
|
1523
|
-
* capture. */
|
|
1524
1040
|
const attemptBreaker = this.breakerAbort;
|
|
1525
1041
|
const attemptBreakerEpoch = this.breakerEpoch;
|
|
1526
|
-
/** Already-tripped-at-entry: a parallel sibling's breach has failed
|
|
1527
|
-
* the run before this node was scheduled. Rethrow before hooks or the
|
|
1528
|
-
* provider call — a custom provider that doesn't synchronously reject
|
|
1529
|
-
* an aborted signal would otherwise start another model request on a
|
|
1530
|
-
* failed run. */
|
|
1531
1042
|
const entryTripReason = this.resolveTrippedBreakerReason(attemptBreaker.signal);
|
|
1532
1043
|
if (entryTripReason != null) throw entryTripReason;
|
|
1533
1044
|
const agentContext = this.agentContexts.get(agentId);
|
|
1534
1045
|
if (!agentContext) throw new Error(`Agent context not found for agentId: ${agentId}`);
|
|
1535
1046
|
if (!config) throw new Error("No config provided");
|
|
1536
|
-
/**
|
|
1537
|
-
* A `PreemptBoundary` hook halted this run and the sealed commit is
|
|
1538
|
-
* already in state. Enforced at every model node's ENTRY because that
|
|
1539
|
-
* is the only site that covers all of `MultiAgentGraph`'s onward
|
|
1540
|
-
* routing at once — static direct edges, Command fan-out, fan-in
|
|
1541
|
-
* wrappers, and parallel siblings' subsequent inner-loop turns — none
|
|
1542
|
-
* of which consult the halt (the registry signal was deliberately
|
|
1543
|
-
* cleared to keep the stream-cancel from destroying the sealed turn).
|
|
1544
|
-
* Declining the model call turns every routed-to successor into a
|
|
1545
|
-
* no-op, so the outer workflow drains to END without new turns or tool
|
|
1546
|
-
* side effects. Reset per turn in `resetPreemptTotals`, so the next
|
|
1547
|
-
* `processStream` call starts clean.
|
|
1548
|
-
*/
|
|
1549
1047
|
if (this.preemptHaltReason != null) return { messages: [] };
|
|
1550
1048
|
const { messages } = state;
|
|
1551
1049
|
const discoveredNames = require_tools.extractToolDiscoveries(messages);
|
|
@@ -1554,19 +1052,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1554
1052
|
tools: agentContext.getToolsForBinding(),
|
|
1555
1053
|
toolExecution: this.toolExecution
|
|
1556
1054
|
});
|
|
1557
|
-
/**
|
|
1558
|
-
* Anthropic prompt-cache breakpoint on the tool definitions.
|
|
1559
|
-
*
|
|
1560
|
-
* Without this, the (often static) tool inventory shows up as
|
|
1561
|
-
* fresh input on every turn — measured at ~28k tokens/turn for
|
|
1562
|
-
* the local engine's coding-tool bundle, dominating per-turn
|
|
1563
|
-
* cost even when message-level caching is on.
|
|
1564
|
-
*
|
|
1565
|
-
* Strategy: partition tools into [static, deferred] and stamp
|
|
1566
|
-
* `cache_control: ephemeral` on the last static tool.
|
|
1567
|
-
* Discovered deferred tools that arrive across turns sit *after*
|
|
1568
|
-
* the breakpoint and don't invalidate the prefix.
|
|
1569
|
-
*/
|
|
1570
1055
|
let toolsForBinding = rawToolsForBinding;
|
|
1571
1056
|
if (agentContext.provider === "anthropic" && agentContext.clientOptions?.promptCache === true) toolsForBinding = require_anthropicToolCache.partitionAndMarkAnthropicToolCache(rawToolsForBinding, require_anthropicToolCache.makeIsDeferred(agentContext.toolDefinitions), require_cache.resolvePromptCacheTtl(agentContext.clientOptions?.promptCacheTtl)) ?? rawToolsForBinding;
|
|
1572
1057
|
else if (agentContext.provider === "openrouter" && agentContext.clientOptions?.promptCache === true) toolsForBinding = require_toolCache$1.partitionAndMarkOpenRouterToolCache(rawToolsForBinding, require_anthropicToolCache.makeIsDeferred(agentContext.toolDefinitions), require_cache.resolvePromptCacheTtl(agentContext.clientOptions?.promptCacheTtl)) ?? rawToolsForBinding;
|
|
@@ -1585,11 +1070,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1585
1070
|
this.config = config;
|
|
1586
1071
|
let messagesToUse = messages;
|
|
1587
1072
|
let contextUsage = null;
|
|
1588
|
-
/**
|
|
1589
|
-
* Held outside the prune block so overflow recovery — which detours to
|
|
1590
|
-
* the summarize node from the invoke catch below — can preserve the
|
|
1591
|
-
* same masking record the configured trigger preserves.
|
|
1592
|
-
*/
|
|
1593
1073
|
let prunedOriginalToolContent;
|
|
1594
1074
|
if (!agentContext.pruneMessages && agentContext.tokenCounter && agentContext.maxContextTokens != null) agentContext.pruneMessages = require_prune.createPruneMessages({
|
|
1595
1075
|
startIndex: agentContext.indexTokenCountMap[0] != null ? this.startIndex : 0,
|
|
@@ -1619,14 +1099,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1619
1099
|
totalTokensFresh: agentContext.totalTokensFresh
|
|
1620
1100
|
});
|
|
1621
1101
|
prunedOriginalToolContent = newOriginalToolContent;
|
|
1622
|
-
/**
|
|
1623
|
-
* Masking rewrites tool content in `state.messages` in place, so this
|
|
1624
|
-
* map is the only surviving copy of the full output. Persist it on
|
|
1625
|
-
* every prune, not just when a summary is about to be written — the
|
|
1626
|
-
* pruner closure that produced it is discarded on the next reset, and
|
|
1627
|
-
* with it any chance of a later summary restoring the real content.
|
|
1628
|
-
* AgentContext bounds what accumulates.
|
|
1629
|
-
*/
|
|
1630
1102
|
agentContext.preserveOriginalToolContent(newOriginalToolContent);
|
|
1631
1103
|
agentContext.indexTokenCountMap = indexTokenCountMap;
|
|
1632
1104
|
if (calibrationRatio != null && calibrationRatio > 0) agentContext.calibrationRatio = calibrationRatio;
|
|
@@ -1637,21 +1109,10 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1637
1109
|
const currentToolTokens = agentContext.toolSchemaTokens;
|
|
1638
1110
|
if ((currentToolTokens > 0 ? Math.abs(calibratedToolTokens - currentToolTokens) / currentToolTokens : 1) > CALIBRATION_VARIANCE_THRESHOLD) {
|
|
1639
1111
|
agentContext.toolSchemaTokens = calibratedToolTokens;
|
|
1640
|
-
/** Largest-remainder apportionment keeps the per-tool breakdown
|
|
1641
|
-
* summing exactly to the calibrated aggregate */
|
|
1642
1112
|
if (agentContext.toolTokenCounts != null && currentToolTokens > 0) agentContext.toolTokenCounts = require_tokens.apportionTokenCounts(agentContext.toolTokenCounts, calibratedToolTokens / currentToolTokens, calibratedToolTokens);
|
|
1643
1113
|
}
|
|
1644
1114
|
}
|
|
1645
1115
|
messagesToUse = context;
|
|
1646
|
-
/** Dispatched right before the model invoke — a summarization
|
|
1647
|
-
* detour returns from this node without an LLM call, and the
|
|
1648
|
-
* post-summary retry produces its own snapshot.
|
|
1649
|
-
*
|
|
1650
|
-
* The breakdown describes the post-prune prompt: counts from the
|
|
1651
|
-
* kept context, message tokens derived from the same calibrated
|
|
1652
|
-
* budget math as `remainingContextTokens` (the index map is keyed
|
|
1653
|
-
* by pre-prune state indices, so summing it over `context` would
|
|
1654
|
-
* missum); `prePruneContextTokens` carries the pre-prune metric. */
|
|
1655
1116
|
const usageBreakdown = agentContext.getTokenBudgetBreakdown(messages);
|
|
1656
1117
|
usageBreakdown.messageCount = context.length;
|
|
1657
1118
|
contextUsage = {
|
|
@@ -1706,13 +1167,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1706
1167
|
}
|
|
1707
1168
|
}
|
|
1708
1169
|
let finalMessages = messagesToUse;
|
|
1709
|
-
/**
|
|
1710
|
-
* Keep the pruner's provider-grounded aggregate as the authoritative
|
|
1711
|
-
* baseline, then attribute it across retained messages. Provider
|
|
1712
|
-
* transforms can shrink one message while expanding or adding another;
|
|
1713
|
-
* per-origin accounting prevents that unrelated shrink from canceling
|
|
1714
|
-
* the expansion. Raw counts are frozen before in-place formatters run.
|
|
1715
|
-
*/
|
|
1716
1170
|
let providerMessageBaseline;
|
|
1717
1171
|
const providerMessageOrigins = /* @__PURE__ */ new WeakMap();
|
|
1718
1172
|
if (contextUsage != null && agentContext.tokenCounter != null) {
|
|
@@ -1735,11 +1189,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1735
1189
|
if (message instanceof _langchain_core_messages.ToolMessage && typeof message.tool_call_id === "string" && message.tool_call_id.length > 0) return `tool:call:${message.tool_call_id}`;
|
|
1736
1190
|
if (typeof message.id === "string" && message.id.length > 0) return `${type}:id:${message.id}`;
|
|
1737
1191
|
};
|
|
1738
|
-
/**
|
|
1739
|
-
* Provider projections clone messages. Preserve their baseline origin
|
|
1740
|
-
* without writing tracking metadata onto the wire. Synthetic fold
|
|
1741
|
-
* messages intentionally remain unattributed and are charged in full.
|
|
1742
|
-
*/
|
|
1743
1192
|
const trackProviderMessageOrigins = (before, after) => {
|
|
1744
1193
|
if (providerMessageBaseline == null || before === after) return after;
|
|
1745
1194
|
if (before.length === after.length) {
|
|
@@ -1851,17 +1300,9 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1851
1300
|
const applyProviderMessageTransforms = (candidate) => {
|
|
1852
1301
|
let transformed = candidate;
|
|
1853
1302
|
if (require_request.isThinkingEnabled(agentContext.provider, agentContext.clientOptions)) {
|
|
1854
|
-
/**
|
|
1855
|
-
* Current-run AI messages may validly omit a thinking block. The
|
|
1856
|
-
* boundary prevents them from being mistaken for foreign history.
|
|
1857
|
-
*/
|
|
1858
1303
|
const before = transformed;
|
|
1859
1304
|
transformed = trackProviderMessageOrigins(before, require_format.ensureThinkingBlockInMessages(before, agentContext.provider, config, this.startIndex));
|
|
1860
1305
|
}
|
|
1861
|
-
/**
|
|
1862
|
-
* Tool-less destinations cannot send inherited tool blocks without a
|
|
1863
|
-
* tool schema, so fold those interactions into provider-valid content.
|
|
1864
|
-
*/
|
|
1865
1306
|
if (toolsForBinding == null || toolsForBinding.length === 0) {
|
|
1866
1307
|
const before = transformed;
|
|
1867
1308
|
transformed = trackProviderMessageOrigins(before, require_format.foldToolBlocksForToollessAgent(before, config));
|
|
@@ -1870,15 +1311,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1870
1311
|
transformed = trackProviderMessageOrigins(beforeLegacyFormat, require_content.formatContentStrings(beforeLegacyFormat));
|
|
1871
1312
|
}
|
|
1872
1313
|
}
|
|
1873
|
-
/**
|
|
1874
|
-
* Applied HERE for the primary so the cue is part of the MEASURED
|
|
1875
|
-
* payload — the pre-invoke projection and overflow guard run on this
|
|
1876
|
-
* stage's output, and a post-measure append could push a just-fits
|
|
1877
|
-
* prompt over budget unreported (#346 round 2). The attemptInvoke
|
|
1878
|
-
* funnel re-keys per SERVING provider: it strips this cue for a
|
|
1879
|
-
* tolerant fallback and adds it for a Claude fallback behind a
|
|
1880
|
-
* tolerant primary.
|
|
1881
|
-
*/
|
|
1882
1314
|
if (require_llm.isAnthropicLike(agentContext.provider, agentContext.clientOptions)) {
|
|
1883
1315
|
const before = transformed;
|
|
1884
1316
|
transformed = trackProviderMessageOrigins(before, require_handoffCue.appendPredecessorHandoffCue(before, (message) => this.isRunProducedMessage(message)));
|
|
@@ -1977,42 +1409,7 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1977
1409
|
});
|
|
1978
1410
|
}
|
|
1979
1411
|
}
|
|
1980
|
-
/**
|
|
1981
|
-
* Mistral rejects consecutive user turns outright; Bedrock's Converse
|
|
1982
|
-
* API documents strict user/assistant alternation across its model
|
|
1983
|
-
* families, with enforcement varying by family (Claude on Converse
|
|
1984
|
-
* currently tolerates the shape — verified live — but the payload is
|
|
1985
|
-
* normalized for all of them rather than betting on leniency). Four
|
|
1986
|
-
* sites can emit them — the `PostToolBatch` and `PreemptBoundary` hook
|
|
1987
|
-
* boundaries (a consolidated context message followed by one
|
|
1988
|
-
* `HumanMessage` per injected entry), a queue drain carrying more than
|
|
1989
|
-
* one steer, and `run.ts`'s pre-stream context push onto a payload that
|
|
1990
|
-
* already ends on a user turn.
|
|
1991
|
-
*
|
|
1992
|
-
* Normalized here, at the last provider-facing hop, rather than at any
|
|
1993
|
-
* one boundary: the boundaries must keep per-message identity, because
|
|
1994
|
-
* `additional_kwargs.source`/`skillName` drive steer rendering and the
|
|
1995
|
-
* trailing-steer anchor downstream. Graph state and the host's
|
|
1996
|
-
* persisted messages are untouched — this shapes only what goes on the
|
|
1997
|
-
* wire, for the providers that actually care.
|
|
1998
|
-
*
|
|
1999
|
-
* Runs AFTER synthetic-context compaction: that pass can rewrite or
|
|
2000
|
-
* drop messages, so coalescing has to see its output, and it is the
|
|
2001
|
-
* last shaping step before the cache breakpoint is chosen.
|
|
2002
|
-
*/
|
|
2003
1412
|
if (require_alternation.strictAlternationProviders.has(agentContext.provider)) {
|
|
2004
|
-
/**
|
|
2005
|
-
* Wrapped like every other provider transform: the merged message is
|
|
2006
|
-
* a NEW object, and without re-attachment the final pre-invoke
|
|
2007
|
-
* measurement would drop both source turns' calibrated shares and
|
|
2008
|
-
* recharge the merge at full raw estimate — enough to flip a
|
|
2009
|
-
* just-fits payload (the synthetic-context compaction above binary
|
|
2010
|
-
* searches to exactly that) into a spurious pre-invoke overflow. The
|
|
2011
|
-
* merge keeps the first source's id, so the keyed branch re-attaches
|
|
2012
|
-
* that origin; the absorbed turn's tokens are charged as new raw
|
|
2013
|
-
* growth, which only ever under-estimates by less than the old
|
|
2014
|
-
* behavior over-estimated.
|
|
2015
|
-
*/
|
|
2016
1413
|
const beforeCoalesce = finalMessages;
|
|
2017
1414
|
finalMessages = trackProviderMessageOrigins(beforeCoalesce, require_alternation.coalesceAdjacentUserTurns(beforeCoalesce));
|
|
2018
1415
|
}
|
|
@@ -2053,11 +1450,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2053
1450
|
maxToolResultChars: maxProviderToolResultChars,
|
|
2054
1451
|
callOptions: config
|
|
2055
1452
|
}));
|
|
2056
|
-
/**
|
|
2057
|
-
* Prompt-cache placement and orphan sanitization are provider-wire
|
|
2058
|
-
* transforms too. Re-measure after both so no content added after the
|
|
2059
|
-
* earlier artifact/synthetic compaction decision can bypass the guard.
|
|
2060
|
-
*/
|
|
2061
1453
|
finalProjection = measureProviderPayload(finalMessages);
|
|
2062
1454
|
const preInvokeContextOverflowError = !finalProjection.fits ? createProviderPayloadOverflowError({
|
|
2063
1455
|
projection: finalProjection,
|
|
@@ -2095,15 +1487,12 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2095
1487
|
info: `Message pruning removed all messages as none fit in the context window. ${guidance}\n${breakdown}`
|
|
2096
1488
|
}));
|
|
2097
1489
|
}
|
|
2098
|
-
/** Past the empty-prompt guard — a model call is now guaranteed */
|
|
2099
1490
|
if (contextUsage != null) {
|
|
2100
1491
|
if (finalProjection.projectedMessageTokens != null && finalProjection.availableMessageTokens != null) {
|
|
2101
1492
|
contextUsage.breakdown.messageCount = finalMessages.length;
|
|
2102
1493
|
contextUsage.remainingContextTokens = Math.max(0, finalProjection.availableMessageTokens - finalProjection.projectedMessageTokens);
|
|
2103
1494
|
}
|
|
2104
1495
|
require_budget.syncBudgetDerivedFields(contextUsage);
|
|
2105
|
-
/** Awaited so async host handlers receive the pre-invoke snapshot
|
|
2106
|
-
* before any model deltas are emitted */
|
|
2107
1496
|
await require_events.safeDispatchCustomEvent("on_context_usage", contextUsage, config);
|
|
2108
1497
|
}
|
|
2109
1498
|
const invokeStart = Date.now();
|
|
@@ -2125,17 +1514,10 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2125
1514
|
let langfuseHandler;
|
|
2126
1515
|
let invokeConfig = {
|
|
2127
1516
|
...config,
|
|
2128
|
-
/** The run-scoped breaker composed in, so a stream-limit trip in one
|
|
2129
|
-
* parallel agent node also cancels sibling nodes' in-flight model
|
|
2130
|
-
* calls, not only their subagents. */
|
|
2131
1517
|
signal: require_misc.composeAbortSignals(config.signal, attemptBreaker.signal),
|
|
2132
1518
|
metadata: {
|
|
2133
1519
|
...config.metadata ?? {},
|
|
2134
1520
|
...traceMetadata,
|
|
2135
|
-
/** Canonical agent identity, stamped OUTSIDE trace-metadata
|
|
2136
|
-
* filtering: `createLangfuseTraceMetadata` drops values over its
|
|
2137
|
-
* length cap, but scope trust (`isForeignScope`) needs the id
|
|
2138
|
-
* verbatim regardless of length. */
|
|
2139
1521
|
agentId,
|
|
2140
1522
|
[require_streamLimits.STREAM_LIMIT_EPOCH_KEY]: attemptBreakerEpoch
|
|
2141
1523
|
}
|
|
@@ -2160,10 +1542,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2160
1542
|
const metadata = config.metadata;
|
|
2161
1543
|
try {
|
|
2162
1544
|
if (preInvokeContextOverflowError != null) throw preInvokeContextOverflowError;
|
|
2163
|
-
/** Rechecked after the pre-invoke awaits (context-usage dispatch,
|
|
2164
|
-
* hooks): a sibling can trip the breaker while this node is paused
|
|
2165
|
-
* in one of them, and a provider that doesn't synchronously reject
|
|
2166
|
-
* an aborted signal would still start the request. */
|
|
2167
1545
|
{
|
|
2168
1546
|
const preInvokeTrip = this.resolveTrippedBreakerReason(attemptBreaker.signal);
|
|
2169
1547
|
if (preInvokeTrip != null) throw preInvokeTrip;
|
|
@@ -2184,42 +1562,14 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2184
1562
|
graph: this,
|
|
2185
1563
|
metadata
|
|
2186
1564
|
});
|
|
2187
|
-
/**
|
|
2188
|
-
* A tripped stream circuit breaker is a deliberate abort, not a
|
|
2189
|
-
* provider failure: entering overflow recovery or the fallback chain
|
|
2190
|
-
* would spend more provider work after the safety limit fired, and a
|
|
2191
|
-
* succeeding fallback would resolve a run the public contract says
|
|
2192
|
-
* must reject. Rethrow before any recovery path.
|
|
2193
|
-
*/
|
|
2194
1565
|
if (primaryError instanceof require_streamLimits.StreamLimitExceededError) {
|
|
2195
|
-
/** Tripped before rethrowing so parallel agent nodes' in-flight
|
|
2196
|
-
* model calls and subagents stop while the rejection propagates. */
|
|
2197
1566
|
attemptBreaker.abort(primaryError);
|
|
2198
1567
|
throw primaryError;
|
|
2199
1568
|
}
|
|
2200
|
-
/** A sibling that tripped the shared breaker aborts this branch's
|
|
2201
|
-
* composed signal, and some providers surface that as a generic
|
|
2202
|
-
* abort error; entering overflow planning or the fallback chain
|
|
2203
|
-
* would start new provider work after the run-wide breaker fired.
|
|
2204
|
-
* Rethrow the breaker's own stream-limit reason instead. */
|
|
2205
1569
|
{
|
|
2206
1570
|
const trippedReason = this.resolveTrippedBreakerReason(attemptBreaker.signal);
|
|
2207
1571
|
if (trippedReason != null) throw trippedReason;
|
|
2208
1572
|
}
|
|
2209
|
-
/**
|
|
2210
|
-
* A context overflow is a deterministic consequence of the payload,
|
|
2211
|
-
* not a provider being unavailable — so it is answered by compacting
|
|
2212
|
-
* and retrying rather than by re-sending the same oversized prompt
|
|
2213
|
-
* down the fallback chain. Fallbacks still run for every other
|
|
2214
|
-
* failure, and for an overflow whose recovery budget is spent.
|
|
2215
|
-
*/
|
|
2216
|
-
/**
|
|
2217
|
-
* Compaction has to have something to work with. Without a token
|
|
2218
|
-
* counter there is no pruner, and with summarization disabled the
|
|
2219
|
-
* summarize node deliberately no-ops — so in that combination the
|
|
2220
|
-
* retry would resend a byte-identical prompt. Skipping the detour
|
|
2221
|
-
* keeps the original error and one round trip instead of three.
|
|
2222
|
-
*/
|
|
2223
1573
|
const estimatedPromptTokens = getEstimatedPromptTokens(contextUsage);
|
|
2224
1574
|
const canSummarizeOverflow = agentContext.summarizationEnabled === true && require_recency.splitAtRecencyBoundary(messages, {
|
|
2225
1575
|
turns: agentContext.summarizationConfig?.retainRecent?.turns ?? 2,
|
|
@@ -2232,20 +1582,9 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2232
1582
|
return getLocalProviderOverflowMeasurement(error)?.estimatedPromptTokens ?? (resolvedFallbackContext == null ? estimatedPromptTokens : void 0);
|
|
2233
1583
|
};
|
|
2234
1584
|
const planRecovery = (error, attributedFallbackContext) => {
|
|
2235
|
-
/**
|
|
2236
|
-
* When the rejection came from a fallback, plan against *that*
|
|
2237
|
-
* client: its window and output allowance are why it was configured
|
|
2238
|
-
* as an alternative in the first place.
|
|
2239
|
-
*/
|
|
2240
1585
|
const fallbackContext = attributedFallbackContext ?? require_invoke.getFallbackErrorContext(error);
|
|
2241
1586
|
const localMeasurement = getLocalProviderOverflowMeasurement(error);
|
|
2242
1587
|
const recoveryPromptEstimate = getRecoveryPromptEstimate(error, fallbackContext);
|
|
2243
|
-
/**
|
|
2244
|
-
* A previous correction that left the rejected prompt no smaller
|
|
2245
|
-
* proves this state has nothing left to compact. Use the fallback
|
|
2246
|
-
* projection when one exists so unlike provider formats are never
|
|
2247
|
-
* compared through the primary's cheaper pre-projection estimate.
|
|
2248
|
-
*/
|
|
2249
1588
|
if (agentContext.overflowRecoveryStalled(recoveryPromptEstimate)) return null;
|
|
2250
1589
|
const recovery = require_contextOverflowRecovery.planContextOverflowRecovery({
|
|
2251
1590
|
error,
|
|
@@ -2278,12 +1617,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2278
1617
|
estimatedPromptTokens: recoveryPromptEstimate
|
|
2279
1618
|
});
|
|
2280
1619
|
}
|
|
2281
|
-
/**
|
|
2282
|
-
* A fallback can reject the same prompt as too large even when the
|
|
2283
|
-
* primary failed for an unrelated reason — a fallback with a smaller
|
|
2284
|
-
* window is the obvious case. Planning against the exhausted-chain
|
|
2285
|
-
* error keeps that path recoverable instead of surfacing it.
|
|
2286
|
-
*/
|
|
2287
1620
|
try {
|
|
2288
1621
|
result = await require_langfuseRuntimeScope.withLangfuseRuntimeScope(require_langfuseRuntimeScope.resolveLangfuseRuntimeScope({
|
|
2289
1622
|
runLangfuse: this.langfuse,
|
|
@@ -2297,11 +1630,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2297
1630
|
config: invokeConfig,
|
|
2298
1631
|
primaryError,
|
|
2299
1632
|
context: this,
|
|
2300
|
-
/**
|
|
2301
|
-
* Lets the chain recognise a fallback overflow whose signature
|
|
2302
|
-
* carries no reason of its own (Vertex AI's bare 400) and
|
|
2303
|
-
* surface it rather than a later unrelated failure.
|
|
2304
|
-
*/
|
|
2305
1633
|
overflowContext: {
|
|
2306
1634
|
provider: agentContext.provider,
|
|
2307
1635
|
estimatedPromptTokens: getEstimatedPromptTokens(contextUsage),
|
|
@@ -2309,16 +1637,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2309
1637
|
},
|
|
2310
1638
|
prepareProviderMessages: ({ model: fallbackModel, messages: fallbackMessages, provider: fallbackProvider, maxContextTokens: fallbackMaxContextTokens, config: fallbackConfig }) => {
|
|
2311
1639
|
const fallbackToolResultChars = agentContext.maxToolResultChars ?? require_truncation.calculateMaxToolResultChars(fallbackMaxContextTokens ?? agentContext.maxContextTokens);
|
|
2312
|
-
/**
|
|
2313
|
-
* Serving-provider cue shaping BEFORE the fallback payload
|
|
2314
|
-
* is measured: a Claude fallback behind a tolerant primary
|
|
2315
|
-
* gains the cue inside the guarded projection (a prompt
|
|
2316
|
-
* within the cue's cost of the fallback budget must take
|
|
2317
|
-
* the recovery path, not ship oversized), and a tolerant
|
|
2318
|
-
* fallback behind an Anthropic primary sheds the baked cue
|
|
2319
|
-
* before it is measured against the tighter budget. The
|
|
2320
|
-
* attemptInvoke funnel pass then finds nothing to change.
|
|
2321
|
-
*/
|
|
2322
1640
|
const cueShapedFallbackMessages = trackProviderMessageOrigins(fallbackMessages, require_llm.isAnthropicLike(fallbackProvider, { model: require_invoke.resolveServingModelId(fallbackModel) }) ? require_handoffCue.appendPredecessorHandoffCue(fallbackMessages, (m) => this.isRunProducedMessage(m)) : require_handoffCue.removePredecessorHandoffCue(fallbackMessages));
|
|
2323
1641
|
const projectedFallbackMessages = trackProviderMessageOrigins(cueShapedFallbackMessages, require_invoke.projectMessagesForProvider({
|
|
2324
1642
|
model: fallbackModel,
|
|
@@ -2339,14 +1657,10 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2339
1657
|
}));
|
|
2340
1658
|
} catch (fallbackError) {
|
|
2341
1659
|
if (fallbackError instanceof require_streamLimits.StreamLimitExceededError) {
|
|
2342
|
-
/** Same treatment as the primary path: a fallback stream that
|
|
2343
|
-
* trips the breaker must stop parallel agent nodes' model calls
|
|
2344
|
-
* and subagents before the rejection propagates. */
|
|
2345
1660
|
attemptBreaker.abort(fallbackError);
|
|
2346
1661
|
throw fallbackError;
|
|
2347
1662
|
}
|
|
2348
1663
|
{
|
|
2349
|
-
/** Same sibling-abort translation guard as the primary catch. */
|
|
2350
1664
|
const trippedReason = this.resolveTrippedBreakerReason(attemptBreaker.signal);
|
|
2351
1665
|
if (trippedReason != null) throw trippedReason;
|
|
2352
1666
|
}
|
|
@@ -2378,31 +1692,7 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2378
1692
|
await require_langfuse.disposeLangfuseHandler(langfuseHandler);
|
|
2379
1693
|
}
|
|
2380
1694
|
if (!result) throw new Error("No result after model invocation");
|
|
2381
|
-
/**
|
|
2382
|
-
* Fallback: populate toolCallStepIds in the graph execution context.
|
|
2383
|
-
*
|
|
2384
|
-
* When model.stream() is available (the common case), attemptInvoke
|
|
2385
|
-
* processes all chunks through a local ChatModelStreamHandler which
|
|
2386
|
-
* creates run steps and populates toolCallStepIds before returning.
|
|
2387
|
-
* The code below is a fallback for the rare case where model.stream
|
|
2388
|
-
* is unavailable and model.invoke() was used instead.
|
|
2389
|
-
*
|
|
2390
|
-
* Text content is dispatched FIRST so that MESSAGE_CREATION is the
|
|
2391
|
-
* current step when handleToolCalls runs. handleToolCalls then creates
|
|
2392
|
-
* TOOL_CALLS on top of it. The dedup in getMessageId and
|
|
2393
|
-
* toolCallStepIds.has makes this safe when attemptInvoke already
|
|
2394
|
-
* handled everything — both paths become no-ops.
|
|
2395
|
-
*/
|
|
2396
1695
|
const responseMessage = result.messages?.[0];
|
|
2397
|
-
/**
|
|
2398
|
-
* Provenance for the handoff-cue gate: recorded at the node, where the
|
|
2399
|
-
* produced turn is unambiguous. The public ChatModel contract does not
|
|
2400
|
-
* require implementations to set message ids — the reducer would
|
|
2401
|
-
* assign one AFTER this node returns, which is too late for the set —
|
|
2402
|
-
* so an id is assigned here first, the same way the reducer does it
|
|
2403
|
-
* (`v4()`, mirrored into `lc_kwargs`), and the reducer's
|
|
2404
|
-
* keep-existing-id rule makes the state message match.
|
|
2405
|
-
*/
|
|
2406
1696
|
if (responseMessage?.getType() === "ai") {
|
|
2407
1697
|
if (typeof responseMessage.id !== "string" || responseMessage.id === "") {
|
|
2408
1698
|
responseMessage.id = (0, uuid.v4)();
|
|
@@ -2449,11 +1739,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2449
1739
|
}
|
|
2450
1740
|
await require_handlers.handleToolCalls(toolCalls, metadata, this);
|
|
2451
1741
|
}
|
|
2452
|
-
/**
|
|
2453
|
-
* When streaming events are unavailable, ChatModelStreamHandler never
|
|
2454
|
-
* fires. Dispatch final reasoning/text content here. getMessageId makes
|
|
2455
|
-
* this a no-op when the streaming path already handled the same step.
|
|
2456
|
-
*/
|
|
2457
1742
|
if (!hasToolCalls && responseMessage != null) {
|
|
2458
1743
|
if (dispatchableFinalReasoningContent != null && await dispatchReasoningContent({
|
|
2459
1744
|
graph: this,
|
|
@@ -2474,13 +1759,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2474
1759
|
}
|
|
2475
1760
|
const invokeElapsed = ((Date.now() - invokeStart) / 1e3).toFixed(2);
|
|
2476
1761
|
agentContext.currentUsage = this.getUsageMetadata(result.messages?.[0]);
|
|
2477
|
-
/**
|
|
2478
|
-
* Synthetic usage from a sealed turn is an estimate derived from the
|
|
2479
|
-
* host's own counter, so feeding it to calibration would teach a ratio
|
|
2480
|
-
* of exactly 1.0 — self-consistent by construction, and wrong for any
|
|
2481
|
-
* provider whose real ratio differs. It still flows to `currentUsage`
|
|
2482
|
-
* for host billing; it just does not get to move the EMA.
|
|
2483
|
-
*/
|
|
2484
1762
|
const estimatedUsage = (result.messages?.[0])?.response_metadata.estimated_usage === true;
|
|
2485
1763
|
if (agentContext.currentUsage) {
|
|
2486
1764
|
if (!estimatedUsage) agentContext.updateLastCallUsage(agentContext.currentUsage);
|
|
@@ -2497,28 +1775,9 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2497
1775
|
}, invokeMeta, { force: true });
|
|
2498
1776
|
if (responseMessage?.response_metadata.preempted === true) {
|
|
2499
1777
|
const { messages: injected, preventContinuation } = await this.dispatchPreemptBoundary(agentId, config);
|
|
2500
|
-
/**
|
|
2501
|
-
* Release before branching: the slot is held only for the duration of
|
|
2502
|
-
* the drain, and an early return below must not strand it.
|
|
2503
|
-
*/
|
|
2504
1778
|
this.releasePreemptSeal();
|
|
2505
1779
|
if (preventContinuation) {
|
|
2506
|
-
/**
|
|
2507
|
-
* A hook halted at the boundary. Commit the sealed turn and anything
|
|
2508
|
-
* it injected, but do NOT self-loop: `preventContinuation` promises
|
|
2509
|
-
* no further model turn, and the run-loop poll in `processStream`
|
|
2510
|
-
* only sees the halt AFTER the next call would already have started
|
|
2511
|
-
* — direct graph consumers never poll it at all. A trailing injected
|
|
2512
|
-
* HumanMessage carries no tool calls, so `toolsCondition` routes it
|
|
2513
|
-
* to END.
|
|
2514
|
-
*/
|
|
2515
1780
|
this.preemptIncomplete = true;
|
|
2516
|
-
/**
|
|
2517
|
-
* A halting boundary that ALSO injected nothing is still an empty
|
|
2518
|
-
* boundary by the `getPreemptStats().emptyBoundaries` contract —
|
|
2519
|
-
* hosts use the counter for truncated-seal telemetry, and both
|
|
2520
|
-
* paths end the turn with nothing to resume from.
|
|
2521
|
-
*/
|
|
2522
1781
|
if (injected.length === 0) this.preemptEmptyBoundaries += 1;
|
|
2523
1782
|
this.cleanupSignalListener();
|
|
2524
1783
|
return injected.length > 0 ? { messages: [...result.messages ?? [], ...injected] } : result;
|
|
@@ -2528,12 +1787,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2528
1787
|
this.cleanupSignalListener();
|
|
2529
1788
|
return { messages: [...result.messages ?? [], ...injected] };
|
|
2530
1789
|
}
|
|
2531
|
-
/**
|
|
2532
|
-
* Nothing to inject — the host cancelled or already drained. Do NOT
|
|
2533
|
-
* self-loop: a trailing model turn with no new input is dropped by
|
|
2534
|
-
* some Gemini models and read as prefill by Anthropic. Do NOT pretend
|
|
2535
|
-
* the turn completed either; the answer really was cut short.
|
|
2536
|
-
*/
|
|
2537
1790
|
this.preemptEmptyBoundaries += 1;
|
|
2538
1791
|
this.preemptIncomplete = true;
|
|
2539
1792
|
}
|
|
@@ -2541,19 +1794,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2541
1794
|
return result;
|
|
2542
1795
|
};
|
|
2543
1796
|
}
|
|
2544
|
-
/**
|
|
2545
|
-
* Fires `PreemptBoundary` after a sealed turn and returns whatever the
|
|
2546
|
-
* hooks asked to inject, converted through the same `convertInjectedMessages`
|
|
2547
|
-
* the tool boundary uses so the two sites cannot emit different shapes.
|
|
2548
|
-
*
|
|
2549
|
-
* Never throws: a drain that fails or times out costs the injection, not the
|
|
2550
|
-
* run. The caller treats an empty result as "nothing to resume with".
|
|
2551
|
-
*
|
|
2552
|
-
* `preventContinuation` is surfaced alongside the messages rather than left
|
|
2553
|
-
* to the registry halt signal, which `processStream` only polls between
|
|
2554
|
-
* stream events — by then the self-loop it was meant to prevent has already
|
|
2555
|
-
* issued another model call, and a direct graph consumer never polls it.
|
|
2556
|
-
*/
|
|
2557
1797
|
async dispatchPreemptBoundary(agentId, config) {
|
|
2558
1798
|
if (this.hookRegistry == null) return EMPTY_PREEMPT_BOUNDARY;
|
|
2559
1799
|
const configurable = config?.configurable;
|
|
@@ -2571,62 +1811,15 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2571
1811
|
},
|
|
2572
1812
|
sessionId: runId,
|
|
2573
1813
|
timeoutMs: require_constants.PREEMPT_BOUNDARY_HOOK_TIMEOUT_MS,
|
|
2574
|
-
/**
|
|
2575
|
-
* The host's own abort signal(s), deliberately NOT `config.signal` —
|
|
2576
|
-
* inside a node the latter is LangGraph's composed signal, which also
|
|
2577
|
-
* fires when an unrelated sibling in the same superstep throws.
|
|
2578
|
-
* Cancellation already returns control in milliseconds without this;
|
|
2579
|
-
* what it buys is that a drain does not keep running after the run it
|
|
2580
|
-
* belongs to died.
|
|
2581
|
-
*
|
|
2582
|
-
* Composed because the host can cancel through either channel: the
|
|
2583
|
-
* construction signal, or the per-call `callerConfig.signal` — the only
|
|
2584
|
-
* one a multi-agent run has, since `MultiAgentGraphConfig` exposes no
|
|
2585
|
-
* construction signal. When both exist they may be different
|
|
2586
|
-
* controllers, and a drain must stop when EITHER fires.
|
|
2587
|
-
*/
|
|
2588
1814
|
signal: require_misc.composeAbortSignals(this.signal, this.callerSignal)
|
|
2589
1815
|
}).catch(() => void 0);
|
|
2590
1816
|
if (result == null) return EMPTY_PREEMPT_BOUNDARY;
|
|
2591
|
-
/**
|
|
2592
|
-
* `executeHooks` raises a registry halt whenever a hook returns
|
|
2593
|
-
* `preventContinuation`. That halt has exactly one consumer — the poll in
|
|
2594
|
-
* `Run.processStream` — and its `break` cancels the stream iterator, which
|
|
2595
|
-
* aborts Pregel. The abort lands BEFORE the outer reducer commits
|
|
2596
|
-
* `StandardGraph.messages`, so honoring the halt here would destroy the
|
|
2597
|
-
* sealed assistant turn: the run returns empty content and the host
|
|
2598
|
-
* persists nothing. Measured deterministically — the commit is several
|
|
2599
|
-
* stream events downstream of the point the halt becomes observable.
|
|
2600
|
-
*
|
|
2601
|
-
* The `preventContinuation` branch in `createCallModel` already enforces
|
|
2602
|
-
* the contract locally by declining to self-loop, and a sealed chunk
|
|
2603
|
-
* provably carries no tool calls, so the turn routes to END after exactly
|
|
2604
|
-
* one model call either way. Clearing the halt therefore costs nothing it
|
|
2605
|
-
* was buying and saves the content the seal exists to preserve.
|
|
2606
|
-
*
|
|
2607
|
-
* Scoped to a halt this event raised, so a halt from an earlier hook in
|
|
2608
|
-
* the same run — `haltRun` is first-write-wins — is left alone.
|
|
2609
|
-
*/
|
|
2610
1817
|
const halt = this.hookRegistry.getHaltSignal(runId);
|
|
2611
1818
|
if (result.preventContinuation === true && halt?.source === "PreemptBoundary") {
|
|
2612
1819
|
this.preemptHaltReason = halt.reason;
|
|
2613
1820
|
this.hookRegistry.clearHaltSignal(runId);
|
|
2614
1821
|
}
|
|
2615
1822
|
const injected = [];
|
|
2616
|
-
/**
|
|
2617
|
-
* `PreemptBoundaryHookOutput` is `BaseHookOutput`, so `additionalContext`
|
|
2618
|
-
* is part of the contract here just as it is at the tool boundary. It has
|
|
2619
|
-
* to be materialized BEFORE the emptiness test, or a hook that returns
|
|
2620
|
-
* context alone would read as "nothing to resume with" and cut the answer
|
|
2621
|
-
* short. Same system-flavored `HumanMessage` convention `ToolNode` uses —
|
|
2622
|
-
* Anthropic and Google reject a mid-conversation `SystemMessage`.
|
|
2623
|
-
*/
|
|
2624
|
-
/**
|
|
2625
|
-
* Whitespace-only entries are dropped for the same reason empty
|
|
2626
|
-
* `injectedMessages` are: `executeHooks` keeps them because their raw
|
|
2627
|
-
* length is nonzero, but a blank turn is not something to resume from —
|
|
2628
|
-
* it costs a model call and strict providers reject it outright.
|
|
2629
|
-
*/
|
|
2630
1823
|
const contexts = result.additionalContexts.filter((context) => context.trim() !== "");
|
|
2631
1824
|
if (contexts.length > 0) injected.push(new _langchain_core_messages.HumanMessage({
|
|
2632
1825
|
content: contexts.join("\n\n"),
|
|
@@ -2650,16 +1843,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2650
1843
|
const getConfig = () => this.config;
|
|
2651
1844
|
const agentContext = this.agentContexts.get(agentId);
|
|
2652
1845
|
if (!agentContext) throw new Error(`Agent context not found for agentId: ${agentId}`);
|
|
2653
|
-
/**
|
|
2654
|
-
* Depth countdown across graph boundaries: the parent's `maxSubagentDepth`
|
|
2655
|
-
* becomes this executor's `maxDepth`. When the child graph is constructed,
|
|
2656
|
-
* `buildChildInputs()` decrements `maxSubagentDepth` on the child's
|
|
2657
|
-
* `AgentInputs` (only when `allowNested: true`; otherwise subagentConfigs
|
|
2658
|
-
* are stripped entirely). The child graph's own `createAgentNode()` then
|
|
2659
|
-
* reads the decremented value here and creates a narrower executor —
|
|
2660
|
-
* recursion is bounded even though each graph has its own separate
|
|
2661
|
-
* executor instance.
|
|
2662
|
-
*/
|
|
2663
1846
|
const effectiveSubagentDepth = agentContext.maxSubagentDepth ?? 1;
|
|
2664
1847
|
if (agentContext.subagentConfigs != null && agentContext.subagentConfigs.length > 0 && effectiveSubagentDepth > 0) {
|
|
2665
1848
|
const executableConfigs = require_childGraphConfig.normalizeSubagentConfigEntries(agentContext.subagentConfigs, agentContext);
|
|
@@ -2692,9 +1875,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2692
1875
|
parentSignal: this.signal,
|
|
2693
1876
|
breakerScope: { controller: () => this.breakerAbort },
|
|
2694
1877
|
hookRegistry: this.hookRegistry,
|
|
2695
|
-
/** Lazy — Run wires the registry onto the graph AFTER
|
|
2696
|
-
* `createWorkflow()` runs, so a direct capture here would be
|
|
2697
|
-
* `undefined` at construction time. */
|
|
2698
1878
|
parentHandlerRegistry: getParentHandlerRegistry,
|
|
2699
1879
|
parentRunId: this.runId ?? "",
|
|
2700
1880
|
parentAgentId: agentContext.agentId,
|
|
@@ -2718,17 +1898,11 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2718
1898
|
const description = typeof input.description === "string" && input.description.trim().length > 0 ? input.description : require_SubagentExecutor.DEFAULT_SUBAGENT_DESCRIPTION;
|
|
2719
1899
|
const subagentType = typeof input.subagent_type === "string" ? input.subagent_type : "";
|
|
2720
1900
|
const threadId = config.configurable?.thread_id;
|
|
2721
|
-
/** Surface the parent call id so child checkpoints, interrupts, and
|
|
2722
|
-
* update events remain correlated across replay and resume. */
|
|
2723
1901
|
const toolRuntime = config;
|
|
2724
1902
|
const toolCall = toolRuntime.toolCall;
|
|
2725
1903
|
let parentToolCallId;
|
|
2726
1904
|
if (typeof toolRuntime.toolCallId === "string" && toolRuntime.toolCallId !== "") parentToolCallId = toolRuntime.toolCallId;
|
|
2727
1905
|
else if (typeof toolCall?.id === "string" && toolCall.id !== "") parentToolCallId = toolCall.id;
|
|
2728
|
-
/** The parent tool batch's entry-captured scope (stamped by
|
|
2729
|
-
* ToolNode before PreToolUse hooks) — binds this child to the
|
|
2730
|
-
* run that dispatched it, not to whatever controller a reset
|
|
2731
|
-
* installed while the hooks were awaited. */
|
|
2732
1906
|
const batchScope = config.configurable?.[require_streamLimits.RUN_BREAKER_SCOPE_CONFIG_KEY];
|
|
2733
1907
|
return (await executor.execute({
|
|
2734
1908
|
description,
|
|
@@ -2737,12 +1911,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2737
1911
|
signal: config.signal,
|
|
2738
1912
|
parentToolCallId,
|
|
2739
1913
|
breaker: batchScope?.controller,
|
|
2740
|
-
/**
|
|
2741
|
-
* Forward the parent's `configurable` so host-set fields
|
|
2742
|
-
* (`requestBody`, `user`, etc.) propagate into the child
|
|
2743
|
-
* workflow. The executor scrubs run-identity fields before
|
|
2744
|
-
* forwarding — see `SubagentExecuteParams.parentConfigurable`.
|
|
2745
|
-
*/
|
|
2746
1914
|
parentConfigurable: config.configurable
|
|
2747
1915
|
})).content;
|
|
2748
1916
|
}, require_SubagentTool.buildSubagentToolParams(executableConfigs));
|
|
@@ -2754,13 +1922,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2754
1922
|
};
|
|
2755
1923
|
if (!agentContext.graphTools) agentContext.graphTools = [];
|
|
2756
1924
|
agentContext.graphTools.push(subagentTool);
|
|
2757
|
-
/**
|
|
2758
|
-
* Refresh toolSchemaTokens to include the subagent tool's schema.
|
|
2759
|
-
* `calculateInstructionTokens()` was kicked off in `fromConfig()`
|
|
2760
|
-
* before graphTools was populated, so its result did not count this
|
|
2761
|
-
* tool. Without this retrigger, token-budget/pruning logic
|
|
2762
|
-
* underestimates prompt overhead.
|
|
2763
|
-
*/
|
|
2764
1925
|
if (agentContext.tokenCounter) {
|
|
2765
1926
|
const { tokenCounter, baseIndexTokenCountMap } = agentContext;
|
|
2766
1927
|
agentContext.tokenCalculationPromise = agentContext.calculateInstructionTokens(tokenCounter).then(() => {
|
|
@@ -2776,11 +1937,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2776
1937
|
const summarizeNode = `${SUMMARIZE}${agentId}`;
|
|
2777
1938
|
const routeMessage = (state, config) => {
|
|
2778
1939
|
this.config = config;
|
|
2779
|
-
/**
|
|
2780
|
-
* A sealed turn that injected messages resumes in the SAME pregel run:
|
|
2781
|
-
* back to the agent node as a new superstep, so the model continues in
|
|
2782
|
-
* one assistant message instead of restarting the graph.
|
|
2783
|
-
*/
|
|
2784
1940
|
if (this.pendingPreemptReturn.delete(agentId)) return agentNode;
|
|
2785
1941
|
if (state.summarizationRequest != null) return summarizeNode;
|
|
2786
1942
|
return require_ToolNode.toolsCondition(state, toolNode, this.invokedToolIds);
|
|
@@ -2819,51 +1975,26 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2819
1975
|
runId: this.runId,
|
|
2820
1976
|
isMultiAgent: this.isMultiAgentGraph(),
|
|
2821
1977
|
hookRegistry: this.hookRegistry,
|
|
2822
|
-
/**
|
|
2823
|
-
* Live references (both maps are cleared in place, never
|
|
2824
|
-
* replaced), so summarization streams share the run's event
|
|
2825
|
-
* budget accounting under their own generation key.
|
|
2826
|
-
*/
|
|
2827
1978
|
streamLimits: this.streamLimits,
|
|
2828
1979
|
streamDeltaEventCounts: this.streamDeltaEventCounts,
|
|
2829
1980
|
streamedToolCallArgTallies: this.streamedToolCallArgTallies,
|
|
2830
|
-
/** Accessor pair, not a value copy: unlike the two maps above,
|
|
2831
|
-
* the credit map is REPLACED by graph resets rather than cleared
|
|
2832
|
-
* in place, and the guards' lazy `??=` must install onto the
|
|
2833
|
-
* graph — a copy held here would survive resets and grow one
|
|
2834
|
-
* attempt-stamped entry per compaction for a retained reused
|
|
2835
|
-
* chunk object. */
|
|
2836
1981
|
get streamLimitChargeCredits() {
|
|
2837
1982
|
return readChargeCredits();
|
|
2838
1983
|
},
|
|
2839
1984
|
set streamLimitChargeCredits(value) {
|
|
2840
1985
|
writeChargeCredits(value);
|
|
2841
1986
|
},
|
|
2842
|
-
/** Live epoch, so summary tallies are creation-tagged and the
|
|
2843
|
-
* resetValues grace sweep treats them like model-attempt
|
|
2844
|
-
* entries. */
|
|
2845
1987
|
get breakerEpoch() {
|
|
2846
1988
|
return readBreakerEpoch();
|
|
2847
1989
|
},
|
|
2848
|
-
/** Accessor pair like the charge credits: summary attempts
|
|
2849
|
-
* lease their generations on the GRAPH's active set, and the
|
|
2850
|
-
* lazy `??=` in the lease helper must install there. */
|
|
2851
1990
|
get activeStreamLimitGenerations() {
|
|
2852
1991
|
return readActiveGenerations();
|
|
2853
1992
|
},
|
|
2854
1993
|
set activeStreamLimitGenerations(value) {
|
|
2855
1994
|
writeActiveGenerations(value);
|
|
2856
1995
|
},
|
|
2857
|
-
/** Read per attempt: a sibling branch tripping the run breaker
|
|
2858
|
-
* must also cancel in-flight summarization model calls. */
|
|
2859
1996
|
getBreakerSignal: () => this.breakerAbort.signal,
|
|
2860
|
-
/** The node captures this at entry so its own chunk handler's
|
|
2861
|
-
* breach trips the run that STARTED the summarization, not a
|
|
2862
|
-
* controller installed by a later reset. */
|
|
2863
1997
|
getBreakerController: () => this.breakerAbort,
|
|
2864
|
-
/** Captured at node entry and stamped into the summary attempt
|
|
2865
|
-
* metadata, so the wire consumer epoch-gates old-run summary
|
|
2866
|
-
* chunks exactly like model-attempt chunks. */
|
|
2867
1998
|
getBreakerEpoch: () => this.breakerEpoch,
|
|
2868
1999
|
dispatchRunStep: async (runStep, nodeConfig) => {
|
|
2869
2000
|
const resolvedConfig = nodeConfig ?? this.config;
|
|
@@ -2921,21 +2052,9 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2921
2052
|
default: () => []
|
|
2922
2053
|
}) })).addNode(this.defaultAgentId, agentNode, { ends: [_langchain_langgraph.END] }).addEdge(_langchain_langgraph.START, this.defaultAgentId).compile(this.compileOptions);
|
|
2923
2054
|
}
|
|
2924
|
-
/**
|
|
2925
|
-
* Indicates if this is a multi-agent graph.
|
|
2926
|
-
* Override in MultiAgentGraph to return true.
|
|
2927
|
-
* Used to conditionally include agentId in RunStep for frontend rendering.
|
|
2928
|
-
*/
|
|
2929
2055
|
isMultiAgentGraph() {
|
|
2930
2056
|
return false;
|
|
2931
2057
|
}
|
|
2932
|
-
/**
|
|
2933
|
-
* Get the parallel group ID for an agent, if any.
|
|
2934
|
-
* Override in MultiAgentGraph to provide actual group IDs.
|
|
2935
|
-
* Group IDs are incrementing numbers (1, 2, 3...) reflecting execution order.
|
|
2936
|
-
* @param _agentId - The agent ID to look up
|
|
2937
|
-
* @returns undefined for StandardGraph (no parallel groups), or group number for MultiAgentGraph
|
|
2938
|
-
*/
|
|
2939
2058
|
getParallelGroupIdForAgent(_agentId) {}
|
|
2940
2059
|
resolveParallelGroupId(agentId, metadata) {
|
|
2941
2060
|
if (metadata == null || !Object.prototype.hasOwnProperty.call(metadata, "__handoff_group_id")) return this.getParallelGroupIdForAgent(agentId);
|
|
@@ -2944,9 +2063,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2944
2063
|
if (typeof runtimeGroupId === "number" && Number.isSafeInteger(runtimeGroupId) && runtimeGroupId > 0) return runtimeGroupId;
|
|
2945
2064
|
return this.getParallelGroupIdForAgent(agentId);
|
|
2946
2065
|
}
|
|
2947
|
-
/**
|
|
2948
|
-
* Dispatches a run step to the client, returns the step ID
|
|
2949
|
-
*/
|
|
2950
2066
|
async dispatchRunStep(stepKey, stepDetails, metadata) {
|
|
2951
2067
|
if (!this.config) throw new Error("No config provided");
|
|
2952
2068
|
const [stepId, stepIndex] = this.generateStepId(stepKey);
|
|
@@ -2971,12 +2087,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2971
2087
|
};
|
|
2972
2088
|
const runId = this.runId ?? "";
|
|
2973
2089
|
if (runId) runStep.runId = runId;
|
|
2974
|
-
/**
|
|
2975
|
-
* `agentId`/`groupId` are multi-agent-only, and `getAgentContext` signals a
|
|
2976
|
-
* miss by throwing — so for a single-agent graph the lookup could only ever
|
|
2977
|
-
* build and discard an Error while producing the same undefined fields.
|
|
2978
|
-
* The constant-time check gates it out of the per-step dispatch path.
|
|
2979
|
-
*/
|
|
2980
2090
|
if (metadata && this.isMultiAgentGraph()) try {
|
|
2981
2091
|
const agentContext = this.getAgentContext(metadata);
|
|
2982
2092
|
if (agentContext.agentId) {
|
|
@@ -2999,20 +2109,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
2999
2109
|
}
|
|
3000
2110
|
return stepId;
|
|
3001
2111
|
}
|
|
3002
|
-
/**
|
|
3003
|
-
* Static version of handleToolCallError to avoid creating strong references
|
|
3004
|
-
* that prevent garbage collection.
|
|
3005
|
-
*
|
|
3006
|
-
* Returns whether the error completion event was actually dispatched. A
|
|
3007
|
-
* tool can error before this graph instance has a run step for the call —
|
|
3008
|
-
* on a resume pass the interrupted batch re-executes IMMEDIATELY on graph
|
|
3009
|
-
* re-entry, before any step replay has registered `toolCallStepIds` (a
|
|
3010
|
-
* fast-failing tool, e.g. a schema-validation reject, loses that race).
|
|
3011
|
-
* That is a caller-recoverable condition, not an invariant violation: the
|
|
3012
|
-
* ToolNode falls back to its normal completion dispatch for the error
|
|
3013
|
-
* ToolMessage when this returns `false`, so throwing here would only
|
|
3014
|
-
* replace a recoverable miss with a lost completion event and a scary log.
|
|
3015
|
-
*/
|
|
3016
2112
|
static async handleToolCallErrorStatic(graph, data, metadata) {
|
|
3017
2113
|
if (!data.id) {
|
|
3018
2114
|
console.warn("No Tool ID provided for Tool Error");
|
|
@@ -3050,10 +2146,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
3050
2146
|
});
|
|
3051
2147
|
return true;
|
|
3052
2148
|
}
|
|
3053
|
-
/**
|
|
3054
|
-
* Instance method that delegates to the static method
|
|
3055
|
-
* Kept for backward compatibility
|
|
3056
|
-
*/
|
|
3057
2149
|
async handleToolCallError(data, metadata) {
|
|
3058
2150
|
return StandardGraph.handleToolCallErrorStatic(this, data, metadata);
|
|
3059
2151
|
}
|