@librechat/agents 3.2.68 → 3.3.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 +117 -3
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/common/enum.cjs +4 -0
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +243 -49
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +103 -28
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/langfuseToolOutputTracing.cjs +4 -0
- package/dist/cjs/langfuseToolOutputTracing.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +11 -2
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/llm/contextOverflowRecovery.cjs +132 -0
- package/dist/cjs/llm/contextOverflowRecovery.cjs.map +1 -0
- package/dist/cjs/llm/google/index.cjs +1 -1
- package/dist/cjs/llm/invoke.cjs +60 -3
- package/dist/cjs/llm/invoke.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +1 -1
- package/dist/cjs/main.cjs +21 -7
- package/dist/cjs/messages/format.cjs +136 -4
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/messages/prune.cjs +16 -5
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/cjs/messages/recency.cjs +2 -0
- package/dist/cjs/messages/recency.cjs.map +1 -1
- package/dist/cjs/prompts/activityLabel.cjs +101 -0
- package/dist/cjs/prompts/activityLabel.cjs.map +1 -0
- package/dist/cjs/run.cjs +177 -3
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/stream.cjs +205 -49
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +55 -7
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +2 -2
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +2 -2
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +69 -8
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +19 -15
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +32 -3
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +1 -1
- package/dist/cjs/utils/errors.cjs +317 -52
- package/dist/cjs/utils/errors.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +118 -4
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/common/enum.mjs +4 -0
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +242 -48
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +103 -28
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/langfuseToolOutputTracing.mjs +4 -1
- package/dist/esm/langfuseToolOutputTracing.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +11 -2
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/llm/contextOverflowRecovery.mjs +130 -0
- package/dist/esm/llm/contextOverflowRecovery.mjs.map +1 -0
- package/dist/esm/llm/google/index.mjs +1 -1
- package/dist/esm/llm/invoke.mjs +59 -4
- package/dist/esm/llm/invoke.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +1 -1
- package/dist/esm/main.mjs +10 -10
- package/dist/esm/messages/format.mjs +136 -5
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/messages/prune.mjs +14 -6
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/messages/recency.mjs +2 -1
- package/dist/esm/messages/recency.mjs.map +1 -1
- package/dist/esm/prompts/activityLabel.mjs +100 -0
- package/dist/esm/prompts/activityLabel.mjs.map +1 -0
- package/dist/esm/run.mjs +178 -4
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/stream.mjs +205 -49
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +55 -7
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +3 -3
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +3 -3
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +62 -9
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +20 -16
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +32 -3
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +1 -1
- package/dist/esm/utils/errors.mjs +317 -53
- package/dist/esm/utils/errors.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +62 -3
- package/dist/types/common/enum.d.ts +5 -1
- package/dist/types/graphs/Graph.d.ts +16 -2
- package/dist/types/graphs/MultiAgentGraph.d.ts +1 -0
- package/dist/types/langfuseToolOutputTracing.d.ts +4 -0
- package/dist/types/llm/contextOverflowRecovery.d.ts +85 -0
- package/dist/types/llm/invoke.d.ts +35 -6
- package/dist/types/messages/format.d.ts +22 -0
- package/dist/types/messages/prune.d.ts +10 -2
- package/dist/types/messages/recency.d.ts +1 -0
- package/dist/types/prompts/activityLabel.d.ts +31 -0
- package/dist/types/run.d.ts +16 -0
- package/dist/types/tools/CodeExecutor.d.ts +14 -1
- package/dist/types/types/activityLabel.d.ts +53 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/llm.d.ts +7 -4
- package/dist/types/types/stream.d.ts +7 -4
- package/dist/types/types/summarize.d.ts +22 -0
- package/dist/types/utils/__tests__/fixtures/contextOverflowSignatures.d.ts +40 -0
- package/dist/types/utils/errors.d.ts +65 -16
- package/dist/types/utils/redactSecrets.d.ts +3 -0
- package/package.json +7 -8
- package/src/agents/AgentContext.ts +188 -7
- package/src/agents/__tests__/AgentContext.overflow.test.ts +205 -0
- package/src/common/enum.ts +4 -0
- package/src/graphs/Graph.ts +409 -58
- package/src/graphs/MultiAgentGraph.ts +184 -46
- package/src/graphs/__tests__/Graph.contextOverflow.test.ts +631 -0
- package/src/langfuseToolOutputTracing.ts +4 -1
- package/src/llm/__tests__/contextOverflowRecovery.test.ts +401 -0
- package/src/llm/__tests__/fallbackOverflow.test.ts +287 -0
- package/src/llm/bedrock/index.ts +25 -12
- package/src/llm/contextOverflowRecovery.ts +292 -0
- package/src/llm/invoke.ts +119 -4
- package/src/messages/foldToollessToolBlocks.test.ts +438 -0
- package/src/messages/format.ts +233 -5
- package/src/messages/prune.ts +24 -11
- package/src/messages/recency.ts +3 -1
- package/src/prompts/activityLabel.ts +177 -0
- package/src/run.ts +322 -3
- package/src/scripts/context-overflow-probe.ts +997 -0
- package/src/specs/activity-label-prompt.test.ts +128 -0
- package/src/specs/activity-label-trace-seed.test.ts +47 -0
- package/src/specs/agent-handoffs.test.ts +903 -1
- package/src/specs/bedrock-toolless.live.test.ts +123 -0
- package/src/specs/context-overflow-recovery.live.test.ts +213 -0
- package/src/splitStream.test.ts +882 -0
- package/src/stream.ts +315 -51
- package/src/summarization/__tests__/aggregator.test.ts +83 -0
- package/src/summarization/__tests__/node.test.ts +139 -0
- package/src/summarization/node.ts +99 -14
- package/src/tools/BashExecutor.ts +4 -2
- package/src/tools/BashProgrammaticToolCalling.ts +4 -7
- package/src/tools/CodeExecutor.ts +119 -8
- package/src/tools/ProgrammaticToolCalling.ts +29 -27
- package/src/tools/ToolNode.ts +50 -8
- package/src/tools/__tests__/CodeApiAuthHeaders.test.ts +297 -3
- package/src/types/activityLabel.ts +55 -0
- package/src/types/index.ts +1 -0
- package/src/types/llm.ts +8 -1
- package/src/types/stream.ts +7 -4
- package/src/types/summarize.ts +22 -0
- package/src/utils/__tests__/errors.test.ts +270 -0
- package/src/utils/__tests__/fixtures/contextOverflowSignatures.ts +336 -0
- package/src/utils/__tests__/redactSecrets.test.ts +56 -0
- package/src/utils/errors.ts +484 -66
- package/src/utils/redactSecrets.ts +61 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.cjs","names":[],"sources":["../../../src/common/enum.ts"],"sourcesContent":["/**\n * Enum representing the various event types emitted during the execution of runnables.\n * These events provide real-time information about the progress and state of different components.\n *\n * @enum {string}\n */\nexport enum GraphEvents {\n /* Custom Events */\n\n /** [Custom] Agent update event in multi-agent graph/workflow */\n ON_AGENT_UPDATE = 'on_agent_update',\n /** [Custom] Delta event for run steps (message creation and tool calls) */\n ON_RUN_STEP = 'on_run_step',\n /** [Custom] Delta event for run steps (tool calls) */\n ON_RUN_STEP_DELTA = 'on_run_step_delta',\n /** [Custom] Completed event for run steps (tool calls) */\n ON_RUN_STEP_COMPLETED = 'on_run_step_completed',\n /** [Custom] Delta events for messages */\n ON_MESSAGE_DELTA = 'on_message_delta',\n /** [Custom] Reasoning Delta events for messages */\n ON_REASONING_DELTA = 'on_reasoning_delta',\n /** [Custom] Request to execute tools - dispatched by ToolNode, handled by host */\n ON_TOOL_EXECUTE = 'on_tool_execute',\n /** [Custom] Emitted when the summarize node begins generating a summary */\n ON_SUMMARIZE_START = 'on_summarize_start',\n /** [Custom] Delta event carrying the completed summary content */\n ON_SUMMARIZE_DELTA = 'on_summarize_delta',\n /** [Custom] Emitted when the summarize node completes with the final summary */\n ON_SUMMARIZE_COMPLETE = 'on_summarize_complete',\n /** [Custom] Progress update from a running subagent (wraps child-graph events so hosts can display activity separately from parent). */\n ON_SUBAGENT_UPDATE = 'on_subagent_update',\n /** [Custom] Diagnostic logging event for context management observability */\n ON_AGENT_LOG = 'on_agent_log',\n /** [Custom] Per-model-call context window usage snapshot (post-prune token budget) */\n ON_CONTEXT_USAGE = 'on_context_usage',\n\n /* Official Events */\n\n /** Custom event, emitted by system */\n ON_CUSTOM_EVENT = 'on_custom_event',\n /** Emitted when a chat model starts processing. */\n CHAT_MODEL_START = 'on_chat_model_start',\n\n /** Emitted when a chat model streams a chunk of its response. */\n CHAT_MODEL_STREAM = 'on_chat_model_stream',\n\n /** Emitted when a chat model completes its processing. */\n CHAT_MODEL_END = 'on_chat_model_end',\n\n /** Emitted when a language model starts processing. */\n LLM_START = 'on_llm_start',\n\n /** Emitted when a language model streams a chunk of its response. */\n LLM_STREAM = 'on_llm_stream',\n\n /** Emitted when a language model completes its processing. */\n LLM_END = 'on_llm_end',\n\n /** Emitted when a chain starts processing. */\n CHAIN_START = 'on_chain_start',\n\n /** Emitted when a chain streams a chunk of its output. */\n CHAIN_STREAM = 'on_chain_stream',\n\n /** Emitted when a chain completes its processing. */\n CHAIN_END = 'on_chain_end',\n\n /** Emitted when a tool starts its operation. */\n TOOL_START = 'on_tool_start',\n\n /** Emitted when a tool completes its operation. */\n TOOL_END = 'on_tool_end',\n\n /** Emitted when a retriever starts its operation. */\n RETRIEVER_START = 'on_retriever_start',\n\n /** Emitted when a retriever completes its operation. */\n RETRIEVER_END = 'on_retriever_end',\n\n /** Emitted when a prompt starts processing. */\n PROMPT_START = 'on_prompt_start',\n\n /** Emitted when a prompt completes its processing. */\n PROMPT_END = 'on_prompt_end',\n}\n\nexport enum Providers {\n OPENAI = 'openAI',\n VERTEXAI = 'vertexai',\n BEDROCK = 'bedrock',\n ANTHROPIC = 'anthropic',\n MISTRALAI = 'mistralai',\n MISTRAL = 'mistral',\n GOOGLE = 'google',\n AZURE = 'azureOpenAI',\n DEEPSEEK = 'deepseek',\n OPENROUTER = 'openrouter',\n XAI = 'xai',\n MOONSHOT = 'moonshot',\n}\n\nexport enum GraphNodeKeys {\n TOOLS = 'tools=',\n AGENT = 'agent=',\n SUMMARIZE = 'summarize=',\n ROUTER = 'router',\n PRE_TOOLS = 'pre_tools',\n POST_TOOLS = 'post_tools',\n}\n\nexport enum GraphNodeActions {\n TOOL_NODE = 'tool_node',\n CALL_MODEL = 'call_model',\n ROUTE_MESSAGE = 'route_message',\n}\n\nexport enum CommonEvents {\n LANGGRAPH = 'LangGraph',\n}\n\nexport enum StepTypes {\n TOOL_CALLS = 'tool_calls',\n MESSAGE_CREATION = 'message_creation',\n}\n\nexport enum ContentTypes {\n TEXT = 'text',\n ERROR = 'error',\n THINK = 'think',\n TOOL_CALL = 'tool_call',\n IMAGE_URL = 'image_url',\n IMAGE_FILE = 'image_file',\n /** Anthropic */\n THINKING = 'thinking',\n /** Vertex AI / Google Common */\n REASONING = 'reasoning',\n /** Multi-Agent Switch */\n AGENT_UPDATE = 'agent_update',\n /** Framework-level conversation summary block */\n SUMMARY = 'summary',\n /** Bedrock */\n REASONING_CONTENT = 'reasoning_content',\n /** Mid-run user steer persisted inline in an assistant message; replayed as a user turn */\n STEER = 'steer',\n}\n\nexport enum ToolCallTypes {\n FUNCTION = 'function',\n RETRIEVAL = 'retrieval',\n FILE_SEARCH = 'file_search',\n CODE_INTERPRETER = 'code_interpreter',\n /* Agents Tool Call */\n TOOL_CALL = 'tool_call',\n}\n\nexport enum Callback {\n TOOL_ERROR = 'handleToolError',\n TOOL_START = 'handleToolStart',\n TOOL_END = 'handleToolEnd',\n CUSTOM_EVENT = 'handleCustomEvent',\n /*\n LLM_START = 'handleLLMStart',\n LLM_NEW_TOKEN = 'handleLLMNewToken',\n LLM_ERROR = 'handleLLMError',\n LLM_END = 'handleLLMEnd',\n CHAT_MODEL_START = 'handleChatModelStart',\n CHAIN_START = 'handleChainStart',\n CHAIN_ERROR = 'handleChainError',\n CHAIN_END = 'handleChainEnd',\n TEXT = 'handleText',\n AGENT_ACTION = 'handleAgentAction',\n AGENT_END = 'handleAgentEnd',\n RETRIEVER_START = 'handleRetrieverStart',\n RETRIEVER_END = 'handleRetrieverEnd',\n RETRIEVER_ERROR = 'handleRetrieverError',\n */\n}\n\nexport enum Constants {\n OFFICIAL_CODE_BASEURL = 'https://api.librechat.ai/v1',\n EXECUTE_CODE = 'execute_code',\n TOOL_SEARCH = 'tool_search',\n PROGRAMMATIC_TOOL_CALLING = 'run_tools_with_code',\n WEB_SEARCH = 'web_search',\n CONTENT_AND_ARTIFACT = 'content_and_artifact',\n LC_TRANSFER_TO_ = 'lc_transfer_to_',\n /** Delimiter for MCP tools: toolName_mcp_serverName */\n MCP_DELIMITER = '_mcp_',\n /** Anthropic server tool ID prefix (web_search, code_execution, etc.) */\n ANTHROPIC_SERVER_TOOL_PREFIX = 'srvtoolu_',\n SKILL_TOOL = 'skill',\n /**\n * Callback-metadata keys stamped by `attemptInvoke` /\n * `tryFallbackProviders` carrying the provider (SDK `Providers` enum\n * value) and configured model that actually served a model invocation.\n * Unlike `ls_provider` — which derived providers inherit from their base\n * class (e.g. DeepSeek/OpenRouter report `'openai'`) — these reflect the\n * SDK's own routing, including fallback-provider calls. Consumed by the\n * subagent usage-capture handler to tag billing events.\n */\n INVOKED_PROVIDER = '__invoked_provider',\n INVOKED_MODEL = '__invoked_model',\n READ_FILE = 'read_file',\n BASH_TOOL = 'bash_tool',\n BASH_PROGRAMMATIC_TOOL_CALLING = 'run_tools_with_bash',\n SUBAGENT = 'subagent',\n /**\n * Local-engine coding tool names. Promoted to `Constants.*` (rather\n * than left as per-file `*ToolName` consts) so consumer UIs — most\n * importantly LibreChat's `getToolIconType` map — can match against\n * canonical strings instead of guessing. Existing matched names:\n * `bash_tool`, `read_file`, `execute_code`, `run_tools_with_code`.\n * The rest below are new and currently fall through to the generic\n * tool icon; once LibreChat adds icons keyed on the same names, the\n * wiring will work without an SDK change.\n */\n WRITE_FILE = 'write_file',\n EDIT_FILE = 'edit_file',\n GREP_SEARCH = 'grep_search',\n GLOB_SEARCH = 'glob_search',\n LIST_DIRECTORY = 'list_directory',\n COMPILE_CHECK = 'compile_check',\n}\n\n/** Tool names that use the code execution environment (shared session, file tracking). */\nexport const CODE_EXECUTION_TOOLS: ReadonlySet<string> = new Set([\n Constants.EXECUTE_CODE,\n Constants.BASH_TOOL,\n Constants.PROGRAMMATIC_TOOL_CALLING,\n Constants.BASH_PROGRAMMATIC_TOOL_CALLING,\n]);\n\n/**\n * Canonical names of the local-engine-specific coding tools — the\n * file/edit/search/typecheck surface that doesn't exist in the\n * remote (sandbox-API) engine. Single source of truth; the per-tool\n * factories, registry definitions, and `createWorkspacePolicyHook`\n * default extractors all key off these.\n *\n * `read_file` is on this list (the existing ReadFile tool is\n * remote-specific; the local engine's `read_file` is a parallel\n * implementation that shares the canonical name so consumer UIs\n * — most importantly LibreChat's `getToolIconType` — render both\n * with the same icon).\n */\nexport const LOCAL_CODING_TOOL_NAMES: readonly string[] = [\n Constants.READ_FILE,\n Constants.WRITE_FILE,\n Constants.EDIT_FILE,\n Constants.GREP_SEARCH,\n Constants.GLOB_SEARCH,\n Constants.LIST_DIRECTORY,\n Constants.COMPILE_CHECK,\n];\n\n/**\n * Every tool name the local coding bundle (`createLocalCodingTools`)\n * exposes — the local-specific tools above plus the bash/code/PTC\n * pair that the local engine wraps around the existing factories.\n * Tests pin against this so any addition/removal in the bundle is\n * accompanied by a deliberate canonical-name update here.\n */\nexport const LOCAL_CODING_BUNDLE_NAMES: readonly string[] = [\n ...LOCAL_CODING_TOOL_NAMES,\n Constants.BASH_TOOL,\n Constants.EXECUTE_CODE,\n Constants.PROGRAMMATIC_TOOL_CALLING,\n Constants.BASH_PROGRAMMATIC_TOOL_CALLING,\n];\n\nexport enum TitleMethod {\n STRUCTURED = 'structured',\n FUNCTIONS = 'functions',\n COMPLETION = 'completion',\n}\n\nexport enum EnvVar {\n CODE_BASEURL = 'LIBRECHAT_CODE_BASEURL',\n CODE_API_RUN_TIMEOUT_MS = 'CODE_API_RUN_TIMEOUT_MS',\n}\n"],"m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;;;;;;;;AAQ1D;;;;;;;;AASA,MAAa,4BAA+C;CAC1D,GAAG;;;;;AAKL;AAEA,IAAY,cAAL,yBAAA,aAAA;CACL,YAAA,gBAAA;CACA,YAAA,eAAA;CACA,YAAA,gBAAA;;AACF,EAAA,CAAA,CAAA;AAEA,IAAY,SAAL,yBAAA,QAAA;CACL,OAAA,kBAAA;CACA,OAAA,6BAAA;;AACF,EAAA,CAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"enum.cjs","names":[],"sources":["../../../src/common/enum.ts"],"sourcesContent":["/**\n * Enum representing the various event types emitted during the execution of runnables.\n * These events provide real-time information about the progress and state of different components.\n *\n * @enum {string}\n */\nexport enum GraphEvents {\n /* Custom Events */\n\n /** [Custom] Agent update event in multi-agent graph/workflow */\n ON_AGENT_UPDATE = 'on_agent_update',\n /** [Custom] Delta event for run steps (message creation and tool calls) */\n ON_RUN_STEP = 'on_run_step',\n /** [Custom] Delta event for run steps (tool calls) */\n ON_RUN_STEP_DELTA = 'on_run_step_delta',\n /** [Custom] Completed event for run steps (tool calls) */\n ON_RUN_STEP_COMPLETED = 'on_run_step_completed',\n /** [Custom] Delta events for messages */\n ON_MESSAGE_DELTA = 'on_message_delta',\n /** [Custom] Reasoning Delta events for messages */\n ON_REASONING_DELTA = 'on_reasoning_delta',\n /** [Custom] Request to execute tools - dispatched by ToolNode, handled by host */\n ON_TOOL_EXECUTE = 'on_tool_execute',\n /** [Custom] Emitted when the summarize node begins generating a summary */\n ON_SUMMARIZE_START = 'on_summarize_start',\n /** [Custom] Delta event carrying the completed summary content */\n ON_SUMMARIZE_DELTA = 'on_summarize_delta',\n /** [Custom] Emitted when the summarize node completes with the final summary */\n ON_SUMMARIZE_COMPLETE = 'on_summarize_complete',\n /** [Custom] Progress update from a running subagent (wraps child-graph events so hosts can display activity separately from parent). */\n ON_SUBAGENT_UPDATE = 'on_subagent_update',\n /** [Custom] Diagnostic logging event for context management observability */\n ON_AGENT_LOG = 'on_agent_log',\n /** [Custom] Per-model-call context window usage snapshot (post-prune token budget) */\n ON_CONTEXT_USAGE = 'on_context_usage',\n\n /* Official Events */\n\n /** Custom event, emitted by system */\n ON_CUSTOM_EVENT = 'on_custom_event',\n /** Emitted when a chat model starts processing. */\n CHAT_MODEL_START = 'on_chat_model_start',\n\n /** Emitted when a chat model streams a chunk of its response. */\n CHAT_MODEL_STREAM = 'on_chat_model_stream',\n\n /** Emitted when a chat model completes its processing. */\n CHAT_MODEL_END = 'on_chat_model_end',\n\n /** Emitted when a language model starts processing. */\n LLM_START = 'on_llm_start',\n\n /** Emitted when a language model streams a chunk of its response. */\n LLM_STREAM = 'on_llm_stream',\n\n /** Emitted when a language model completes its processing. */\n LLM_END = 'on_llm_end',\n\n /** Emitted when a chain starts processing. */\n CHAIN_START = 'on_chain_start',\n\n /** Emitted when a chain streams a chunk of its output. */\n CHAIN_STREAM = 'on_chain_stream',\n\n /** Emitted when a chain completes its processing. */\n CHAIN_END = 'on_chain_end',\n\n /** Emitted when a tool starts its operation. */\n TOOL_START = 'on_tool_start',\n\n /** Emitted when a tool completes its operation. */\n TOOL_END = 'on_tool_end',\n\n /** Emitted when a retriever starts its operation. */\n RETRIEVER_START = 'on_retriever_start',\n\n /** Emitted when a retriever completes its operation. */\n RETRIEVER_END = 'on_retriever_end',\n\n /** Emitted when a prompt starts processing. */\n PROMPT_START = 'on_prompt_start',\n\n /** Emitted when a prompt completes its processing. */\n PROMPT_END = 'on_prompt_end',\n}\n\nexport enum Providers {\n OPENAI = 'openAI',\n VERTEXAI = 'vertexai',\n BEDROCK = 'bedrock',\n ANTHROPIC = 'anthropic',\n MISTRALAI = 'mistralai',\n MISTRAL = 'mistral',\n GOOGLE = 'google',\n AZURE = 'azureOpenAI',\n DEEPSEEK = 'deepseek',\n OPENROUTER = 'openrouter',\n XAI = 'xai',\n MOONSHOT = 'moonshot',\n}\n\nexport enum GraphNodeKeys {\n TOOLS = 'tools=',\n AGENT = 'agent=',\n SUMMARIZE = 'summarize=',\n ROUTER = 'router',\n PRE_TOOLS = 'pre_tools',\n POST_TOOLS = 'post_tools',\n}\n\nexport enum GraphNodeActions {\n TOOL_NODE = 'tool_node',\n CALL_MODEL = 'call_model',\n ROUTE_MESSAGE = 'route_message',\n}\n\nexport enum CommonEvents {\n LANGGRAPH = 'LangGraph',\n}\n\nexport enum StepTypes {\n TOOL_CALLS = 'tool_calls',\n MESSAGE_CREATION = 'message_creation',\n}\n\nexport enum ContentTypes {\n TEXT = 'text',\n ERROR = 'error',\n THINK = 'think',\n TOOL_CALL = 'tool_call',\n IMAGE_URL = 'image_url',\n IMAGE_FILE = 'image_file',\n /** Anthropic */\n THINKING = 'thinking',\n /** Vertex AI / Google Common */\n REASONING = 'reasoning',\n /** Multi-Agent Switch */\n AGENT_UPDATE = 'agent_update',\n /** Framework-level conversation summary block */\n SUMMARY = 'summary',\n /** Bedrock */\n REASONING_CONTENT = 'reasoning_content',\n /** Mid-run user steer persisted inline in an assistant message; replayed as a user turn */\n STEER = 'steer',\n /** Fast-model activity label for a tool/reasoning block; UI-only, never model input */\n ACTIVITY_LABEL = 'activity_label',\n}\n\nexport enum ToolCallTypes {\n FUNCTION = 'function',\n RETRIEVAL = 'retrieval',\n FILE_SEARCH = 'file_search',\n CODE_INTERPRETER = 'code_interpreter',\n /* Agents Tool Call */\n TOOL_CALL = 'tool_call',\n}\n\nexport enum Callback {\n TOOL_ERROR = 'handleToolError',\n TOOL_START = 'handleToolStart',\n TOOL_END = 'handleToolEnd',\n CUSTOM_EVENT = 'handleCustomEvent',\n /*\n LLM_START = 'handleLLMStart',\n LLM_NEW_TOKEN = 'handleLLMNewToken',\n LLM_ERROR = 'handleLLMError',\n LLM_END = 'handleLLMEnd',\n CHAT_MODEL_START = 'handleChatModelStart',\n CHAIN_START = 'handleChainStart',\n CHAIN_ERROR = 'handleChainError',\n CHAIN_END = 'handleChainEnd',\n TEXT = 'handleText',\n AGENT_ACTION = 'handleAgentAction',\n AGENT_END = 'handleAgentEnd',\n RETRIEVER_START = 'handleRetrieverStart',\n RETRIEVER_END = 'handleRetrieverEnd',\n RETRIEVER_ERROR = 'handleRetrieverError',\n */\n}\n\nexport enum Constants {\n OFFICIAL_CODE_BASEURL = 'https://api.librechat.ai/v1',\n EXECUTE_CODE = 'execute_code',\n TOOL_SEARCH = 'tool_search',\n PROGRAMMATIC_TOOL_CALLING = 'run_tools_with_code',\n WEB_SEARCH = 'web_search',\n CONTENT_AND_ARTIFACT = 'content_and_artifact',\n LC_TRANSFER_TO_ = 'lc_transfer_to_',\n HANDOFF_PARALLEL_BATCH = '__handoff_parallel_batch',\n HANDOFF_GROUP_ID = '__handoff_group_id',\n /** Delimiter for MCP tools: toolName_mcp_serverName */\n MCP_DELIMITER = '_mcp_',\n /** Anthropic server tool ID prefix (web_search, code_execution, etc.) */\n ANTHROPIC_SERVER_TOOL_PREFIX = 'srvtoolu_',\n SKILL_TOOL = 'skill',\n /**\n * Callback-metadata keys stamped by `attemptInvoke` /\n * `tryFallbackProviders` carrying the provider (SDK `Providers` enum\n * value) and configured model that actually served a model invocation.\n * Unlike `ls_provider` — which derived providers inherit from their base\n * class (e.g. DeepSeek/OpenRouter report `'openai'`) — these reflect the\n * SDK's own routing, including fallback-provider calls. Consumed by the\n * subagent usage-capture handler to tag billing events.\n */\n INVOKED_PROVIDER = '__invoked_provider',\n INVOKED_MODEL = '__invoked_model',\n READ_FILE = 'read_file',\n BASH_TOOL = 'bash_tool',\n BASH_PROGRAMMATIC_TOOL_CALLING = 'run_tools_with_bash',\n SUBAGENT = 'subagent',\n /**\n * Local-engine coding tool names. Promoted to `Constants.*` (rather\n * than left as per-file `*ToolName` consts) so consumer UIs — most\n * importantly LibreChat's `getToolIconType` map — can match against\n * canonical strings instead of guessing. Existing matched names:\n * `bash_tool`, `read_file`, `execute_code`, `run_tools_with_code`.\n * The rest below are new and currently fall through to the generic\n * tool icon; once LibreChat adds icons keyed on the same names, the\n * wiring will work without an SDK change.\n */\n WRITE_FILE = 'write_file',\n EDIT_FILE = 'edit_file',\n GREP_SEARCH = 'grep_search',\n GLOB_SEARCH = 'glob_search',\n LIST_DIRECTORY = 'list_directory',\n COMPILE_CHECK = 'compile_check',\n}\n\n/** Tool names that use the code execution environment (shared session, file tracking). */\nexport const CODE_EXECUTION_TOOLS: ReadonlySet<string> = new Set([\n Constants.EXECUTE_CODE,\n Constants.BASH_TOOL,\n Constants.PROGRAMMATIC_TOOL_CALLING,\n Constants.BASH_PROGRAMMATIC_TOOL_CALLING,\n]);\n\n/**\n * Canonical names of the local-engine-specific coding tools — the\n * file/edit/search/typecheck surface that doesn't exist in the\n * remote (sandbox-API) engine. Single source of truth; the per-tool\n * factories, registry definitions, and `createWorkspacePolicyHook`\n * default extractors all key off these.\n *\n * `read_file` is on this list (the existing ReadFile tool is\n * remote-specific; the local engine's `read_file` is a parallel\n * implementation that shares the canonical name so consumer UIs\n * — most importantly LibreChat's `getToolIconType` — render both\n * with the same icon).\n */\nexport const LOCAL_CODING_TOOL_NAMES: readonly string[] = [\n Constants.READ_FILE,\n Constants.WRITE_FILE,\n Constants.EDIT_FILE,\n Constants.GREP_SEARCH,\n Constants.GLOB_SEARCH,\n Constants.LIST_DIRECTORY,\n Constants.COMPILE_CHECK,\n];\n\n/**\n * Every tool name the local coding bundle (`createLocalCodingTools`)\n * exposes — the local-specific tools above plus the bash/code/PTC\n * pair that the local engine wraps around the existing factories.\n * Tests pin against this so any addition/removal in the bundle is\n * accompanied by a deliberate canonical-name update here.\n */\nexport const LOCAL_CODING_BUNDLE_NAMES: readonly string[] = [\n ...LOCAL_CODING_TOOL_NAMES,\n Constants.BASH_TOOL,\n Constants.EXECUTE_CODE,\n Constants.PROGRAMMATIC_TOOL_CALLING,\n Constants.BASH_PROGRAMMATIC_TOOL_CALLING,\n];\n\nexport enum TitleMethod {\n STRUCTURED = 'structured',\n FUNCTIONS = 'functions',\n COMPLETION = 'completion',\n}\n\nexport enum EnvVar {\n CODE_BASEURL = 'LIBRECHAT_CODE_BASEURL',\n COD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mBAAA;;AACF,EAAA,CAAA,CAAA;;AAGA,MAAa,uBAA4C,IAAI,IAAI;;;;;AAKjE,CAAC;;;;;;;;;;;;;;AAeD,MAAa,0BAA6C;;;;;;;;AAQ1D;;;;;;;;AASA,MAAa,4BAA+C;CAC1D,GAAG;;;;;AAKL;AAEA,IAAY,cAAL,yBAAA,aAAA;CACL,YAAA,gBAAA;CACA,YAAA,eAAA;CACA,YAAA,gBAAA;;AACF,EAAA,CAAA,CAAA;AAEA,IAAY,SAAL,yBAAA,QAAA;CACL,OAAA,kBAAA;CACA,OAAA,6BAAA;;AACF,EAAA,CAAA,CAAA"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const require_langfuseConfig = require("../langfuseConfig.cjs");
|
|
2
2
|
const require_langfuseRuntimeScope = require("../langfuseRuntimeScope.cjs");
|
|
3
3
|
const require_langfuse = require("../langfuse.cjs");
|
|
4
|
+
const require_langfuseToolOutputTracing = require("../langfuseToolOutputTracing.cjs");
|
|
4
5
|
const require_callbacks = require("../utils/callbacks.cjs");
|
|
5
6
|
const require_enum = require("../common/enum.cjs");
|
|
6
7
|
require("../common/index.cjs");
|
|
7
8
|
const require_tokens = require("../utils/tokens.cjs");
|
|
8
|
-
const require_langfuseToolOutputTracing = require("../langfuseToolOutputTracing.cjs");
|
|
9
9
|
const require_instrumentation = require("../instrumentation.cjs");
|
|
10
10
|
const require_core = require("../messages/core.cjs");
|
|
11
11
|
const require_ids = require("../messages/ids.cjs");
|
|
@@ -18,6 +18,7 @@ const require_anthropicToolCache = require("../messages/anthropicToolCache.cjs")
|
|
|
18
18
|
const require_content = require("../messages/content.cjs");
|
|
19
19
|
const require_tools = require("../messages/tools.cjs");
|
|
20
20
|
const require_reducer = require("../messages/reducer.cjs");
|
|
21
|
+
const require_recency = require("../messages/recency.cjs");
|
|
21
22
|
require("../messages/index.cjs");
|
|
22
23
|
const require_graph = require("../utils/graph.cjs");
|
|
23
24
|
const require_llm = require("../utils/llm.cjs");
|
|
@@ -26,7 +27,11 @@ const require_toolOutputReferences = require("../tools/toolOutputReferences.cjs"
|
|
|
26
27
|
const require_events$1 = require("../events.cjs");
|
|
27
28
|
const require_run = require("../utils/run.cjs");
|
|
28
29
|
require("../utils/index.cjs");
|
|
29
|
-
const
|
|
30
|
+
const require_contextOverflowRecovery = require("../llm/contextOverflowRecovery.cjs");
|
|
31
|
+
const require_toolCache = require("../llm/bedrock/toolCache.cjs");
|
|
32
|
+
const require_init = require("../llm/init.cjs");
|
|
33
|
+
const require_invoke = require("../llm/invoke.cjs");
|
|
34
|
+
const require_toolCache$1 = require("../llm/openrouter/toolCache.cjs");
|
|
30
35
|
const require_LocalCodingTools = require("../tools/local/LocalCodingTools.cjs");
|
|
31
36
|
const require_CloudflareSandboxTools = require("../tools/cloudflare/CloudflareSandboxTools.cjs");
|
|
32
37
|
require("../tools/cloudflare/index.cjs");
|
|
@@ -35,9 +40,6 @@ require("../tools/local/index.cjs");
|
|
|
35
40
|
const require_ToolNode = require("../tools/ToolNode.cjs");
|
|
36
41
|
const require_SubagentExecutor = require("../tools/subagent/SubagentExecutor.cjs");
|
|
37
42
|
require("../tools/subagent/index.cjs");
|
|
38
|
-
const require_toolCache$1 = require("../llm/bedrock/toolCache.cjs");
|
|
39
|
-
const require_init = require("../llm/init.cjs");
|
|
40
|
-
const require_invoke = require("../llm/invoke.cjs");
|
|
41
43
|
const require_SubagentTool = require("../tools/SubagentTool.cjs");
|
|
42
44
|
const require_index$6 = require("../summarization/index.cjs");
|
|
43
45
|
const require_request = require("../llm/request.cjs");
|
|
@@ -161,6 +163,33 @@ function clearCurrentDeltaStepMarkers({ graph, metadata }) {
|
|
|
161
163
|
graph.reasoningStepHasDeltas.delete(stepId);
|
|
162
164
|
}
|
|
163
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* The completion allowance the caller configured, under whichever key the
|
|
168
|
+
* provider's client uses. Providers count it against the same ceiling as the
|
|
169
|
+
* prompt, so overflow recovery has to reserve it when the error did not
|
|
170
|
+
* itemize the total.
|
|
171
|
+
*/
|
|
172
|
+
function getConfiguredCompletionTokens(clientOptions) {
|
|
173
|
+
const options = clientOptions;
|
|
174
|
+
for (const value of [options?.maxTokens, options?.maxOutputTokens]) if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Our own estimate of the prompt that was actually sent, derived from the
|
|
178
|
+
* pre-invoke usage snapshot. Used to corroborate ambiguous provider errors
|
|
179
|
+
* and to measure how far our token accounting sits from the provider's.
|
|
180
|
+
*/
|
|
181
|
+
function getEstimatedPromptTokens(contextUsage) {
|
|
182
|
+
const budget = contextUsage?.contextBudget;
|
|
183
|
+
const remaining = contextUsage?.remainingContextTokens;
|
|
184
|
+
if (budget == null || remaining == null || !Number.isFinite(budget) || !Number.isFinite(remaining)) return;
|
|
185
|
+
const used = budget - remaining;
|
|
186
|
+
return used > 0 ? used : void 0;
|
|
187
|
+
}
|
|
188
|
+
function minDefined(left, right) {
|
|
189
|
+
if (left == null) return right;
|
|
190
|
+
if (right == null) return left;
|
|
191
|
+
return Math.min(left, right);
|
|
192
|
+
}
|
|
164
193
|
async function dispatchMessageCreationStep({ graph, stepKey, messageId, metadata }) {
|
|
165
194
|
await graph.dispatchRunStep(stepKey, {
|
|
166
195
|
type: "message_creation",
|
|
@@ -457,9 +486,13 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
457
486
|
overrideModel;
|
|
458
487
|
/** Optional compile options passed into workflow.compile() */
|
|
459
488
|
compileOptions;
|
|
489
|
+
/** Whether the workflow was actually compiled with a checkpointer. */
|
|
490
|
+
hasCompiledCheckpointer = false;
|
|
460
491
|
messages = [];
|
|
461
492
|
/** Cached run messages preserved before clearHeavyState() so getRunMessages() works after cleanup. */
|
|
462
493
|
cachedRunMessages;
|
|
494
|
+
/** Checkpoint scope whose messages match index-keyed tool snapshots. */
|
|
495
|
+
originalToolContentCheckpointScope;
|
|
463
496
|
runId;
|
|
464
497
|
/**
|
|
465
498
|
* Boundary between historical messages (loaded from conversation state)
|
|
@@ -498,7 +531,7 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
498
531
|
}
|
|
499
532
|
this.defaultAgentId = agents[0].agentId;
|
|
500
533
|
}
|
|
501
|
-
resetValues(keepContent) {
|
|
534
|
+
resetValues(keepContent, checkpointScope) {
|
|
502
535
|
this.messages = [];
|
|
503
536
|
this.cachedRunMessages = void 0;
|
|
504
537
|
this.config = require_graph.resetIfNotEmpty(this.config, void 0);
|
|
@@ -525,14 +558,18 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
525
558
|
this.reasoningStepHasDeltas = require_graph.resetIfNotEmpty(this.reasoningStepHasDeltas, /* @__PURE__ */ new Set());
|
|
526
559
|
this.prelimMessageIdsByStepKey = require_graph.resetIfNotEmpty(this.prelimMessageIdsByStepKey, /* @__PURE__ */ new Map());
|
|
527
560
|
this.invokedToolIds = require_graph.resetIfNotEmpty(this.invokedToolIds, void 0);
|
|
528
|
-
|
|
561
|
+
const hasScopedCheckpoint = this.hasCompiledCheckpointer && checkpointScope != null && checkpointScope !== "";
|
|
562
|
+
const preserveOriginalToolContent = hasScopedCheckpoint && this.originalToolContentCheckpointScope === checkpointScope;
|
|
563
|
+
for (const context of this.agentContexts.values()) context.reset({ preserveOriginalToolContent });
|
|
564
|
+
this.originalToolContentCheckpointScope = hasScopedCheckpoint ? checkpointScope : void 0;
|
|
529
565
|
}
|
|
530
566
|
clearHeavyState() {
|
|
531
567
|
this.cachedRunMessages = this.messages.slice(this.startIndex);
|
|
532
568
|
super.clearHeavyState();
|
|
533
569
|
this.messages = [];
|
|
534
570
|
this.overrideModel = void 0;
|
|
535
|
-
|
|
571
|
+
const preserveOriginalToolContent = this.hasCompiledCheckpointer && this.originalToolContentCheckpointScope != null;
|
|
572
|
+
for (const context of this.agentContexts.values()) context.reset({ preserveOriginalToolContent });
|
|
536
573
|
}
|
|
537
574
|
getRunStep(stepId) {
|
|
538
575
|
const index = this.contentIndexMap.get(stepId);
|
|
@@ -767,6 +804,49 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
767
804
|
this.signal.removeEventListener("abort", client.abortHandler);
|
|
768
805
|
client.abortHandler = void 0;
|
|
769
806
|
}
|
|
807
|
+
/**
|
|
808
|
+
* Applies a context-overflow recovery plan and hands control to the
|
|
809
|
+
* summarize node, which compacts and then routes straight back here for a
|
|
810
|
+
* retry against the corrected budget.
|
|
811
|
+
*
|
|
812
|
+
* Returning the detour rather than rethrowing is the whole point: the
|
|
813
|
+
* caller never sees the provider's rejection, only a slightly longer turn.
|
|
814
|
+
*/
|
|
815
|
+
beginOverflowRecovery({ recovery, agentContext, agentId, config, originalToolContent, estimatedPromptTokens }) {
|
|
816
|
+
const previousBudget = agentContext.maxContextTokens;
|
|
817
|
+
/**
|
|
818
|
+
* Deterministic compaction first. Re-pruning against the corrected budget
|
|
819
|
+
* raises context pressure, which is what drives the pruner's tool-output
|
|
820
|
+
* truncation and observation masking — no model call, no cost, and no
|
|
821
|
+
* message content lost. A summarization call is held back until that has
|
|
822
|
+
* been tried and the provider rejected the prompt again.
|
|
823
|
+
*/
|
|
824
|
+
const allowSummarization = agentContext.shouldSummarizeOverflow();
|
|
825
|
+
agentContext.preserveOriginalToolContent(originalToolContent);
|
|
826
|
+
agentContext.applyContextBudgetCorrection(recovery.budgetTokens, estimatedPromptTokens);
|
|
827
|
+
agentContext.applyObservedOverflowCalibration(recovery.info.provider, recovery.observedCalibrationRatio);
|
|
828
|
+
require_events.emitAgentLog(config, "warn", "graph", "Provider rejected the prompt as too large — compacting and retrying", {
|
|
829
|
+
kind: recovery.info.kind,
|
|
830
|
+
previousBudget,
|
|
831
|
+
recoveredBudget: recovery.budgetTokens,
|
|
832
|
+
providerReportedLimit: recovery.info.limitTokens,
|
|
833
|
+
providerReportedTokens: recovery.info.requestedTokens,
|
|
834
|
+
providerReportedPromptTokens: recovery.info.promptTokens,
|
|
835
|
+
observedCalibrationRatio: recovery.observedCalibrationRatio,
|
|
836
|
+
detectedBy: recovery.info.source,
|
|
837
|
+
attempt: agentContext.overflowRecoveryAttempts,
|
|
838
|
+
compaction: allowSummarization ? "summarize" : "compress"
|
|
839
|
+
}, {
|
|
840
|
+
runId: this.runId,
|
|
841
|
+
agentId
|
|
842
|
+
}, { force: true });
|
|
843
|
+
return { summarizationRequest: {
|
|
844
|
+
remainingContextTokens: 0,
|
|
845
|
+
agentId: agentId || agentContext.agentId,
|
|
846
|
+
reason: "overflow",
|
|
847
|
+
allowSummarization
|
|
848
|
+
} };
|
|
849
|
+
}
|
|
770
850
|
createCallModel(agentId = "default") {
|
|
771
851
|
return async (state, config) => {
|
|
772
852
|
const agentContext = this.agentContexts.get(agentId);
|
|
@@ -794,10 +874,10 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
794
874
|
*/
|
|
795
875
|
let toolsForBinding = rawToolsForBinding;
|
|
796
876
|
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;
|
|
797
|
-
else if (agentContext.provider === "openrouter" && agentContext.clientOptions?.promptCache === true) toolsForBinding = require_toolCache.partitionAndMarkOpenRouterToolCache(rawToolsForBinding, require_anthropicToolCache.makeIsDeferred(agentContext.toolDefinitions), require_cache.resolvePromptCacheTtl(agentContext.clientOptions?.promptCacheTtl)) ?? rawToolsForBinding;
|
|
877
|
+
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;
|
|
798
878
|
else if (agentContext.provider === "bedrock" && agentContext.clientOptions?.promptCache === true) {
|
|
799
879
|
const bedrockModel = agentContext.clientOptions?.model;
|
|
800
|
-
if (bedrockModel == null || require_cache.supportsBedrockToolCache(bedrockModel)) toolsForBinding = require_toolCache
|
|
880
|
+
if (bedrockModel == null || require_cache.supportsBedrockToolCache(bedrockModel)) toolsForBinding = require_toolCache.partitionAndMarkBedrockToolCache(rawToolsForBinding, require_anthropicToolCache.makeIsDeferred(agentContext.toolDefinitions)) ?? rawToolsForBinding;
|
|
801
881
|
}
|
|
802
882
|
let model = this.overrideModel ?? require_init.initializeModel({
|
|
803
883
|
tools: toolsForBinding,
|
|
@@ -810,6 +890,12 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
810
890
|
this.config = config;
|
|
811
891
|
let messagesToUse = messages;
|
|
812
892
|
let contextUsage = null;
|
|
893
|
+
/**
|
|
894
|
+
* Held outside the prune block so overflow recovery — which detours to
|
|
895
|
+
* the summarize node from the invoke catch below — can preserve the
|
|
896
|
+
* same masking record the configured trigger preserves.
|
|
897
|
+
*/
|
|
898
|
+
let prunedOriginalToolContent;
|
|
813
899
|
if (!agentContext.pruneMessages && agentContext.tokenCounter && agentContext.maxContextTokens != null) agentContext.pruneMessages = require_prune.createPruneMessages({
|
|
814
900
|
startIndex: agentContext.indexTokenCountMap[0] != null ? this.startIndex : 0,
|
|
815
901
|
provider: agentContext.provider,
|
|
@@ -830,12 +916,22 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
830
916
|
}
|
|
831
917
|
});
|
|
832
918
|
if (agentContext.pruneMessages) {
|
|
833
|
-
const { context, indexTokenCountMap, messagesToRefine, prePruneContextTokens, remainingContextTokens,
|
|
919
|
+
const { context, indexTokenCountMap, messagesToRefine, prePruneContextTokens, remainingContextTokens, newOriginalToolContent, calibrationRatio, resolvedInstructionOverhead, contextBudget, effectiveInstructionTokens } = agentContext.pruneMessages({
|
|
834
920
|
messages,
|
|
835
921
|
usageMetadata: agentContext.currentUsage,
|
|
836
922
|
lastCallUsage: agentContext.lastCallUsage,
|
|
837
923
|
totalTokensFresh: agentContext.totalTokensFresh
|
|
838
924
|
});
|
|
925
|
+
prunedOriginalToolContent = newOriginalToolContent;
|
|
926
|
+
/**
|
|
927
|
+
* Masking rewrites tool content in `state.messages` in place, so this
|
|
928
|
+
* map is the only surviving copy of the full output. Persist it on
|
|
929
|
+
* every prune, not just when a summary is about to be written — the
|
|
930
|
+
* pruner closure that produced it is discarded on the next reset, and
|
|
931
|
+
* with it any chance of a later summary restoring the real content.
|
|
932
|
+
* AgentContext bounds what accumulates.
|
|
933
|
+
*/
|
|
934
|
+
agentContext.preserveOriginalToolContent(newOriginalToolContent);
|
|
839
935
|
agentContext.indexTokenCountMap = indexTokenCountMap;
|
|
840
936
|
if (calibrationRatio != null && calibrationRatio > 0) agentContext.calibrationRatio = calibrationRatio;
|
|
841
937
|
if (resolvedInstructionOverhead != null) {
|
|
@@ -882,31 +978,6 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
882
978
|
remainingContextTokens,
|
|
883
979
|
messagesToRefineCount: messagesToRefine.length
|
|
884
980
|
})) {
|
|
885
|
-
if (originalToolContent != null && originalToolContent.size > 0)
|
|
886
|
-
/**
|
|
887
|
-
* Merge — never overwrite — the pruner's masking record
|
|
888
|
-
* into pendingOriginalToolContent. Carry-over entries
|
|
889
|
-
* from a prior summarize (preserved by the recency
|
|
890
|
-
* window for masked tool messages still in the tail) and
|
|
891
|
-
* the current pruner's new entries are both keyed by
|
|
892
|
-
* indices in the current `state.messages`, so a key-wise
|
|
893
|
-
* union is correct. Overwriting would discard the
|
|
894
|
-
* carry-over and reduce summary fidelity when those
|
|
895
|
-
* masked tail messages eventually move into the head.
|
|
896
|
-
*/
|
|
897
|
-
if (agentContext.pendingOriginalToolContent == null) agentContext.pendingOriginalToolContent = originalToolContent;
|
|
898
|
-
else {
|
|
899
|
-
for (const [idx, content] of originalToolContent) agentContext.pendingOriginalToolContent.set(idx, content);
|
|
900
|
-
/**
|
|
901
|
-
* Re-apply the per-store char cap after the union. The
|
|
902
|
-
* pruner enforces ORIGINAL_CONTENT_MAX_CHARS inside its
|
|
903
|
-
* own map via the onContentStored callback, but a
|
|
904
|
-
* key-wise merge with recency carry-over bypasses that
|
|
905
|
-
* accounting and could let the merged map grow without
|
|
906
|
-
* bound across long sessions.
|
|
907
|
-
*/
|
|
908
|
-
require_prune.enforceOriginalContentCap(agentContext.pendingOriginalToolContent);
|
|
909
|
-
}
|
|
910
981
|
require_events.emitAgentLog(config, "info", "graph", "Summarization triggered", void 0, {
|
|
911
982
|
runId: this.runId,
|
|
912
983
|
agentId
|
|
@@ -987,6 +1058,19 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
987
1058
|
* model treats as suspicious injected content.
|
|
988
1059
|
*/
|
|
989
1060
|
finalMessages = require_format.ensureThinkingBlockInMessages(finalMessages, agentContext.provider, config, this.startIndex);
|
|
1061
|
+
/**
|
|
1062
|
+
* A destination that binds no tools is invoked without a tool schema, but
|
|
1063
|
+
* in a multi-agent graph it can still inherit a prior agent's toolUse/
|
|
1064
|
+
* toolResult history. Bedrock's Converse API (and other tool-schema-strict
|
|
1065
|
+
* providers) reject such a request when no top-level toolConfig is sent.
|
|
1066
|
+
* Fold that historical tool content into plain text so the tool-less agent
|
|
1067
|
+
* receives valid, context-preserving messages. Handoff tools count as
|
|
1068
|
+
* bound tools, so a tool-less router mid-handoff is not affected.
|
|
1069
|
+
*/
|
|
1070
|
+
if (toolsForBinding == null || toolsForBinding.length === 0) {
|
|
1071
|
+
finalMessages = require_format.foldToolBlocksForToollessAgent(finalMessages, config);
|
|
1072
|
+
if (agentContext.useLegacyContent) finalMessages = require_content.formatContentStrings(finalMessages);
|
|
1073
|
+
}
|
|
990
1074
|
const anthropicPromptCacheEnabled = agentContext.provider === "anthropic" && agentContext.clientOptions?.promptCache === true;
|
|
991
1075
|
const openRouterPromptCacheEnabled = agentContext.provider === "openrouter" && agentContext.clientOptions?.promptCache === true;
|
|
992
1076
|
const bedrockPromptCacheEnabled = agentContext.provider === "bedrock" && agentContext.clientOptions?.promptCache === true;
|
|
@@ -1124,17 +1208,115 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1124
1208
|
graph: this,
|
|
1125
1209
|
metadata
|
|
1126
1210
|
});
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1211
|
+
/**
|
|
1212
|
+
* A context overflow is a deterministic consequence of the payload,
|
|
1213
|
+
* not a provider being unavailable — so it is answered by compacting
|
|
1214
|
+
* and retrying rather than by re-sending the same oversized prompt
|
|
1215
|
+
* down the fallback chain. Fallbacks still run for every other
|
|
1216
|
+
* failure, and for an overflow whose recovery budget is spent.
|
|
1217
|
+
*/
|
|
1218
|
+
/**
|
|
1219
|
+
* Compaction has to have something to work with. Without a token
|
|
1220
|
+
* counter there is no pruner, and with summarization disabled the
|
|
1221
|
+
* summarize node deliberately no-ops — so in that combination the
|
|
1222
|
+
* retry would resend a byte-identical prompt. Skipping the detour
|
|
1223
|
+
* keeps the original error and one round trip instead of three.
|
|
1224
|
+
*/
|
|
1225
|
+
const estimatedPromptTokens = getEstimatedPromptTokens(contextUsage);
|
|
1226
|
+
/**
|
|
1227
|
+
* A previous correction that left the prompt no smaller proves this
|
|
1228
|
+
* state has nothing left to compact — an emptied message list whose
|
|
1229
|
+
* content rides along in an injected summary, for instance. Measuring
|
|
1230
|
+
* that beats trying to predict every such configuration.
|
|
1231
|
+
*/
|
|
1232
|
+
const recoveryStalled = agentContext.overflowRecoveryStalled(estimatedPromptTokens);
|
|
1233
|
+
const canSummarizeOverflow = agentContext.summarizationEnabled === true && require_recency.splitAtRecencyBoundary(messages, {
|
|
1234
|
+
turns: agentContext.summarizationConfig?.retainRecent?.turns ?? 2,
|
|
1235
|
+
tokens: agentContext.summarizationConfig?.retainRecent?.tokens,
|
|
1236
|
+
tokenCounter: agentContext.tokenCounter
|
|
1237
|
+
}).head.length > 0;
|
|
1238
|
+
const planRecovery = (error, attributedFallbackContext) => {
|
|
1239
|
+
if (recoveryStalled) return null;
|
|
1240
|
+
/**
|
|
1241
|
+
* When the rejection came from a fallback, plan against *that*
|
|
1242
|
+
* client: its window and output allowance are why it was configured
|
|
1243
|
+
* as an alternative in the first place.
|
|
1244
|
+
*/
|
|
1245
|
+
const fallbackContext = attributedFallbackContext ?? require_invoke.getFallbackErrorContext(error);
|
|
1246
|
+
const recovery = require_contextOverflowRecovery.planContextOverflowRecovery({
|
|
1247
|
+
error,
|
|
1248
|
+
provider: fallbackContext?.provider ?? agentContext.provider,
|
|
1249
|
+
maxContextTokens: fallbackContext?.maxContextTokens ?? agentContext.maxContextTokens,
|
|
1250
|
+
estimatedPromptTokens,
|
|
1251
|
+
calibrationRatio: agentContext.calibrationRatio,
|
|
1252
|
+
instructionTokens: agentContext.instructionTokens,
|
|
1253
|
+
canSummarize: agentContext.summarizationEnabled === true,
|
|
1254
|
+
configuredCompletionTokens: getConfiguredCompletionTokens(fallbackContext?.clientOptions ?? agentContext.clientOptions),
|
|
1255
|
+
attemptsSoFar: agentContext.overflowRecoveryAttempts
|
|
1256
|
+
});
|
|
1257
|
+
if (recovery == null) return null;
|
|
1258
|
+
const translatedRecovery = fallbackContext != null ? {
|
|
1259
|
+
...recovery,
|
|
1260
|
+
budgetTokens: minDefined(require_contextOverflowRecovery.getBlindRecoveryBudget(agentContext.maxContextTokens), require_contextOverflowRecovery.translateRecoveryBudget(recovery.budgetTokens, recovery.observedCalibrationRatio ?? 5, agentContext.calibrationRatio)),
|
|
1261
|
+
observedCalibrationRatio: void 0
|
|
1262
|
+
} : recovery;
|
|
1263
|
+
return canSummarizeOverflow || agentContext.tokenCounter != null && translatedRecovery.budgetTokens != null ? translatedRecovery : null;
|
|
1264
|
+
};
|
|
1265
|
+
const recovery = planRecovery(primaryError);
|
|
1266
|
+
if (recovery != null) return this.beginOverflowRecovery({
|
|
1267
|
+
recovery,
|
|
1268
|
+
agentContext,
|
|
1269
|
+
agentId,
|
|
1270
|
+
config,
|
|
1271
|
+
originalToolContent: prunedOriginalToolContent,
|
|
1272
|
+
estimatedPromptTokens
|
|
1273
|
+
});
|
|
1274
|
+
/**
|
|
1275
|
+
* A fallback can reject the same prompt as too large even when the
|
|
1276
|
+
* primary failed for an unrelated reason — a fallback with a smaller
|
|
1277
|
+
* window is the obvious case. Planning against the exhausted-chain
|
|
1278
|
+
* error keeps that path recoverable instead of surfacing it.
|
|
1279
|
+
*/
|
|
1280
|
+
try {
|
|
1281
|
+
result = await require_langfuseRuntimeScope.withLangfuseRuntimeScope(require_langfuseRuntimeScope.resolveLangfuseRuntimeScope({
|
|
1282
|
+
runLangfuse: this.langfuse,
|
|
1283
|
+
langfuseOverlay: agentContext.langfuse
|
|
1284
|
+
}), () => require_invoke.tryFallbackProviders({
|
|
1285
|
+
fallbacks,
|
|
1286
|
+
tools: agentContext.tools,
|
|
1287
|
+
messages: finalMessages,
|
|
1288
|
+
config: invokeConfig,
|
|
1289
|
+
primaryError,
|
|
1290
|
+
context: this,
|
|
1291
|
+
/**
|
|
1292
|
+
* Lets the chain recognise a fallback overflow whose signature
|
|
1293
|
+
* carries no reason of its own (Vertex AI's bare 400) and
|
|
1294
|
+
* surface it rather than a later unrelated failure.
|
|
1295
|
+
*/
|
|
1296
|
+
overflowContext: {
|
|
1297
|
+
provider: agentContext.provider,
|
|
1298
|
+
estimatedPromptTokens: getEstimatedPromptTokens(contextUsage),
|
|
1299
|
+
maxContextTokens: agentContext.maxContextTokens
|
|
1300
|
+
}
|
|
1301
|
+
}));
|
|
1302
|
+
} catch (fallbackError) {
|
|
1303
|
+
const overflowCandidates = require_invoke.getFallbackOverflowCandidates(fallbackError);
|
|
1304
|
+
let fallbackRecovery = null;
|
|
1305
|
+
for (const candidate of overflowCandidates) {
|
|
1306
|
+
fallbackRecovery = planRecovery(candidate.error, candidate.context);
|
|
1307
|
+
if (fallbackRecovery != null) break;
|
|
1308
|
+
}
|
|
1309
|
+
if (overflowCandidates.length === 0) fallbackRecovery = planRecovery(fallbackError);
|
|
1310
|
+
if (fallbackRecovery == null) throw fallbackError;
|
|
1311
|
+
return this.beginOverflowRecovery({
|
|
1312
|
+
recovery: fallbackRecovery,
|
|
1313
|
+
agentContext,
|
|
1314
|
+
agentId,
|
|
1315
|
+
config,
|
|
1316
|
+
originalToolContent: prunedOriginalToolContent,
|
|
1317
|
+
estimatedPromptTokens
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1138
1320
|
} finally {
|
|
1139
1321
|
await require_langfuse.disposeLangfuseHandler(langfuseHandler);
|
|
1140
1322
|
}
|
|
@@ -1373,9 +1555,13 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1373
1555
|
isMultiAgent: this.isMultiAgentGraph(),
|
|
1374
1556
|
hookRegistry: this.hookRegistry,
|
|
1375
1557
|
dispatchRunStep: async (runStep, nodeConfig) => {
|
|
1558
|
+
const resolvedConfig = nodeConfig ?? this.config;
|
|
1559
|
+
if (runStep.agentId != null) {
|
|
1560
|
+
const groupId = this.resolveParallelGroupId(runStep.agentId, resolvedConfig?.metadata);
|
|
1561
|
+
if (groupId != null) runStep.groupId = groupId;
|
|
1562
|
+
}
|
|
1376
1563
|
this.contentData.push(runStep);
|
|
1377
1564
|
this.contentIndexMap.set(runStep.id, runStep.index);
|
|
1378
|
-
const resolvedConfig = nodeConfig ?? this.config;
|
|
1379
1565
|
const handler = this.handlerRegistry?.getHandler("on_run_step");
|
|
1380
1566
|
if (handler) {
|
|
1381
1567
|
await handler.handle("on_run_step", runStep, resolvedConfig?.configurable, this);
|
|
@@ -1403,6 +1589,7 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1403
1589
|
})).addEdge(_langchain_langgraph.START, agentNode).addConditionalEdges(agentNode, routeMessage).addEdge(summarizeNode, agentNode).addEdge(toolNode, agentContext.toolEnd ? _langchain_langgraph.END : agentNode).compile();
|
|
1404
1590
|
}
|
|
1405
1591
|
createWorkflow() {
|
|
1592
|
+
this.hasCompiledCheckpointer = this.compileOptions?.checkpointer != null;
|
|
1406
1593
|
const agentNode = this.createAgentNode(this.defaultAgentId);
|
|
1407
1594
|
return new _langchain_langgraph.StateGraph(_langchain_langgraph.Annotation.Root({ messages: (0, _langchain_langgraph.Annotation)({
|
|
1408
1595
|
reducer: (a, b) => {
|
|
@@ -1430,6 +1617,13 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1430
1617
|
* @returns undefined for StandardGraph (no parallel groups), or group number for MultiAgentGraph
|
|
1431
1618
|
*/
|
|
1432
1619
|
getParallelGroupIdForAgent(_agentId) {}
|
|
1620
|
+
resolveParallelGroupId(agentId, metadata) {
|
|
1621
|
+
if (metadata == null || !Object.prototype.hasOwnProperty.call(metadata, "__handoff_group_id")) return this.getParallelGroupIdForAgent(agentId);
|
|
1622
|
+
const runtimeGroupId = metadata["__handoff_group_id"];
|
|
1623
|
+
if (runtimeGroupId === null) return;
|
|
1624
|
+
if (typeof runtimeGroupId === "number" && Number.isSafeInteger(runtimeGroupId) && runtimeGroupId > 0) return runtimeGroupId;
|
|
1625
|
+
return this.getParallelGroupIdForAgent(agentId);
|
|
1626
|
+
}
|
|
1433
1627
|
/**
|
|
1434
1628
|
* Dispatches a run step to the client, returns the step ID
|
|
1435
1629
|
*/
|
|
@@ -1455,7 +1649,7 @@ var StandardGraph = class StandardGraph extends Graph {
|
|
|
1455
1649
|
const agentContext = this.getAgentContext(metadata);
|
|
1456
1650
|
if (this.isMultiAgentGraph() && agentContext.agentId) {
|
|
1457
1651
|
runStep.agentId = agentContext.agentId;
|
|
1458
|
-
const groupId = this.
|
|
1652
|
+
const groupId = this.resolveParallelGroupId(agentContext.agentId, metadata);
|
|
1459
1653
|
if (groupId != null) runStep.groupId = groupId;
|
|
1460
1654
|
}
|
|
1461
1655
|
} catch (_e) {}
|