@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.d.mts
CHANGED
|
@@ -299,7 +299,7 @@ declare const validateToolInput: (key: string, input: any) => boolean;
|
|
|
299
299
|
type AgentClient = CompiledStateGraph<any, any, any, any, any>;
|
|
300
300
|
interface AgentLattice {
|
|
301
301
|
config: AgentConfig;
|
|
302
|
-
client
|
|
302
|
+
client?: AgentClient | undefined;
|
|
303
303
|
}
|
|
304
304
|
|
|
305
305
|
/**
|
|
@@ -363,6 +363,14 @@ declare class AgentLatticeManager extends BaseLatticeManager<AgentLattice> {
|
|
|
363
363
|
* @returns 返回Agent构建参数
|
|
364
364
|
*/
|
|
365
365
|
private buildAgentParams;
|
|
366
|
+
/**
|
|
367
|
+
* Create an AgentClient from AgentLattice config
|
|
368
|
+
*
|
|
369
|
+
* @param agentLattice Agent Lattice object
|
|
370
|
+
* @param options Build options
|
|
371
|
+
* @returns AgentClient instance
|
|
372
|
+
*/
|
|
373
|
+
createAgentClientFromConfig(agentLattice: AgentLattice, options?: GraphBuildOptions): AgentClient;
|
|
366
374
|
/**
|
|
367
375
|
* 初始化Agent客户端
|
|
368
376
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -299,7 +299,7 @@ declare const validateToolInput: (key: string, input: any) => boolean;
|
|
|
299
299
|
type AgentClient = CompiledStateGraph<any, any, any, any, any>;
|
|
300
300
|
interface AgentLattice {
|
|
301
301
|
config: AgentConfig;
|
|
302
|
-
client
|
|
302
|
+
client?: AgentClient | undefined;
|
|
303
303
|
}
|
|
304
304
|
|
|
305
305
|
/**
|
|
@@ -363,6 +363,14 @@ declare class AgentLatticeManager extends BaseLatticeManager<AgentLattice> {
|
|
|
363
363
|
* @returns 返回Agent构建参数
|
|
364
364
|
*/
|
|
365
365
|
private buildAgentParams;
|
|
366
|
+
/**
|
|
367
|
+
* Create an AgentClient from AgentLattice config
|
|
368
|
+
*
|
|
369
|
+
* @param agentLattice Agent Lattice object
|
|
370
|
+
* @param options Build options
|
|
371
|
+
* @returns AgentClient instance
|
|
372
|
+
*/
|
|
373
|
+
createAgentClientFromConfig(agentLattice: AgentLattice, options?: GraphBuildOptions): AgentClient;
|
|
366
374
|
/**
|
|
367
375
|
* 初始化Agent客户端
|
|
368
376
|
*
|
package/dist/index.js
CHANGED
|
@@ -44,7 +44,7 @@ __export(index_exports, {
|
|
|
44
44
|
ThreadStatus: () => ThreadStatus,
|
|
45
45
|
ToolLatticeManager: () => ToolLatticeManager,
|
|
46
46
|
agentLatticeManager: () => agentLatticeManager,
|
|
47
|
-
getAgentClient: () =>
|
|
47
|
+
getAgentClient: () => getAgentClient2,
|
|
48
48
|
getAgentConfig: () => getAgentConfig,
|
|
49
49
|
getAgentLattice: () => getAgentLattice,
|
|
50
50
|
getAllAgentConfigs: () => getAllAgentConfigs,
|
|
@@ -627,7 +627,7 @@ registerToolLattice(
|
|
|
627
627
|
{
|
|
628
628
|
name: "internet_search",
|
|
629
629
|
description: "Run a web search",
|
|
630
|
-
needUserApprove:
|
|
630
|
+
needUserApprove: false,
|
|
631
631
|
schema: import_zod2.default.object({
|
|
632
632
|
query: import_zod2.default.string().describe("The search query"),
|
|
633
633
|
maxResults: import_zod2.default.number().optional().default(5).describe("Maximum number of results to return"),
|
|
@@ -783,7 +783,6 @@ var ReActAgentGraphBuilder = class {
|
|
|
783
783
|
var import_tools3 = require("@langchain/core/tools");
|
|
784
784
|
var import_messages2 = require("@langchain/core/messages");
|
|
785
785
|
var import_langgraph5 = require("@langchain/langgraph");
|
|
786
|
-
var import_prebuilt2 = require("@langchain/langgraph/prebuilt");
|
|
787
786
|
var import_zod6 = require("zod");
|
|
788
787
|
|
|
789
788
|
// src/deep_agent/tools.ts
|
|
@@ -1215,6 +1214,7 @@ var editFile = (0, import_tools2.tool)(
|
|
|
1215
1214
|
);
|
|
1216
1215
|
|
|
1217
1216
|
// src/deep_agent/subAgent.ts
|
|
1217
|
+
var import_protocols3 = require("@axiom-lattice/protocols");
|
|
1218
1218
|
var BUILTIN_TOOLS = {
|
|
1219
1219
|
write_todos: writeTodos,
|
|
1220
1220
|
read_file: readFile,
|
|
@@ -1236,30 +1236,28 @@ function createTaskTool(inputs) {
|
|
|
1236
1236
|
const allTools = { ...BUILTIN_TOOLS, ...tools };
|
|
1237
1237
|
const agentsMap = /* @__PURE__ */ new Map();
|
|
1238
1238
|
for (const subagent of subagents) {
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
)
|
|
1239
|
+
let reactAgent;
|
|
1240
|
+
const agentLattice = getAgentLattice(subagent.key);
|
|
1241
|
+
if (agentLattice) {
|
|
1242
|
+
reactAgent = agentLattice.client;
|
|
1243
|
+
} else {
|
|
1244
|
+
const subagentTools = [];
|
|
1245
|
+
if ((0, import_protocols3.hasTools)(subagent)) {
|
|
1246
|
+
for (const toolName of (0, import_protocols3.getToolsFromConfig)(subagent)) {
|
|
1247
|
+
const resolvedTool = allTools[toolName];
|
|
1248
|
+
if (resolvedTool) {
|
|
1249
|
+
subagentTools.push(resolvedTool);
|
|
1250
|
+
} else {
|
|
1251
|
+
console.warn(
|
|
1252
|
+
`Warning: Tool '${toolName}' not found for agent '${subagent.name}'`
|
|
1253
|
+
);
|
|
1254
|
+
}
|
|
1249
1255
|
}
|
|
1256
|
+
} else {
|
|
1257
|
+
subagentTools.push(...Object.values(allTools));
|
|
1250
1258
|
}
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
}
|
|
1254
|
-
const reactAgent = (0, import_prebuilt2.createReactAgent)({
|
|
1255
|
-
llm: model,
|
|
1256
|
-
tools: subagentTools,
|
|
1257
|
-
stateSchema,
|
|
1258
|
-
messageModifier: subagent.prompt,
|
|
1259
|
-
// checkpointer: false,
|
|
1260
|
-
checkpointer: getCheckpointSaver("default"),
|
|
1261
|
-
postModelHook
|
|
1262
|
-
});
|
|
1259
|
+
reactAgent = createAgentClientFromAgentLattice({ config: subagent });
|
|
1260
|
+
}
|
|
1263
1261
|
agentsMap.set(subagent.name, reactAgent);
|
|
1264
1262
|
}
|
|
1265
1263
|
return (0, import_tools3.tool)(
|
|
@@ -1363,7 +1361,7 @@ var DeepAgentState = import_langgraph6.MessagesZodState.extend({
|
|
|
1363
1361
|
});
|
|
1364
1362
|
|
|
1365
1363
|
// src/deep_agent/graph.ts
|
|
1366
|
-
var
|
|
1364
|
+
var import_prebuilt2 = require("@langchain/langgraph/prebuilt");
|
|
1367
1365
|
var BASE_PROMPT = `You have access to a number of standard tools
|
|
1368
1366
|
|
|
1369
1367
|
## \`write_todos\`
|
|
@@ -1410,7 +1408,7 @@ function createDeepAgent(params = {}) {
|
|
|
1410
1408
|
allTools.push(taskTool);
|
|
1411
1409
|
}
|
|
1412
1410
|
const finalInstructions = instructions ? instructions + BASE_PROMPT : BASE_PROMPT;
|
|
1413
|
-
return (0,
|
|
1411
|
+
return (0, import_prebuilt2.createReactAgent)({
|
|
1414
1412
|
llm: model,
|
|
1415
1413
|
tools: allTools,
|
|
1416
1414
|
stateSchema,
|
|
@@ -1436,13 +1434,9 @@ var DeepAgentGraphBuilder = class {
|
|
|
1436
1434
|
return createDeepAgent({
|
|
1437
1435
|
tools,
|
|
1438
1436
|
model: params.model,
|
|
1437
|
+
stateSchema: params.stateSchema,
|
|
1439
1438
|
instructions: params.prompt,
|
|
1440
|
-
subagents: params.subAgents.map((sa) =>
|
|
1441
|
-
name: sa.key,
|
|
1442
|
-
description: sa.config.description,
|
|
1443
|
-
prompt: sa.config.prompt,
|
|
1444
|
-
tools: sa.config.tools || []
|
|
1445
|
-
}))
|
|
1439
|
+
subagents: params.subAgents.map((sa) => sa.config)
|
|
1446
1440
|
});
|
|
1447
1441
|
}
|
|
1448
1442
|
};
|
|
@@ -1661,7 +1655,7 @@ _MemoryManager.instance = memory2;
|
|
|
1661
1655
|
var MemoryManager = _MemoryManager;
|
|
1662
1656
|
|
|
1663
1657
|
// src/createPlanExecuteAgent.ts
|
|
1664
|
-
var
|
|
1658
|
+
var import_prebuilt3 = require("@langchain/langgraph/prebuilt");
|
|
1665
1659
|
var PlanExecuteState = import_langgraph8.Annotation.Root({
|
|
1666
1660
|
// 输入
|
|
1667
1661
|
input: (0, import_langgraph8.Annotation)({
|
|
@@ -1718,7 +1712,7 @@ function createPlanExecuteAgent(config) {
|
|
|
1718
1712
|
maxSteps,
|
|
1719
1713
|
toolsCount: executorTools.length
|
|
1720
1714
|
});
|
|
1721
|
-
const agentExecutor = (0,
|
|
1715
|
+
const agentExecutor = (0, import_prebuilt3.createReactAgent)({
|
|
1722
1716
|
tools: executorTools,
|
|
1723
1717
|
llm
|
|
1724
1718
|
});
|
|
@@ -1820,7 +1814,7 @@ ${executorTools.map((tool5) => tool5.name).join("\n")}
|
|
|
1820
1814
|
returnDirect: true
|
|
1821
1815
|
}
|
|
1822
1816
|
);
|
|
1823
|
-
const replanAgent = (0,
|
|
1817
|
+
const replanAgent = (0, import_prebuilt3.createReactAgent)({
|
|
1824
1818
|
tools: [responseTool, planTool],
|
|
1825
1819
|
llm
|
|
1826
1820
|
});
|
|
@@ -2043,6 +2037,7 @@ var AgentGraphBuilderFactory = class _AgentGraphBuilderFactory {
|
|
|
2043
2037
|
};
|
|
2044
2038
|
|
|
2045
2039
|
// src/agent_lattice/builders/AgentParamsBuilder.ts
|
|
2040
|
+
var import_protocols4 = require("@axiom-lattice/protocols");
|
|
2046
2041
|
var AgentParamsBuilder = class {
|
|
2047
2042
|
/**
|
|
2048
2043
|
* constructor
|
|
@@ -2060,7 +2055,7 @@ var AgentParamsBuilder = class {
|
|
|
2060
2055
|
* @returns Agent build parameters
|
|
2061
2056
|
*/
|
|
2062
2057
|
buildParams(agentLattice, options) {
|
|
2063
|
-
const toolKeys = options?.overrideTools || agentLattice.config
|
|
2058
|
+
const toolKeys = options?.overrideTools || (0, import_protocols4.getToolsFromConfig)(agentLattice.config);
|
|
2064
2059
|
const tools = toolKeys.map((toolKey) => {
|
|
2065
2060
|
const toolLattice = toolLatticeManager.getToolLattice(toolKey);
|
|
2066
2061
|
if (!toolLattice) {
|
|
@@ -2077,7 +2072,7 @@ var AgentParamsBuilder = class {
|
|
|
2077
2072
|
if (!model) {
|
|
2078
2073
|
throw new Error(`Model "${modelKey}" does not exist`);
|
|
2079
2074
|
}
|
|
2080
|
-
const subAgentKeys = agentLattice.config
|
|
2075
|
+
const subAgentKeys = (0, import_protocols4.getSubAgentsFromConfig)(agentLattice.config);
|
|
2081
2076
|
const subAgents = subAgentKeys.map((agentKey) => {
|
|
2082
2077
|
const subAgentLattice = this.getAgentLatticeFunc(agentKey);
|
|
2083
2078
|
if (!subAgentLattice) {
|
|
@@ -2089,10 +2084,17 @@ var AgentParamsBuilder = class {
|
|
|
2089
2084
|
client: subAgentLattice.client
|
|
2090
2085
|
};
|
|
2091
2086
|
});
|
|
2087
|
+
let internalSubAgents = [];
|
|
2088
|
+
if ((0, import_protocols4.isDeepAgentConfig)(agentLattice.config)) {
|
|
2089
|
+
internalSubAgents = agentLattice.config.internalSubAgents?.map((i) => ({
|
|
2090
|
+
key: i.key,
|
|
2091
|
+
config: i
|
|
2092
|
+
})) || [];
|
|
2093
|
+
}
|
|
2092
2094
|
return {
|
|
2093
2095
|
tools,
|
|
2094
2096
|
model,
|
|
2095
|
-
subAgents,
|
|
2097
|
+
subAgents: [...subAgents, ...internalSubAgents],
|
|
2096
2098
|
prompt: agentLattice.config.prompt,
|
|
2097
2099
|
stateSchema: agentLattice.config.schema
|
|
2098
2100
|
};
|
|
@@ -2195,11 +2197,25 @@ var AgentLatticeManager = class _AgentLatticeManager extends BaseLatticeManager
|
|
|
2195
2197
|
* @returns 返回Agent构建参数
|
|
2196
2198
|
*/
|
|
2197
2199
|
buildAgentParams(agentLattice, options) {
|
|
2198
|
-
const paramsBuilder = new AgentParamsBuilder(
|
|
2199
|
-
|
|
2200
|
-
|
|
2200
|
+
const paramsBuilder = new AgentParamsBuilder((key) => {
|
|
2201
|
+
this.initializeClient(key);
|
|
2202
|
+
return this.getAgentLattice(key);
|
|
2203
|
+
});
|
|
2201
2204
|
return paramsBuilder.buildParams(agentLattice, options);
|
|
2202
2205
|
}
|
|
2206
|
+
/**
|
|
2207
|
+
* Create an AgentClient from AgentLattice config
|
|
2208
|
+
*
|
|
2209
|
+
* @param agentLattice Agent Lattice object
|
|
2210
|
+
* @param options Build options
|
|
2211
|
+
* @returns AgentClient instance
|
|
2212
|
+
*/
|
|
2213
|
+
createAgentClientFromConfig(agentLattice, options) {
|
|
2214
|
+
const factory = AgentGraphBuilderFactory.getInstance();
|
|
2215
|
+
const builder = factory.getBuilder(agentLattice.config.type);
|
|
2216
|
+
const params = this.buildAgentParams(agentLattice, options);
|
|
2217
|
+
return builder.build(agentLattice, params);
|
|
2218
|
+
}
|
|
2203
2219
|
/**
|
|
2204
2220
|
* 初始化Agent客户端
|
|
2205
2221
|
*
|
|
@@ -2217,10 +2233,7 @@ var AgentLatticeManager = class _AgentLatticeManager extends BaseLatticeManager
|
|
|
2217
2233
|
if (agentLattice.client) {
|
|
2218
2234
|
return agentLattice.client;
|
|
2219
2235
|
}
|
|
2220
|
-
const
|
|
2221
|
-
const builder = factory.getBuilder(agentLattice.config.type);
|
|
2222
|
-
const params = this.buildAgentParams(agentLattice, options);
|
|
2223
|
-
const graph = builder.build(agentLattice, params);
|
|
2236
|
+
const graph = this.createAgentClientFromConfig(agentLattice, options);
|
|
2224
2237
|
agentLattice.client = graph;
|
|
2225
2238
|
return graph;
|
|
2226
2239
|
}
|
|
@@ -2238,7 +2251,8 @@ var getAgentLattice = (key) => agentLatticeManager.getAgentLattice(key);
|
|
|
2238
2251
|
var getAgentConfig = (key) => agentLatticeManager.getAgentConfig(key);
|
|
2239
2252
|
var getAllAgentConfigs = () => agentLatticeManager.getAllAgentConfigs();
|
|
2240
2253
|
var validateAgentInput = (key, input) => agentLatticeManager.validateAgentInput(key, input);
|
|
2241
|
-
var
|
|
2254
|
+
var getAgentClient2 = (key, options) => agentLatticeManager.initializeClient(key, options);
|
|
2255
|
+
var createAgentClientFromAgentLattice = (agentLattice, options) => agentLatticeManager.createAgentClientFromConfig(agentLattice, options);
|
|
2242
2256
|
|
|
2243
2257
|
// src/chunk_buffer_lattice/ChunkBuffer.ts
|
|
2244
2258
|
var ChunkBuffer = class {
|