@illuma-ai/agents 1.0.81
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/README.md +485 -0
- package/dist/cjs/agents/AgentContext.cjs +734 -0
- package/dist/cjs/agents/AgentContext.cjs.map +1 -0
- package/dist/cjs/common/enum.cjs +190 -0
- package/dist/cjs/common/enum.cjs.map +1 -0
- package/dist/cjs/events.cjs +172 -0
- package/dist/cjs/events.cjs.map +1 -0
- package/dist/cjs/graphs/Graph.cjs +1615 -0
- package/dist/cjs/graphs/Graph.cjs.map +1 -0
- package/dist/cjs/graphs/MultiAgentGraph.cjs +890 -0
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -0
- package/dist/cjs/instrumentation.cjs +21 -0
- package/dist/cjs/instrumentation.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/index.cjs +292 -0
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/types.cjs +50 -0
- package/dist/cjs/llm/anthropic/types.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +630 -0
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +218 -0
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/utils/tools.cjs +29 -0
- package/dist/cjs/llm/anthropic/utils/tools.cjs.map +1 -0
- package/dist/cjs/llm/bedrock/index.cjs +282 -0
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -0
- package/dist/cjs/llm/fake.cjs +97 -0
- package/dist/cjs/llm/fake.cjs.map +1 -0
- package/dist/cjs/llm/google/index.cjs +216 -0
- package/dist/cjs/llm/google/index.cjs.map +1 -0
- package/dist/cjs/llm/google/utils/common.cjs +647 -0
- package/dist/cjs/llm/google/utils/common.cjs.map +1 -0
- package/dist/cjs/llm/openai/index.cjs +1028 -0
- package/dist/cjs/llm/openai/index.cjs.map +1 -0
- package/dist/cjs/llm/openai/utils/index.cjs +765 -0
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -0
- package/dist/cjs/llm/openrouter/index.cjs +212 -0
- package/dist/cjs/llm/openrouter/index.cjs.map +1 -0
- package/dist/cjs/llm/providers.cjs +43 -0
- package/dist/cjs/llm/providers.cjs.map +1 -0
- package/dist/cjs/llm/text.cjs +69 -0
- package/dist/cjs/llm/text.cjs.map +1 -0
- package/dist/cjs/llm/vertexai/index.cjs +329 -0
- package/dist/cjs/llm/vertexai/index.cjs.map +1 -0
- package/dist/cjs/main.cjs +240 -0
- package/dist/cjs/main.cjs.map +1 -0
- package/dist/cjs/messages/cache.cjs +387 -0
- package/dist/cjs/messages/cache.cjs.map +1 -0
- package/dist/cjs/messages/content.cjs +53 -0
- package/dist/cjs/messages/content.cjs.map +1 -0
- package/dist/cjs/messages/core.cjs +367 -0
- package/dist/cjs/messages/core.cjs.map +1 -0
- package/dist/cjs/messages/format.cjs +761 -0
- package/dist/cjs/messages/format.cjs.map +1 -0
- package/dist/cjs/messages/ids.cjs +23 -0
- package/dist/cjs/messages/ids.cjs.map +1 -0
- package/dist/cjs/messages/prune.cjs +398 -0
- package/dist/cjs/messages/prune.cjs.map +1 -0
- package/dist/cjs/messages/tools.cjs +96 -0
- package/dist/cjs/messages/tools.cjs.map +1 -0
- package/dist/cjs/run.cjs +328 -0
- package/dist/cjs/run.cjs.map +1 -0
- package/dist/cjs/schemas/validate.cjs +324 -0
- package/dist/cjs/schemas/validate.cjs.map +1 -0
- package/dist/cjs/splitStream.cjs +210 -0
- package/dist/cjs/splitStream.cjs.map +1 -0
- package/dist/cjs/stream.cjs +620 -0
- package/dist/cjs/stream.cjs.map +1 -0
- package/dist/cjs/tools/BrowserTools.cjs +248 -0
- package/dist/cjs/tools/BrowserTools.cjs.map +1 -0
- package/dist/cjs/tools/Calculator.cjs +66 -0
- package/dist/cjs/tools/Calculator.cjs.map +1 -0
- package/dist/cjs/tools/CodeExecutor.cjs +234 -0
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -0
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +636 -0
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -0
- package/dist/cjs/tools/ToolNode.cjs +548 -0
- package/dist/cjs/tools/ToolNode.cjs.map +1 -0
- package/dist/cjs/tools/ToolSearch.cjs +909 -0
- package/dist/cjs/tools/ToolSearch.cjs.map +1 -0
- package/dist/cjs/tools/handlers.cjs +255 -0
- package/dist/cjs/tools/handlers.cjs.map +1 -0
- package/dist/cjs/tools/schema.cjs +31 -0
- package/dist/cjs/tools/schema.cjs.map +1 -0
- package/dist/cjs/tools/search/anthropic.cjs +40 -0
- package/dist/cjs/tools/search/anthropic.cjs.map +1 -0
- package/dist/cjs/tools/search/content.cjs +140 -0
- package/dist/cjs/tools/search/content.cjs.map +1 -0
- package/dist/cjs/tools/search/firecrawl.cjs +179 -0
- package/dist/cjs/tools/search/firecrawl.cjs.map +1 -0
- package/dist/cjs/tools/search/format.cjs +203 -0
- package/dist/cjs/tools/search/format.cjs.map +1 -0
- package/dist/cjs/tools/search/highlights.cjs +245 -0
- package/dist/cjs/tools/search/highlights.cjs.map +1 -0
- package/dist/cjs/tools/search/rerankers.cjs +174 -0
- package/dist/cjs/tools/search/rerankers.cjs.map +1 -0
- package/dist/cjs/tools/search/schema.cjs +117 -0
- package/dist/cjs/tools/search/schema.cjs.map +1 -0
- package/dist/cjs/tools/search/search.cjs +566 -0
- package/dist/cjs/tools/search/search.cjs.map +1 -0
- package/dist/cjs/tools/search/serper-scraper.cjs +132 -0
- package/dist/cjs/tools/search/serper-scraper.cjs.map +1 -0
- package/dist/cjs/tools/search/tool.cjs +456 -0
- package/dist/cjs/tools/search/tool.cjs.map +1 -0
- package/dist/cjs/tools/search/utils.cjs +66 -0
- package/dist/cjs/tools/search/utils.cjs.map +1 -0
- package/dist/cjs/types/graph.cjs +29 -0
- package/dist/cjs/types/graph.cjs.map +1 -0
- package/dist/cjs/utils/contextAnalytics.cjs +66 -0
- package/dist/cjs/utils/contextAnalytics.cjs.map +1 -0
- package/dist/cjs/utils/events.cjs +31 -0
- package/dist/cjs/utils/events.cjs.map +1 -0
- package/dist/cjs/utils/graph.cjs +16 -0
- package/dist/cjs/utils/graph.cjs.map +1 -0
- package/dist/cjs/utils/handlers.cjs +70 -0
- package/dist/cjs/utils/handlers.cjs.map +1 -0
- package/dist/cjs/utils/llm.cjs +27 -0
- package/dist/cjs/utils/llm.cjs.map +1 -0
- package/dist/cjs/utils/misc.cjs +56 -0
- package/dist/cjs/utils/misc.cjs.map +1 -0
- package/dist/cjs/utils/run.cjs +73 -0
- package/dist/cjs/utils/run.cjs.map +1 -0
- package/dist/cjs/utils/schema.cjs +27 -0
- package/dist/cjs/utils/schema.cjs.map +1 -0
- package/dist/cjs/utils/title.cjs +125 -0
- package/dist/cjs/utils/title.cjs.map +1 -0
- package/dist/cjs/utils/tokens.cjs +125 -0
- package/dist/cjs/utils/tokens.cjs.map +1 -0
- package/dist/cjs/utils/toonFormat.cjs +388 -0
- package/dist/cjs/utils/toonFormat.cjs.map +1 -0
- package/dist/esm/agents/AgentContext.mjs +732 -0
- package/dist/esm/agents/AgentContext.mjs.map +1 -0
- package/dist/esm/common/enum.mjs +190 -0
- package/dist/esm/common/enum.mjs.map +1 -0
- package/dist/esm/events.mjs +164 -0
- package/dist/esm/events.mjs.map +1 -0
- package/dist/esm/graphs/Graph.mjs +1612 -0
- package/dist/esm/graphs/Graph.mjs.map +1 -0
- package/dist/esm/graphs/MultiAgentGraph.mjs +888 -0
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -0
- package/dist/esm/instrumentation.mjs +19 -0
- package/dist/esm/instrumentation.mjs.map +1 -0
- package/dist/esm/llm/anthropic/index.mjs +290 -0
- package/dist/esm/llm/anthropic/index.mjs.map +1 -0
- package/dist/esm/llm/anthropic/types.mjs +48 -0
- package/dist/esm/llm/anthropic/types.mjs.map +1 -0
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +627 -0
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -0
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +216 -0
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -0
- package/dist/esm/llm/anthropic/utils/tools.mjs +27 -0
- package/dist/esm/llm/anthropic/utils/tools.mjs.map +1 -0
- package/dist/esm/llm/bedrock/index.mjs +280 -0
- package/dist/esm/llm/bedrock/index.mjs.map +1 -0
- package/dist/esm/llm/fake.mjs +94 -0
- package/dist/esm/llm/fake.mjs.map +1 -0
- package/dist/esm/llm/google/index.mjs +214 -0
- package/dist/esm/llm/google/index.mjs.map +1 -0
- package/dist/esm/llm/google/utils/common.mjs +638 -0
- package/dist/esm/llm/google/utils/common.mjs.map +1 -0
- package/dist/esm/llm/openai/index.mjs +1018 -0
- package/dist/esm/llm/openai/index.mjs.map +1 -0
- package/dist/esm/llm/openai/utils/index.mjs +759 -0
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -0
- package/dist/esm/llm/openrouter/index.mjs +210 -0
- package/dist/esm/llm/openrouter/index.mjs.map +1 -0
- package/dist/esm/llm/providers.mjs +39 -0
- package/dist/esm/llm/providers.mjs.map +1 -0
- package/dist/esm/llm/text.mjs +67 -0
- package/dist/esm/llm/text.mjs.map +1 -0
- package/dist/esm/llm/vertexai/index.mjs +327 -0
- package/dist/esm/llm/vertexai/index.mjs.map +1 -0
- package/dist/esm/main.mjs +37 -0
- package/dist/esm/main.mjs.map +1 -0
- package/dist/esm/messages/cache.mjs +382 -0
- package/dist/esm/messages/cache.mjs.map +1 -0
- package/dist/esm/messages/content.mjs +51 -0
- package/dist/esm/messages/content.mjs.map +1 -0
- package/dist/esm/messages/core.mjs +359 -0
- package/dist/esm/messages/core.mjs.map +1 -0
- package/dist/esm/messages/format.mjs +752 -0
- package/dist/esm/messages/format.mjs.map +1 -0
- package/dist/esm/messages/ids.mjs +21 -0
- package/dist/esm/messages/ids.mjs.map +1 -0
- package/dist/esm/messages/prune.mjs +393 -0
- package/dist/esm/messages/prune.mjs.map +1 -0
- package/dist/esm/messages/tools.mjs +93 -0
- package/dist/esm/messages/tools.mjs.map +1 -0
- package/dist/esm/run.mjs +325 -0
- package/dist/esm/run.mjs.map +1 -0
- package/dist/esm/schemas/validate.mjs +317 -0
- package/dist/esm/schemas/validate.mjs.map +1 -0
- package/dist/esm/splitStream.mjs +207 -0
- package/dist/esm/splitStream.mjs.map +1 -0
- package/dist/esm/stream.mjs +616 -0
- package/dist/esm/stream.mjs.map +1 -0
- package/dist/esm/tools/BrowserTools.mjs +244 -0
- package/dist/esm/tools/BrowserTools.mjs.map +1 -0
- package/dist/esm/tools/Calculator.mjs +41 -0
- package/dist/esm/tools/Calculator.mjs.map +1 -0
- package/dist/esm/tools/CodeExecutor.mjs +226 -0
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -0
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +622 -0
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -0
- package/dist/esm/tools/ToolNode.mjs +545 -0
- package/dist/esm/tools/ToolNode.mjs.map +1 -0
- package/dist/esm/tools/ToolSearch.mjs +870 -0
- package/dist/esm/tools/ToolSearch.mjs.map +1 -0
- package/dist/esm/tools/handlers.mjs +250 -0
- package/dist/esm/tools/handlers.mjs.map +1 -0
- package/dist/esm/tools/schema.mjs +28 -0
- package/dist/esm/tools/schema.mjs.map +1 -0
- package/dist/esm/tools/search/anthropic.mjs +37 -0
- package/dist/esm/tools/search/anthropic.mjs.map +1 -0
- package/dist/esm/tools/search/content.mjs +119 -0
- package/dist/esm/tools/search/content.mjs.map +1 -0
- package/dist/esm/tools/search/firecrawl.mjs +176 -0
- package/dist/esm/tools/search/firecrawl.mjs.map +1 -0
- package/dist/esm/tools/search/format.mjs +201 -0
- package/dist/esm/tools/search/format.mjs.map +1 -0
- package/dist/esm/tools/search/highlights.mjs +243 -0
- package/dist/esm/tools/search/highlights.mjs.map +1 -0
- package/dist/esm/tools/search/rerankers.mjs +168 -0
- package/dist/esm/tools/search/rerankers.mjs.map +1 -0
- package/dist/esm/tools/search/schema.mjs +104 -0
- package/dist/esm/tools/search/schema.mjs.map +1 -0
- package/dist/esm/tools/search/search.mjs +563 -0
- package/dist/esm/tools/search/search.mjs.map +1 -0
- package/dist/esm/tools/search/serper-scraper.mjs +129 -0
- package/dist/esm/tools/search/serper-scraper.mjs.map +1 -0
- package/dist/esm/tools/search/tool.mjs +454 -0
- package/dist/esm/tools/search/tool.mjs.map +1 -0
- package/dist/esm/tools/search/utils.mjs +61 -0
- package/dist/esm/tools/search/utils.mjs.map +1 -0
- package/dist/esm/types/graph.mjs +26 -0
- package/dist/esm/types/graph.mjs.map +1 -0
- package/dist/esm/utils/contextAnalytics.mjs +64 -0
- package/dist/esm/utils/contextAnalytics.mjs.map +1 -0
- package/dist/esm/utils/events.mjs +29 -0
- package/dist/esm/utils/events.mjs.map +1 -0
- package/dist/esm/utils/graph.mjs +13 -0
- package/dist/esm/utils/graph.mjs.map +1 -0
- package/dist/esm/utils/handlers.mjs +68 -0
- package/dist/esm/utils/handlers.mjs.map +1 -0
- package/dist/esm/utils/llm.mjs +24 -0
- package/dist/esm/utils/llm.mjs.map +1 -0
- package/dist/esm/utils/misc.mjs +53 -0
- package/dist/esm/utils/misc.mjs.map +1 -0
- package/dist/esm/utils/run.mjs +70 -0
- package/dist/esm/utils/run.mjs.map +1 -0
- package/dist/esm/utils/schema.mjs +24 -0
- package/dist/esm/utils/schema.mjs.map +1 -0
- package/dist/esm/utils/title.mjs +122 -0
- package/dist/esm/utils/title.mjs.map +1 -0
- package/dist/esm/utils/tokens.mjs +121 -0
- package/dist/esm/utils/tokens.mjs.map +1 -0
- package/dist/esm/utils/toonFormat.mjs +381 -0
- package/dist/esm/utils/toonFormat.mjs.map +1 -0
- package/dist/types/agents/AgentContext.d.ts +293 -0
- package/dist/types/common/enum.d.ts +155 -0
- package/dist/types/common/index.d.ts +1 -0
- package/dist/types/events.d.ts +31 -0
- package/dist/types/graphs/Graph.d.ts +216 -0
- package/dist/types/graphs/MultiAgentGraph.d.ts +104 -0
- package/dist/types/graphs/index.d.ts +2 -0
- package/dist/types/index.d.ts +21 -0
- package/dist/types/instrumentation.d.ts +1 -0
- package/dist/types/llm/anthropic/index.d.ts +39 -0
- package/dist/types/llm/anthropic/types.d.ts +37 -0
- package/dist/types/llm/anthropic/utils/message_inputs.d.ts +14 -0
- package/dist/types/llm/anthropic/utils/message_outputs.d.ts +14 -0
- package/dist/types/llm/anthropic/utils/output_parsers.d.ts +22 -0
- package/dist/types/llm/anthropic/utils/tools.d.ts +3 -0
- package/dist/types/llm/bedrock/index.d.ts +141 -0
- package/dist/types/llm/bedrock/types.d.ts +27 -0
- package/dist/types/llm/bedrock/utils/index.d.ts +5 -0
- package/dist/types/llm/bedrock/utils/message_inputs.d.ts +31 -0
- package/dist/types/llm/bedrock/utils/message_outputs.d.ts +33 -0
- package/dist/types/llm/fake.d.ts +31 -0
- package/dist/types/llm/google/index.d.ts +24 -0
- package/dist/types/llm/google/types.d.ts +42 -0
- package/dist/types/llm/google/utils/common.d.ts +34 -0
- package/dist/types/llm/google/utils/tools.d.ts +10 -0
- package/dist/types/llm/google/utils/zod_to_genai_parameters.d.ts +14 -0
- package/dist/types/llm/openai/index.d.ts +127 -0
- package/dist/types/llm/openai/types.d.ts +10 -0
- package/dist/types/llm/openai/utils/index.d.ts +29 -0
- package/dist/types/llm/openrouter/index.d.ts +15 -0
- package/dist/types/llm/providers.d.ts +5 -0
- package/dist/types/llm/text.d.ts +21 -0
- package/dist/types/llm/vertexai/index.d.ts +293 -0
- package/dist/types/messages/cache.d.ts +54 -0
- package/dist/types/messages/content.d.ts +7 -0
- package/dist/types/messages/core.d.ts +14 -0
- package/dist/types/messages/format.d.ts +137 -0
- package/dist/types/messages/ids.d.ts +3 -0
- package/dist/types/messages/index.d.ts +7 -0
- package/dist/types/messages/prune.d.ts +52 -0
- package/dist/types/messages/reducer.d.ts +9 -0
- package/dist/types/messages/tools.d.ts +17 -0
- package/dist/types/mockStream.d.ts +32 -0
- package/dist/types/prompts/collab.d.ts +1 -0
- package/dist/types/prompts/index.d.ts +2 -0
- package/dist/types/prompts/taskmanager.d.ts +41 -0
- package/dist/types/run.d.ts +41 -0
- package/dist/types/schemas/index.d.ts +1 -0
- package/dist/types/schemas/validate.d.ts +59 -0
- package/dist/types/splitStream.d.ts +37 -0
- package/dist/types/stream.d.ts +15 -0
- package/dist/types/test/mockTools.d.ts +28 -0
- package/dist/types/tools/BrowserTools.d.ts +87 -0
- package/dist/types/tools/Calculator.d.ts +34 -0
- package/dist/types/tools/CodeExecutor.d.ts +57 -0
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +138 -0
- package/dist/types/tools/ToolNode.d.ts +51 -0
- package/dist/types/tools/ToolSearch.d.ts +219 -0
- package/dist/types/tools/handlers.d.ts +22 -0
- package/dist/types/tools/schema.d.ts +12 -0
- package/dist/types/tools/search/anthropic.d.ts +16 -0
- package/dist/types/tools/search/content.d.ts +4 -0
- package/dist/types/tools/search/firecrawl.d.ts +54 -0
- package/dist/types/tools/search/format.d.ts +5 -0
- package/dist/types/tools/search/highlights.d.ts +13 -0
- package/dist/types/tools/search/index.d.ts +3 -0
- package/dist/types/tools/search/rerankers.d.ts +38 -0
- package/dist/types/tools/search/schema.d.ts +103 -0
- package/dist/types/tools/search/search.d.ts +8 -0
- package/dist/types/tools/search/serper-scraper.d.ts +59 -0
- package/dist/types/tools/search/test.d.ts +1 -0
- package/dist/types/tools/search/tool.d.ts +3 -0
- package/dist/types/tools/search/types.d.ts +575 -0
- package/dist/types/tools/search/utils.d.ts +10 -0
- package/dist/types/types/graph.d.ts +399 -0
- package/dist/types/types/index.d.ts +5 -0
- package/dist/types/types/llm.d.ts +105 -0
- package/dist/types/types/messages.d.ts +4 -0
- package/dist/types/types/run.d.ts +112 -0
- package/dist/types/types/stream.d.ts +308 -0
- package/dist/types/types/tools.d.ts +296 -0
- package/dist/types/utils/contextAnalytics.d.ts +37 -0
- package/dist/types/utils/events.d.ts +6 -0
- package/dist/types/utils/graph.d.ts +2 -0
- package/dist/types/utils/handlers.d.ts +34 -0
- package/dist/types/utils/index.d.ts +9 -0
- package/dist/types/utils/llm.d.ts +3 -0
- package/dist/types/utils/llmConfig.d.ts +3 -0
- package/dist/types/utils/logging.d.ts +1 -0
- package/dist/types/utils/misc.d.ts +7 -0
- package/dist/types/utils/run.d.ts +27 -0
- package/dist/types/utils/schema.d.ts +8 -0
- package/dist/types/utils/title.d.ts +4 -0
- package/dist/types/utils/tokens.d.ts +28 -0
- package/dist/types/utils/toonFormat.d.ts +111 -0
- package/package.json +190 -0
- package/src/agents/AgentContext.test.ts +458 -0
- package/src/agents/AgentContext.ts +972 -0
- package/src/agents/__tests__/AgentContext.test.ts +805 -0
- package/src/agents/__tests__/resolveStructuredOutputMode.test.ts +137 -0
- package/src/common/enum.ts +203 -0
- package/src/common/index.ts +2 -0
- package/src/events.ts +223 -0
- package/src/graphs/Graph.ts +2228 -0
- package/src/graphs/MultiAgentGraph.ts +1063 -0
- package/src/graphs/__tests__/structured-output.integration.test.ts +809 -0
- package/src/graphs/__tests__/structured-output.test.ts +183 -0
- package/src/graphs/index.ts +2 -0
- package/src/index.ts +34 -0
- package/src/instrumentation.ts +22 -0
- package/src/llm/anthropic/Jacob_Lee_Resume_2023.pdf +0 -0
- package/src/llm/anthropic/index.ts +413 -0
- package/src/llm/anthropic/llm.spec.ts +1442 -0
- package/src/llm/anthropic/types.ts +140 -0
- package/src/llm/anthropic/utils/message_inputs.ts +757 -0
- package/src/llm/anthropic/utils/message_outputs.ts +289 -0
- package/src/llm/anthropic/utils/output_parsers.ts +133 -0
- package/src/llm/anthropic/utils/tools.ts +29 -0
- package/src/llm/bedrock/__tests__/bedrock-caching.test.ts +495 -0
- package/src/llm/bedrock/index.ts +411 -0
- package/src/llm/bedrock/llm.spec.ts +616 -0
- package/src/llm/bedrock/types.ts +51 -0
- package/src/llm/bedrock/utils/index.ts +18 -0
- package/src/llm/bedrock/utils/message_inputs.ts +563 -0
- package/src/llm/bedrock/utils/message_outputs.ts +310 -0
- package/src/llm/fake.ts +133 -0
- package/src/llm/google/data/gettysburg10.wav +0 -0
- package/src/llm/google/data/hotdog.jpg +0 -0
- package/src/llm/google/index.ts +337 -0
- package/src/llm/google/llm.spec.ts +934 -0
- package/src/llm/google/types.ts +56 -0
- package/src/llm/google/utils/common.ts +873 -0
- package/src/llm/google/utils/tools.ts +160 -0
- package/src/llm/google/utils/zod_to_genai_parameters.ts +86 -0
- package/src/llm/openai/index.ts +1366 -0
- package/src/llm/openai/types.ts +24 -0
- package/src/llm/openai/utils/index.ts +1035 -0
- package/src/llm/openai/utils/isReasoningModel.test.ts +90 -0
- package/src/llm/openrouter/index.ts +291 -0
- package/src/llm/providers.ts +52 -0
- package/src/llm/text.ts +94 -0
- package/src/llm/vertexai/index.ts +359 -0
- package/src/messages/__tests__/tools.test.ts +473 -0
- package/src/messages/cache.test.ts +1261 -0
- package/src/messages/cache.ts +518 -0
- package/src/messages/content.test.ts +362 -0
- package/src/messages/content.ts +63 -0
- package/src/messages/core.ts +473 -0
- package/src/messages/ensureThinkingBlock.test.ts +468 -0
- package/src/messages/format.ts +1029 -0
- package/src/messages/formatAgentMessages.test.ts +1513 -0
- package/src/messages/formatAgentMessages.tools.test.ts +419 -0
- package/src/messages/formatMessage.test.ts +693 -0
- package/src/messages/ids.ts +26 -0
- package/src/messages/index.ts +7 -0
- package/src/messages/labelContentByAgent.test.ts +887 -0
- package/src/messages/prune.ts +568 -0
- package/src/messages/reducer.ts +80 -0
- package/src/messages/shiftIndexTokenCountMap.test.ts +81 -0
- package/src/messages/tools.ts +108 -0
- package/src/mockStream.ts +99 -0
- package/src/prompts/collab.ts +6 -0
- package/src/prompts/index.ts +2 -0
- package/src/prompts/taskmanager.ts +61 -0
- package/src/run.ts +467 -0
- package/src/schemas/index.ts +2 -0
- package/src/schemas/schema-preparation.test.ts +500 -0
- package/src/schemas/validate.test.ts +358 -0
- package/src/schemas/validate.ts +454 -0
- package/src/scripts/abort.ts +157 -0
- package/src/scripts/ant_web_search.ts +158 -0
- package/src/scripts/ant_web_search_edge_case.ts +162 -0
- package/src/scripts/ant_web_search_error_edge_case.ts +148 -0
- package/src/scripts/args.ts +48 -0
- package/src/scripts/caching.ts +132 -0
- package/src/scripts/cli.ts +172 -0
- package/src/scripts/cli2.ts +133 -0
- package/src/scripts/cli3.ts +184 -0
- package/src/scripts/cli4.ts +191 -0
- package/src/scripts/cli5.ts +191 -0
- package/src/scripts/code_exec.ts +213 -0
- package/src/scripts/code_exec_files.ts +236 -0
- package/src/scripts/code_exec_multi_session.ts +241 -0
- package/src/scripts/code_exec_ptc.ts +334 -0
- package/src/scripts/code_exec_session.ts +282 -0
- package/src/scripts/code_exec_simple.ts +147 -0
- package/src/scripts/content.ts +138 -0
- package/src/scripts/empty_input.ts +137 -0
- package/src/scripts/handoff-test.ts +135 -0
- package/src/scripts/image.ts +178 -0
- package/src/scripts/memory.ts +97 -0
- package/src/scripts/multi-agent-chain.ts +331 -0
- package/src/scripts/multi-agent-conditional.ts +221 -0
- package/src/scripts/multi-agent-document-review-chain.ts +197 -0
- package/src/scripts/multi-agent-hybrid-flow.ts +310 -0
- package/src/scripts/multi-agent-parallel-start.ts +265 -0
- package/src/scripts/multi-agent-parallel.ts +394 -0
- package/src/scripts/multi-agent-sequence.ts +217 -0
- package/src/scripts/multi-agent-supervisor.ts +365 -0
- package/src/scripts/multi-agent-test.ts +186 -0
- package/src/scripts/parallel-asymmetric-tools-test.ts +274 -0
- package/src/scripts/parallel-full-metadata-test.ts +240 -0
- package/src/scripts/parallel-tools-test.ts +340 -0
- package/src/scripts/programmatic_exec.ts +396 -0
- package/src/scripts/programmatic_exec_agent.ts +231 -0
- package/src/scripts/search.ts +146 -0
- package/src/scripts/sequential-full-metadata-test.ts +197 -0
- package/src/scripts/simple.ts +225 -0
- package/src/scripts/single-agent-metadata-test.ts +198 -0
- package/src/scripts/stream.ts +140 -0
- package/src/scripts/test-custom-prompt-key.ts +145 -0
- package/src/scripts/test-handoff-input.ts +170 -0
- package/src/scripts/test-handoff-preamble.ts +277 -0
- package/src/scripts/test-multi-agent-list-handoff.ts +417 -0
- package/src/scripts/test-parallel-agent-labeling.ts +325 -0
- package/src/scripts/test-parallel-handoffs.ts +291 -0
- package/src/scripts/test-thinking-handoff-bedrock.ts +153 -0
- package/src/scripts/test-thinking-handoff.ts +155 -0
- package/src/scripts/test-tools-before-handoff.ts +226 -0
- package/src/scripts/test_code_api.ts +361 -0
- package/src/scripts/thinking-bedrock.ts +159 -0
- package/src/scripts/thinking.ts +171 -0
- package/src/scripts/tool_search.ts +162 -0
- package/src/scripts/tools.ts +177 -0
- package/src/specs/agent-handoffs.test.ts +888 -0
- package/src/specs/anthropic.simple.test.ts +387 -0
- package/src/specs/azure.simple.test.ts +364 -0
- package/src/specs/cache.simple.test.ts +396 -0
- package/src/specs/deepseek.simple.test.ts +283 -0
- package/src/specs/emergency-prune.test.ts +407 -0
- package/src/specs/moonshot.simple.test.ts +358 -0
- package/src/specs/openai.simple.test.ts +311 -0
- package/src/specs/openrouter.simple.test.ts +107 -0
- package/src/specs/prune.test.ts +901 -0
- package/src/specs/reasoning.test.ts +201 -0
- package/src/specs/spec.utils.ts +3 -0
- package/src/specs/thinking-handoff.test.ts +620 -0
- package/src/specs/thinking-prune.test.ts +703 -0
- package/src/specs/token-distribution-edge-case.test.ts +316 -0
- package/src/specs/token-memoization.test.ts +32 -0
- package/src/specs/tool-error.test.ts +198 -0
- package/src/splitStream.test.ts +691 -0
- package/src/splitStream.ts +234 -0
- package/src/stream.test.ts +94 -0
- package/src/stream.ts +801 -0
- package/src/test/mockTools.ts +386 -0
- package/src/tools/BrowserTools.ts +393 -0
- package/src/tools/Calculator.test.ts +278 -0
- package/src/tools/Calculator.ts +46 -0
- package/src/tools/CodeExecutor.ts +270 -0
- package/src/tools/ProgrammaticToolCalling.ts +785 -0
- package/src/tools/ToolNode.ts +674 -0
- package/src/tools/ToolSearch.ts +1095 -0
- package/src/tools/__tests__/BrowserTools.test.ts +265 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.ts +319 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +1006 -0
- package/src/tools/__tests__/ToolSearch.integration.test.ts +162 -0
- package/src/tools/__tests__/ToolSearch.test.ts +1003 -0
- package/src/tools/handlers.ts +363 -0
- package/src/tools/schema.ts +37 -0
- package/src/tools/search/anthropic.ts +51 -0
- package/src/tools/search/content.test.ts +173 -0
- package/src/tools/search/content.ts +147 -0
- package/src/tools/search/firecrawl.ts +210 -0
- package/src/tools/search/format.ts +250 -0
- package/src/tools/search/highlights.ts +320 -0
- package/src/tools/search/index.ts +3 -0
- package/src/tools/search/jina-reranker.test.ts +130 -0
- package/src/tools/search/output.md +2775 -0
- package/src/tools/search/rerankers.ts +242 -0
- package/src/tools/search/schema.ts +113 -0
- package/src/tools/search/search.ts +768 -0
- package/src/tools/search/serper-scraper.ts +155 -0
- package/src/tools/search/test.html +884 -0
- package/src/tools/search/test.md +643 -0
- package/src/tools/search/test.ts +159 -0
- package/src/tools/search/tool.ts +657 -0
- package/src/tools/search/types.ts +665 -0
- package/src/tools/search/utils.ts +79 -0
- package/src/types/graph.test.ts +218 -0
- package/src/types/graph.ts +533 -0
- package/src/types/index.ts +6 -0
- package/src/types/llm.ts +140 -0
- package/src/types/messages.ts +4 -0
- package/src/types/run.ts +128 -0
- package/src/types/stream.ts +417 -0
- package/src/types/tools.ts +355 -0
- package/src/utils/contextAnalytics.ts +103 -0
- package/src/utils/events.ts +32 -0
- package/src/utils/graph.ts +11 -0
- package/src/utils/handlers.ts +107 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/llm.ts +26 -0
- package/src/utils/llmConfig.ts +208 -0
- package/src/utils/logging.ts +48 -0
- package/src/utils/misc.ts +57 -0
- package/src/utils/run.ts +106 -0
- package/src/utils/schema.ts +35 -0
- package/src/utils/title.ts +177 -0
- package/src/utils/tokens.ts +142 -0
- package/src/utils/toonFormat.ts +475 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { ToolNode } from '@langchain/langgraph/prebuilt';
|
|
2
|
+
import { Runnable, RunnableConfig } from '@langchain/core/runnables';
|
|
3
|
+
import type { UsageMetadata, BaseMessage } from '@langchain/core/messages';
|
|
4
|
+
import type { ToolCall } from '@langchain/core/messages/tool';
|
|
5
|
+
import type * as t from '@/types';
|
|
6
|
+
import { Providers } from '@/common';
|
|
7
|
+
import { type ContextAnalytics } from '@/utils/contextAnalytics';
|
|
8
|
+
import { ToolNode as CustomToolNode } from '@/tools/ToolNode';
|
|
9
|
+
import { AgentContext } from '@/agents/AgentContext';
|
|
10
|
+
import { HandlerRegistry } from '@/events';
|
|
11
|
+
export declare abstract class Graph<T extends t.BaseGraphState = t.BaseGraphState, _TNodeName extends string = string> {
|
|
12
|
+
abstract resetValues(): void;
|
|
13
|
+
abstract initializeTools({ currentTools, currentToolMap, }: {
|
|
14
|
+
currentTools?: t.GraphTools;
|
|
15
|
+
currentToolMap?: t.ToolMap;
|
|
16
|
+
}): CustomToolNode<T> | ToolNode<T>;
|
|
17
|
+
abstract initializeModel({ currentModel, tools, clientOptions, }: {
|
|
18
|
+
currentModel?: t.ChatModel;
|
|
19
|
+
tools?: t.GraphTools;
|
|
20
|
+
clientOptions?: t.ClientOptions;
|
|
21
|
+
}): Runnable;
|
|
22
|
+
abstract getRunMessages(): BaseMessage[] | undefined;
|
|
23
|
+
abstract getContentParts(): t.MessageContentComplex[] | undefined;
|
|
24
|
+
abstract generateStepId(stepKey: string): [string, number];
|
|
25
|
+
abstract getKeyList(metadata: Record<string, unknown> | undefined): (string | number | undefined)[];
|
|
26
|
+
abstract getStepKey(metadata: Record<string, unknown> | undefined): string;
|
|
27
|
+
abstract checkKeyList(keyList: (string | number | undefined)[]): boolean;
|
|
28
|
+
abstract getStepIdByKey(stepKey: string, index?: number): string;
|
|
29
|
+
abstract getRunStep(stepId: string): t.RunStep | undefined;
|
|
30
|
+
abstract dispatchRunStep(stepKey: string, stepDetails: t.StepDetails, metadata?: Record<string, unknown>): Promise<string>;
|
|
31
|
+
abstract dispatchRunStepDelta(id: string, delta: t.ToolCallDelta): Promise<void>;
|
|
32
|
+
abstract dispatchMessageDelta(id: string, delta: t.MessageDelta): Promise<void>;
|
|
33
|
+
abstract dispatchReasoningDelta(stepId: string, delta: t.ReasoningDelta): Promise<void>;
|
|
34
|
+
abstract handleToolCallCompleted(data: t.ToolEndData, metadata?: Record<string, unknown>, omitOutput?: boolean): Promise<void>;
|
|
35
|
+
abstract createCallModel(agentId?: string, currentModel?: t.ChatModel): (state: T, config?: RunnableConfig) => Promise<Partial<T>>;
|
|
36
|
+
messageStepHasToolCalls: Map<string, boolean>;
|
|
37
|
+
messageIdsByStepKey: Map<string, string>;
|
|
38
|
+
prelimMessageIdsByStepKey: Map<string, string>;
|
|
39
|
+
config: RunnableConfig | undefined;
|
|
40
|
+
contentData: t.RunStep[];
|
|
41
|
+
stepKeyIds: Map<string, string[]>;
|
|
42
|
+
contentIndexMap: Map<string, number>;
|
|
43
|
+
toolCallStepIds: Map<string, string>;
|
|
44
|
+
signal?: AbortSignal;
|
|
45
|
+
/** Set of invoked tool call IDs from non-message run steps completed mid-run, if any */
|
|
46
|
+
invokedToolIds?: Set<string>;
|
|
47
|
+
handlerRegistry: HandlerRegistry | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Tool session contexts for automatic state persistence across tool invocations.
|
|
50
|
+
* Keyed by tool name (e.g., Constants.EXECUTE_CODE).
|
|
51
|
+
* Currently supports code execution session tracking (session_id, files).
|
|
52
|
+
*/
|
|
53
|
+
sessions: t.ToolSessionMap;
|
|
54
|
+
}
|
|
55
|
+
export declare class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
56
|
+
overrideModel?: t.ChatModel;
|
|
57
|
+
/** Optional compile options passed into workflow.compile() */
|
|
58
|
+
compileOptions?: t.CompileOptions | undefined;
|
|
59
|
+
messages: BaseMessage[];
|
|
60
|
+
runId: string | undefined;
|
|
61
|
+
startIndex: number;
|
|
62
|
+
signal?: AbortSignal;
|
|
63
|
+
/** Map of agent contexts by agent ID */
|
|
64
|
+
agentContexts: Map<string, AgentContext>;
|
|
65
|
+
/** Default agent ID to use */
|
|
66
|
+
defaultAgentId: string;
|
|
67
|
+
/** Normalized finish/stop reason from the last LLM invocation */
|
|
68
|
+
lastFinishReason: string | undefined;
|
|
69
|
+
constructor({ runId, signal, agents, tokenCounter, indexTokenCountMap, }: t.StandardGraphInput);
|
|
70
|
+
resetValues(keepContent?: boolean): void;
|
|
71
|
+
/**
|
|
72
|
+
* Returns the normalized finish/stop reason from the last LLM invocation.
|
|
73
|
+
* Used by callers to detect when the response was truncated due to max_tokens.
|
|
74
|
+
*/
|
|
75
|
+
getLastFinishReason(): string | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Estimates a human-friendly description of the conversation timeframe based on message count.
|
|
78
|
+
* Uses rough heuristics to provide context about how much history is available.
|
|
79
|
+
*
|
|
80
|
+
* @param messageCount - Number of messages in the remaining context
|
|
81
|
+
* @returns A friendly description like "the last few minutes", "the past hour", etc.
|
|
82
|
+
*/
|
|
83
|
+
getContextTimeframeDescription(messageCount: number): string;
|
|
84
|
+
getRunStep(stepId: string): t.RunStep | undefined;
|
|
85
|
+
getAgentContext(metadata: Record<string, unknown> | undefined): AgentContext;
|
|
86
|
+
getStepKey(metadata: Record<string, unknown> | undefined): string;
|
|
87
|
+
getStepIdByKey(stepKey: string, index?: number): string;
|
|
88
|
+
generateStepId(stepKey: string): [string, number];
|
|
89
|
+
getKeyList(metadata: Record<string, unknown> | undefined): (string | number | undefined)[];
|
|
90
|
+
checkKeyList(keyList: (string | number | undefined)[]): boolean;
|
|
91
|
+
getRunMessages(): BaseMessage[] | undefined;
|
|
92
|
+
getContentParts(): t.MessageContentComplex[] | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Get all run steps, optionally filtered by agent ID
|
|
95
|
+
*/
|
|
96
|
+
getRunSteps(agentId?: string): t.RunStep[];
|
|
97
|
+
/**
|
|
98
|
+
* Get run steps grouped by agent ID
|
|
99
|
+
*/
|
|
100
|
+
getRunStepsByAgent(): Map<string, t.RunStep[]>;
|
|
101
|
+
/**
|
|
102
|
+
* Get agent IDs that participated in this run
|
|
103
|
+
*/
|
|
104
|
+
getActiveAgentIds(): string[];
|
|
105
|
+
/**
|
|
106
|
+
* Maps contentPart indices to agent IDs for post-run analysis
|
|
107
|
+
* Returns a map where key is the contentPart index and value is the agentId
|
|
108
|
+
*/
|
|
109
|
+
getContentPartAgentMap(): Map<number, string>;
|
|
110
|
+
/**
|
|
111
|
+
* Get the context breakdown from the primary agent for admin token tracking.
|
|
112
|
+
* Returns detailed token counts for instructions, tools, etc.
|
|
113
|
+
*/
|
|
114
|
+
getContextBreakdown(): {
|
|
115
|
+
instructions: number;
|
|
116
|
+
artifacts: number;
|
|
117
|
+
tools: number;
|
|
118
|
+
toolCount: number;
|
|
119
|
+
toolContext: number;
|
|
120
|
+
total: number;
|
|
121
|
+
toolsDetail: Array<{
|
|
122
|
+
name: string;
|
|
123
|
+
tokens: number;
|
|
124
|
+
}>;
|
|
125
|
+
toolContextDetail: Array<{
|
|
126
|
+
name: string;
|
|
127
|
+
tokens: number;
|
|
128
|
+
}>;
|
|
129
|
+
} | null;
|
|
130
|
+
/**
|
|
131
|
+
* Get the latest context analytics from the graph.
|
|
132
|
+
* Returns metrics like utilization %, TOON stats, message breakdown.
|
|
133
|
+
*/
|
|
134
|
+
getContextAnalytics(): ContextAnalytics | null;
|
|
135
|
+
/** Store the latest context analytics for retrieval after run */
|
|
136
|
+
private lastContextAnalytics;
|
|
137
|
+
createSystemRunnable({ provider, clientOptions, instructions, additional_instructions, }: {
|
|
138
|
+
provider?: Providers;
|
|
139
|
+
clientOptions?: t.ClientOptions;
|
|
140
|
+
instructions?: string;
|
|
141
|
+
additional_instructions?: string;
|
|
142
|
+
}): t.SystemRunnable | undefined;
|
|
143
|
+
initializeTools({ currentTools, currentToolMap, agentContext, }: {
|
|
144
|
+
currentTools?: t.GraphTools;
|
|
145
|
+
currentToolMap?: t.ToolMap;
|
|
146
|
+
agentContext?: AgentContext;
|
|
147
|
+
}): CustomToolNode<t.BaseGraphState> | ToolNode<t.BaseGraphState>;
|
|
148
|
+
initializeModel({ provider, tools, clientOptions, }: {
|
|
149
|
+
provider: Providers;
|
|
150
|
+
tools?: t.GraphTools;
|
|
151
|
+
clientOptions?: t.ClientOptions;
|
|
152
|
+
}): Runnable;
|
|
153
|
+
overrideTestModel(responses: string[], sleep?: number, toolCalls?: ToolCall[]): void;
|
|
154
|
+
getNewModel({ provider, clientOptions, }: {
|
|
155
|
+
provider: Providers;
|
|
156
|
+
clientOptions?: t.ClientOptions;
|
|
157
|
+
}): t.ChatModelInstance;
|
|
158
|
+
getUsageMetadata(finalMessage?: BaseMessage): Partial<UsageMetadata> | undefined;
|
|
159
|
+
/** Execute model invocation with streaming support */
|
|
160
|
+
private attemptInvoke;
|
|
161
|
+
/**
|
|
162
|
+
* Execute model invocation with structured output.
|
|
163
|
+
* Uses native constrained decoding (jsonSchema method) for supported providers,
|
|
164
|
+
* or falls back to withStructuredOutput with functionCalling/jsonMode.
|
|
165
|
+
*
|
|
166
|
+
* Native mode uses provider APIs directly:
|
|
167
|
+
* - Anthropic: output_config.format via LangChain's method: 'json_schema'
|
|
168
|
+
* - OpenAI/Azure: response_format.json_schema via LangChain's method: 'jsonSchema'
|
|
169
|
+
* - Bedrock: falls back to functionCalling (LangChain doesn't support native yet)
|
|
170
|
+
*/
|
|
171
|
+
private attemptStructuredInvoke;
|
|
172
|
+
cleanupSignalListener(currentModel?: t.ChatModel): void;
|
|
173
|
+
/**
|
|
174
|
+
* Perform structured output invocation: creates a fresh model without tools bound,
|
|
175
|
+
* removes thinking configuration, invokes with the schema, emits the event,
|
|
176
|
+
* and returns a clean AIMessageChunk without tool_calls.
|
|
177
|
+
*
|
|
178
|
+
* Used by both the immediate path (no tools) and the deferred path (after tool use).
|
|
179
|
+
*/
|
|
180
|
+
private performStructuredOutput;
|
|
181
|
+
createCallModel(agentId?: string): (state: t.BaseGraphState, config?: RunnableConfig) => Promise<Partial<t.BaseGraphState>>;
|
|
182
|
+
createAgentNode(agentId: string): t.CompiledAgentWorfklow;
|
|
183
|
+
createWorkflow(): t.CompiledStateWorkflow;
|
|
184
|
+
/**
|
|
185
|
+
* Indicates if this is a multi-agent graph.
|
|
186
|
+
* Override in MultiAgentGraph to return true.
|
|
187
|
+
* Used to conditionally include agentId in RunStep for frontend rendering.
|
|
188
|
+
*/
|
|
189
|
+
protected isMultiAgentGraph(): boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Get the parallel group ID for an agent, if any.
|
|
192
|
+
* Override in MultiAgentGraph to provide actual group IDs.
|
|
193
|
+
* Group IDs are incrementing numbers (1, 2, 3...) reflecting execution order.
|
|
194
|
+
* @param _agentId - The agent ID to look up
|
|
195
|
+
* @returns undefined for StandardGraph (no parallel groups), or group number for MultiAgentGraph
|
|
196
|
+
*/
|
|
197
|
+
protected getParallelGroupIdForAgent(_agentId: string): number | undefined;
|
|
198
|
+
/**
|
|
199
|
+
* Dispatches a run step to the client, returns the step ID
|
|
200
|
+
*/
|
|
201
|
+
dispatchRunStep(stepKey: string, stepDetails: t.StepDetails, metadata?: Record<string, unknown>): Promise<string>;
|
|
202
|
+
handleToolCallCompleted(data: t.ToolEndData, metadata?: Record<string, unknown>, omitOutput?: boolean): Promise<void>;
|
|
203
|
+
/**
|
|
204
|
+
* Static version of handleToolCallError to avoid creating strong references
|
|
205
|
+
* that prevent garbage collection
|
|
206
|
+
*/
|
|
207
|
+
static handleToolCallErrorStatic(graph: StandardGraph, data: t.ToolErrorData, metadata?: Record<string, unknown>): Promise<void>;
|
|
208
|
+
/**
|
|
209
|
+
* Instance method that delegates to the static method
|
|
210
|
+
* Kept for backward compatibility
|
|
211
|
+
*/
|
|
212
|
+
handleToolCallError(data: t.ToolErrorData, metadata?: Record<string, unknown>): Promise<void>;
|
|
213
|
+
dispatchRunStepDelta(id: string, delta: t.ToolCallDelta): Promise<void>;
|
|
214
|
+
dispatchMessageDelta(id: string, delta: t.MessageDelta): Promise<void>;
|
|
215
|
+
dispatchReasoningDelta: (stepId: string, delta: t.ReasoningDelta) => Promise<void>;
|
|
216
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type * as t from '@/types';
|
|
2
|
+
import { StandardGraph } from './Graph';
|
|
3
|
+
/**
|
|
4
|
+
* MultiAgentGraph extends StandardGraph to support dynamic multi-agent workflows
|
|
5
|
+
* with handoffs, fan-in/fan-out, and other composable patterns.
|
|
6
|
+
*
|
|
7
|
+
* Key behavior:
|
|
8
|
+
* - Agents with ONLY handoff edges: Can dynamically route to any handoff destination
|
|
9
|
+
* - Agents with ONLY direct edges: Always follow their direct edges
|
|
10
|
+
* - Agents with BOTH: Use Command for exclusive routing (handoff OR direct, not both)
|
|
11
|
+
* - If handoff occurs: Only the handoff destination executes
|
|
12
|
+
* - If no handoff: Direct edges execute (potentially in parallel)
|
|
13
|
+
*
|
|
14
|
+
* This enables the common pattern where an agent either delegates (handoff)
|
|
15
|
+
* OR continues its workflow (direct edges), but not both simultaneously.
|
|
16
|
+
*/
|
|
17
|
+
export declare class MultiAgentGraph extends StandardGraph {
|
|
18
|
+
private edges;
|
|
19
|
+
private startingNodes;
|
|
20
|
+
private directEdges;
|
|
21
|
+
private handoffEdges;
|
|
22
|
+
/**
|
|
23
|
+
* Map of agentId to parallel group info.
|
|
24
|
+
* Contains groupId (incrementing number reflecting execution order) for agents in parallel groups.
|
|
25
|
+
* Sequential agents (not in any parallel group) have undefined entry.
|
|
26
|
+
*
|
|
27
|
+
* Example for: researcher -> [analyst1, analyst2, analyst3] -> summarizer
|
|
28
|
+
* - researcher: undefined (sequential, order 0)
|
|
29
|
+
* - analyst1, analyst2, analyst3: { groupId: 1 } (parallel group, order 1)
|
|
30
|
+
* - summarizer: undefined (sequential, order 2)
|
|
31
|
+
*/
|
|
32
|
+
private agentParallelGroups;
|
|
33
|
+
constructor(input: t.MultiAgentGraphInput);
|
|
34
|
+
/**
|
|
35
|
+
* Categorize edges into handoff and direct types
|
|
36
|
+
*/
|
|
37
|
+
private categorizeEdges;
|
|
38
|
+
/**
|
|
39
|
+
* Analyze graph structure to determine starting nodes and connections
|
|
40
|
+
*/
|
|
41
|
+
private analyzeGraph;
|
|
42
|
+
/**
|
|
43
|
+
* Compute parallel groups by traversing the graph in execution order.
|
|
44
|
+
* Assigns incrementing group IDs that reflect the sequential order of execution.
|
|
45
|
+
*
|
|
46
|
+
* For: researcher -> [analyst1, analyst2, analyst3] -> summarizer
|
|
47
|
+
* - researcher: no group (first sequential node)
|
|
48
|
+
* - analyst1, analyst2, analyst3: groupId 1 (first parallel group)
|
|
49
|
+
* - summarizer: no group (next sequential node)
|
|
50
|
+
*
|
|
51
|
+
* This allows frontend to render in order:
|
|
52
|
+
* Row 0: researcher
|
|
53
|
+
* Row 1: [analyst1, analyst2, analyst3] (grouped)
|
|
54
|
+
* Row 2: summarizer
|
|
55
|
+
*/
|
|
56
|
+
private computeParallelCapability;
|
|
57
|
+
/**
|
|
58
|
+
* Get the parallel group ID for an agent, if any.
|
|
59
|
+
* Returns undefined if the agent is not part of a parallel group.
|
|
60
|
+
* Group IDs are incrementing numbers reflecting execution order.
|
|
61
|
+
*/
|
|
62
|
+
getParallelGroupId(agentId: string): number | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Override to indicate this is a multi-agent graph.
|
|
65
|
+
* Enables agentId to be included in RunStep for frontend agent labeling.
|
|
66
|
+
*/
|
|
67
|
+
protected isMultiAgentGraph(): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Override base class method to provide parallel group IDs for run steps.
|
|
70
|
+
*/
|
|
71
|
+
protected getParallelGroupIdForAgent(agentId: string): number | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Create handoff tools for agents based on handoff edges only
|
|
74
|
+
*/
|
|
75
|
+
private createHandoffTools;
|
|
76
|
+
/**
|
|
77
|
+
* Create handoff tools for an edge (handles multiple destinations)
|
|
78
|
+
* @param edge - The graph edge defining the handoff
|
|
79
|
+
* @param sourceAgentId - The ID of the agent that will perform the handoff
|
|
80
|
+
* @param sourceAgentName - The human-readable name of the source agent
|
|
81
|
+
*/
|
|
82
|
+
private createHandoffToolsForEdge;
|
|
83
|
+
/**
|
|
84
|
+
* Create a complete agent subgraph (similar to createReactAgent)
|
|
85
|
+
*/
|
|
86
|
+
private createAgentSubgraph;
|
|
87
|
+
/**
|
|
88
|
+
* Detects if the current agent is receiving a handoff and processes the messages accordingly.
|
|
89
|
+
* Returns filtered messages with the transfer tool call/message removed, plus any instructions,
|
|
90
|
+
* source agent, and parallel sibling information extracted from the transfer.
|
|
91
|
+
*
|
|
92
|
+
* Supports both single handoffs (last message is the transfer) and parallel handoffs
|
|
93
|
+
* (multiple transfer ToolMessages, need to find the one targeting this agent).
|
|
94
|
+
*
|
|
95
|
+
* @param messages - Current state messages
|
|
96
|
+
* @param agentId - The agent ID to check for handoff reception
|
|
97
|
+
* @returns Object with filtered messages, extracted instructions, source agent, and parallel siblings
|
|
98
|
+
*/
|
|
99
|
+
private processHandoffReception;
|
|
100
|
+
/**
|
|
101
|
+
* Create the multi-agent workflow with dynamic handoffs
|
|
102
|
+
*/
|
|
103
|
+
createWorkflow(): t.CompiledMultiAgentWorkflow;
|
|
104
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export * from './run';
|
|
2
|
+
export * from './stream';
|
|
3
|
+
export * from './splitStream';
|
|
4
|
+
export * from './events';
|
|
5
|
+
export * from './messages';
|
|
6
|
+
export * from './graphs';
|
|
7
|
+
export * from './tools/Calculator';
|
|
8
|
+
export * from './tools/CodeExecutor';
|
|
9
|
+
export * from './tools/BrowserTools';
|
|
10
|
+
export * from './tools/ProgrammaticToolCalling';
|
|
11
|
+
export * from './tools/ToolSearch';
|
|
12
|
+
export * from './tools/ToolNode';
|
|
13
|
+
export * from './tools/schema';
|
|
14
|
+
export * from './tools/handlers';
|
|
15
|
+
export * from './tools/search';
|
|
16
|
+
export * from './schemas';
|
|
17
|
+
export * from './common';
|
|
18
|
+
export * from './utils';
|
|
19
|
+
export type * from './types';
|
|
20
|
+
export { CustomOpenAIClient } from './llm/openai';
|
|
21
|
+
export { getChatModelClass, llmProviders } from './llm/providers';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ChatAnthropicMessages } from '@langchain/anthropic';
|
|
2
|
+
import { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
3
|
+
import type { BaseChatModelParams } from '@langchain/core/language_models/chat_models';
|
|
4
|
+
import type { BaseMessage, UsageMetadata } from '@langchain/core/messages';
|
|
5
|
+
import type { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
|
|
6
|
+
import type { AnthropicInput } from '@langchain/anthropic';
|
|
7
|
+
import type { AnthropicMessageCreateParams, AnthropicStreamingMessageCreateParams } from '@/llm/anthropic/types';
|
|
8
|
+
export type CustomAnthropicInput = AnthropicInput & {
|
|
9
|
+
_lc_stream_delay?: number;
|
|
10
|
+
} & BaseChatModelParams;
|
|
11
|
+
/**
|
|
12
|
+
* A type representing additional parameters that can be passed to the
|
|
13
|
+
* Anthropic API.
|
|
14
|
+
*/
|
|
15
|
+
type Kwargs = Record<string, any>;
|
|
16
|
+
export declare class CustomAnthropic extends ChatAnthropicMessages {
|
|
17
|
+
_lc_stream_delay: number;
|
|
18
|
+
private message_start;
|
|
19
|
+
private message_delta;
|
|
20
|
+
private tools_in_params?;
|
|
21
|
+
private emitted_usage?;
|
|
22
|
+
top_k: number | undefined;
|
|
23
|
+
constructor(fields?: CustomAnthropicInput);
|
|
24
|
+
static lc_name(): 'IllumaAnthropic';
|
|
25
|
+
/**
|
|
26
|
+
* Get the parameters used to invoke the model
|
|
27
|
+
*/
|
|
28
|
+
invocationParams(options?: this['ParsedCallOptions']): Omit<AnthropicMessageCreateParams | AnthropicStreamingMessageCreateParams, 'messages'> & Kwargs;
|
|
29
|
+
/**
|
|
30
|
+
* Get stream usage as returned by this client's API response.
|
|
31
|
+
* @returns The stream usage object.
|
|
32
|
+
*/
|
|
33
|
+
getStreamUsage(): UsageMetadata | undefined;
|
|
34
|
+
resetTokenEvents(): void;
|
|
35
|
+
setDirectFields(fields?: CustomAnthropicInput): void;
|
|
36
|
+
private createGenerationChunk;
|
|
37
|
+
_streamResponseChunks(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
import { BindToolsInput } from '@langchain/core/language_models/chat_models';
|
|
3
|
+
export type AnthropicStreamUsage = Anthropic.Usage;
|
|
4
|
+
export type AnthropicMessageDeltaEvent = Anthropic.MessageDeltaEvent;
|
|
5
|
+
export type AnthropicMessageStartEvent = Anthropic.MessageStartEvent;
|
|
6
|
+
export type AnthropicToolResponse = {
|
|
7
|
+
type: 'tool_use';
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
input: Record<string, any>;
|
|
11
|
+
};
|
|
12
|
+
export type AnthropicMessageParam = Anthropic.MessageParam;
|
|
13
|
+
export type AnthropicMessageResponse = Anthropic.ContentBlock | AnthropicToolResponse;
|
|
14
|
+
export type AnthropicMessageCreateParams = Anthropic.MessageCreateParamsNonStreaming;
|
|
15
|
+
export type AnthropicStreamingMessageCreateParams = Anthropic.MessageCreateParamsStreaming;
|
|
16
|
+
export type AnthropicThinkingConfigParam = Anthropic.ThinkingConfigParam;
|
|
17
|
+
export type AnthropicMessageStreamEvent = Anthropic.MessageStreamEvent;
|
|
18
|
+
export type AnthropicRequestOptions = Anthropic.RequestOptions;
|
|
19
|
+
export type AnthropicToolChoice = {
|
|
20
|
+
type: 'tool';
|
|
21
|
+
name: string;
|
|
22
|
+
} | 'any' | 'auto' | 'none' | string;
|
|
23
|
+
export type ChatAnthropicToolType = Anthropic.Messages.Tool | BindToolsInput;
|
|
24
|
+
export type AnthropicTextBlockParam = Anthropic.Messages.TextBlockParam;
|
|
25
|
+
export type AnthropicImageBlockParam = Anthropic.Messages.ImageBlockParam;
|
|
26
|
+
export type AnthropicToolUseBlockParam = Anthropic.Messages.ToolUseBlockParam;
|
|
27
|
+
export type AnthropicToolResultBlockParam = Anthropic.Messages.ToolResultBlockParam;
|
|
28
|
+
export type AnthropicDocumentBlockParam = Anthropic.Messages.DocumentBlockParam;
|
|
29
|
+
export type AnthropicThinkingBlockParam = Anthropic.Messages.ThinkingBlockParam;
|
|
30
|
+
export type AnthropicRedactedThinkingBlockParam = Anthropic.Messages.RedactedThinkingBlockParam;
|
|
31
|
+
export type AnthropicServerToolUseBlockParam = Anthropic.Messages.ServerToolUseBlockParam;
|
|
32
|
+
export type AnthropicWebSearchToolResultBlockParam = Anthropic.Messages.WebSearchToolResultBlockParam;
|
|
33
|
+
export type AnthropicWebSearchResultBlockParam = Anthropic.Messages.WebSearchResultBlockParam;
|
|
34
|
+
export type AnthropicSearchResultBlockParam = Anthropic.Beta.BetaSearchResultBlockParam;
|
|
35
|
+
export type AnthropicContentBlock = AnthropicTextBlockParam | AnthropicImageBlockParam | AnthropicToolUseBlockParam | AnthropicToolResultBlockParam | AnthropicDocumentBlockParam | AnthropicThinkingBlockParam | AnthropicRedactedThinkingBlockParam | AnthropicServerToolUseBlockParam | AnthropicWebSearchToolResultBlockParam | AnthropicWebSearchResultBlockParam;
|
|
36
|
+
export type ChatAnthropicContentBlock = AnthropicTextBlockParam | AnthropicImageBlockParam | AnthropicToolUseBlockParam | AnthropicToolResultBlockParam | AnthropicDocumentBlockParam | AnthropicThinkingBlockParam | AnthropicRedactedThinkingBlockParam | AnthropicServerToolUseBlockParam | AnthropicWebSearchToolResultBlockParam | AnthropicWebSearchResultBlockParam | AnthropicSearchResultBlockParam;
|
|
37
|
+
export declare function isAnthropicImageBlockParam(block: unknown): block is AnthropicImageBlockParam;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This util file contains functions for converting LangChain messages to Anthropic messages.
|
|
3
|
+
*/
|
|
4
|
+
import { type BaseMessage } from '@langchain/core/messages';
|
|
5
|
+
import { ToolCall } from '@langchain/core/messages/tool';
|
|
6
|
+
import { AnthropicMessageCreateParams, AnthropicToolResponse } from '../types';
|
|
7
|
+
export declare function _convertLangChainToolCallToAnthropic(toolCall: ToolCall): AnthropicToolResponse;
|
|
8
|
+
/**
|
|
9
|
+
* Formats messages as a prompt for the model.
|
|
10
|
+
* Used in LangSmith, export is important here.
|
|
11
|
+
* @param messages The base messages to format as a prompt.
|
|
12
|
+
* @returns The formatted prompt.
|
|
13
|
+
*/
|
|
14
|
+
export declare function _convertMessagesToAnthropicPayload(messages: BaseMessage[]): AnthropicMessageCreateParams;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This util file contains functions for converting Anthropic messages to LangChain messages.
|
|
3
|
+
*/
|
|
4
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
5
|
+
import { AIMessageChunk } from '@langchain/core/messages';
|
|
6
|
+
import { ChatGeneration } from '@langchain/core/outputs';
|
|
7
|
+
import { AnthropicMessageResponse } from '../types';
|
|
8
|
+
export declare function _makeMessageChunkFromAnthropicEvent(data: Anthropic.Messages.RawMessageStreamEvent, fields: {
|
|
9
|
+
streamUsage: boolean;
|
|
10
|
+
coerceContentToString: boolean;
|
|
11
|
+
}): {
|
|
12
|
+
chunk: AIMessageChunk;
|
|
13
|
+
} | null;
|
|
14
|
+
export declare function anthropicResponseToChatMessages(messages: AnthropicMessageResponse[], additionalKwargs: Record<string, unknown>): ChatGeneration[];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseLLMOutputParser } from '@langchain/core/output_parsers';
|
|
2
|
+
import { JsonOutputKeyToolsParserParamsInterop } from '@langchain/core/output_parsers/openai_tools';
|
|
3
|
+
import { ChatGeneration } from '@langchain/core/outputs';
|
|
4
|
+
import { ToolCall } from '@langchain/core/messages/tool';
|
|
5
|
+
import { InteropZodType } from '@langchain/core/utils/types';
|
|
6
|
+
interface AnthropicToolsOutputParserParams<T extends Record<string, any>> extends JsonOutputKeyToolsParserParamsInterop<T> {
|
|
7
|
+
}
|
|
8
|
+
export declare class AnthropicToolsOutputParser<T extends Record<string, any> = Record<string, any>> extends BaseLLMOutputParser<T> {
|
|
9
|
+
static lc_name(): string;
|
|
10
|
+
lc_namespace: string[];
|
|
11
|
+
returnId: boolean;
|
|
12
|
+
/** The type of tool calls to return. */
|
|
13
|
+
keyName: string;
|
|
14
|
+
/** Whether to return only the first tool call. */
|
|
15
|
+
returnSingle: boolean;
|
|
16
|
+
zodSchema?: InteropZodType<T>;
|
|
17
|
+
constructor(params: AnthropicToolsOutputParserParams<T>);
|
|
18
|
+
protected _validateResult(result: unknown): Promise<T>;
|
|
19
|
+
parseResult(generations: ChatGeneration[]): Promise<T>;
|
|
20
|
+
}
|
|
21
|
+
export declare function extractToolCalls(content: Record<string, any>[]): ToolCall[];
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Anthropic } from '@anthropic-ai/sdk';
|
|
2
|
+
import { AnthropicToolChoice } from '../types.js';
|
|
3
|
+
export declare function handleToolChoice(toolChoice?: AnthropicToolChoice): Anthropic.Messages.ToolChoiceAuto | Anthropic.Messages.ToolChoiceAny | Anthropic.Messages.ToolChoiceTool | undefined;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optimized ChatBedrockConverse wrapper that fixes contentBlockIndex conflicts
|
|
3
|
+
* and adds support for:
|
|
4
|
+
*
|
|
5
|
+
* - Prompt caching support for Bedrock Converse API (Illuma feature)
|
|
6
|
+
* - Application Inference Profiles (PR #9129)
|
|
7
|
+
* - Service Tiers (Priority/Standard/Flex) (PR #9785) - requires AWS SDK 3.966.0+
|
|
8
|
+
*
|
|
9
|
+
* Bedrock sends the same contentBlockIndex for both text and tool_use content blocks,
|
|
10
|
+
* causing LangChain's merge logic to fail with "field[contentBlockIndex] already exists"
|
|
11
|
+
* errors. This wrapper simply strips contentBlockIndex from response_metadata to avoid
|
|
12
|
+
* the conflict.
|
|
13
|
+
*
|
|
14
|
+
* The contentBlockIndex field is only used internally by Bedrock's streaming protocol
|
|
15
|
+
* and isn't needed by application logic - the index field on tool_call_chunks serves
|
|
16
|
+
* the purpose of tracking tool call ordering.
|
|
17
|
+
*
|
|
18
|
+
* PROMPT CACHING:
|
|
19
|
+
* When promptCache: true is set, this wrapper adds cachePoint markers to the tools array
|
|
20
|
+
* to enable Bedrock prompt caching for tool definitions. This allows tool schemas to be
|
|
21
|
+
* cached and reused across requests, reducing latency and costs.
|
|
22
|
+
*
|
|
23
|
+
* CACHE TOKEN EXTRACTION:
|
|
24
|
+
* LangChain AWS doesn't extract cacheReadInputTokens/cacheWriteInputTokens from Bedrock's
|
|
25
|
+
* response. This wrapper adds input_token_details to usage_metadata with cache information.
|
|
26
|
+
*/
|
|
27
|
+
import { ChatBedrockConverse } from '@langchain/aws';
|
|
28
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
29
|
+
import { ChatGenerationChunk, ChatResult } from '@langchain/core/outputs';
|
|
30
|
+
import type { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
|
|
31
|
+
import type { ChatBedrockConverseInput } from '@langchain/aws';
|
|
32
|
+
/**
|
|
33
|
+
* Service tier type for Bedrock invocations.
|
|
34
|
+
* Requires AWS SDK >= 3.966.0 to actually work.
|
|
35
|
+
* @see https://docs.aws.amazon.com/bedrock/latest/userguide/service-tiers-inference.html
|
|
36
|
+
*/
|
|
37
|
+
export type ServiceTierType = 'priority' | 'default' | 'flex' | 'reserved';
|
|
38
|
+
/**
|
|
39
|
+
* Extended input interface with additional features:
|
|
40
|
+
* - promptCache: Enable Bedrock prompt caching for tool definitions
|
|
41
|
+
* - applicationInferenceProfile: Use an inference profile ARN instead of model ID
|
|
42
|
+
* - serviceTier: Specify service tier (Priority, Standard, Flex, Reserved)
|
|
43
|
+
*/
|
|
44
|
+
export interface CustomChatBedrockConverseInput extends ChatBedrockConverseInput {
|
|
45
|
+
/**
|
|
46
|
+
* Enable Bedrock prompt caching for tool definitions.
|
|
47
|
+
* When true, adds cachePoint markers to tools array.
|
|
48
|
+
*/
|
|
49
|
+
promptCache?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Application Inference Profile ARN to use for the model.
|
|
52
|
+
* For example, "arn:aws:bedrock:eu-west-1:123456789102:application-inference-profile/fm16bt65tzgx"
|
|
53
|
+
* When provided, this ARN will be used for the actual inference calls instead of the model ID.
|
|
54
|
+
* Must still provide `model` as normal modelId to benefit from all the metadata.
|
|
55
|
+
* @see https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-create.html
|
|
56
|
+
*/
|
|
57
|
+
applicationInferenceProfile?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Service tier for model invocation.
|
|
60
|
+
* Specifies the processing tier type used for serving the request.
|
|
61
|
+
* Supported values are 'priority', 'default', 'flex', and 'reserved'.
|
|
62
|
+
*
|
|
63
|
+
* - 'priority': Prioritized processing for lower latency
|
|
64
|
+
* - 'default': Standard processing tier
|
|
65
|
+
* - 'flex': Flexible processing tier with lower cost
|
|
66
|
+
* - 'reserved': Reserved capacity for consistent performance
|
|
67
|
+
*
|
|
68
|
+
* If not provided, AWS uses the default tier.
|
|
69
|
+
* Note: Requires AWS SDK >= 3.966.0 to work.
|
|
70
|
+
* @see https://docs.aws.amazon.com/bedrock/latest/userguide/service-tiers-inference.html
|
|
71
|
+
*/
|
|
72
|
+
serviceTier?: ServiceTierType;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Extended call options with serviceTier override support.
|
|
76
|
+
*/
|
|
77
|
+
export interface CustomChatBedrockConverseCallOptions {
|
|
78
|
+
serviceTier?: ServiceTierType;
|
|
79
|
+
}
|
|
80
|
+
export declare class CustomChatBedrockConverse extends ChatBedrockConverse {
|
|
81
|
+
/** Enable Bedrock prompt caching for tool definitions */
|
|
82
|
+
promptCache: boolean;
|
|
83
|
+
/** Application Inference Profile ARN to use instead of model ID */
|
|
84
|
+
applicationInferenceProfile?: string;
|
|
85
|
+
/** Service tier for model invocation */
|
|
86
|
+
serviceTier?: ServiceTierType;
|
|
87
|
+
constructor(fields?: CustomChatBedrockConverseInput);
|
|
88
|
+
static lc_name(): string;
|
|
89
|
+
/**
|
|
90
|
+
* Get the model ID to use for API calls.
|
|
91
|
+
* Returns applicationInferenceProfile if set, otherwise returns this.model.
|
|
92
|
+
*/
|
|
93
|
+
protected getModelId(): string;
|
|
94
|
+
/**
|
|
95
|
+
* Override invocationParams to:
|
|
96
|
+
* 1. Add cachePoint to tools when promptCache is enabled
|
|
97
|
+
* 2. Add serviceTier support
|
|
98
|
+
*
|
|
99
|
+
* CACHING STRATEGY: Separate cachePoints for core tools and MCP tools
|
|
100
|
+
* - Core tools (web_search, execute_code, etc.) are stable → cache first
|
|
101
|
+
* - MCP tools (have '_mcp_' in name) are dynamic → cache separately after
|
|
102
|
+
* - This allows core tools to stay cached when MCP selection changes
|
|
103
|
+
*
|
|
104
|
+
* NOTE: Only Claude models support cachePoint - Nova and other models will reject it.
|
|
105
|
+
*/
|
|
106
|
+
invocationParams(options?: this['ParsedCallOptions'] & CustomChatBedrockConverseCallOptions): ReturnType<ChatBedrockConverse['invocationParams']> & {
|
|
107
|
+
serviceTier?: {
|
|
108
|
+
type: ServiceTierType;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Override _generateNonStreaming to use applicationInferenceProfile as modelId.
|
|
113
|
+
* Uses the same model-swapping pattern as streaming for consistency.
|
|
114
|
+
*/
|
|
115
|
+
_generateNonStreaming(messages: BaseMessage[], options: this['ParsedCallOptions'] & CustomChatBedrockConverseCallOptions, runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
|
|
116
|
+
/**
|
|
117
|
+
* Override _streamResponseChunks to:
|
|
118
|
+
* 1. Use applicationInferenceProfile as modelId (by temporarily swapping this.model)
|
|
119
|
+
* 2. Strip contentBlockIndex from response_metadata to prevent merge conflicts
|
|
120
|
+
* 3. Extract cacheReadInputTokens/cacheWriteInputTokens and add to usage_metadata
|
|
121
|
+
*
|
|
122
|
+
* Note: We delegate to super._streamResponseChunks() to preserve @langchain/aws's
|
|
123
|
+
* internal chunk handling which correctly preserves array content for reasoning blocks.
|
|
124
|
+
*/
|
|
125
|
+
_streamResponseChunks(messages: BaseMessage[], options: this['ParsedCallOptions'] & CustomChatBedrockConverseCallOptions, runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
126
|
+
/**
|
|
127
|
+
* Process a chunk by:
|
|
128
|
+
* 1. Removing contentBlockIndex from response_metadata
|
|
129
|
+
* 2. Extracting cache token information from Bedrock's usage data
|
|
130
|
+
*/
|
|
131
|
+
private processChunk;
|
|
132
|
+
/**
|
|
133
|
+
* Check if contentBlockIndex exists at any level in the object
|
|
134
|
+
*/
|
|
135
|
+
private hasContentBlockIndex;
|
|
136
|
+
/**
|
|
137
|
+
* Recursively remove contentBlockIndex from all levels of an object
|
|
138
|
+
*/
|
|
139
|
+
private removeContentBlockIndex;
|
|
140
|
+
}
|
|
141
|
+
export type { ChatBedrockConverseInput };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for Bedrock Converse utilities.
|
|
3
|
+
*/
|
|
4
|
+
import type { Message as BedrockMessage, SystemContentBlock as BedrockSystemContentBlock, ContentBlock as BedrockContentBlock, ConverseResponse, ContentBlockDeltaEvent, ConverseStreamMetadataEvent, ContentBlockStartEvent, ReasoningContentBlock, ReasoningContentBlockDelta } from '@aws-sdk/client-bedrock-runtime';
|
|
5
|
+
/**
|
|
6
|
+
* Reasoning content block type for LangChain messages.
|
|
7
|
+
*/
|
|
8
|
+
export interface MessageContentReasoningBlock {
|
|
9
|
+
type: 'reasoning_content';
|
|
10
|
+
reasoningText?: {
|
|
11
|
+
text?: string;
|
|
12
|
+
signature?: string;
|
|
13
|
+
};
|
|
14
|
+
redactedContent?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface MessageContentReasoningBlockReasoningTextPartial {
|
|
17
|
+
type: 'reasoning_content';
|
|
18
|
+
reasoningText: {
|
|
19
|
+
text?: string;
|
|
20
|
+
signature?: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface MessageContentReasoningBlockRedacted {
|
|
24
|
+
type: 'reasoning_content';
|
|
25
|
+
redactedContent: string;
|
|
26
|
+
}
|
|
27
|
+
export type { BedrockMessage, BedrockSystemContentBlock, BedrockContentBlock, ConverseResponse, ContentBlockDeltaEvent, ConverseStreamMetadataEvent, ContentBlockStartEvent, ReasoningContentBlock, ReasoningContentBlockDelta, };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bedrock Converse utility exports.
|
|
3
|
+
*/
|
|
4
|
+
export { convertToConverseMessages, extractImageInfo, langchainReasoningBlockToBedrockReasoningBlock, concatenateLangchainReasoningBlocks, } from './message_inputs';
|
|
5
|
+
export { convertConverseMessageToLangChainMessage, handleConverseStreamContentBlockStart, handleConverseStreamContentBlockDelta, handleConverseStreamMetadata, bedrockReasoningBlockToLangchainReasoningBlock, bedrockReasoningDeltaToLangchainPartialReasoningBlock, } from './message_outputs';
|