illuma-agents 1.0.2 → 1.0.4
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/LICENSE +25 -21
- package/dist/cjs/agents/AgentContext.cjs +222 -0
- package/dist/cjs/agents/AgentContext.cjs.map +1 -0
- package/dist/cjs/common/enum.cjs +5 -4
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/events.cjs +7 -5
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +328 -207
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +507 -0
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/google/index.cjs.map +1 -1
- package/dist/cjs/llm/ollama/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +35 -0
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs +3 -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/providers.cjs +0 -2
- package/dist/cjs/llm/providers.cjs.map +1 -1
- package/dist/cjs/llm/vertexai/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +12 -1
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +123 -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/format.cjs +17 -29
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/run.cjs +119 -74
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/stream.cjs +77 -73
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/tools/Calculator.cjs +45 -0
- package/dist/cjs/tools/Calculator.cjs.map +1 -0
- package/dist/cjs/tools/CodeExecutor.cjs +22 -22
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +5 -3
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/handlers.cjs +20 -20
- package/dist/cjs/tools/handlers.cjs.map +1 -1
- package/dist/cjs/utils/events.cjs +31 -0
- package/dist/cjs/utils/events.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/tokens.cjs +54 -7
- package/dist/cjs/utils/tokens.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +220 -0
- package/dist/esm/agents/AgentContext.mjs.map +1 -0
- package/dist/esm/common/enum.mjs +5 -4
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/events.mjs +7 -5
- package/dist/esm/events.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +330 -209
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +505 -0
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -0
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/google/index.mjs.map +1 -1
- package/dist/esm/llm/ollama/index.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +35 -0
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs +3 -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/providers.mjs +0 -2
- package/dist/esm/llm/providers.mjs.map +1 -1
- package/dist/esm/llm/vertexai/index.mjs.map +1 -1
- package/dist/esm/main.mjs +7 -2
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/messages/cache.mjs +120 -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/format.mjs +18 -29
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/run.mjs +119 -74
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/stream.mjs +77 -73
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/tools/Calculator.mjs +24 -0
- package/dist/esm/tools/Calculator.mjs.map +1 -0
- package/dist/esm/tools/CodeExecutor.mjs +22 -22
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +5 -3
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/handlers.mjs +20 -20
- package/dist/esm/tools/handlers.mjs.map +1 -1
- package/dist/esm/utils/events.mjs +29 -0
- package/dist/esm/utils/events.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/tokens.mjs +54 -8
- package/dist/esm/utils/tokens.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +94 -0
- package/dist/types/common/enum.d.ts +7 -5
- package/dist/types/events.d.ts +3 -3
- package/dist/types/graphs/Graph.d.ts +60 -66
- package/dist/types/graphs/MultiAgentGraph.d.ts +47 -0
- package/dist/types/graphs/index.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/llm/openai/index.d.ts +10 -0
- package/dist/types/messages/cache.d.ts +20 -0
- package/dist/types/messages/content.d.ts +7 -0
- package/dist/types/messages/format.d.ts +1 -7
- package/dist/types/messages/index.d.ts +2 -0
- package/dist/types/messages/reducer.d.ts +9 -0
- package/dist/types/run.d.ts +16 -10
- package/dist/types/stream.d.ts +4 -3
- package/dist/types/tools/Calculator.d.ts +8 -0
- package/dist/types/tools/ToolNode.d.ts +1 -1
- package/dist/types/tools/handlers.d.ts +9 -7
- package/dist/types/tools/search/tool.d.ts +4 -4
- package/dist/types/types/graph.d.ts +124 -11
- package/dist/types/types/llm.d.ts +13 -9
- package/dist/types/types/messages.d.ts +4 -0
- package/dist/types/types/run.d.ts +46 -8
- package/dist/types/types/stream.d.ts +3 -2
- package/dist/types/utils/events.d.ts +6 -0
- package/dist/types/utils/handlers.d.ts +34 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/tokens.d.ts +24 -0
- package/package.json +162 -145
- package/src/agents/AgentContext.ts +323 -0
- package/src/common/enum.ts +177 -176
- package/src/events.ts +197 -191
- package/src/graphs/Graph.ts +1058 -846
- package/src/graphs/MultiAgentGraph.ts +598 -0
- package/src/graphs/index.ts +2 -1
- package/src/index.ts +25 -24
- package/src/llm/anthropic/index.ts +413 -413
- package/src/llm/google/index.ts +222 -222
- package/src/llm/google/utils/zod_to_genai_parameters.ts +86 -88
- package/src/llm/ollama/index.ts +92 -92
- package/src/llm/openai/index.ts +894 -853
- package/src/llm/openai/utils/index.ts +920 -918
- package/src/llm/openrouter/index.ts +60 -60
- package/src/llm/providers.ts +55 -57
- package/src/llm/vertexai/index.ts +360 -360
- package/src/messages/cache.test.ts +461 -0
- package/src/messages/cache.ts +151 -0
- package/src/messages/content.test.ts +362 -0
- package/src/messages/content.ts +63 -0
- package/src/messages/format.ts +611 -625
- package/src/messages/formatAgentMessages.test.ts +1144 -917
- package/src/messages/index.ts +6 -4
- package/src/messages/reducer.ts +80 -0
- package/src/run.ts +447 -381
- package/src/scripts/abort.ts +157 -138
- package/src/scripts/ant_web_search.ts +158 -158
- package/src/scripts/cli.ts +172 -167
- package/src/scripts/cli2.ts +133 -125
- package/src/scripts/cli3.ts +184 -178
- package/src/scripts/cli4.ts +191 -184
- package/src/scripts/cli5.ts +191 -184
- package/src/scripts/code_exec.ts +213 -214
- package/src/scripts/code_exec_simple.ts +147 -129
- package/src/scripts/content.ts +138 -120
- package/src/scripts/handoff-test.ts +135 -0
- package/src/scripts/multi-agent-chain.ts +278 -0
- package/src/scripts/multi-agent-conditional.ts +220 -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.ts +343 -0
- package/src/scripts/multi-agent-sequence.ts +212 -0
- package/src/scripts/multi-agent-supervisor.ts +364 -0
- package/src/scripts/multi-agent-test.ts +186 -0
- package/src/scripts/search.ts +146 -150
- package/src/scripts/simple.ts +225 -225
- package/src/scripts/stream.ts +140 -122
- package/src/scripts/test-custom-prompt-key.ts +145 -0
- package/src/scripts/test-handoff-input.ts +170 -0
- package/src/scripts/test-multi-agent-list-handoff.ts +261 -0
- package/src/scripts/test-tools-before-handoff.ts +222 -0
- package/src/scripts/tools.ts +153 -155
- package/src/specs/agent-handoffs.test.ts +889 -0
- package/src/specs/anthropic.simple.test.ts +320 -317
- package/src/specs/azure.simple.test.ts +325 -316
- package/src/specs/openai.simple.test.ts +311 -316
- package/src/specs/openrouter.simple.test.ts +107 -0
- package/src/specs/prune.test.ts +758 -763
- package/src/specs/reasoning.test.ts +201 -165
- package/src/specs/thinking-prune.test.ts +769 -703
- package/src/specs/token-memoization.test.ts +39 -0
- package/src/stream.ts +664 -651
- package/src/tools/Calculator.test.ts +278 -0
- package/src/tools/Calculator.ts +25 -0
- package/src/tools/CodeExecutor.ts +220 -220
- package/src/tools/ToolNode.ts +170 -170
- package/src/tools/handlers.ts +341 -336
- package/src/types/graph.ts +372 -185
- package/src/types/llm.ts +141 -140
- package/src/types/messages.ts +4 -0
- package/src/types/run.ts +128 -89
- package/src/types/stream.ts +401 -400
- package/src/utils/events.ts +32 -0
- package/src/utils/handlers.ts +107 -0
- package/src/utils/index.ts +6 -5
- package/src/utils/llmConfig.ts +183 -183
- package/src/utils/tokens.ts +129 -70
- package/dist/types/scripts/abort.d.ts +0 -1
- package/dist/types/scripts/ant_web_search.d.ts +0 -1
- package/dist/types/scripts/args.d.ts +0 -7
- package/dist/types/scripts/caching.d.ts +0 -1
- package/dist/types/scripts/cli.d.ts +0 -1
- package/dist/types/scripts/cli2.d.ts +0 -1
- package/dist/types/scripts/cli3.d.ts +0 -1
- package/dist/types/scripts/cli4.d.ts +0 -1
- package/dist/types/scripts/cli5.d.ts +0 -1
- package/dist/types/scripts/code_exec.d.ts +0 -1
- package/dist/types/scripts/code_exec_files.d.ts +0 -1
- package/dist/types/scripts/code_exec_simple.d.ts +0 -1
- package/dist/types/scripts/content.d.ts +0 -1
- package/dist/types/scripts/empty_input.d.ts +0 -1
- package/dist/types/scripts/image.d.ts +0 -1
- package/dist/types/scripts/memory.d.ts +0 -1
- package/dist/types/scripts/search.d.ts +0 -1
- package/dist/types/scripts/simple.d.ts +0 -1
- package/dist/types/scripts/stream.d.ts +0 -1
- package/dist/types/scripts/thinking.d.ts +0 -1
- package/dist/types/scripts/tools.d.ts +0 -1
- package/dist/types/specs/spec.utils.d.ts +0 -1
- package/dist/types/tools/example.d.ts +0 -78
- package/src/tools/example.ts +0 -129
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { SystemMessage } from '@langchain/core/messages';
|
|
2
|
+
import type { UsageMetadata, BaseMessage } from '@langchain/core/messages';
|
|
3
|
+
import type { RunnableConfig, Runnable } from '@langchain/core/runnables';
|
|
4
|
+
import type * as t from '@/types';
|
|
5
|
+
import type { createPruneMessages } from '@/messages';
|
|
6
|
+
import { ContentTypes, Providers } from '@/common';
|
|
7
|
+
/**
|
|
8
|
+
* Encapsulates agent-specific state that can vary between agents in a multi-agent system
|
|
9
|
+
*/
|
|
10
|
+
export declare class AgentContext {
|
|
11
|
+
/**
|
|
12
|
+
* Create an AgentContext from configuration with token accounting initialization
|
|
13
|
+
*/
|
|
14
|
+
static fromConfig(agentConfig: t.AgentInputs, tokenCounter?: t.TokenCounter, indexTokenCountMap?: Record<string, number>): AgentContext;
|
|
15
|
+
/** Agent identifier */
|
|
16
|
+
agentId: string;
|
|
17
|
+
/** Provider for this specific agent */
|
|
18
|
+
provider: Providers;
|
|
19
|
+
/** Client options for this agent */
|
|
20
|
+
clientOptions?: t.ClientOptions;
|
|
21
|
+
/** Token count map indexed by message position */
|
|
22
|
+
indexTokenCountMap: Record<string, number | undefined>;
|
|
23
|
+
/** Maximum context tokens for this agent */
|
|
24
|
+
maxContextTokens?: number;
|
|
25
|
+
/** Current usage metadata for this agent */
|
|
26
|
+
currentUsage?: Partial<UsageMetadata>;
|
|
27
|
+
/** Prune messages function configured for this agent */
|
|
28
|
+
pruneMessages?: ReturnType<typeof createPruneMessages>;
|
|
29
|
+
/** Token counter function for this agent */
|
|
30
|
+
tokenCounter?: t.TokenCounter;
|
|
31
|
+
/** Instructions/system message token count */
|
|
32
|
+
instructionTokens: number;
|
|
33
|
+
/** The amount of time that should pass before another consecutive API call */
|
|
34
|
+
streamBuffer?: number;
|
|
35
|
+
/** Last stream call timestamp for rate limiting */
|
|
36
|
+
lastStreamCall?: number;
|
|
37
|
+
/** Tools available to this agent */
|
|
38
|
+
tools?: t.GraphTools;
|
|
39
|
+
/** Tool map for this agent */
|
|
40
|
+
toolMap?: t.ToolMap;
|
|
41
|
+
/** Instructions for this agent */
|
|
42
|
+
instructions?: string;
|
|
43
|
+
/** Additional instructions for this agent */
|
|
44
|
+
additionalInstructions?: string;
|
|
45
|
+
/** Reasoning key for this agent */
|
|
46
|
+
reasoningKey: 'reasoning_content' | 'reasoning';
|
|
47
|
+
/** Last token for reasoning detection */
|
|
48
|
+
lastToken?: string;
|
|
49
|
+
/** Token type switch state */
|
|
50
|
+
tokenTypeSwitch?: 'reasoning' | 'content';
|
|
51
|
+
/** Current token type being processed */
|
|
52
|
+
currentTokenType: ContentTypes.TEXT | ContentTypes.THINK | 'think_and_text';
|
|
53
|
+
/** Whether tools should end the workflow */
|
|
54
|
+
toolEnd: boolean;
|
|
55
|
+
/** System runnable for this agent */
|
|
56
|
+
systemRunnable?: Runnable<BaseMessage[], (BaseMessage | SystemMessage)[], RunnableConfig<Record<string, unknown>>>;
|
|
57
|
+
/** Promise for token calculation initialization */
|
|
58
|
+
tokenCalculationPromise?: Promise<void>;
|
|
59
|
+
/** Format content blocks as strings (for legacy compatibility) */
|
|
60
|
+
useLegacyContent: boolean;
|
|
61
|
+
constructor({ agentId, provider, clientOptions, maxContextTokens, streamBuffer, tokenCounter, tools, toolMap, instructions, additionalInstructions, reasoningKey, toolEnd, instructionTokens, useLegacyContent, }: {
|
|
62
|
+
agentId: string;
|
|
63
|
+
provider: Providers;
|
|
64
|
+
clientOptions?: t.ClientOptions;
|
|
65
|
+
maxContextTokens?: number;
|
|
66
|
+
streamBuffer?: number;
|
|
67
|
+
tokenCounter?: t.TokenCounter;
|
|
68
|
+
tools?: t.GraphTools;
|
|
69
|
+
toolMap?: t.ToolMap;
|
|
70
|
+
instructions?: string;
|
|
71
|
+
additionalInstructions?: string;
|
|
72
|
+
reasoningKey?: 'reasoning_content' | 'reasoning';
|
|
73
|
+
toolEnd?: boolean;
|
|
74
|
+
instructionTokens?: number;
|
|
75
|
+
useLegacyContent?: boolean;
|
|
76
|
+
});
|
|
77
|
+
/**
|
|
78
|
+
* Create system runnable from instructions and calculate tokens if tokenCounter is available
|
|
79
|
+
*/
|
|
80
|
+
private createSystemRunnable;
|
|
81
|
+
/**
|
|
82
|
+
* Reset context for a new run
|
|
83
|
+
*/
|
|
84
|
+
reset(): void;
|
|
85
|
+
/**
|
|
86
|
+
* Update the token count map with instruction tokens
|
|
87
|
+
*/
|
|
88
|
+
updateTokenMapWithInstructions(baseTokenMap: Record<string, number>): void;
|
|
89
|
+
/**
|
|
90
|
+
* Calculate tool tokens and add to instruction tokens
|
|
91
|
+
* Note: System message tokens are calculated during systemRunnable creation
|
|
92
|
+
*/
|
|
93
|
+
calculateInstructionTokens(tokenCounter: t.TokenCounter): Promise<void>;
|
|
94
|
+
}
|
|
@@ -52,7 +52,6 @@ export declare enum GraphEvents {
|
|
|
52
52
|
}
|
|
53
53
|
export declare enum Providers {
|
|
54
54
|
OPENAI = "openAI",
|
|
55
|
-
BEDROCK_LEGACY = "bedrock_legacy",
|
|
56
55
|
VERTEXAI = "vertexai",
|
|
57
56
|
BEDROCK = "bedrock",
|
|
58
57
|
ANTHROPIC = "anthropic",
|
|
@@ -66,8 +65,9 @@ export declare enum Providers {
|
|
|
66
65
|
XAI = "xai"
|
|
67
66
|
}
|
|
68
67
|
export declare enum GraphNodeKeys {
|
|
69
|
-
TOOLS = "tools",
|
|
70
|
-
AGENT = "agent",
|
|
68
|
+
TOOLS = "tools=",
|
|
69
|
+
AGENT = "agent=",
|
|
70
|
+
ROUTER = "router",
|
|
71
71
|
PRE_TOOLS = "pre_tools",
|
|
72
72
|
POST_TOOLS = "post_tools"
|
|
73
73
|
}
|
|
@@ -109,13 +109,15 @@ export declare enum ToolCallTypes {
|
|
|
109
109
|
export declare enum Callback {
|
|
110
110
|
TOOL_ERROR = "handleToolError",
|
|
111
111
|
TOOL_START = "handleToolStart",
|
|
112
|
-
TOOL_END = "handleToolEnd"
|
|
112
|
+
TOOL_END = "handleToolEnd",
|
|
113
|
+
CUSTOM_EVENT = "handleCustomEvent"
|
|
113
114
|
}
|
|
114
115
|
export declare enum Constants {
|
|
115
116
|
OFFICIAL_CODE_BASEURL = "https://api.illuma.ai/v1",
|
|
116
117
|
EXECUTE_CODE = "execute_code",
|
|
117
118
|
WEB_SEARCH = "web_search",
|
|
118
|
-
CONTENT_AND_ARTIFACT = "content_and_artifact"
|
|
119
|
+
CONTENT_AND_ARTIFACT = "content_and_artifact",
|
|
120
|
+
LC_TRANSFER_TO_ = "lc_transfer_to_"
|
|
119
121
|
}
|
|
120
122
|
export declare enum TitleMethod {
|
|
121
123
|
STRUCTURED = "structured",
|
package/dist/types/events.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { UsageMetadata, BaseMessageFields } from '@langchain/core/messages';
|
|
2
|
-
import type {
|
|
2
|
+
import type { MultiAgentGraph, StandardGraph } from '@/graphs';
|
|
3
3
|
import type * as t from '@/types';
|
|
4
4
|
export declare class HandlerRegistry {
|
|
5
5
|
private handlers;
|
|
@@ -9,13 +9,13 @@ export declare class HandlerRegistry {
|
|
|
9
9
|
export declare class ModelEndHandler implements t.EventHandler {
|
|
10
10
|
collectedUsage?: UsageMetadata[];
|
|
11
11
|
constructor(collectedUsage?: UsageMetadata[]);
|
|
12
|
-
handle(event: string, data: t.ModelEndData, metadata?: Record<string, unknown>, graph?:
|
|
12
|
+
handle(event: string, data: t.ModelEndData, metadata?: Record<string, unknown>, graph?: StandardGraph | MultiAgentGraph): Promise<void>;
|
|
13
13
|
}
|
|
14
14
|
export declare class ToolEndHandler implements t.EventHandler {
|
|
15
15
|
private callback?;
|
|
16
16
|
private omitOutput?;
|
|
17
17
|
constructor(callback?: t.ToolEndCallback, omitOutput?: (name?: string) => boolean);
|
|
18
|
-
handle(event: string, data: t.StreamEventData | undefined, metadata?: Record<string, unknown>, graph?:
|
|
18
|
+
handle(event: string, data: t.StreamEventData | undefined, metadata?: Record<string, unknown>, graph?: StandardGraph | MultiAgentGraph): Promise<void>;
|
|
19
19
|
}
|
|
20
20
|
export declare class TestLLMStreamHandler implements t.EventHandler {
|
|
21
21
|
handle(event: string, data: t.StreamEventData | undefined): void;
|
|
@@ -1,29 +1,23 @@
|
|
|
1
1
|
import { ToolNode } from '@langchain/langgraph/prebuilt';
|
|
2
|
-
import { START } from '@langchain/langgraph';
|
|
3
2
|
import { Runnable, RunnableConfig } from '@langchain/core/runnables';
|
|
4
|
-
import {
|
|
5
|
-
import type { BaseMessage, UsageMetadata } from '@langchain/core/messages';
|
|
6
|
-
import type * as t from '@/types';
|
|
7
|
-
import { Providers, GraphNodeKeys, Callback, ContentTypes } from '@/common';
|
|
3
|
+
import type { UsageMetadata, BaseMessage } from '@langchain/core/messages';
|
|
8
4
|
import type { ToolCall } from '@langchain/core/messages/tool';
|
|
5
|
+
import type * as t from '@/types';
|
|
6
|
+
import { Providers } from '@/common';
|
|
9
7
|
import { ToolNode as CustomToolNode } from '@/tools/ToolNode';
|
|
10
|
-
import {
|
|
8
|
+
import { AgentContext } from '@/agents/AgentContext';
|
|
11
9
|
import { HandlerRegistry } from '@/events';
|
|
12
|
-
export
|
|
13
|
-
export type ClientCallback<T extends unknown[]> = (graph: StandardGraph, ...args: T) => void;
|
|
14
|
-
export type ClientCallbacks = {
|
|
15
|
-
[Callback.TOOL_ERROR]?: ClientCallback<[Error, string]>;
|
|
16
|
-
[Callback.TOOL_START]?: ClientCallback<unknown[]>;
|
|
17
|
-
[Callback.TOOL_END]?: ClientCallback<unknown[]>;
|
|
18
|
-
};
|
|
19
|
-
export type SystemCallbacks = {
|
|
20
|
-
[K in keyof ClientCallbacks]: ClientCallbacks[K] extends ClientCallback<infer Args> ? (...args: Args) => void : never;
|
|
21
|
-
};
|
|
22
|
-
export declare abstract class Graph<T extends t.BaseGraphState = t.BaseGraphState, TNodeName extends string = string> {
|
|
10
|
+
export declare abstract class Graph<T extends t.BaseGraphState = t.BaseGraphState, _TNodeName extends string = string> {
|
|
23
11
|
abstract resetValues(): void;
|
|
24
|
-
abstract
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
abstract initializeTools({ currentTools, currentToolMap, }: {
|
|
13
|
+
currentTools?: t.GraphTools;
|
|
14
|
+
currentToolMap?: t.ToolMap;
|
|
15
|
+
}): CustomToolNode<T> | ToolNode<T>;
|
|
16
|
+
abstract initializeModel({ currentModel, tools, clientOptions, }: {
|
|
17
|
+
currentModel?: t.ChatModel;
|
|
18
|
+
tools?: t.GraphTools;
|
|
19
|
+
clientOptions?: t.ClientOptions;
|
|
20
|
+
}): Runnable;
|
|
27
21
|
abstract getRunMessages(): BaseMessage[] | undefined;
|
|
28
22
|
abstract getContentParts(): t.MessageContentComplex[] | undefined;
|
|
29
23
|
abstract generateStepId(stepKey: string): [string, number];
|
|
@@ -32,17 +26,12 @@ export declare abstract class Graph<T extends t.BaseGraphState = t.BaseGraphStat
|
|
|
32
26
|
abstract checkKeyList(keyList: (string | number | undefined)[]): boolean;
|
|
33
27
|
abstract getStepIdByKey(stepKey: string, index?: number): string;
|
|
34
28
|
abstract getRunStep(stepId: string): t.RunStep | undefined;
|
|
35
|
-
abstract dispatchRunStep(stepKey: string, stepDetails: t.StepDetails): string
|
|
36
|
-
abstract dispatchRunStepDelta(id: string, delta: t.ToolCallDelta): void
|
|
37
|
-
abstract dispatchMessageDelta(id: string, delta: t.MessageDelta): void
|
|
38
|
-
abstract dispatchReasoningDelta(stepId: string, delta: t.ReasoningDelta): void
|
|
39
|
-
abstract handleToolCallCompleted(data: t.ToolEndData, metadata?: Record<string, unknown>, omitOutput?: boolean): void
|
|
40
|
-
abstract createCallModel(): (state: T, config?: RunnableConfig) => Promise<Partial<T>>;
|
|
41
|
-
abstract createWorkflow(): t.CompiledWorkflow<T>;
|
|
42
|
-
lastToken?: string;
|
|
43
|
-
tokenTypeSwitch?: 'reasoning' | 'content';
|
|
44
|
-
reasoningKey: 'reasoning_content' | 'reasoning';
|
|
45
|
-
currentTokenType: ContentTypes.TEXT | ContentTypes.THINK | 'think_and_text';
|
|
29
|
+
abstract dispatchRunStep(stepKey: string, stepDetails: t.StepDetails): Promise<string>;
|
|
30
|
+
abstract dispatchRunStepDelta(id: string, delta: t.ToolCallDelta): Promise<void>;
|
|
31
|
+
abstract dispatchMessageDelta(id: string, delta: t.MessageDelta): Promise<void>;
|
|
32
|
+
abstract dispatchReasoningDelta(stepId: string, delta: t.ReasoningDelta): Promise<void>;
|
|
33
|
+
abstract handleToolCallCompleted(data: t.ToolEndData, metadata?: Record<string, unknown>, omitOutput?: boolean): Promise<void>;
|
|
34
|
+
abstract createCallModel(agentId?: string, currentModel?: t.ChatModel): (state: T, config?: RunnableConfig) => Promise<Partial<T>>;
|
|
46
35
|
messageStepHasToolCalls: Map<string, boolean>;
|
|
47
36
|
messageIdsByStepKey: Map<string, string>;
|
|
48
37
|
prelimMessageIdsByStepKey: Map<string, string>;
|
|
@@ -51,36 +40,27 @@ export declare abstract class Graph<T extends t.BaseGraphState = t.BaseGraphStat
|
|
|
51
40
|
stepKeyIds: Map<string, string[]>;
|
|
52
41
|
contentIndexMap: Map<string, number>;
|
|
53
42
|
toolCallStepIds: Map<string, string>;
|
|
54
|
-
currentUsage: Partial<UsageMetadata> | undefined;
|
|
55
|
-
indexTokenCountMap: Record<string, number | undefined>;
|
|
56
|
-
maxContextTokens: number | undefined;
|
|
57
|
-
pruneMessages?: ReturnType<typeof createPruneMessages>;
|
|
58
|
-
/** The amount of time that should pass before another consecutive API call */
|
|
59
|
-
streamBuffer: number | undefined;
|
|
60
|
-
tokenCounter?: t.TokenCounter;
|
|
61
43
|
signal?: AbortSignal;
|
|
62
44
|
/** Set of invoked tool call IDs from non-message run steps completed mid-run, if any */
|
|
63
45
|
invokedToolIds?: Set<string>;
|
|
64
46
|
handlerRegistry: HandlerRegistry | undefined;
|
|
65
47
|
}
|
|
66
|
-
export declare class StandardGraph extends Graph<t.BaseGraphState, GraphNode> {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
/** The last recorded timestamp that a stream API call was invoked */
|
|
71
|
-
lastStreamCall: number | undefined;
|
|
72
|
-
systemMessage: SystemMessage | undefined;
|
|
48
|
+
export declare class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
49
|
+
overrideModel?: t.ChatModel;
|
|
50
|
+
/** Optional compile options passed into workflow.compile() */
|
|
51
|
+
compileOptions?: t.CompileOptions | undefined;
|
|
73
52
|
messages: BaseMessage[];
|
|
74
53
|
runId: string | undefined;
|
|
75
|
-
tools?: t.GraphTools;
|
|
76
|
-
toolMap?: t.ToolMap;
|
|
77
54
|
startIndex: number;
|
|
78
|
-
provider: Providers;
|
|
79
|
-
toolEnd: boolean;
|
|
80
55
|
signal?: AbortSignal;
|
|
81
|
-
|
|
56
|
+
/** Map of agent contexts by agent ID */
|
|
57
|
+
agentContexts: Map<string, AgentContext>;
|
|
58
|
+
/** Default agent ID to use */
|
|
59
|
+
defaultAgentId: string;
|
|
60
|
+
constructor({ runId, signal, agents, tokenCounter, indexTokenCountMap, }: t.StandardGraphInput);
|
|
82
61
|
resetValues(keepContent?: boolean): void;
|
|
83
62
|
getRunStep(stepId: string): t.RunStep | undefined;
|
|
63
|
+
getAgentContext(metadata: Record<string, unknown> | undefined): AgentContext;
|
|
84
64
|
getStepKey(metadata: Record<string, unknown> | undefined): string;
|
|
85
65
|
getStepIdByKey(stepKey: string, index?: number): string;
|
|
86
66
|
generateStepId(stepKey: string): [string, number];
|
|
@@ -88,35 +68,49 @@ export declare class StandardGraph extends Graph<t.BaseGraphState, GraphNode> {
|
|
|
88
68
|
checkKeyList(keyList: (string | number | undefined)[]): boolean;
|
|
89
69
|
getRunMessages(): BaseMessage[] | undefined;
|
|
90
70
|
getContentParts(): t.MessageContentComplex[] | undefined;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
71
|
+
createSystemRunnable({ provider, clientOptions, instructions, additional_instructions, }: {
|
|
72
|
+
provider?: Providers;
|
|
73
|
+
clientOptions?: t.ClientOptions;
|
|
74
|
+
instructions?: string;
|
|
75
|
+
additional_instructions?: string;
|
|
76
|
+
}): t.SystemRunnable | undefined;
|
|
77
|
+
initializeTools({ currentTools, currentToolMap, }: {
|
|
78
|
+
currentTools?: t.GraphTools;
|
|
79
|
+
currentToolMap?: t.ToolMap;
|
|
80
|
+
}): CustomToolNode<t.BaseGraphState> | ToolNode<t.BaseGraphState>;
|
|
81
|
+
initializeModel({ provider, tools, clientOptions, }: {
|
|
82
|
+
provider: Providers;
|
|
83
|
+
tools?: t.GraphTools;
|
|
84
|
+
clientOptions?: t.ClientOptions;
|
|
85
|
+
}): Runnable;
|
|
94
86
|
overrideTestModel(responses: string[], sleep?: number, toolCalls?: ToolCall[]): void;
|
|
95
|
-
getNewModel({ provider, clientOptions,
|
|
87
|
+
getNewModel({ provider, clientOptions, }: {
|
|
96
88
|
provider: Providers;
|
|
97
89
|
clientOptions?: t.ClientOptions;
|
|
98
|
-
omitOptions?: Set<string>;
|
|
99
90
|
}): t.ChatModelInstance;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
91
|
+
getUsageMetadata(finalMessage?: BaseMessage): Partial<UsageMetadata> | undefined;
|
|
92
|
+
/** Execute model invocation with streaming support */
|
|
93
|
+
private attemptInvoke;
|
|
94
|
+
cleanupSignalListener(currentModel?: t.ChatModel): void;
|
|
95
|
+
createCallModel(agentId?: string, currentModel?: t.ChatModel): (state: t.BaseGraphState, config?: RunnableConfig) => Promise<Partial<t.BaseGraphState>>;
|
|
96
|
+
createAgentNode(agentId: string): t.CompiledAgentWorfklow;
|
|
97
|
+
createWorkflow(): t.CompiledStateWorkflow;
|
|
104
98
|
/**
|
|
105
99
|
* Dispatches a run step to the client, returns the step ID
|
|
106
100
|
*/
|
|
107
|
-
dispatchRunStep(stepKey: string, stepDetails: t.StepDetails): string
|
|
108
|
-
handleToolCallCompleted(data: t.ToolEndData, metadata?: Record<string, unknown>, omitOutput?: boolean): void
|
|
101
|
+
dispatchRunStep(stepKey: string, stepDetails: t.StepDetails): Promise<string>;
|
|
102
|
+
handleToolCallCompleted(data: t.ToolEndData, metadata?: Record<string, unknown>, omitOutput?: boolean): Promise<void>;
|
|
109
103
|
/**
|
|
110
104
|
* Static version of handleToolCallError to avoid creating strong references
|
|
111
105
|
* that prevent garbage collection
|
|
112
106
|
*/
|
|
113
|
-
static handleToolCallErrorStatic(graph: StandardGraph, data: t.ToolErrorData, metadata?: Record<string, unknown>): void
|
|
107
|
+
static handleToolCallErrorStatic(graph: StandardGraph, data: t.ToolErrorData, metadata?: Record<string, unknown>): Promise<void>;
|
|
114
108
|
/**
|
|
115
109
|
* Instance method that delegates to the static method
|
|
116
110
|
* Kept for backward compatibility
|
|
117
111
|
*/
|
|
118
|
-
handleToolCallError(data: t.ToolErrorData, metadata?: Record<string, unknown>): void
|
|
119
|
-
dispatchRunStepDelta(id: string, delta: t.ToolCallDelta): void
|
|
120
|
-
dispatchMessageDelta(id: string, delta: t.MessageDelta): void
|
|
121
|
-
dispatchReasoningDelta: (stepId: string, delta: t.ReasoningDelta) => void
|
|
112
|
+
handleToolCallError(data: t.ToolErrorData, metadata?: Record<string, unknown>): Promise<void>;
|
|
113
|
+
dispatchRunStepDelta(id: string, delta: t.ToolCallDelta): Promise<void>;
|
|
114
|
+
dispatchMessageDelta(id: string, delta: t.MessageDelta): Promise<void>;
|
|
115
|
+
dispatchReasoningDelta: (stepId: string, delta: t.ReasoningDelta) => Promise<void>;
|
|
122
116
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
constructor(input: t.MultiAgentGraphInput);
|
|
23
|
+
/**
|
|
24
|
+
* Categorize edges into handoff and direct types
|
|
25
|
+
*/
|
|
26
|
+
private categorizeEdges;
|
|
27
|
+
/**
|
|
28
|
+
* Analyze graph structure to determine starting nodes and connections
|
|
29
|
+
*/
|
|
30
|
+
private analyzeGraph;
|
|
31
|
+
/**
|
|
32
|
+
* Create handoff tools for agents based on handoff edges only
|
|
33
|
+
*/
|
|
34
|
+
private createHandoffTools;
|
|
35
|
+
/**
|
|
36
|
+
* Create handoff tools for an edge (handles multiple destinations)
|
|
37
|
+
*/
|
|
38
|
+
private createHandoffToolsForEdge;
|
|
39
|
+
/**
|
|
40
|
+
* Create a complete agent subgraph (similar to createReactAgent)
|
|
41
|
+
*/
|
|
42
|
+
private createAgentSubgraph;
|
|
43
|
+
/**
|
|
44
|
+
* Create the multi-agent workflow with dynamic handoffs
|
|
45
|
+
*/
|
|
46
|
+
createWorkflow(): t.CompiledMultiAgentWorkflow;
|
|
47
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -40,6 +40,10 @@ export declare class CustomAzureOpenAIClient extends AzureOpenAIClient {
|
|
|
40
40
|
}
|
|
41
41
|
/** @ts-expect-error We are intentionally overriding `getReasoningParams` */
|
|
42
42
|
export declare class ChatOpenAI extends OriginalChatOpenAI<t.ChatOpenAICallOptions> {
|
|
43
|
+
_lc_stream_delay?: number;
|
|
44
|
+
constructor(fields?: t.ChatOpenAICallOptions & {
|
|
45
|
+
_lc_stream_delay?: number;
|
|
46
|
+
} & t.OpenAIChatInput['modelKwargs']);
|
|
43
47
|
get exposedClient(): CustomOpenAIClient;
|
|
44
48
|
static lc_name(): string;
|
|
45
49
|
protected _getClientOptions(options?: OpenAICoreRequestOptions): OpenAICoreRequestOptions;
|
|
@@ -54,6 +58,10 @@ export declare class ChatOpenAI extends OriginalChatOpenAI<t.ChatOpenAICallOptio
|
|
|
54
58
|
}
|
|
55
59
|
/** @ts-expect-error We are intentionally overriding `getReasoningParams` */
|
|
56
60
|
export declare class AzureChatOpenAI extends OriginalAzureChatOpenAI {
|
|
61
|
+
_lc_stream_delay?: number;
|
|
62
|
+
constructor(fields?: t.AzureOpenAIInput & {
|
|
63
|
+
_lc_stream_delay?: number;
|
|
64
|
+
});
|
|
57
65
|
get exposedClient(): CustomOpenAIClient;
|
|
58
66
|
static lc_name(): 'IllumaAzureOpenAI';
|
|
59
67
|
/**
|
|
@@ -87,6 +95,7 @@ export interface XAIUsageMetadata extends OpenAIClient.Completions.CompletionUsa
|
|
|
87
95
|
num_sources_used?: number;
|
|
88
96
|
}
|
|
89
97
|
export declare class ChatXAI extends OriginalChatXAI {
|
|
98
|
+
_lc_stream_delay?: number;
|
|
90
99
|
constructor(fields?: Partial<ChatXAIInput> & {
|
|
91
100
|
configuration?: {
|
|
92
101
|
baseURL?: string;
|
|
@@ -94,6 +103,7 @@ export declare class ChatXAI extends OriginalChatXAI {
|
|
|
94
103
|
clientConfig?: {
|
|
95
104
|
baseURL?: string;
|
|
96
105
|
};
|
|
106
|
+
_lc_stream_delay?: number;
|
|
97
107
|
});
|
|
98
108
|
static lc_name(): 'IllumaXAI';
|
|
99
109
|
get exposedClient(): CustomOpenAIClient;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseMessage, MessageContentComplex } from '@langchain/core/messages';
|
|
2
|
+
import type { AnthropicMessage } from '@/types/messages';
|
|
3
|
+
type MessageWithContent = {
|
|
4
|
+
content?: string | MessageContentComplex[];
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Anthropic API: Adds cache control to the appropriate user messages in the payload.
|
|
8
|
+
* @param messages - The array of message objects.
|
|
9
|
+
* @returns - The updated array of message objects with cache control added.
|
|
10
|
+
*/
|
|
11
|
+
export declare function addCacheControl<T extends AnthropicMessage | BaseMessage>(messages: T[]): T[];
|
|
12
|
+
/**
|
|
13
|
+
* Adds Bedrock Converse API cache points to the last two messages.
|
|
14
|
+
* Inserts `{ cachePoint: { type: 'default' } }` as a separate content block
|
|
15
|
+
* immediately after the last text block in each targeted message.
|
|
16
|
+
* @param messages - The array of message objects.
|
|
17
|
+
* @returns - The updated array of message objects with cache points added.
|
|
18
|
+
*/
|
|
19
|
+
export declare function addBedrockCacheControl<T extends Partial<BaseMessage> & MessageWithContent>(messages: T[]): T[];
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
2
|
+
/**
|
|
3
|
+
* Formats an array of messages for LangChain, making sure all content fields are strings
|
|
4
|
+
* @param {Array<HumanMessage | AIMessage | SystemMessage | ToolMessage>} payload - The array of messages to format.
|
|
5
|
+
* @returns {Array<HumanMessage | AIMessage | SystemMessage | ToolMessage>} - The array of formatted LangChain messages, including ToolMessages for tool calls.
|
|
6
|
+
*/
|
|
7
|
+
export declare const formatContentStrings: (payload: Array<BaseMessage>) => Array<BaseMessage>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AIMessage, ToolMessage,
|
|
1
|
+
import { AIMessage, ToolMessage, HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
2
|
import type { MessageContentImageUrl } from '@langchain/core/messages';
|
|
3
3
|
import type { MessageContentComplex, TPayload } from '@/types';
|
|
4
4
|
import { Providers } from '@/common';
|
|
@@ -95,12 +95,6 @@ export declare const formatAgentMessages: (payload: TPayload, indexTokenCountMap
|
|
|
95
95
|
messages: Array<HumanMessage | AIMessage | SystemMessage | ToolMessage>;
|
|
96
96
|
indexTokenCountMap?: Record<number, number>;
|
|
97
97
|
};
|
|
98
|
-
/**
|
|
99
|
-
* Formats an array of messages for LangChain, making sure all content fields are strings
|
|
100
|
-
* @param payload - The array of messages to format.
|
|
101
|
-
* @returns - The array of formatted LangChain messages, including ToolMessages for tool calls.
|
|
102
|
-
*/
|
|
103
|
-
export declare const formatContentStrings: (payload: Array<BaseMessage>) => Array<BaseMessage>;
|
|
104
98
|
/**
|
|
105
99
|
* Adds a value at key 0 for system messages and shifts all key indices by one in an indexTokenCountMap.
|
|
106
100
|
* This is useful when adding a system message at the beginning of a conversation.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseMessage, BaseMessageLike } from '@langchain/core/messages';
|
|
2
|
+
export declare const REMOVE_ALL_MESSAGES = "__remove_all__";
|
|
3
|
+
export type Messages = Array<BaseMessage | BaseMessageLike> | BaseMessage | BaseMessageLike;
|
|
4
|
+
/**
|
|
5
|
+
* Prebuilt reducer that combines returned messages.
|
|
6
|
+
* Can handle standard messages and special modifiers like {@link RemoveMessage}
|
|
7
|
+
* instances.
|
|
8
|
+
*/
|
|
9
|
+
export declare function messagesStateReducer(left: Messages, right: Messages): BaseMessage[];
|
package/dist/types/run.d.ts
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
import './instrumentation';
|
|
2
2
|
import type { MessageContentComplex, BaseMessage } from '@langchain/core/messages';
|
|
3
3
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
4
|
-
import type { ClientCallbacks, SystemCallbacks } from '@/graphs/Graph';
|
|
5
4
|
import type * as t from '@/types';
|
|
6
|
-
import {
|
|
5
|
+
import { MultiAgentGraph } from '@/graphs/MultiAgentGraph';
|
|
7
6
|
import { StandardGraph } from '@/graphs/Graph';
|
|
8
7
|
export declare const defaultOmitOptions: Set<string>;
|
|
9
|
-
export declare class Run<
|
|
10
|
-
graphRunnable?: t.CompiledWorkflow<T, Partial<T>, string>;
|
|
11
|
-
private handlerRegistry;
|
|
8
|
+
export declare class Run<_T extends t.BaseGraphState> {
|
|
12
9
|
id: string;
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
private tokenCounter?;
|
|
11
|
+
private handlerRegistry?;
|
|
12
|
+
private indexTokenCountMap?;
|
|
13
|
+
graphRunnable?: t.CompiledStateWorkflow;
|
|
14
|
+
Graph: StandardGraph | MultiAgentGraph | undefined;
|
|
15
15
|
returnContent: boolean;
|
|
16
16
|
private constructor();
|
|
17
|
-
private
|
|
17
|
+
private createLegacyGraph;
|
|
18
|
+
private createMultiAgentGraph;
|
|
18
19
|
static create<T extends t.BaseGraphState>(config: t.RunConfig): Promise<Run<T>>;
|
|
19
20
|
getRunMessages(): BaseMessage[] | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a custom event callback handler that intercepts custom events
|
|
23
|
+
* and processes them through our handler registry instead of EventStreamCallbackHandler
|
|
24
|
+
*/
|
|
25
|
+
private createCustomEventCallback;
|
|
20
26
|
processStream(inputs: t.IState, config: Partial<RunnableConfig> & {
|
|
21
27
|
version: 'v1' | 'v2';
|
|
22
28
|
run_id?: string;
|
|
23
29
|
}, streamOptions?: t.EventStreamOptions): Promise<MessageContentComplex[] | undefined>;
|
|
24
30
|
private createSystemCallback;
|
|
25
|
-
getCallbacks(clientCallbacks: ClientCallbacks): SystemCallbacks;
|
|
26
|
-
generateTitle({ provider, inputText, contentParts, titlePrompt, clientOptions, chainOptions, skipLanguage,
|
|
31
|
+
getCallbacks(clientCallbacks: t.ClientCallbacks): t.SystemCallbacks;
|
|
32
|
+
generateTitle({ provider, inputText, contentParts, titlePrompt, clientOptions, chainOptions, skipLanguage, titleMethod, titlePromptTemplate, }: t.RunTitleOptions): Promise<{
|
|
27
33
|
language?: string;
|
|
28
34
|
title?: string;
|
|
29
35
|
}>;
|
package/dist/types/stream.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AIMessageChunk } from '@langchain/core/messages';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AgentContext } from '@/agents/AgentContext';
|
|
3
|
+
import type { StandardGraph } from '@/graphs';
|
|
3
4
|
import type * as t from '@/types';
|
|
4
5
|
import { Providers } from '@/common';
|
|
5
6
|
export declare function getChunkContent({ chunk, provider, reasoningKey, }: {
|
|
@@ -8,7 +9,7 @@ export declare function getChunkContent({ chunk, provider, reasoningKey, }: {
|
|
|
8
9
|
reasoningKey: 'reasoning_content' | 'reasoning';
|
|
9
10
|
}): string | t.MessageContentComplex[] | undefined;
|
|
10
11
|
export declare class ChatModelStreamHandler implements t.EventHandler {
|
|
11
|
-
handle(event: string, data: t.StreamEventData, metadata?: Record<string, unknown>, graph?:
|
|
12
|
-
handleReasoning(chunk: Partial<AIMessageChunk>,
|
|
12
|
+
handle(event: string, data: t.StreamEventData, metadata?: Record<string, unknown>, graph?: StandardGraph): Promise<void>;
|
|
13
|
+
handleReasoning(chunk: Partial<AIMessageChunk>, agentContext: AgentContext): void;
|
|
13
14
|
}
|
|
14
15
|
export declare function createContentAggregator(): t.ContentAggregatorResult;
|
|
@@ -19,4 +19,4 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
19
19
|
getToolUsageCounts(): ReadonlyMap<string, number>;
|
|
20
20
|
protected run(input: any, config: RunnableConfig): Promise<T>;
|
|
21
21
|
}
|
|
22
|
-
export declare function toolsCondition(state: BaseMessage[] | typeof MessagesAnnotation.State, invokedToolIds?: Set<string>):
|
|
22
|
+
export declare function toolsCondition<T extends string>(state: BaseMessage[] | typeof MessagesAnnotation.State, toolNode: T, invokedToolIds?: Set<string>): T | typeof END;
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import type { ToolCall, ToolCallChunk } from '@langchain/core/messages/tool';
|
|
2
|
-
import type {
|
|
2
|
+
import type { MultiAgentGraph, StandardGraph } from '@/graphs';
|
|
3
|
+
import type { AgentContext } from '@/agents/AgentContext';
|
|
3
4
|
import type * as t from '@/types';
|
|
4
5
|
export declare function handleToolCallChunks({ graph, stepKey, toolCallChunks, }: {
|
|
5
|
-
graph:
|
|
6
|
+
graph: StandardGraph | MultiAgentGraph;
|
|
6
7
|
stepKey: string;
|
|
7
8
|
toolCallChunks: ToolCallChunk[];
|
|
8
|
-
}): void
|
|
9
|
-
export declare const handleToolCalls: (toolCalls?: ToolCall[], metadata?: Record<string, unknown>, graph?:
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
export declare const handleToolCalls: (toolCalls?: ToolCall[], metadata?: Record<string, unknown>, graph?: StandardGraph | MultiAgentGraph) => Promise<void>;
|
|
10
11
|
export declare const toolResultTypes: Set<string>;
|
|
11
12
|
/**
|
|
12
13
|
* Handles the result of a server tool call; in other words, a provider's built-in tool.
|
|
13
14
|
* As of 2025-07-06, only Anthropic handles server tool calls with this pattern.
|
|
14
15
|
*/
|
|
15
|
-
export declare function handleServerToolResult({ content, metadata,
|
|
16
|
+
export declare function handleServerToolResult({ graph, content, metadata, agentContext, }: {
|
|
17
|
+
graph: StandardGraph | MultiAgentGraph;
|
|
16
18
|
content?: string | t.MessageContentComplex[];
|
|
17
19
|
metadata?: Record<string, unknown>;
|
|
18
|
-
|
|
19
|
-
}): boolean
|
|
20
|
+
agentContext?: AgentContext;
|
|
21
|
+
}): Promise<boolean>;
|
|
@@ -39,16 +39,16 @@ export declare const createSearchTool: (config?: t.SearchToolConfig) => DynamicS
|
|
|
39
39
|
news: z.ZodOptional<z.ZodBoolean>;
|
|
40
40
|
}, "strip", z.ZodTypeAny, {
|
|
41
41
|
query: string;
|
|
42
|
-
date?: DATE_RANGE | undefined;
|
|
43
|
-
images?: boolean | undefined;
|
|
44
42
|
videos?: boolean | undefined;
|
|
43
|
+
images?: boolean | undefined;
|
|
45
44
|
news?: boolean | undefined;
|
|
45
|
+
date?: DATE_RANGE | undefined;
|
|
46
46
|
country?: unknown;
|
|
47
47
|
}, {
|
|
48
48
|
query: string;
|
|
49
|
-
date?: DATE_RANGE | undefined;
|
|
50
|
-
images?: boolean | undefined;
|
|
51
49
|
videos?: boolean | undefined;
|
|
50
|
+
images?: boolean | undefined;
|
|
52
51
|
news?: boolean | undefined;
|
|
52
|
+
date?: DATE_RANGE | undefined;
|
|
53
53
|
country?: unknown;
|
|
54
54
|
}>>;
|