@axiom-lattice/core 2.0.1 → 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 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: AgentClient | undefined;
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: AgentClient | undefined;
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: () => 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: true,
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
- const subagentTools = [];
1240
- if (subagent.tools) {
1241
- for (const toolName of subagent.tools) {
1242
- const resolvedTool = allTools[toolName];
1243
- if (resolvedTool) {
1244
- subagentTools.push(resolvedTool);
1245
- } else {
1246
- console.warn(
1247
- `Warning: Tool '${toolName}' not found for agent '${subagent.name}'`
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
- } else {
1252
- subagentTools.push(...Object.values(allTools));
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 import_prebuilt3 = require("@langchain/langgraph/prebuilt");
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, import_prebuilt3.createReactAgent)({
1411
+ return (0, import_prebuilt2.createReactAgent)({
1414
1412
  llm: model,
1415
1413
  tools: allTools,
1416
1414
  stateSchema,
@@ -1438,12 +1436,7 @@ var DeepAgentGraphBuilder = class {
1438
1436
  model: params.model,
1439
1437
  stateSchema: params.stateSchema,
1440
1438
  instructions: params.prompt,
1441
- subagents: params.subAgents.map((sa) => ({
1442
- name: sa.key,
1443
- description: sa.config.description,
1444
- prompt: sa.config.prompt,
1445
- tools: sa.config.tools
1446
- }))
1439
+ subagents: params.subAgents.map((sa) => sa.config)
1447
1440
  });
1448
1441
  }
1449
1442
  };
@@ -1662,7 +1655,7 @@ _MemoryManager.instance = memory2;
1662
1655
  var MemoryManager = _MemoryManager;
1663
1656
 
1664
1657
  // src/createPlanExecuteAgent.ts
1665
- var import_prebuilt4 = require("@langchain/langgraph/prebuilt");
1658
+ var import_prebuilt3 = require("@langchain/langgraph/prebuilt");
1666
1659
  var PlanExecuteState = import_langgraph8.Annotation.Root({
1667
1660
  // 输入
1668
1661
  input: (0, import_langgraph8.Annotation)({
@@ -1719,7 +1712,7 @@ function createPlanExecuteAgent(config) {
1719
1712
  maxSteps,
1720
1713
  toolsCount: executorTools.length
1721
1714
  });
1722
- const agentExecutor = (0, import_prebuilt4.createReactAgent)({
1715
+ const agentExecutor = (0, import_prebuilt3.createReactAgent)({
1723
1716
  tools: executorTools,
1724
1717
  llm
1725
1718
  });
@@ -1821,7 +1814,7 @@ ${executorTools.map((tool5) => tool5.name).join("\n")}
1821
1814
  returnDirect: true
1822
1815
  }
1823
1816
  );
1824
- const replanAgent = (0, import_prebuilt4.createReactAgent)({
1817
+ const replanAgent = (0, import_prebuilt3.createReactAgent)({
1825
1818
  tools: [responseTool, planTool],
1826
1819
  llm
1827
1820
  });
@@ -2044,6 +2037,7 @@ var AgentGraphBuilderFactory = class _AgentGraphBuilderFactory {
2044
2037
  };
2045
2038
 
2046
2039
  // src/agent_lattice/builders/AgentParamsBuilder.ts
2040
+ var import_protocols4 = require("@axiom-lattice/protocols");
2047
2041
  var AgentParamsBuilder = class {
2048
2042
  /**
2049
2043
  * constructor
@@ -2061,7 +2055,7 @@ var AgentParamsBuilder = class {
2061
2055
  * @returns Agent build parameters
2062
2056
  */
2063
2057
  buildParams(agentLattice, options) {
2064
- const toolKeys = options?.overrideTools || agentLattice.config.tools || [];
2058
+ const toolKeys = options?.overrideTools || (0, import_protocols4.getToolsFromConfig)(agentLattice.config);
2065
2059
  const tools = toolKeys.map((toolKey) => {
2066
2060
  const toolLattice = toolLatticeManager.getToolLattice(toolKey);
2067
2061
  if (!toolLattice) {
@@ -2078,7 +2072,7 @@ var AgentParamsBuilder = class {
2078
2072
  if (!model) {
2079
2073
  throw new Error(`Model "${modelKey}" does not exist`);
2080
2074
  }
2081
- const subAgentKeys = agentLattice.config.subAgents || [];
2075
+ const subAgentKeys = (0, import_protocols4.getSubAgentsFromConfig)(agentLattice.config);
2082
2076
  const subAgents = subAgentKeys.map((agentKey) => {
2083
2077
  const subAgentLattice = this.getAgentLatticeFunc(agentKey);
2084
2078
  if (!subAgentLattice) {
@@ -2090,10 +2084,17 @@ var AgentParamsBuilder = class {
2090
2084
  client: subAgentLattice.client
2091
2085
  };
2092
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
+ }
2093
2094
  return {
2094
2095
  tools,
2095
2096
  model,
2096
- subAgents,
2097
+ subAgents: [...subAgents, ...internalSubAgents],
2097
2098
  prompt: agentLattice.config.prompt,
2098
2099
  stateSchema: agentLattice.config.schema
2099
2100
  };
@@ -2196,11 +2197,25 @@ var AgentLatticeManager = class _AgentLatticeManager extends BaseLatticeManager
2196
2197
  * @returns 返回Agent构建参数
2197
2198
  */
2198
2199
  buildAgentParams(agentLattice, options) {
2199
- const paramsBuilder = new AgentParamsBuilder(
2200
- (key) => this.getAgentLattice(key)
2201
- );
2200
+ const paramsBuilder = new AgentParamsBuilder((key) => {
2201
+ this.initializeClient(key);
2202
+ return this.getAgentLattice(key);
2203
+ });
2202
2204
  return paramsBuilder.buildParams(agentLattice, options);
2203
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
+ }
2204
2219
  /**
2205
2220
  * 初始化Agent客户端
2206
2221
  *
@@ -2218,10 +2233,7 @@ var AgentLatticeManager = class _AgentLatticeManager extends BaseLatticeManager
2218
2233
  if (agentLattice.client) {
2219
2234
  return agentLattice.client;
2220
2235
  }
2221
- const factory = AgentGraphBuilderFactory.getInstance();
2222
- const builder = factory.getBuilder(agentLattice.config.type);
2223
- const params = this.buildAgentParams(agentLattice, options);
2224
- const graph = builder.build(agentLattice, params);
2236
+ const graph = this.createAgentClientFromConfig(agentLattice, options);
2225
2237
  agentLattice.client = graph;
2226
2238
  return graph;
2227
2239
  }
@@ -2239,7 +2251,8 @@ var getAgentLattice = (key) => agentLatticeManager.getAgentLattice(key);
2239
2251
  var getAgentConfig = (key) => agentLatticeManager.getAgentConfig(key);
2240
2252
  var getAllAgentConfigs = () => agentLatticeManager.getAllAgentConfigs();
2241
2253
  var validateAgentInput = (key, input) => agentLatticeManager.validateAgentInput(key, input);
2242
- var getAgentClient = (key, options) => agentLatticeManager.initializeClient(key, options);
2254
+ var getAgentClient2 = (key, options) => agentLatticeManager.initializeClient(key, options);
2255
+ var createAgentClientFromAgentLattice = (agentLattice, options) => agentLatticeManager.createAgentClientFromConfig(agentLattice, options);
2243
2256
 
2244
2257
  // src/chunk_buffer_lattice/ChunkBuffer.ts
2245
2258
  var ChunkBuffer = class {