@axiom-lattice/core 2.1.21 → 2.1.23

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.mjs CHANGED
@@ -5232,7 +5232,7 @@ function returnCommandWithStateUpdate(result, toolCallId) {
5232
5232
  ...stateUpdate,
5233
5233
  messages: [
5234
5234
  new ToolMessage2({
5235
- content: lastMessage?.content || "Task completed",
5235
+ content: lastMessage?.content || "Task Failed to complete",
5236
5236
  tool_call_id: toolCallId,
5237
5237
  name: "task"
5238
5238
  })
@@ -5313,28 +5313,42 @@ function createTaskTool(options) {
5313
5313
  return tool34(
5314
5314
  async (input, config) => {
5315
5315
  const { description, subagent_type } = input;
5316
- if (!(subagent_type in subagentGraphs)) {
5317
- const allowedTypes = Object.keys(subagentGraphs).map((k) => `\`${k}\``).join(", ");
5318
- throw new Error(
5319
- `Error: invoked agent of type ${subagent_type}, the only allowed types are ${allowedTypes}`
5320
- );
5321
- }
5322
- const subagent = subagentGraphs[subagent_type];
5323
- const currentState = getCurrentTaskInput2();
5324
- const subagentState = filterStateForSubagent(currentState);
5325
- subagentState.messages = [new HumanMessage({ content: description })];
5326
- const subagent_thread_id = config.configurable?.thread_id + "____" + subagent_type + "_" + config.toolCall.id;
5327
- console.log(subagent_thread_id);
5328
- const workerResult = await agentWorkerGraph.invoke({
5329
- assistant_id: subagent_type,
5330
- thread_id: subagent_thread_id,
5331
- input: { ...subagentState, message: description }
5332
- });
5333
- const result = workerResult.finalState?.values;
5334
- if (!config.toolCall?.id) {
5335
- throw new Error("Tool call ID is required for subagent invocation");
5316
+ try {
5317
+ if (!(subagent_type in subagentGraphs)) {
5318
+ const allowedTypes = Object.keys(subagentGraphs).map((k) => `\`${k}\``).join(", ");
5319
+ throw new Error(
5320
+ `Error: invoked agent of type ${subagent_type}, the only allowed types are ${allowedTypes}`
5321
+ );
5322
+ }
5323
+ const subagent = subagentGraphs[subagent_type];
5324
+ const currentState = getCurrentTaskInput2();
5325
+ const subagentState = filterStateForSubagent(currentState);
5326
+ subagentState.messages = [new HumanMessage({ content: description })];
5327
+ const subagent_thread_id = config.configurable?.thread_id + "____" + subagent_type + "_" + config.toolCall.id;
5328
+ console.log(subagent_thread_id);
5329
+ const workerResult = await agentWorkerGraph.invoke({
5330
+ assistant_id: subagent_type,
5331
+ thread_id: subagent_thread_id,
5332
+ input: { ...subagentState, message: description }
5333
+ });
5334
+ const result = workerResult.finalState?.values;
5335
+ if (!config.toolCall?.id) {
5336
+ throw new Error("Tool call ID is required for subagent invocation");
5337
+ }
5338
+ return returnCommandWithStateUpdate(result, config.toolCall.id);
5339
+ } catch (error) {
5340
+ return new Command2({
5341
+ update: {
5342
+ messages: [
5343
+ new ToolMessage2({
5344
+ content: error instanceof Error ? error.message : "Task Failed to complete",
5345
+ tool_call_id: config.toolCall.id,
5346
+ name: "task"
5347
+ })
5348
+ ]
5349
+ }
5350
+ });
5336
5351
  }
5337
- return returnCommandWithStateUpdate(result, config.toolCall.id);
5338
5352
  },
5339
5353
  {
5340
5354
  name: "task",
@@ -5999,6 +6013,26 @@ var AgentParamsBuilder = class {
5999
6013
  }
6000
6014
  };
6001
6015
 
6016
+ // src/agent_lattice/utils/mergeAgentConfig.ts
6017
+ var NON_INHERITABLE_FIELDS = /* @__PURE__ */ new Set([
6018
+ "key",
6019
+ "extendsAgent"
6020
+ ]);
6021
+ function mergeAgentConfig(parent, child) {
6022
+ const merged = { ...parent };
6023
+ for (const [key, value] of Object.entries(child)) {
6024
+ if (NON_INHERITABLE_FIELDS.has(key)) {
6025
+ continue;
6026
+ }
6027
+ if (value !== void 0) {
6028
+ merged[key] = value;
6029
+ }
6030
+ }
6031
+ merged.key = child.key;
6032
+ delete merged.extendsAgent;
6033
+ return merged;
6034
+ }
6035
+
6002
6036
  // src/agent_lattice/AgentLatticeManager.ts
6003
6037
  function assistantToConfig(assistant) {
6004
6038
  const graphDef = typeof assistant.graphDefinition === "object" && assistant.graphDefinition !== null ? assistant.graphDefinition : {};
@@ -6154,6 +6188,39 @@ var AgentLatticeManager = class _AgentLatticeManager extends BaseLatticeManager
6154
6188
  return false;
6155
6189
  }
6156
6190
  }
6191
+ /**
6192
+ * Resolve inherited config by walking the extendsAgent chain.
6193
+ *
6194
+ * If config.extendsAgent is set, fetches the parent config, recursively
6195
+ * resolves the parent's own inheritance, then merges parent with child
6196
+ * (child's explicit fields override parent's).
6197
+ *
6198
+ * @param config - The agent config to resolve
6199
+ * @param visited - Set of visited keys to detect circular inheritance
6200
+ * @returns A fully resolved AgentConfig with inheritance applied
6201
+ */
6202
+ resolveInheritedConfig(config, visited = /* @__PURE__ */ new Set()) {
6203
+ if (!config.extendsAgent) {
6204
+ return config;
6205
+ }
6206
+ if (visited.has(config.key)) {
6207
+ throw new Error(
6208
+ `Circular agent inheritance detected: "${config.key}" already visited in chain [${[...visited].join(" -> ")}]`
6209
+ );
6210
+ }
6211
+ visited.add(config.key);
6212
+ const parentLattice = this.getAgentLattice(config.extendsAgent);
6213
+ if (!parentLattice) {
6214
+ throw new Error(
6215
+ `Parent agent "${config.extendsAgent}" not found when resolving inheritance for "${config.key}"`
6216
+ );
6217
+ }
6218
+ const resolvedParent = this.resolveInheritedConfig(
6219
+ parentLattice.config,
6220
+ visited
6221
+ );
6222
+ return mergeAgentConfig(resolvedParent, config);
6223
+ }
6157
6224
  /**
6158
6225
  * 构建Agent参数
6159
6226
  *
@@ -6176,10 +6243,15 @@ var AgentLatticeManager = class _AgentLatticeManager extends BaseLatticeManager
6176
6243
  * @returns AgentClient instance
6177
6244
  */
6178
6245
  createAgentClientFromConfig(agentLattice, options) {
6246
+ const resolvedConfig = this.resolveInheritedConfig(agentLattice.config);
6247
+ const resolvedLattice = {
6248
+ ...agentLattice,
6249
+ config: resolvedConfig
6250
+ };
6179
6251
  const factory = AgentGraphBuilderFactory.getInstance();
6180
- const builder = factory.getBuilder(agentLattice.config.type);
6181
- const params = this.buildAgentParams(agentLattice, options);
6182
- return builder.build(agentLattice, params);
6252
+ const builder = factory.getBuilder(resolvedConfig.type);
6253
+ const params = this.buildAgentParams(resolvedLattice, options);
6254
+ return builder.build(resolvedLattice, params);
6183
6255
  }
6184
6256
  /**
6185
6257
  * 初始化Agent客户端