@axiom-lattice/core 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +61 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -560,7 +560,7 @@ registerToolLattice(
|
|
|
560
560
|
{
|
|
561
561
|
name: "internet_search",
|
|
562
562
|
description: "Run a web search",
|
|
563
|
-
needUserApprove:
|
|
563
|
+
needUserApprove: false,
|
|
564
564
|
schema: z2.object({
|
|
565
565
|
query: z2.string().describe("The search query"),
|
|
566
566
|
maxResults: z2.number().optional().default(5).describe("Maximum number of results to return"),
|
|
@@ -591,7 +591,16 @@ registerToolLattice(
|
|
|
591
591
|
import {
|
|
592
592
|
AgentType,
|
|
593
593
|
AgentConfig,
|
|
594
|
-
|
|
594
|
+
ReactAgentConfig,
|
|
595
|
+
DeepAgentConfig,
|
|
596
|
+
PlanExecuteAgentConfig,
|
|
597
|
+
SequentialAgentConfig,
|
|
598
|
+
AgentConfigWithTools,
|
|
599
|
+
GraphBuildOptions,
|
|
600
|
+
hasTools,
|
|
601
|
+
isDeepAgentConfig,
|
|
602
|
+
getToolsFromConfig,
|
|
603
|
+
getSubAgentsFromConfig
|
|
595
604
|
} from "@axiom-lattice/protocols";
|
|
596
605
|
|
|
597
606
|
// src/agent_lattice/builders/ReActAgentGraphBuilder.ts
|
|
@@ -724,7 +733,6 @@ import {
|
|
|
724
733
|
getCurrentTaskInput as getCurrentTaskInput2,
|
|
725
734
|
GraphInterrupt
|
|
726
735
|
} from "@langchain/langgraph";
|
|
727
|
-
import { createReactAgent as createReactAgent2 } from "@langchain/langgraph/prebuilt";
|
|
728
736
|
import { z as z5 } from "zod";
|
|
729
737
|
|
|
730
738
|
// src/deep_agent/tools.ts
|
|
@@ -1156,6 +1164,10 @@ var editFile = tool2(
|
|
|
1156
1164
|
);
|
|
1157
1165
|
|
|
1158
1166
|
// src/deep_agent/subAgent.ts
|
|
1167
|
+
import {
|
|
1168
|
+
getToolsFromConfig as getToolsFromConfig2,
|
|
1169
|
+
hasTools as hasTools2
|
|
1170
|
+
} from "@axiom-lattice/protocols";
|
|
1159
1171
|
var BUILTIN_TOOLS = {
|
|
1160
1172
|
write_todos: writeTodos,
|
|
1161
1173
|
read_file: readFile,
|
|
@@ -1177,30 +1189,28 @@ function createTaskTool(inputs) {
|
|
|
1177
1189
|
const allTools = { ...BUILTIN_TOOLS, ...tools };
|
|
1178
1190
|
const agentsMap = /* @__PURE__ */ new Map();
|
|
1179
1191
|
for (const subagent of subagents) {
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
)
|
|
1192
|
+
let reactAgent;
|
|
1193
|
+
const agentLattice = getAgentLattice(subagent.key);
|
|
1194
|
+
if (agentLattice) {
|
|
1195
|
+
reactAgent = agentLattice.client;
|
|
1196
|
+
} else {
|
|
1197
|
+
const subagentTools = [];
|
|
1198
|
+
if (hasTools2(subagent)) {
|
|
1199
|
+
for (const toolName of getToolsFromConfig2(subagent)) {
|
|
1200
|
+
const resolvedTool = allTools[toolName];
|
|
1201
|
+
if (resolvedTool) {
|
|
1202
|
+
subagentTools.push(resolvedTool);
|
|
1203
|
+
} else {
|
|
1204
|
+
console.warn(
|
|
1205
|
+
`Warning: Tool '${toolName}' not found for agent '${subagent.name}'`
|
|
1206
|
+
);
|
|
1207
|
+
}
|
|
1190
1208
|
}
|
|
1209
|
+
} else {
|
|
1210
|
+
subagentTools.push(...Object.values(allTools));
|
|
1191
1211
|
}
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
}
|
|
1195
|
-
const reactAgent = createReactAgent2({
|
|
1196
|
-
llm: model,
|
|
1197
|
-
tools: subagentTools,
|
|
1198
|
-
stateSchema,
|
|
1199
|
-
messageModifier: subagent.prompt,
|
|
1200
|
-
// checkpointer: false,
|
|
1201
|
-
checkpointer: getCheckpointSaver("default"),
|
|
1202
|
-
postModelHook
|
|
1203
|
-
});
|
|
1212
|
+
reactAgent = createAgentClientFromAgentLattice({ config: subagent });
|
|
1213
|
+
}
|
|
1204
1214
|
agentsMap.set(subagent.name, reactAgent);
|
|
1205
1215
|
}
|
|
1206
1216
|
return tool3(
|
|
@@ -1304,7 +1314,7 @@ var DeepAgentState = MessagesZodState2.extend({
|
|
|
1304
1314
|
});
|
|
1305
1315
|
|
|
1306
1316
|
// src/deep_agent/graph.ts
|
|
1307
|
-
import { createReactAgent as
|
|
1317
|
+
import { createReactAgent as createReactAgent2 } from "@langchain/langgraph/prebuilt";
|
|
1308
1318
|
var BASE_PROMPT = `You have access to a number of standard tools
|
|
1309
1319
|
|
|
1310
1320
|
## \`write_todos\`
|
|
@@ -1351,7 +1361,7 @@ function createDeepAgent(params = {}) {
|
|
|
1351
1361
|
allTools.push(taskTool);
|
|
1352
1362
|
}
|
|
1353
1363
|
const finalInstructions = instructions ? instructions + BASE_PROMPT : BASE_PROMPT;
|
|
1354
|
-
return
|
|
1364
|
+
return createReactAgent2({
|
|
1355
1365
|
llm: model,
|
|
1356
1366
|
tools: allTools,
|
|
1357
1367
|
stateSchema,
|
|
@@ -1377,13 +1387,9 @@ var DeepAgentGraphBuilder = class {
|
|
|
1377
1387
|
return createDeepAgent({
|
|
1378
1388
|
tools,
|
|
1379
1389
|
model: params.model,
|
|
1390
|
+
stateSchema: params.stateSchema,
|
|
1380
1391
|
instructions: params.prompt,
|
|
1381
|
-
subagents: params.subAgents.map((sa) =>
|
|
1382
|
-
name: sa.key,
|
|
1383
|
-
description: sa.config.description,
|
|
1384
|
-
prompt: sa.config.prompt,
|
|
1385
|
-
tools: sa.config.tools || []
|
|
1386
|
-
}))
|
|
1392
|
+
subagents: params.subAgents.map((sa) => sa.config)
|
|
1387
1393
|
});
|
|
1388
1394
|
}
|
|
1389
1395
|
};
|
|
@@ -1613,7 +1619,7 @@ _MemoryManager.instance = memory2;
|
|
|
1613
1619
|
var MemoryManager = _MemoryManager;
|
|
1614
1620
|
|
|
1615
1621
|
// src/createPlanExecuteAgent.ts
|
|
1616
|
-
import { createReactAgent as
|
|
1622
|
+
import { createReactAgent as createReactAgent3 } from "@langchain/langgraph/prebuilt";
|
|
1617
1623
|
var PlanExecuteState = Annotation.Root({
|
|
1618
1624
|
// 输入
|
|
1619
1625
|
input: Annotation({
|
|
@@ -1670,7 +1676,7 @@ function createPlanExecuteAgent(config) {
|
|
|
1670
1676
|
maxSteps,
|
|
1671
1677
|
toolsCount: executorTools.length
|
|
1672
1678
|
});
|
|
1673
|
-
const agentExecutor =
|
|
1679
|
+
const agentExecutor = createReactAgent3({
|
|
1674
1680
|
tools: executorTools,
|
|
1675
1681
|
llm
|
|
1676
1682
|
});
|
|
@@ -1772,7 +1778,7 @@ ${executorTools.map((tool5) => tool5.name).join("\n")}
|
|
|
1772
1778
|
returnDirect: true
|
|
1773
1779
|
}
|
|
1774
1780
|
);
|
|
1775
|
-
const replanAgent =
|
|
1781
|
+
const replanAgent = createReactAgent3({
|
|
1776
1782
|
tools: [responseTool, planTool],
|
|
1777
1783
|
llm
|
|
1778
1784
|
});
|
|
@@ -1995,6 +2001,11 @@ var AgentGraphBuilderFactory = class _AgentGraphBuilderFactory {
|
|
|
1995
2001
|
};
|
|
1996
2002
|
|
|
1997
2003
|
// src/agent_lattice/builders/AgentParamsBuilder.ts
|
|
2004
|
+
import {
|
|
2005
|
+
getToolsFromConfig as getToolsFromConfig3,
|
|
2006
|
+
getSubAgentsFromConfig as getSubAgentsFromConfig2,
|
|
2007
|
+
isDeepAgentConfig as isDeepAgentConfig2
|
|
2008
|
+
} from "@axiom-lattice/protocols";
|
|
1998
2009
|
var AgentParamsBuilder = class {
|
|
1999
2010
|
/**
|
|
2000
2011
|
* constructor
|
|
@@ -2012,7 +2023,7 @@ var AgentParamsBuilder = class {
|
|
|
2012
2023
|
* @returns Agent build parameters
|
|
2013
2024
|
*/
|
|
2014
2025
|
buildParams(agentLattice, options) {
|
|
2015
|
-
const toolKeys = options?.overrideTools || agentLattice.config
|
|
2026
|
+
const toolKeys = options?.overrideTools || getToolsFromConfig3(agentLattice.config);
|
|
2016
2027
|
const tools = toolKeys.map((toolKey) => {
|
|
2017
2028
|
const toolLattice = toolLatticeManager.getToolLattice(toolKey);
|
|
2018
2029
|
if (!toolLattice) {
|
|
@@ -2029,7 +2040,7 @@ var AgentParamsBuilder = class {
|
|
|
2029
2040
|
if (!model) {
|
|
2030
2041
|
throw new Error(`Model "${modelKey}" does not exist`);
|
|
2031
2042
|
}
|
|
2032
|
-
const subAgentKeys = agentLattice.config
|
|
2043
|
+
const subAgentKeys = getSubAgentsFromConfig2(agentLattice.config);
|
|
2033
2044
|
const subAgents = subAgentKeys.map((agentKey) => {
|
|
2034
2045
|
const subAgentLattice = this.getAgentLatticeFunc(agentKey);
|
|
2035
2046
|
if (!subAgentLattice) {
|
|
@@ -2041,10 +2052,17 @@ var AgentParamsBuilder = class {
|
|
|
2041
2052
|
client: subAgentLattice.client
|
|
2042
2053
|
};
|
|
2043
2054
|
});
|
|
2055
|
+
let internalSubAgents = [];
|
|
2056
|
+
if (isDeepAgentConfig2(agentLattice.config)) {
|
|
2057
|
+
internalSubAgents = agentLattice.config.internalSubAgents?.map((i) => ({
|
|
2058
|
+
key: i.key,
|
|
2059
|
+
config: i
|
|
2060
|
+
})) || [];
|
|
2061
|
+
}
|
|
2044
2062
|
return {
|
|
2045
2063
|
tools,
|
|
2046
2064
|
model,
|
|
2047
|
-
subAgents,
|
|
2065
|
+
subAgents: [...subAgents, ...internalSubAgents],
|
|
2048
2066
|
prompt: agentLattice.config.prompt,
|
|
2049
2067
|
stateSchema: agentLattice.config.schema
|
|
2050
2068
|
};
|
|
@@ -2147,11 +2165,25 @@ var AgentLatticeManager = class _AgentLatticeManager extends BaseLatticeManager
|
|
|
2147
2165
|
* @returns 返回Agent构建参数
|
|
2148
2166
|
*/
|
|
2149
2167
|
buildAgentParams(agentLattice, options) {
|
|
2150
|
-
const paramsBuilder = new AgentParamsBuilder(
|
|
2151
|
-
|
|
2152
|
-
|
|
2168
|
+
const paramsBuilder = new AgentParamsBuilder((key) => {
|
|
2169
|
+
this.initializeClient(key);
|
|
2170
|
+
return this.getAgentLattice(key);
|
|
2171
|
+
});
|
|
2153
2172
|
return paramsBuilder.buildParams(agentLattice, options);
|
|
2154
2173
|
}
|
|
2174
|
+
/**
|
|
2175
|
+
* Create an AgentClient from AgentLattice config
|
|
2176
|
+
*
|
|
2177
|
+
* @param agentLattice Agent Lattice object
|
|
2178
|
+
* @param options Build options
|
|
2179
|
+
* @returns AgentClient instance
|
|
2180
|
+
*/
|
|
2181
|
+
createAgentClientFromConfig(agentLattice, options) {
|
|
2182
|
+
const factory = AgentGraphBuilderFactory.getInstance();
|
|
2183
|
+
const builder = factory.getBuilder(agentLattice.config.type);
|
|
2184
|
+
const params = this.buildAgentParams(agentLattice, options);
|
|
2185
|
+
return builder.build(agentLattice, params);
|
|
2186
|
+
}
|
|
2155
2187
|
/**
|
|
2156
2188
|
* 初始化Agent客户端
|
|
2157
2189
|
*
|
|
@@ -2169,10 +2201,7 @@ var AgentLatticeManager = class _AgentLatticeManager extends BaseLatticeManager
|
|
|
2169
2201
|
if (agentLattice.client) {
|
|
2170
2202
|
return agentLattice.client;
|
|
2171
2203
|
}
|
|
2172
|
-
const
|
|
2173
|
-
const builder = factory.getBuilder(agentLattice.config.type);
|
|
2174
|
-
const params = this.buildAgentParams(agentLattice, options);
|
|
2175
|
-
const graph = builder.build(agentLattice, params);
|
|
2204
|
+
const graph = this.createAgentClientFromConfig(agentLattice, options);
|
|
2176
2205
|
agentLattice.client = graph;
|
|
2177
2206
|
return graph;
|
|
2178
2207
|
}
|
|
@@ -2190,7 +2219,8 @@ var getAgentLattice = (key) => agentLatticeManager.getAgentLattice(key);
|
|
|
2190
2219
|
var getAgentConfig = (key) => agentLatticeManager.getAgentConfig(key);
|
|
2191
2220
|
var getAllAgentConfigs = () => agentLatticeManager.getAllAgentConfigs();
|
|
2192
2221
|
var validateAgentInput = (key, input) => agentLatticeManager.validateAgentInput(key, input);
|
|
2193
|
-
var
|
|
2222
|
+
var getAgentClient2 = (key, options) => agentLatticeManager.initializeClient(key, options);
|
|
2223
|
+
var createAgentClientFromAgentLattice = (agentLattice, options) => agentLatticeManager.createAgentClientFromConfig(agentLattice, options);
|
|
2194
2224
|
|
|
2195
2225
|
// src/chunk_buffer_lattice/ChunkBuffer.ts
|
|
2196
2226
|
var ChunkBuffer = class {
|
|
@@ -2520,7 +2550,7 @@ export {
|
|
|
2520
2550
|
ThreadStatus,
|
|
2521
2551
|
ToolLatticeManager,
|
|
2522
2552
|
agentLatticeManager,
|
|
2523
|
-
getAgentClient,
|
|
2553
|
+
getAgentClient2 as getAgentClient,
|
|
2524
2554
|
getAgentConfig,
|
|
2525
2555
|
getAgentLattice,
|
|
2526
2556
|
getAllAgentConfigs,
|