@librechat/agents 3.2.2 → 3.2.31
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 +3 -2
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +200 -54
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/hooks/createWorkspacePolicyHook.cjs +13 -7
- package/dist/cjs/hooks/createWorkspacePolicyHook.cjs.map +1 -1
- package/dist/cjs/hooks/executeHooks.cjs.map +1 -1
- package/dist/cjs/hooks/types.cjs.map +1 -1
- package/dist/cjs/instrumentation.cjs +33 -0
- package/dist/cjs/instrumentation.cjs.map +1 -1
- package/dist/cjs/langfuse.cjs +17 -1
- package/dist/cjs/langfuse.cjs.map +1 -1
- package/dist/cjs/langfuseToolOutputTracing.cjs +2 -2
- package/dist/cjs/langfuseToolOutputTracing.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/index.cjs +1 -1
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +2 -2
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/toolCache.cjs +8 -5
- package/dist/cjs/llm/bedrock/toolCache.cjs.map +1 -1
- package/dist/cjs/llm/fake.cjs +16 -14
- package/dist/cjs/llm/fake.cjs.map +1 -1
- package/dist/cjs/llm/google/index.cjs +22 -0
- package/dist/cjs/llm/google/index.cjs.map +1 -1
- package/dist/cjs/llm/google/utils/common.cjs +88 -27
- package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
- package/dist/cjs/llm/init.cjs +2 -2
- package/dist/cjs/llm/invoke.cjs +108 -11
- package/dist/cjs/llm/invoke.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +1 -1
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
- package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
- package/dist/cjs/llm/vertexai/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +1 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +8 -7
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/content.cjs.map +1 -1
- package/dist/cjs/messages/contextPruning.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +124 -17
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/cjs/messages/reducer.cjs +1 -1
- package/dist/cjs/messages/reducer.cjs.map +1 -1
- package/dist/cjs/messages/tools.cjs +1 -1
- package/dist/cjs/messages/tools.cjs.map +1 -1
- package/dist/cjs/openai/index.cjs.map +1 -1
- package/dist/cjs/responses/index.cjs.map +1 -1
- package/dist/cjs/run.cjs +47 -21
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/session/AgentSession.cjs +4 -4
- package/dist/cjs/session/AgentSession.cjs.map +1 -1
- package/dist/cjs/session/JsonlSessionStore.cjs +2 -2
- package/dist/cjs/session/JsonlSessionStore.cjs.map +1 -1
- package/dist/cjs/session/handlers.cjs +2 -2
- package/dist/cjs/session/handlers.cjs.map +1 -1
- package/dist/cjs/stream.cjs +248 -25
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +1 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/Calculator.cjs +1 -1
- package/dist/cjs/tools/Calculator.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/SubagentTool.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +37 -18
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/ToolSearch.cjs +1 -1
- package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs +7 -4
- package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareSandboxTools.cjs +4 -4
- package/dist/cjs/tools/cloudflare/CloudflareSandboxTools.cjs.map +1 -1
- package/dist/cjs/tools/handlers.cjs +2 -1
- package/dist/cjs/tools/handlers.cjs.map +1 -1
- package/dist/cjs/tools/local/CompileCheckTool.cjs.map +1 -1
- package/dist/cjs/tools/local/FileCheckpointer.cjs +2 -1
- package/dist/cjs/tools/local/FileCheckpointer.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalCodingTools.cjs +45 -19
- package/dist/cjs/tools/local/LocalCodingTools.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs +3 -3
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalExecutionTools.cjs +2 -2
- package/dist/cjs/tools/local/LocalExecutionTools.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +4 -3
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/local/attachments.cjs +0 -5
- package/dist/cjs/tools/local/attachments.cjs.map +1 -1
- package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs +4 -4
- package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs.map +1 -1
- package/dist/cjs/tools/search/firecrawl.cjs +1 -1
- package/dist/cjs/tools/search/firecrawl.cjs.map +1 -1
- package/dist/cjs/tools/search/rerankers.cjs +7 -3
- package/dist/cjs/tools/search/rerankers.cjs.map +1 -1
- package/dist/cjs/tools/search/tavily-search.cjs +1 -1
- package/dist/cjs/tools/search/tavily-search.cjs.map +1 -1
- package/dist/cjs/tools/search/utils.cjs +76 -8
- package/dist/cjs/tools/search/utils.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/utils/handlers.cjs +1 -1
- package/dist/cjs/utils/handlers.cjs.map +1 -1
- package/dist/cjs/utils/run.cjs +1 -1
- package/dist/cjs/utils/run.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +3 -2
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/events.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +200 -54
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/hooks/createWorkspacePolicyHook.mjs +13 -7
- package/dist/esm/hooks/createWorkspacePolicyHook.mjs.map +1 -1
- package/dist/esm/hooks/executeHooks.mjs.map +1 -1
- package/dist/esm/hooks/types.mjs.map +1 -1
- package/dist/esm/instrumentation.mjs +33 -1
- package/dist/esm/instrumentation.mjs.map +1 -1
- package/dist/esm/langfuse.mjs +17 -2
- package/dist/esm/langfuse.mjs.map +1 -1
- package/dist/esm/langfuseToolOutputTracing.mjs +2 -2
- package/dist/esm/langfuseToolOutputTracing.mjs.map +1 -1
- package/dist/esm/llm/anthropic/index.mjs +1 -1
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +2 -2
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/llm/bedrock/toolCache.mjs +8 -5
- package/dist/esm/llm/bedrock/toolCache.mjs.map +1 -1
- package/dist/esm/llm/fake.mjs +16 -14
- package/dist/esm/llm/fake.mjs.map +1 -1
- package/dist/esm/llm/google/index.mjs +23 -1
- package/dist/esm/llm/google/index.mjs.map +1 -1
- package/dist/esm/llm/google/utils/common.mjs +88 -27
- package/dist/esm/llm/google/utils/common.mjs.map +1 -1
- package/dist/esm/llm/init.mjs +2 -2
- package/dist/esm/llm/invoke.mjs +104 -7
- package/dist/esm/llm/invoke.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +1 -1
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs +1 -1
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/index.mjs.map +1 -1
- package/dist/esm/llm/vertexai/index.mjs.map +1 -1
- package/dist/esm/main.mjs +1 -1
- package/dist/esm/messages/cache.mjs +8 -7
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/content.mjs.map +1 -1
- package/dist/esm/messages/contextPruning.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +124 -18
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/messages/reducer.mjs +1 -1
- package/dist/esm/messages/reducer.mjs.map +1 -1
- package/dist/esm/messages/tools.mjs +1 -1
- package/dist/esm/messages/tools.mjs.map +1 -1
- package/dist/esm/openai/index.mjs.map +1 -1
- package/dist/esm/responses/index.mjs.map +1 -1
- package/dist/esm/run.mjs +47 -21
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/session/AgentSession.mjs +4 -4
- package/dist/esm/session/AgentSession.mjs.map +1 -1
- package/dist/esm/session/JsonlSessionStore.mjs +2 -2
- package/dist/esm/session/JsonlSessionStore.mjs.map +1 -1
- package/dist/esm/session/handlers.mjs +2 -2
- package/dist/esm/session/handlers.mjs.map +1 -1
- package/dist/esm/stream.mjs +248 -25
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +1 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/Calculator.mjs +1 -1
- package/dist/esm/tools/Calculator.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +1 -1
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/SubagentTool.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +37 -18
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/ToolSearch.mjs +1 -1
- package/dist/esm/tools/ToolSearch.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs +7 -4
- package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareSandboxTools.mjs +4 -4
- package/dist/esm/tools/cloudflare/CloudflareSandboxTools.mjs.map +1 -1
- package/dist/esm/tools/handlers.mjs +2 -1
- package/dist/esm/tools/handlers.mjs.map +1 -1
- package/dist/esm/tools/local/CompileCheckTool.mjs.map +1 -1
- package/dist/esm/tools/local/FileCheckpointer.mjs +2 -1
- package/dist/esm/tools/local/FileCheckpointer.mjs.map +1 -1
- package/dist/esm/tools/local/LocalCodingTools.mjs +45 -19
- package/dist/esm/tools/local/LocalCodingTools.mjs.map +1 -1
- package/dist/esm/tools/local/LocalExecutionEngine.mjs +3 -3
- package/dist/esm/tools/local/LocalExecutionEngine.mjs.map +1 -1
- package/dist/esm/tools/local/LocalExecutionTools.mjs +2 -2
- package/dist/esm/tools/local/LocalExecutionTools.mjs.map +1 -1
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +4 -3
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/local/attachments.mjs +0 -5
- package/dist/esm/tools/local/attachments.mjs.map +1 -1
- package/dist/esm/tools/local/resolveLocalExecutionTools.mjs +4 -4
- package/dist/esm/tools/local/resolveLocalExecutionTools.mjs.map +1 -1
- package/dist/esm/tools/search/firecrawl.mjs +1 -1
- package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
- package/dist/esm/tools/search/rerankers.mjs +8 -4
- package/dist/esm/tools/search/rerankers.mjs.map +1 -1
- package/dist/esm/tools/search/tavily-search.mjs +1 -1
- package/dist/esm/tools/search/tavily-search.mjs.map +1 -1
- package/dist/esm/tools/search/utils.mjs +76 -9
- package/dist/esm/tools/search/utils.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/utils/handlers.mjs +1 -1
- package/dist/esm/utils/handlers.mjs.map +1 -1
- package/dist/esm/utils/run.mjs +1 -1
- package/dist/esm/utils/run.mjs.map +1 -1
- package/dist/types/agents/__tests__/promptCacheLiveHelpers.d.ts +1 -1
- package/dist/types/events.d.ts +1 -1
- package/dist/types/graphs/Graph.d.ts +7 -1
- package/dist/types/hooks/executeHooks.d.ts +1 -1
- package/dist/types/hooks/types.d.ts +5 -0
- package/dist/types/instrumentation.d.ts +1 -0
- package/dist/types/langfuse.d.ts +4 -0
- package/dist/types/llm/anthropic/utils/message_inputs.d.ts +1 -1
- package/dist/types/llm/anthropic/utils/message_outputs.d.ts +1 -1
- package/dist/types/llm/anthropic/utils/output_parsers.d.ts +2 -2
- package/dist/types/llm/bedrock/index.d.ts +2 -2
- package/dist/types/llm/fake.d.ts +3 -3
- package/dist/types/llm/google/index.d.ts +1 -0
- package/dist/types/llm/google/types.d.ts +1 -1
- package/dist/types/llm/google/utils/common.d.ts +2 -2
- package/dist/types/llm/google/utils/tools.d.ts +1 -1
- package/dist/types/llm/google/utils/zod_to_genai_parameters.d.ts +1 -1
- package/dist/types/llm/openai/index.d.ts +2 -2
- package/dist/types/llm/openai/utils/index.d.ts +1 -1
- package/dist/types/llm/openrouter/index.d.ts +4 -4
- package/dist/types/messages/contextPruning.d.ts +1 -1
- package/dist/types/messages/format.d.ts +9 -4
- package/dist/types/messages/prune.d.ts +1 -1
- package/dist/types/session/JsonlSessionStore.d.ts +1 -1
- package/dist/types/session/handlers.d.ts +1 -1
- package/dist/types/session/types.d.ts +1 -1
- package/dist/types/summarization/node.d.ts +1 -1
- package/dist/types/tools/SubagentTool.d.ts +2 -2
- package/dist/types/tools/ToolNode.d.ts +9 -2
- package/dist/types/tools/cloudflare/CloudflareSandboxExecutionEngine.d.ts +1 -1
- package/dist/types/tools/search/types.d.ts +1 -1
- package/dist/types/tools/search/utils.d.ts +11 -0
- package/dist/types/types/graph.d.ts +12 -4
- package/dist/types/types/llm.d.ts +4 -3
- package/dist/types/types/messages.d.ts +1 -1
- package/dist/types/types/run.d.ts +6 -6
- package/dist/types/types/stream.d.ts +2 -2
- package/dist/types/types/tools.d.ts +5 -1
- package/dist/types/utils/handlers.d.ts +2 -2
- package/dist/types/utils/run.d.ts +1 -1
- package/package.json +6 -3
- package/src/__tests__/stream.eagerEventExecution.test.ts +543 -6
- package/src/agents/AgentContext.ts +2 -2
- package/src/agents/__tests__/AgentContext.test.ts +3 -3
- package/src/agents/__tests__/promptCacheLiveHelpers.ts +1 -1
- package/src/events.ts +1 -1
- package/src/graphs/Graph.ts +329 -72
- package/src/graphs/MultiAgentGraph.ts +1 -1
- package/src/graphs/__tests__/Graph.reasoning.test.ts +919 -6
- package/src/graphs/__tests__/MultiAgentGraph.test.ts +1 -1
- package/src/graphs/__tests__/composition.smoke.test.ts +1 -1
- package/src/hooks/__tests__/HookRegistry.test.ts +1 -1
- package/src/hooks/__tests__/compactHooks.test.ts +8 -8
- package/src/hooks/__tests__/createWorkspacePolicyHook.test.ts +34 -22
- package/src/hooks/__tests__/executeHooks.test.ts +3 -3
- package/src/hooks/__tests__/integration.test.ts +3 -3
- package/src/hooks/__tests__/toolHooks.test.ts +10 -10
- package/src/hooks/createWorkspacePolicyHook.ts +17 -14
- package/src/hooks/executeHooks.ts +1 -1
- package/src/hooks/types.ts +5 -0
- package/src/instrumentation.ts +49 -8
- package/src/langfuse.ts +35 -1
- package/src/langfuseToolOutputTracing.ts +2 -2
- package/src/llm/anthropic/index.ts +1 -1
- package/src/llm/anthropic/utils/message_inputs.ts +1 -1
- package/src/llm/anthropic/utils/message_outputs.ts +3 -5
- package/src/llm/anthropic/utils/output_parsers.ts +5 -5
- package/src/llm/bedrock/index.ts +4 -4
- package/src/llm/bedrock/toolCache.test.ts +48 -9
- package/src/llm/bedrock/toolCache.ts +11 -6
- package/src/llm/custom-chat-models.smoke.test.ts +114 -0
- package/src/llm/fake.ts +30 -25
- package/src/llm/google/index.ts +43 -1
- package/src/llm/google/llm.spec.ts +173 -1
- package/src/llm/google/types.ts +1 -1
- package/src/llm/google/utils/common.ts +154 -45
- package/src/llm/google/utils/tools.ts +8 -8
- package/src/llm/google/utils/zod_to_genai_parameters.ts +4 -4
- package/src/llm/invoke.test.ts +3 -3
- package/src/llm/invoke.ts +170 -10
- package/src/llm/openai/index.ts +4 -4
- package/src/llm/openai/utils/index.ts +14 -14
- package/src/llm/openrouter/index.ts +4 -4
- package/src/llm/openrouter/reasoning.test.ts +2 -2
- package/src/llm/vertexai/fixThoughtSignatures.test.ts +1 -1
- package/src/llm/vertexai/index.ts +1 -1
- package/src/messages/cache.test.ts +22 -0
- package/src/messages/cache.ts +25 -12
- package/src/messages/content.ts +1 -1
- package/src/messages/contextPruning.ts +1 -1
- package/src/messages/format.ts +227 -43
- package/src/messages/formatAgentMessages.skills.test.ts +105 -26
- package/src/messages/formatAgentMessages.test.ts +841 -10
- package/src/messages/labelContentByAgent.test.ts +2 -2
- package/src/messages/prune.ts +1 -1
- package/src/messages/reducer.ts +1 -1
- package/src/messages/tools.ts +1 -1
- package/src/openai/__tests__/openai.test.ts +2 -2
- package/src/openai/index.ts +1 -1
- package/src/responses/__tests__/responses.test.ts +2 -2
- package/src/responses/index.ts +1 -1
- package/src/run.ts +82 -47
- package/src/session/AgentSession.ts +6 -6
- package/src/session/JsonlSessionStore.ts +3 -3
- package/src/session/__tests__/JsonlSessionStore.test.ts +5 -5
- package/src/session/__tests__/handlers.test.ts +2 -2
- package/src/session/handlers.ts +5 -5
- package/src/session/types.ts +1 -1
- package/src/specs/agent-handoffs.test.ts +1 -1
- package/src/specs/deterministic-trace-id.test.ts +50 -0
- package/src/specs/langfuse-callbacks.test.ts +2 -2
- package/src/specs/langfuse-metadata.test.ts +39 -0
- package/src/specs/langfuse-tool-output-tracing.test.ts +1 -1
- package/src/specs/multi-agent-summarization.test.ts +4 -4
- package/src/specs/subagent.test.ts +3 -3
- package/src/specs/summarization-unit.test.ts +1 -1
- package/src/specs/thinking-handoff.test.ts +1 -1
- package/src/splitStream.test.ts +48 -0
- package/src/stream.test.ts +53 -3
- package/src/stream.ts +450 -39
- package/src/summarization/__tests__/aggregator.test.ts +2 -2
- package/src/summarization/__tests__/node.test.ts +2 -2
- package/src/summarization/node.ts +1 -1
- package/src/tools/BashProgrammaticToolCalling.ts +5 -5
- package/src/tools/Calculator.ts +1 -1
- package/src/tools/CodeExecutor.ts +2 -4
- package/src/tools/SubagentTool.ts +2 -2
- package/src/tools/ToolNode.ts +37 -16
- package/src/tools/ToolSearch.ts +1 -1
- package/src/tools/__tests__/CloudflareSandboxExecution.test.ts +4 -4
- package/src/tools/__tests__/CodeApiAuthHeaders.test.ts +12 -12
- package/src/tools/__tests__/LocalExecutionTools.test.ts +125 -93
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +29 -5
- package/src/tools/__tests__/ReadFile.test.ts +1 -1
- package/src/tools/__tests__/SkillTool.test.ts +4 -4
- package/src/tools/__tests__/SubagentExecutor.test.ts +17 -13
- package/src/tools/__tests__/SubagentTool.test.ts +2 -2
- package/src/tools/__tests__/ToolNode.eagerEventExecution.test.ts +1 -1
- package/src/tools/__tests__/ToolNode.outputReferences.test.ts +2 -5
- package/src/tools/__tests__/ToolNode.session.test.ts +1 -1
- package/src/tools/__tests__/ToolSearch.test.ts +1 -1
- package/src/tools/__tests__/annotateMessagesForLLM.test.ts +1 -1
- package/src/tools/__tests__/directToolHITLResumeScope.test.ts +35 -32
- package/src/tools/__tests__/directToolHooks.test.ts +41 -0
- package/src/tools/__tests__/handlers.test.ts +2 -2
- package/src/tools/__tests__/hitl.test.ts +11 -11
- package/src/tools/__tests__/localToolNames.test.ts +8 -6
- package/src/tools/__tests__/skillCatalog.test.ts +1 -1
- package/src/tools/__tests__/subagentHooks.test.ts +20 -10
- package/src/tools/__tests__/workspaceSeam.test.ts +20 -7
- package/src/tools/cloudflare/CloudflareSandboxExecutionEngine.ts +9 -6
- package/src/tools/cloudflare/CloudflareSandboxTools.ts +19 -19
- package/src/tools/handlers.ts +5 -5
- package/src/tools/local/CompileCheckTool.ts +4 -7
- package/src/tools/local/FileCheckpointer.ts +6 -5
- package/src/tools/local/LocalCodingTools.ts +100 -45
- package/src/tools/local/LocalExecutionEngine.ts +5 -5
- package/src/tools/local/LocalExecutionTools.ts +9 -9
- package/src/tools/local/LocalProgrammaticToolCalling.ts +5 -4
- package/src/tools/local/attachments.ts +0 -6
- package/src/tools/local/resolveLocalExecutionTools.ts +15 -15
- package/src/tools/search/firecrawl.ts +1 -1
- package/src/tools/search/jina-reranker.test.ts +148 -37
- package/src/tools/search/rerankers.ts +14 -4
- package/src/tools/search/tavily-search.ts +2 -2
- package/src/tools/search/types.ts +1 -1
- package/src/tools/search/utils.ts +99 -9
- package/src/tools/subagent/SubagentExecutor.ts +12 -6
- package/src/types/graph.ts +20 -12
- package/src/types/llm.ts +7 -6
- package/src/types/messages.ts +1 -1
- package/src/types/run.ts +7 -7
- package/src/types/stream.ts +2 -2
- package/src/types/tools.ts +5 -1
- package/src/utils/handlers.ts +2 -2
- package/src/utils/llmConfig.ts +1 -1
- package/src/utils/logging.ts +20 -10
- package/src/utils/run.ts +2 -2
package/src/stream.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/stream.ts
|
|
2
|
+
import type { ToolCall, ToolCallChunk } from '@langchain/core/messages/tool';
|
|
2
3
|
import type { ChatOpenAIReasoningSummary } from '@langchain/openai';
|
|
3
4
|
import type { AIMessageChunk } from '@langchain/core/messages';
|
|
4
|
-
import type { ToolCall, ToolCallChunk } from '@langchain/core/messages/tool';
|
|
5
5
|
import type { AgentContext } from '@/agents/AgentContext';
|
|
6
6
|
import type { StandardGraph } from '@/graphs';
|
|
7
7
|
import type * as t from '@/types';
|
|
@@ -16,32 +16,37 @@ import {
|
|
|
16
16
|
LOCAL_CODING_BUNDLE_NAMES,
|
|
17
17
|
} from '@/common';
|
|
18
18
|
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} from '@/tools/
|
|
23
|
-
import { getMessageId } from '@/messages';
|
|
24
|
-
import { safeDispatchCustomEvent } from '@/utils/events';
|
|
19
|
+
getStreamedToolCallSeal,
|
|
20
|
+
getStreamedToolCallAdapter,
|
|
21
|
+
type StreamedToolCallSeal,
|
|
22
|
+
} from '@/tools/streamedToolCallSeals';
|
|
25
23
|
import {
|
|
26
24
|
buildToolExecutionRequestPlan,
|
|
27
25
|
coerceRecordArgs,
|
|
28
26
|
normalizeError,
|
|
29
27
|
} from '@/tools/eagerEventExecution';
|
|
28
|
+
import {
|
|
29
|
+
handleServerToolResult,
|
|
30
|
+
handleToolCallChunks,
|
|
31
|
+
handleToolCalls,
|
|
32
|
+
} from '@/tools/handlers';
|
|
30
33
|
import {
|
|
31
34
|
calculateMaxToolResultChars,
|
|
32
35
|
truncateToolResultContent,
|
|
33
36
|
} from '@/utils/truncation';
|
|
34
|
-
import {
|
|
35
|
-
getStreamedToolCallSeal,
|
|
36
|
-
getStreamedToolCallAdapter,
|
|
37
|
-
type StreamedToolCallSeal,
|
|
38
|
-
} from '@/tools/streamedToolCallSeals';
|
|
39
37
|
import { TOOL_OUTPUT_REF_PATTERN } from '@/tools/toolOutputReferences';
|
|
38
|
+
import { safeDispatchCustomEvent } from '@/utils/events';
|
|
39
|
+
import { isGoogleLike } from '@/utils/llm';
|
|
40
|
+
import { getMessageId } from '@/messages';
|
|
40
41
|
|
|
41
42
|
const LOCAL_CODING_BUNDLE_NAME_SET: ReadonlySet<string> = new Set(
|
|
42
43
|
LOCAL_CODING_BUNDLE_NAMES
|
|
43
44
|
);
|
|
44
45
|
|
|
46
|
+
type ReasoningSummaryLike = {
|
|
47
|
+
summary?: Array<{ text?: string }>;
|
|
48
|
+
};
|
|
49
|
+
|
|
45
50
|
/**
|
|
46
51
|
* Parses content to extract thinking sections enclosed in <think> tags using string operations
|
|
47
52
|
* @param content The content to parse
|
|
@@ -329,6 +334,230 @@ function hasDirectToolCallChunkStateInStep(args: {
|
|
|
329
334
|
return false;
|
|
330
335
|
}
|
|
331
336
|
|
|
337
|
+
function isGoogleServerSideToolContentPart(
|
|
338
|
+
contentPart: t.MessageContentComplex
|
|
339
|
+
): boolean {
|
|
340
|
+
return contentPart.type === 'toolCall' || contentPart.type === 'toolResponse';
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function isTextContentPart(contentPart: t.MessageContentComplex): boolean {
|
|
344
|
+
return contentPart.type?.startsWith(ContentTypes.TEXT) ?? false;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function isReasoningContentPart(contentPart: t.MessageContentComplex): boolean {
|
|
348
|
+
return (
|
|
349
|
+
(contentPart.type?.startsWith(ContentTypes.THINKING) ?? false) ||
|
|
350
|
+
(contentPart.type?.startsWith(ContentTypes.REASONING) ?? false) ||
|
|
351
|
+
(contentPart.type?.startsWith(ContentTypes.REASONING_CONTENT) ?? false) ||
|
|
352
|
+
contentPart.type === 'redacted_thinking'
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function getReasoningTextFromContentPart(
|
|
357
|
+
contentPart: t.MessageContentComplex
|
|
358
|
+
): string {
|
|
359
|
+
return (
|
|
360
|
+
(contentPart as t.ThinkingContentText).thinking ??
|
|
361
|
+
(contentPart as Partial<t.GoogleReasoningContentText>).reasoning ??
|
|
362
|
+
(contentPart as Partial<t.BedrockReasoningContentText>).reasoningText
|
|
363
|
+
?.text ??
|
|
364
|
+
''
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function getReasoningTextFromChunk(
|
|
369
|
+
chunk: Partial<AIMessageChunk>,
|
|
370
|
+
agentContext: AgentContext
|
|
371
|
+
): string {
|
|
372
|
+
const reasoning = chunk.additional_kwargs?.[agentContext.reasoningKey] as
|
|
373
|
+
| string
|
|
374
|
+
| Partial<ChatOpenAIReasoningSummary>
|
|
375
|
+
| undefined;
|
|
376
|
+
if (typeof reasoning === 'string') {
|
|
377
|
+
return reasoning;
|
|
378
|
+
}
|
|
379
|
+
return reasoning?.summary?.[0]?.text ?? '';
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const googleServerSideToolStepIdsByGraph = new WeakMap<
|
|
383
|
+
StandardGraph,
|
|
384
|
+
Set<string>
|
|
385
|
+
>();
|
|
386
|
+
|
|
387
|
+
function markGoogleServerSideToolMessageStep(
|
|
388
|
+
graph: StandardGraph,
|
|
389
|
+
stepId: string
|
|
390
|
+
): void {
|
|
391
|
+
const stepIds = googleServerSideToolStepIdsByGraph.get(graph) ?? new Set();
|
|
392
|
+
stepIds.add(stepId);
|
|
393
|
+
googleServerSideToolStepIdsByGraph.set(graph, stepIds);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function isGoogleServerSideToolMessageStep(
|
|
397
|
+
graph: StandardGraph,
|
|
398
|
+
stepId: string
|
|
399
|
+
): boolean {
|
|
400
|
+
return googleServerSideToolStepIdsByGraph.get(graph)?.has(stepId) === true;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function shouldStartFreshMessageStepAfterGoogleServerSideTool({
|
|
404
|
+
graph,
|
|
405
|
+
stepId,
|
|
406
|
+
runStep,
|
|
407
|
+
content,
|
|
408
|
+
}: {
|
|
409
|
+
graph: StandardGraph;
|
|
410
|
+
stepId: string;
|
|
411
|
+
runStep?: t.RunStep;
|
|
412
|
+
content: string | t.MessageContentComplex[];
|
|
413
|
+
}): boolean {
|
|
414
|
+
if (
|
|
415
|
+
runStep?.type !== StepTypes.MESSAGE_CREATION ||
|
|
416
|
+
!isGoogleServerSideToolMessageStep(graph, stepId)
|
|
417
|
+
) {
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
420
|
+
if (typeof content === 'string') {
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
return (
|
|
424
|
+
content.every((c) => isTextContentPart(c)) ||
|
|
425
|
+
content.every((c) => isReasoningContentPart(c))
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
async function dispatchMessageCreationStep({
|
|
430
|
+
graph,
|
|
431
|
+
stepKey,
|
|
432
|
+
metadata,
|
|
433
|
+
}: {
|
|
434
|
+
graph: StandardGraph;
|
|
435
|
+
stepKey: string;
|
|
436
|
+
metadata?: Record<string, unknown>;
|
|
437
|
+
}): Promise<string> {
|
|
438
|
+
const messageId = getMessageId(stepKey, graph, true) ?? '';
|
|
439
|
+
return graph.dispatchRunStep(
|
|
440
|
+
stepKey,
|
|
441
|
+
{
|
|
442
|
+
type: StepTypes.MESSAGE_CREATION,
|
|
443
|
+
message_creation: {
|
|
444
|
+
message_id: messageId,
|
|
445
|
+
},
|
|
446
|
+
},
|
|
447
|
+
metadata
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
async function dispatchMessageContentParts({
|
|
452
|
+
graph,
|
|
453
|
+
stepKey,
|
|
454
|
+
content,
|
|
455
|
+
metadata,
|
|
456
|
+
}: {
|
|
457
|
+
graph: StandardGraph;
|
|
458
|
+
stepKey: string;
|
|
459
|
+
content: t.MessageContentComplex[];
|
|
460
|
+
metadata?: Record<string, unknown>;
|
|
461
|
+
}): Promise<void> {
|
|
462
|
+
for (const contentPart of content) {
|
|
463
|
+
const currentStepId = await dispatchMessageCreationStep({
|
|
464
|
+
graph,
|
|
465
|
+
stepKey,
|
|
466
|
+
metadata,
|
|
467
|
+
});
|
|
468
|
+
if (isGoogleServerSideToolContentPart(contentPart)) {
|
|
469
|
+
markGoogleServerSideToolMessageStep(graph, currentStepId);
|
|
470
|
+
}
|
|
471
|
+
await graph.dispatchMessageDelta(
|
|
472
|
+
currentStepId,
|
|
473
|
+
{
|
|
474
|
+
content: [contentPart],
|
|
475
|
+
},
|
|
476
|
+
metadata
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
async function dispatchReasoningContentParts({
|
|
482
|
+
graph,
|
|
483
|
+
stepKey,
|
|
484
|
+
content,
|
|
485
|
+
metadata,
|
|
486
|
+
}: {
|
|
487
|
+
graph: StandardGraph;
|
|
488
|
+
stepKey: string;
|
|
489
|
+
content: t.MessageContentComplex[];
|
|
490
|
+
metadata?: Record<string, unknown>;
|
|
491
|
+
}): Promise<void> {
|
|
492
|
+
if (content.length === 0) {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
const currentStepId = await dispatchMessageCreationStep({
|
|
496
|
+
graph,
|
|
497
|
+
stepKey,
|
|
498
|
+
metadata,
|
|
499
|
+
});
|
|
500
|
+
await graph.dispatchReasoningDelta(
|
|
501
|
+
currentStepId,
|
|
502
|
+
{
|
|
503
|
+
content,
|
|
504
|
+
},
|
|
505
|
+
metadata
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
async function dispatchGoogleServerSideToolStreamContent({
|
|
510
|
+
graph,
|
|
511
|
+
stepKey,
|
|
512
|
+
chunk,
|
|
513
|
+
agentContext,
|
|
514
|
+
content,
|
|
515
|
+
metadata,
|
|
516
|
+
}: {
|
|
517
|
+
graph: StandardGraph;
|
|
518
|
+
stepKey: string;
|
|
519
|
+
chunk: Partial<AIMessageChunk>;
|
|
520
|
+
agentContext: AgentContext;
|
|
521
|
+
content: t.MessageContentComplex[];
|
|
522
|
+
metadata?: Record<string, unknown>;
|
|
523
|
+
}): Promise<void> {
|
|
524
|
+
const reasoningContent: t.MessageContentComplex[] = [];
|
|
525
|
+
const reasoningText = getReasoningTextFromChunk(chunk, agentContext);
|
|
526
|
+
if (reasoningText !== '') {
|
|
527
|
+
reasoningContent.push({
|
|
528
|
+
type: ContentTypes.THINK,
|
|
529
|
+
think: reasoningText,
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
reasoningContent.push(
|
|
533
|
+
...content
|
|
534
|
+
.filter((contentPart) => isReasoningContentPart(contentPart))
|
|
535
|
+
.map((contentPart) => ({
|
|
536
|
+
type: ContentTypes.THINK,
|
|
537
|
+
think: getReasoningTextFromContentPart(contentPart),
|
|
538
|
+
}))
|
|
539
|
+
.filter((contentPart) => contentPart.think !== '')
|
|
540
|
+
);
|
|
541
|
+
await dispatchReasoningContentParts({
|
|
542
|
+
graph,
|
|
543
|
+
stepKey,
|
|
544
|
+
content: reasoningContent,
|
|
545
|
+
metadata,
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
const messageContent = content.filter(
|
|
549
|
+
(contentPart) =>
|
|
550
|
+
isTextContentPart(contentPart) ||
|
|
551
|
+
isGoogleServerSideToolContentPart(contentPart)
|
|
552
|
+
);
|
|
553
|
+
await dispatchMessageContentParts({
|
|
554
|
+
graph,
|
|
555
|
+
stepKey,
|
|
556
|
+
content: messageContent,
|
|
557
|
+
metadata,
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
|
|
332
561
|
type EagerToolExecutionEntry = {
|
|
333
562
|
id: string;
|
|
334
563
|
toolName: string;
|
|
@@ -890,6 +1119,14 @@ export function getChunkContent({
|
|
|
890
1119
|
provider?: Providers;
|
|
891
1120
|
reasoningKey: 'reasoning_content' | 'reasoning';
|
|
892
1121
|
}): string | t.MessageContentComplex[] | undefined {
|
|
1122
|
+
if (
|
|
1123
|
+
isGoogleLike(provider) &&
|
|
1124
|
+
Array.isArray(chunk?.content) &&
|
|
1125
|
+
chunk.content.some((c) => isGoogleServerSideToolContentPart(c))
|
|
1126
|
+
) {
|
|
1127
|
+
return chunk.content;
|
|
1128
|
+
}
|
|
1129
|
+
|
|
893
1130
|
if (
|
|
894
1131
|
(provider === Providers.OPENAI || provider === Providers.AZURE) &&
|
|
895
1132
|
(
|
|
@@ -909,16 +1146,6 @@ export function getChunkContent({
|
|
|
909
1146
|
| undefined
|
|
910
1147
|
)?.summary?.[0]?.text;
|
|
911
1148
|
}
|
|
912
|
-
/**
|
|
913
|
-
* For OpenRouter, reasoning is stored in additional_kwargs.reasoning (not reasoning_content).
|
|
914
|
-
* NOTE: We intentionally do NOT extract text from reasoning_details here.
|
|
915
|
-
* The reasoning_details array contains the FULL accumulated reasoning text (set only on final chunk),
|
|
916
|
-
* but individual reasoning tokens are already streamed via additional_kwargs.reasoning.
|
|
917
|
-
* Extracting from reasoning_details would cause duplication.
|
|
918
|
-
* The reasoning_details is only used for:
|
|
919
|
-
* 1. Detecting reasoning mode in handleReasoning()
|
|
920
|
-
* 2. Final message storage (for thought signatures)
|
|
921
|
-
*/
|
|
922
1149
|
if (provider === Providers.OPENROUTER) {
|
|
923
1150
|
// Content presence signals end of reasoning phase - prefer content over reasoning
|
|
924
1151
|
// This handles transitional chunks that may have both reasoning and content
|
|
@@ -929,11 +1156,158 @@ export function getChunkContent({
|
|
|
929
1156
|
if (reasoning != null && reasoning !== '') {
|
|
930
1157
|
return reasoning;
|
|
931
1158
|
}
|
|
1159
|
+
const reasoningContent = chunk?.additional_kwargs?.reasoning_content as
|
|
1160
|
+
| string
|
|
1161
|
+
| undefined;
|
|
1162
|
+
if (reasoningContent != null && reasoningContent !== '') {
|
|
1163
|
+
return reasoningContent;
|
|
1164
|
+
}
|
|
932
1165
|
return chunk?.content;
|
|
933
1166
|
}
|
|
1167
|
+
const keyedReasoning = chunk?.additional_kwargs?.[reasoningKey] as
|
|
1168
|
+
| string
|
|
1169
|
+
| undefined;
|
|
1170
|
+
if (
|
|
1171
|
+
typeof chunk?.content === 'string' &&
|
|
1172
|
+
chunk.content !== '' &&
|
|
1173
|
+
keyedReasoning != null &&
|
|
1174
|
+
keyedReasoning !== ''
|
|
1175
|
+
) {
|
|
1176
|
+
return chunk.content;
|
|
1177
|
+
}
|
|
1178
|
+
return ((keyedReasoning as string | undefined) ?? '') || chunk?.content;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
function isDisableStreamingEnabled(
|
|
1182
|
+
clientOptions: t.ClientOptions | undefined
|
|
1183
|
+
): boolean {
|
|
1184
|
+
return (
|
|
1185
|
+
clientOptions != null &&
|
|
1186
|
+
'disableStreaming' in clientOptions &&
|
|
1187
|
+
clientOptions.disableStreaming === true
|
|
1188
|
+
);
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
function hasReasoningContent(
|
|
1192
|
+
value: string | ReasoningSummaryLike | object[] | null | undefined
|
|
1193
|
+
): boolean {
|
|
1194
|
+
if (typeof value === 'string') {
|
|
1195
|
+
return value !== '';
|
|
1196
|
+
}
|
|
1197
|
+
if (Array.isArray(value)) {
|
|
1198
|
+
return value.length > 0;
|
|
1199
|
+
}
|
|
1200
|
+
if (value == null) {
|
|
1201
|
+
return false;
|
|
1202
|
+
}
|
|
1203
|
+
return (
|
|
1204
|
+
value.summary?.some(
|
|
1205
|
+
(summary) => summary.text != null && summary.text.length > 0
|
|
1206
|
+
) === true
|
|
1207
|
+
);
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
function shouldDeferMixedFinalReasoningChunk({
|
|
1211
|
+
chunk,
|
|
1212
|
+
agentContext,
|
|
1213
|
+
}: {
|
|
1214
|
+
chunk: Partial<AIMessageChunk>;
|
|
1215
|
+
agentContext: AgentContext;
|
|
1216
|
+
}): boolean {
|
|
1217
|
+
if (
|
|
1218
|
+
(chunk.tool_calls?.length ?? 0) > 0 ||
|
|
1219
|
+
(chunk.tool_call_chunks?.length ?? 0) > 0 ||
|
|
1220
|
+
typeof chunk.content !== 'string' ||
|
|
1221
|
+
chunk.content === ''
|
|
1222
|
+
) {
|
|
1223
|
+
return false;
|
|
1224
|
+
}
|
|
1225
|
+
const additionalKwargs = chunk.additional_kwargs;
|
|
1226
|
+
if (
|
|
1227
|
+
agentContext.provider === Providers.OPENROUTER &&
|
|
1228
|
+
hasReasoningContent(additionalKwargs?.reasoning_details as object[])
|
|
1229
|
+
) {
|
|
1230
|
+
return true;
|
|
1231
|
+
}
|
|
1232
|
+
if (!isDisableStreamingEnabled(agentContext.clientOptions)) {
|
|
1233
|
+
return false;
|
|
1234
|
+
}
|
|
1235
|
+
return (
|
|
1236
|
+
hasReasoningContent(
|
|
1237
|
+
additionalKwargs?.[agentContext.reasoningKey] as
|
|
1238
|
+
| string
|
|
1239
|
+
| ReasoningSummaryLike
|
|
1240
|
+
| null
|
|
1241
|
+
| undefined
|
|
1242
|
+
) ||
|
|
1243
|
+
hasReasoningContent(
|
|
1244
|
+
additionalKwargs?.reasoning_content as
|
|
1245
|
+
| string
|
|
1246
|
+
| ReasoningSummaryLike
|
|
1247
|
+
| null
|
|
1248
|
+
| undefined
|
|
1249
|
+
) ||
|
|
1250
|
+
hasReasoningContent(
|
|
1251
|
+
additionalKwargs?.reasoning as
|
|
1252
|
+
| string
|
|
1253
|
+
| ReasoningSummaryLike
|
|
1254
|
+
| null
|
|
1255
|
+
| undefined
|
|
1256
|
+
) ||
|
|
1257
|
+
hasReasoningContent(additionalKwargs?.reasoning_details as object[])
|
|
1258
|
+
);
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
function hasCurrentTextDeltaStep({
|
|
1262
|
+
graph,
|
|
1263
|
+
metadata,
|
|
1264
|
+
}: {
|
|
1265
|
+
graph: StandardGraph;
|
|
1266
|
+
metadata?: Record<string, unknown>;
|
|
1267
|
+
}): boolean {
|
|
1268
|
+
if (metadata == null) {
|
|
1269
|
+
return false;
|
|
1270
|
+
}
|
|
1271
|
+
const baseStepKey = graph.getStepBaseKey(metadata);
|
|
1272
|
+
for (const [stepKey, stepIds] of graph.stepKeyIds) {
|
|
1273
|
+
if (stepKey !== baseStepKey && !stepKey.startsWith(`${baseStepKey}_`)) {
|
|
1274
|
+
continue;
|
|
1275
|
+
}
|
|
1276
|
+
if (stepIds.some((stepId) => graph.messageStepHasTextDeltas.has(stepId))) {
|
|
1277
|
+
return true;
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
return false;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
function shouldSkipLateOpenRouterReasoningChunk({
|
|
1284
|
+
chunk,
|
|
1285
|
+
agentContext,
|
|
1286
|
+
graph,
|
|
1287
|
+
metadata,
|
|
1288
|
+
}: {
|
|
1289
|
+
chunk: Partial<AIMessageChunk>;
|
|
1290
|
+
agentContext: AgentContext;
|
|
1291
|
+
graph: StandardGraph;
|
|
1292
|
+
metadata?: Record<string, unknown>;
|
|
1293
|
+
}): boolean {
|
|
1294
|
+
if (
|
|
1295
|
+
agentContext.provider !== Providers.OPENROUTER ||
|
|
1296
|
+
(chunk.tool_calls?.length ?? 0) > 0 ||
|
|
1297
|
+
(chunk.tool_call_chunks?.length ?? 0) > 0 ||
|
|
1298
|
+
(chunk.content != null && chunk.content !== '')
|
|
1299
|
+
) {
|
|
1300
|
+
return false;
|
|
1301
|
+
}
|
|
934
1302
|
return (
|
|
935
|
-
((chunk
|
|
936
|
-
|
|
1303
|
+
(hasReasoningContent(chunk.additional_kwargs?.reasoning as string) ||
|
|
1304
|
+
hasReasoningContent(
|
|
1305
|
+
chunk.additional_kwargs?.reasoning_content as string
|
|
1306
|
+
) ||
|
|
1307
|
+
hasReasoningContent(
|
|
1308
|
+
chunk.additional_kwargs?.reasoning_details as object[]
|
|
1309
|
+
)) &&
|
|
1310
|
+
hasCurrentTextDeltaStep({ graph, metadata })
|
|
937
1311
|
);
|
|
938
1312
|
}
|
|
939
1313
|
|
|
@@ -974,11 +1348,39 @@ export class ChatModelStreamHandler implements t.EventHandler {
|
|
|
974
1348
|
if (skipHandling) {
|
|
975
1349
|
return;
|
|
976
1350
|
}
|
|
1351
|
+
if (shouldDeferMixedFinalReasoningChunk({ chunk, agentContext })) {
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1354
|
+
if (
|
|
1355
|
+
shouldSkipLateOpenRouterReasoningChunk({
|
|
1356
|
+
chunk,
|
|
1357
|
+
agentContext,
|
|
1358
|
+
graph,
|
|
1359
|
+
metadata,
|
|
1360
|
+
})
|
|
1361
|
+
) {
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
977
1364
|
this.handleReasoning(chunk, agentContext);
|
|
978
1365
|
const stepKey = graph.getStepKey(metadata);
|
|
979
1366
|
let hasToolCalls = false;
|
|
980
1367
|
const hasToolCallChunks =
|
|
981
1368
|
(chunk.tool_call_chunks && chunk.tool_call_chunks.length > 0) ?? false;
|
|
1369
|
+
const hasGoogleServerSideToolContent =
|
|
1370
|
+
isGoogleLike(agentContext.provider) &&
|
|
1371
|
+
Array.isArray(content) &&
|
|
1372
|
+
content.some((c) => isGoogleServerSideToolContentPart(c));
|
|
1373
|
+
if (hasGoogleServerSideToolContent && Array.isArray(content)) {
|
|
1374
|
+
await dispatchGoogleServerSideToolStreamContent({
|
|
1375
|
+
graph,
|
|
1376
|
+
stepKey,
|
|
1377
|
+
chunk,
|
|
1378
|
+
agentContext,
|
|
1379
|
+
content,
|
|
1380
|
+
metadata,
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
|
|
982
1384
|
if (
|
|
983
1385
|
chunk.tool_calls &&
|
|
984
1386
|
chunk.tool_calls.length > 0 &&
|
|
@@ -1069,6 +1471,10 @@ export class ChatModelStreamHandler implements t.EventHandler {
|
|
|
1069
1471
|
return;
|
|
1070
1472
|
}
|
|
1071
1473
|
|
|
1474
|
+
if (hasGoogleServerSideToolContent) {
|
|
1475
|
+
return;
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1072
1478
|
const message_id = getMessageId(stepKey, graph) ?? '';
|
|
1073
1479
|
if (message_id) {
|
|
1074
1480
|
await graph.dispatchRunStep(
|
|
@@ -1083,8 +1489,19 @@ export class ChatModelStreamHandler implements t.EventHandler {
|
|
|
1083
1489
|
);
|
|
1084
1490
|
}
|
|
1085
1491
|
|
|
1086
|
-
|
|
1087
|
-
|
|
1492
|
+
let stepId = graph.getStepIdByKey(stepKey);
|
|
1493
|
+
let runStep = graph.getRunStep(stepId);
|
|
1494
|
+
if (
|
|
1495
|
+
shouldStartFreshMessageStepAfterGoogleServerSideTool({
|
|
1496
|
+
graph,
|
|
1497
|
+
stepId,
|
|
1498
|
+
runStep,
|
|
1499
|
+
content,
|
|
1500
|
+
})
|
|
1501
|
+
) {
|
|
1502
|
+
stepId = await dispatchMessageCreationStep({ graph, stepKey, metadata });
|
|
1503
|
+
runStep = graph.getRunStep(stepId);
|
|
1504
|
+
}
|
|
1088
1505
|
if (!runStep) {
|
|
1089
1506
|
console.warn(`\n
|
|
1090
1507
|
==============================================================
|
|
@@ -1186,9 +1603,7 @@ hasToolCallChunks: ${hasToolCallChunks}
|
|
|
1186
1603
|
metadata
|
|
1187
1604
|
);
|
|
1188
1605
|
}
|
|
1189
|
-
} else if (
|
|
1190
|
-
content.every((c) => c.type?.startsWith(ContentTypes.TEXT) ?? false)
|
|
1191
|
-
) {
|
|
1606
|
+
} else if (content.every((c) => isTextContentPart(c))) {
|
|
1192
1607
|
await graph.dispatchMessageDelta(
|
|
1193
1608
|
stepId,
|
|
1194
1609
|
{
|
|
@@ -1196,15 +1611,7 @@ hasToolCallChunks: ${hasToolCallChunks}
|
|
|
1196
1611
|
},
|
|
1197
1612
|
metadata
|
|
1198
1613
|
);
|
|
1199
|
-
} else if (
|
|
1200
|
-
content.every(
|
|
1201
|
-
(c) =>
|
|
1202
|
-
(c.type?.startsWith(ContentTypes.THINKING) ?? false) ||
|
|
1203
|
-
(c.type?.startsWith(ContentTypes.REASONING) ?? false) ||
|
|
1204
|
-
(c.type?.startsWith(ContentTypes.REASONING_CONTENT) ?? false) ||
|
|
1205
|
-
c.type === 'redacted_thinking'
|
|
1206
|
-
)
|
|
1207
|
-
) {
|
|
1614
|
+
} else if (content.every((c) => isReasoningContentPart(c))) {
|
|
1208
1615
|
await graph.dispatchReasoningDelta(
|
|
1209
1616
|
stepId,
|
|
1210
1617
|
{
|
|
@@ -1255,7 +1662,9 @@ hasToolCallChunks: ${hasToolCallChunks}
|
|
|
1255
1662
|
Array.isArray(chunk.additional_kwargs.reasoning_details) &&
|
|
1256
1663
|
chunk.additional_kwargs.reasoning_details.length > 0) ||
|
|
1257
1664
|
(typeof chunk.additional_kwargs?.reasoning === 'string' &&
|
|
1258
|
-
chunk.additional_kwargs.reasoning !== '')
|
|
1665
|
+
chunk.additional_kwargs.reasoning !== '') ||
|
|
1666
|
+
(typeof chunk.additional_kwargs?.reasoning_content === 'string' &&
|
|
1667
|
+
chunk.additional_kwargs.reasoning_content !== ''))
|
|
1259
1668
|
) {
|
|
1260
1669
|
reasoning_content = 'valid';
|
|
1261
1670
|
}
|
|
@@ -1388,6 +1797,8 @@ export function createContentAggregator(): t.ContentAggregatorResult {
|
|
|
1388
1797
|
};
|
|
1389
1798
|
|
|
1390
1799
|
contentParts[index] = update;
|
|
1800
|
+
} else if (partType === 'toolCall' || partType === 'toolResponse') {
|
|
1801
|
+
contentParts[index] = contentPart;
|
|
1391
1802
|
} else if (partType === ContentTypes.SUMMARY) {
|
|
1392
1803
|
const currentSummary = contentParts[index] as
|
|
1393
1804
|
| t.SummaryContentBlock
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createContentAggregator } from '@/stream';
|
|
2
|
-
import { ContentTypes, GraphEvents, StepTypes } from '@/common';
|
|
3
1
|
import type * as t from '@/types';
|
|
2
|
+
import { ContentTypes, GraphEvents, StepTypes } from '@/common';
|
|
3
|
+
import { createContentAggregator } from '@/stream';
|
|
4
4
|
|
|
5
5
|
describe('createContentAggregator – SUMMARY accumulation', () => {
|
|
6
6
|
it('accumulates text from multiple ON_SUMMARIZE_DELTA events', () => {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { AIMessage, HumanMessage, ToolMessage } from '@langchain/core/messages';
|
|
2
2
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
3
3
|
import type * as t from '@/types';
|
|
4
|
-
import { GraphEvents, Providers } from '@/common';
|
|
5
4
|
import {
|
|
6
5
|
createSummarizeNode,
|
|
7
6
|
DEFAULT_SUMMARIZATION_PROMPT,
|
|
8
7
|
DEFAULT_UPDATE_SUMMARIZATION_PROMPT,
|
|
9
8
|
} from '@/summarization/node';
|
|
9
|
+
import { AgentContext } from '@/agents/AgentContext';
|
|
10
|
+
import { GraphEvents, Providers } from '@/common';
|
|
10
11
|
import * as providers from '@/llm/providers';
|
|
11
12
|
import * as eventUtils from '@/utils/events';
|
|
12
|
-
import { AgentContext } from '@/agents/AgentContext';
|
|
13
13
|
|
|
14
14
|
// ---------------------------------------------------------------------------
|
|
15
15
|
// Helpers
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
HumanMessage,
|
|
5
5
|
SystemMessage,
|
|
6
6
|
} from '@langchain/core/messages';
|
|
7
|
-
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
8
7
|
import type { UsageMetadata, BaseMessage } from '@langchain/core/messages';
|
|
8
|
+
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
9
9
|
import type { AgentContext } from '@/agents/AgentContext';
|
|
10
10
|
import type { HookRegistry } from '@/hooks';
|
|
11
11
|
import type { OnChunk } from '@/llm/invoke';
|
|
@@ -3,11 +3,6 @@ import { tool, DynamicStructuredTool } from '@langchain/core/tools';
|
|
|
3
3
|
import type { ToolCall } from '@langchain/core/messages/tool';
|
|
4
4
|
import type { ProgrammaticToolCallingJsonSchema } from './ptcTimeout';
|
|
5
5
|
import type * as t from '@/types';
|
|
6
|
-
import {
|
|
7
|
-
makeRequest,
|
|
8
|
-
executeTools,
|
|
9
|
-
formatCompletedResponse,
|
|
10
|
-
} from './ProgrammaticToolCalling';
|
|
11
6
|
import {
|
|
12
7
|
BASH_SHELL_GUIDANCE,
|
|
13
8
|
CODE_ARTIFACT_PATH_GUIDANCE,
|
|
@@ -19,6 +14,11 @@ import {
|
|
|
19
14
|
createCodeApiRunTimeoutSchema,
|
|
20
15
|
resolveCodeApiRunTimeoutMs,
|
|
21
16
|
} from './ptcTimeout';
|
|
17
|
+
import {
|
|
18
|
+
makeRequest,
|
|
19
|
+
executeTools,
|
|
20
|
+
formatCompletedResponse,
|
|
21
|
+
} from './ProgrammaticToolCalling';
|
|
22
22
|
import { Constants } from '@/common';
|
|
23
23
|
|
|
24
24
|
config();
|
package/src/tools/Calculator.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { config } from 'dotenv';
|
|
2
2
|
import fetch, { RequestInit } from 'node-fetch';
|
|
3
3
|
import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
4
|
-
import { tool, DynamicStructuredTool } from '@langchain/core/tools';
|
|
5
4
|
import { getEnvironmentVariable } from '@langchain/core/utils/env';
|
|
5
|
+
import { tool, DynamicStructuredTool } from '@langchain/core/tools';
|
|
6
6
|
import type * as t from '@/types';
|
|
7
7
|
import { appendCodeSessionFileSummary } from '@/tools/CodeSessionFileSummary';
|
|
8
8
|
import { EnvVar, Constants } from '@/common';
|
|
@@ -255,9 +255,7 @@ function createCodeExecutionTool(
|
|
|
255
255
|
(error as Error | undefined)?.message ?? '',
|
|
256
256
|
code
|
|
257
257
|
);
|
|
258
|
-
throw new Error(
|
|
259
|
-
`Execution error:\n\n${messageWithReminder}`
|
|
260
|
-
);
|
|
258
|
+
throw new Error(`Execution error:\n\n${messageWithReminder}`);
|
|
261
259
|
}
|
|
262
260
|
},
|
|
263
261
|
{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Constants } from '@/common';
|
|
2
|
-
import type { SubagentConfig } from '@/types';
|
|
3
1
|
import type { JsonSchemaType, LCTool } from '@/types/tools';
|
|
2
|
+
import type { SubagentConfig } from '@/types';
|
|
3
|
+
import { Constants } from '@/common';
|
|
4
4
|
|
|
5
5
|
export const SubagentToolName = Constants.SUBAGENT;
|
|
6
6
|
|