@axiom-lattice/core 2.1.45 → 2.1.46

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.js CHANGED
@@ -48,7 +48,7 @@ __export(index_exports, {
48
48
  FileSystemSkillStore: () => FileSystemSkillStore,
49
49
  FilesystemBackend: () => FilesystemBackend,
50
50
  GraphBuildOptions: () => import_protocols.GraphBuildOptions,
51
- HumanMessage: () => import_messages3.HumanMessage,
51
+ HumanMessage: () => import_messages4.HumanMessage,
52
52
  InMemoryAssistantStore: () => InMemoryAssistantStore,
53
53
  InMemoryChunkBuffer: () => InMemoryChunkBuffer,
54
54
  InMemoryDatabaseConfigStore: () => InMemoryDatabaseConfigStore,
@@ -116,6 +116,7 @@ __export(index_exports, {
116
116
  createQueryTablesListTool: () => createQueryTablesListTool,
117
117
  createTeamMiddleware: () => createTeamMiddleware,
118
118
  createTeammateTools: () => createTeammateTools,
119
+ createUnknownToolHandlerMiddleware: () => createUnknownToolHandlerMiddleware,
119
120
  createWidgetMiddleware: () => createWidgetMiddleware,
120
121
  decrypt: () => decrypt,
121
122
  describeCronExpression: () => describeCronExpression,
@@ -845,11 +846,11 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
845
846
  * @param key Lattice键名
846
847
  * @param tool 已有的StructuredTool实例
847
848
  */
848
- registerExistingTool(key, tool50) {
849
+ registerExistingTool(key, tool51) {
849
850
  const config = {
850
- name: tool50.name,
851
- description: tool50.description,
852
- schema: tool50.schema,
851
+ name: tool51.name,
852
+ description: tool51.description,
853
+ schema: tool51.schema,
853
854
  // StructuredTool的schema已经是Zod兼容的
854
855
  needUserApprove: false
855
856
  // MCP工具默认不需要用户批准
@@ -857,7 +858,7 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
857
858
  const toolLattice = {
858
859
  key,
859
860
  config,
860
- client: tool50
861
+ client: tool51
861
862
  };
862
863
  this.register(key, toolLattice);
863
864
  }
@@ -883,7 +884,7 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
883
884
  };
884
885
  var toolLatticeManager = ToolLatticeManager.getInstance();
885
886
  var registerToolLattice = (key, config, executor) => toolLatticeManager.registerLattice(key, config, executor);
886
- var registerExistingTool = (key, tool50) => toolLatticeManager.registerExistingTool(key, tool50);
887
+ var registerExistingTool = (key, tool51) => toolLatticeManager.registerExistingTool(key, tool51);
887
888
  var getToolLattice = (key) => toolLatticeManager.getToolLattice(key);
888
889
  var getToolDefinition = (key) => toolLatticeManager.getToolDefinition(key);
889
890
  var getToolClient = (key) => toolLatticeManager.getToolClient(key);
@@ -4737,7 +4738,7 @@ var createBrowserGetInfoTool = ({ isolatedLevel }) => {
4737
4738
  };
4738
4739
 
4739
4740
  // src/index.ts
4740
- var import_messages3 = require("@langchain/core/messages");
4741
+ var import_messages4 = require("@langchain/core/messages");
4741
4742
 
4742
4743
  // src/agent_lattice/types.ts
4743
4744
  var import_protocols = require("@axiom-lattice/protocols");
@@ -4830,7 +4831,7 @@ var createReactAgentSchema = (schema) => {
4830
4831
  };
4831
4832
 
4832
4833
  // src/agent_lattice/builders/ReActAgentGraphBuilder.ts
4833
- var import_langchain53 = require("langchain");
4834
+ var import_langchain55 = require("langchain");
4834
4835
 
4835
4836
  // src/deep_agent_new/backends/sandboxFiles.ts
4836
4837
  var import_sandbox2 = require("@agent-infra/sandbox");
@@ -9422,7 +9423,7 @@ function createShowWidgetTool() {
9422
9423
  },
9423
9424
  {
9424
9425
  name: "show_widget",
9425
- description: "Render an interactive HTML widget or SVG diagram visible to the user. Use for: charts, dashboards, calculators, forms, diagrams, timers, games, visualizations. The widget appears in a panel next to the chat. Users can interact with it and send data back via window.sendToAgent(data). IMPORTANT: Always call load_guidelines before your first show_widget.",
9426
+ description: "Render an interactive HTML widget or SVG diagram visible to the user. Use for: charts, dashboards, calculators, forms, diagrams, timers, games, visualizations. The widget appears in a panel next to the chat. Users can interact with it and send data back via window.sendPrompt(data). IMPORTANT: Always call load_guidelines before your first show_widget.",
9426
9427
  schema: ShowWidgetInputSchema
9427
9428
  }
9428
9429
  );
@@ -9953,9 +9954,198 @@ ${bootstrapSections.join("\n\n")}
9953
9954
  });
9954
9955
  }
9955
9956
 
9957
+ // src/middlewares/unknownToolHandlerMiddleware.ts
9958
+ var import_langchain53 = require("langchain");
9959
+ var import_messages = require("@langchain/core/messages");
9960
+ function createUnknownToolHandlerMiddleware(config = {}) {
9961
+ const {
9962
+ strategy = "error",
9963
+ errorMessageTemplate = (name, tools) => `Error: Tool "${name}" does not exist.
9964
+
9965
+ Available tools:
9966
+ ` + tools.map((t) => ` - ${t}`).join("\n") + `
9967
+
9968
+ Please select a valid tool from the list above.`
9969
+ } = config;
9970
+ return (0, import_langchain53.createMiddleware)({
9971
+ name: "UnknownToolHandlerMiddleware",
9972
+ /**
9973
+ * wrapModelCall hook
9974
+ *
9975
+ * The only place to access request.tools (all available tools).
9976
+ * Identifies unknown tools and stores error info in metadata.
9977
+ *
9978
+ * Key: Preserve all tool_calls in original AIMessage, including unknown ones.
9979
+ * This allows the model to see what it selected in the next round.
9980
+ */
9981
+ wrapModelCall: async (request, handler) => {
9982
+ const availableTools = request.tools || [];
9983
+ const availableToolNames = availableTools.map((t) => t.name);
9984
+ const availableToolSet = new Set(availableToolNames);
9985
+ const aiResponse = await handler(request);
9986
+ if (!aiResponse.tool_calls || aiResponse.tool_calls.length === 0) {
9987
+ return aiResponse;
9988
+ }
9989
+ const unknownToolCalls = [];
9990
+ for (const toolCall of aiResponse.tool_calls) {
9991
+ if (!availableToolSet.has(toolCall.name)) {
9992
+ unknownToolCalls.push(toolCall);
9993
+ }
9994
+ }
9995
+ if (unknownToolCalls.length === 0) {
9996
+ return aiResponse;
9997
+ }
9998
+ if (strategy === "strict") {
9999
+ const unknownNames = unknownToolCalls.map((t) => t.name).join(", ");
10000
+ throw new Error(
10001
+ `Unknown tools detected: ${unknownNames}. Available tools: ${availableToolNames.join(", ")}`
10002
+ );
10003
+ }
10004
+ const unknownToolErrors = unknownToolCalls.map((toolCall) => ({
10005
+ toolName: toolCall.name,
10006
+ toolCallId: toolCall.id,
10007
+ errorMessage: errorMessageTemplate(toolCall.name, availableToolNames)
10008
+ }));
10009
+ const modifiedResponse = new import_messages.AIMessage({
10010
+ content: aiResponse.content,
10011
+ tool_calls: aiResponse.tool_calls,
10012
+ // Key: preserve all tool_calls, don't delete unknown
10013
+ response_metadata: {
10014
+ ...aiResponse.response_metadata,
10015
+ _unknownToolErrors: unknownToolErrors
10016
+ }
10017
+ });
10018
+ if (aiResponse.id) {
10019
+ modifiedResponse.id = aiResponse.id;
10020
+ }
10021
+ return modifiedResponse;
10022
+ },
10023
+ /**
10024
+ * afterModel hook
10025
+ *
10026
+ * Processes unknown tool errors stored in metadata.
10027
+ * Generates error ToolMessages and jumps back to model.
10028
+ *
10029
+ * Key: Uses jumpTo: "model" to form agent loop.
10030
+ * Without jumpTo, the graph would end after ToolNode without returning to model.
10031
+ */
10032
+ afterModel: {
10033
+ canJumpTo: ["model"],
10034
+ hook: async (state) => {
10035
+ const { messages } = state;
10036
+ if (!messages || messages.length === 0) {
10037
+ return;
10038
+ }
10039
+ const lastMessage = messages[messages.length - 1];
10040
+ if (!import_messages.AIMessage.isInstance(lastMessage)) {
10041
+ return;
10042
+ }
10043
+ const unknownToolErrors = lastMessage.response_metadata?._unknownToolErrors;
10044
+ if (!unknownToolErrors || !Array.isArray(unknownToolErrors) || unknownToolErrors.length === 0) {
10045
+ return;
10046
+ }
10047
+ const errorToolMessages = unknownToolErrors.map(
10048
+ (error) => new import_messages.ToolMessage({
10049
+ content: error.errorMessage,
10050
+ name: error.toolName,
10051
+ tool_call_id: error.toolCallId,
10052
+ status: "error"
10053
+ })
10054
+ );
10055
+ delete lastMessage.response_metadata._unknownToolErrors;
10056
+ return {
10057
+ messages: errorToolMessages,
10058
+ jumpTo: "model"
10059
+ };
10060
+ }
10061
+ }
10062
+ });
10063
+ }
10064
+
10065
+ // src/deep_agent_new/middleware/date.ts
10066
+ var import_langchain54 = require("langchain");
10067
+ var import_zod49 = require("zod");
10068
+ function formatCurrentDate(timezone = "UTC") {
10069
+ const now = /* @__PURE__ */ new Date();
10070
+ let validTimezone = timezone;
10071
+ try {
10072
+ Intl.DateTimeFormat(void 0, { timeZone: timezone });
10073
+ } catch {
10074
+ validTimezone = "UTC";
10075
+ }
10076
+ const dateFormatOptions = {
10077
+ timeZone: validTimezone,
10078
+ year: "numeric",
10079
+ month: "2-digit",
10080
+ day: "2-digit"
10081
+ };
10082
+ return new Intl.DateTimeFormat("en-US", dateFormatOptions).format(now);
10083
+ }
10084
+ function generateDateContext(timezone = "UTC") {
10085
+ const formattedDate = formatCurrentDate(timezone);
10086
+ if (timezone === "UTC") {
10087
+ return `Current Date: ${formattedDate}`;
10088
+ }
10089
+ const utcDate = formatCurrentDate("UTC");
10090
+ return `Current Date: ${formattedDate} (UTC: ${utcDate})`;
10091
+ }
10092
+ function createDateMiddleware(options = {}) {
10093
+ const timezone = options.timezone || "UTC";
10094
+ const dateContext = generateDateContext(timezone);
10095
+ return (0, import_langchain54.createMiddleware)({
10096
+ name: "DateMiddleware",
10097
+ tools: [
10098
+ (0, import_langchain54.tool)(
10099
+ async () => {
10100
+ const now = /* @__PURE__ */ new Date();
10101
+ let validTimezone = timezone;
10102
+ try {
10103
+ Intl.DateTimeFormat(void 0, { timeZone: timezone });
10104
+ } catch {
10105
+ validTimezone = "UTC";
10106
+ }
10107
+ const localTimeOptions = {
10108
+ timeZone: validTimezone,
10109
+ year: "numeric",
10110
+ month: "2-digit",
10111
+ day: "2-digit",
10112
+ hour: "2-digit",
10113
+ minute: "2-digit",
10114
+ second: "2-digit",
10115
+ hour12: false
10116
+ };
10117
+ const localTime = new Intl.DateTimeFormat("en-US", localTimeOptions).format(now);
10118
+ return JSON.stringify({
10119
+ local_time: `${localTime} (${validTimezone})`,
10120
+ iso_date: now.toISOString().split("T")[0],
10121
+ timestamp: now.toISOString(),
10122
+ timezone: validTimezone
10123
+ });
10124
+ },
10125
+ {
10126
+ name: "get_current_date_time",
10127
+ description: "Get the exact current date and time at the moment of invocation. Use this when the user asks about the current time (e.g., 'what time is it', '\u51E0\u70B9\u4E86', '\u73B0\u5728\u51E0\u70B9'), or when you need to know the precise time for scheduling, deadlines, or time-sensitive operations.",
10128
+ schema: import_zod49.z.object({})
10129
+ }
10130
+ )
10131
+ ],
10132
+ wrapModelCall: async (request, handler) => {
10133
+ const currentSystemPrompt = request.systemPrompt || "";
10134
+ const newSystemPrompt = currentSystemPrompt ? `${dateContext}
10135
+
10136
+ ${currentSystemPrompt}` : dateContext;
10137
+ return handler({
10138
+ ...request,
10139
+ systemPrompt: newSystemPrompt
10140
+ });
10141
+ }
10142
+ });
10143
+ }
10144
+
9956
10145
  // src/agent_lattice/builders/commonMiddleware.ts
9957
10146
  async function createCommonMiddlewares(middlewareConfigs, filesystemBackend) {
9958
10147
  const middlewares = [];
10148
+ middlewares.push(createUnknownToolHandlerMiddleware());
9959
10149
  middlewares.push(createModelSelectorMiddleware());
9960
10150
  const filesystemConfig = middlewareConfigs.find((m) => m.type === "filesystem");
9961
10151
  if (filesystemConfig?.enabled && filesystemBackend) {
@@ -10016,6 +10206,9 @@ async function createCommonMiddlewares(middlewareConfigs, filesystemBackend) {
10016
10206
  }));
10017
10207
  }
10018
10208
  break;
10209
+ case "date":
10210
+ middlewares.push(createDateMiddleware(config.config));
10211
+ break;
10019
10212
  }
10020
10213
  }
10021
10214
  return middlewares;
@@ -10069,14 +10262,14 @@ var ReActAgentGraphBuilder = class {
10069
10262
  */
10070
10263
  async build(agentLattice, params) {
10071
10264
  const tools = params.tools.map((t) => {
10072
- const tool50 = getToolClient(t.key);
10073
- return tool50;
10074
- }).filter((tool50) => tool50 !== void 0);
10265
+ const tool51 = getToolClient(t.key);
10266
+ return tool51;
10267
+ }).filter((tool51) => tool51 !== void 0);
10075
10268
  const stateSchema2 = createReactAgentSchema(params.stateSchema);
10076
10269
  const middlewareConfigs = params.middleware || [];
10077
10270
  const filesystemBackend = this.createFilesystemBackendFactory(middlewareConfigs, agentLattice);
10078
10271
  const middlewares = await createCommonMiddlewares(middlewareConfigs, filesystemBackend);
10079
- return (0, import_langchain53.createAgent)({
10272
+ return (0, import_langchain55.createAgent)({
10080
10273
  model: params.model,
10081
10274
  tools,
10082
10275
  systemPrompt: params.prompt,
@@ -10089,13 +10282,13 @@ var ReActAgentGraphBuilder = class {
10089
10282
  };
10090
10283
 
10091
10284
  // src/deep_agent_new/agent.ts
10092
- var import_langchain57 = require("langchain");
10285
+ var import_langchain59 = require("langchain");
10093
10286
 
10094
10287
  // src/deep_agent_new/middleware/subagents.ts
10095
10288
  var import_v32 = require("zod/v3");
10096
- var import_langchain54 = require("langchain");
10289
+ var import_langchain56 = require("langchain");
10097
10290
  var import_langgraph7 = require("@langchain/langgraph");
10098
- var import_messages = require("@langchain/core/messages");
10291
+ var import_messages2 = require("@langchain/core/messages");
10099
10292
 
10100
10293
  // src/agent_worker/agent_worker_graph.ts
10101
10294
  var import_langgraph6 = require("@langchain/langgraph");
@@ -10655,7 +10848,7 @@ function returnCommandWithStateUpdate(result, toolCallId) {
10655
10848
  update: {
10656
10849
  ...stateUpdate,
10657
10850
  messages: [
10658
- new import_langchain54.ToolMessage({
10851
+ new import_langchain56.ToolMessage({
10659
10852
  content: lastMessage?.content || "Task Failed to complete",
10660
10853
  tool_call_id: toolCallId,
10661
10854
  name: "task"
@@ -10680,10 +10873,10 @@ function getSubagents(options) {
10680
10873
  const generalPurposeMiddleware = [...defaultSubagentMiddleware];
10681
10874
  if (defaultInterruptOn) {
10682
10875
  generalPurposeMiddleware.push(
10683
- (0, import_langchain54.humanInTheLoopMiddleware)({ interruptOn: defaultInterruptOn })
10876
+ (0, import_langchain56.humanInTheLoopMiddleware)({ interruptOn: defaultInterruptOn })
10684
10877
  );
10685
10878
  }
10686
- const generalPurposeSubagent = (0, import_langchain54.createAgent)({
10879
+ const generalPurposeSubagent = (0, import_langchain56.createAgent)({
10687
10880
  model: defaultModel,
10688
10881
  systemPrompt: DEFAULT_SUBAGENT_PROMPT,
10689
10882
  tools: defaultTools,
@@ -10706,8 +10899,8 @@ function getSubagents(options) {
10706
10899
  const middleware = agentParams.middleware ? [...defaultSubagentMiddleware, ...agentParams.middleware] : [...defaultSubagentMiddleware];
10707
10900
  const interruptOn = agentParams.interruptOn || defaultInterruptOn;
10708
10901
  if (interruptOn)
10709
- middleware.push((0, import_langchain54.humanInTheLoopMiddleware)({ interruptOn }));
10710
- agents[agentParams.key] = (0, import_langchain54.createAgent)({
10902
+ middleware.push((0, import_langchain56.humanInTheLoopMiddleware)({ interruptOn }));
10903
+ agents[agentParams.key] = (0, import_langchain56.createAgent)({
10711
10904
  model: agentParams.model ?? defaultModel,
10712
10905
  systemPrompt: agentParams.systemPrompt,
10713
10906
  tools: agentParams.tools ?? defaultTools,
@@ -10737,7 +10930,7 @@ function createTaskTool(options) {
10737
10930
  generalPurposeAgent
10738
10931
  });
10739
10932
  const finalTaskDescription = taskDescription ? taskDescription : getTaskToolDescription(subagentDescriptions);
10740
- return (0, import_langchain54.tool)(
10933
+ return (0, import_langchain56.tool)(
10741
10934
  async (input, config) => {
10742
10935
  const { description, subagent_type } = input;
10743
10936
  let assistant_id = subagent_type;
@@ -10767,7 +10960,7 @@ function createTaskTool(options) {
10767
10960
  }
10768
10961
  const currentState = (0, import_langgraph7.getCurrentTaskInput)();
10769
10962
  const subagentState = filterStateForSubagent(currentState);
10770
- subagentState.messages = [new import_messages.HumanMessage({ content: description })];
10963
+ subagentState.messages = [new import_messages2.HumanMessage({ content: description })];
10771
10964
  const subagent_thread_id = config.configurable?.thread_id + "____" + assistant_id + "_" + config.toolCall.id;
10772
10965
  const workerResult = await agentWorkerGraph.invoke({
10773
10966
  assistant_id,
@@ -10791,7 +10984,7 @@ function createTaskTool(options) {
10791
10984
  return new import_langgraph7.Command({
10792
10985
  update: {
10793
10986
  messages: [
10794
- new import_langchain54.ToolMessage({
10987
+ new import_langchain56.ToolMessage({
10795
10988
  content: error instanceof Error ? error.message : "Task Failed to complete",
10796
10989
  tool_call_id: config.toolCall.id,
10797
10990
  name: "task"
@@ -10835,7 +11028,7 @@ function createSubAgentMiddleware(options) {
10835
11028
  generalPurposeAgent,
10836
11029
  taskDescription
10837
11030
  });
10838
- return (0, import_langchain54.createMiddleware)({
11031
+ return (0, import_langchain56.createMiddleware)({
10839
11032
  name: "subAgentMiddleware",
10840
11033
  tools: [taskTool],
10841
11034
  wrapModelCall: async (request, handler) => {
@@ -10855,11 +11048,11 @@ ${systemPrompt}` : systemPrompt;
10855
11048
  }
10856
11049
 
10857
11050
  // src/deep_agent_new/middleware/patch_tool_calls.ts
10858
- var import_langchain55 = require("langchain");
10859
- var import_messages2 = require("@langchain/core/messages");
11051
+ var import_langchain57 = require("langchain");
11052
+ var import_messages3 = require("@langchain/core/messages");
10860
11053
  var import_langgraph8 = require("@langchain/langgraph");
10861
11054
  function createPatchToolCallsMiddleware() {
10862
- return (0, import_langchain55.createMiddleware)({
11055
+ return (0, import_langchain57.createMiddleware)({
10863
11056
  name: "patchToolCallsMiddleware",
10864
11057
  beforeAgent: async (state) => {
10865
11058
  const messages = state.messages;
@@ -10870,15 +11063,15 @@ function createPatchToolCallsMiddleware() {
10870
11063
  for (let i = 0; i < messages.length; i++) {
10871
11064
  const msg = messages[i];
10872
11065
  patchedMessages.push(msg);
10873
- if (import_langchain55.AIMessage.isInstance(msg) && msg.tool_calls != null) {
11066
+ if (import_langchain57.AIMessage.isInstance(msg) && msg.tool_calls != null) {
10874
11067
  for (const toolCall of msg.tool_calls) {
10875
11068
  const correspondingToolMsg = messages.slice(i).find(
10876
- (m) => import_langchain55.ToolMessage.isInstance(m) && m.tool_call_id === toolCall.id
11069
+ (m) => import_langchain57.ToolMessage.isInstance(m) && m.tool_call_id === toolCall.id
10877
11070
  );
10878
11071
  if (!correspondingToolMsg) {
10879
11072
  const toolMsg = `Tool call ${toolCall.name} with id ${toolCall.id} was cancelled - another message came in before it could be completed.`;
10880
11073
  patchedMessages.push(
10881
- new import_langchain55.ToolMessage({
11074
+ new import_langchain57.ToolMessage({
10882
11075
  content: toolMsg,
10883
11076
  name: toolCall.name,
10884
11077
  tool_call_id: toolCall.id
@@ -10890,7 +11083,7 @@ function createPatchToolCallsMiddleware() {
10890
11083
  }
10891
11084
  return {
10892
11085
  messages: [
10893
- new import_messages2.RemoveMessage({ id: import_langgraph8.REMOVE_ALL_MESSAGES }),
11086
+ new import_messages3.RemoveMessage({ id: import_langgraph8.REMOVE_ALL_MESSAGES }),
10894
11087
  ...patchedMessages
10895
11088
  ]
10896
11089
  };
@@ -11995,8 +12188,8 @@ var MemoryBackend = class {
11995
12188
 
11996
12189
  // src/deep_agent_new/middleware/todos.ts
11997
12190
  var import_langgraph9 = require("@langchain/langgraph");
11998
- var import_zod49 = require("zod");
11999
- var import_langchain56 = require("langchain");
12191
+ var import_zod50 = require("zod");
12192
+ var import_langchain58 = require("langchain");
12000
12193
  var WRITE_TODOS_DESCRIPTION = `Use this tool to create and manage a structured task list for your current work session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
12001
12194
  It also helps the user understand the progress of the task and overall progress of their requests.
12002
12195
  Only use this tool if you think it will be helpful in staying organized. If the user's request is trivial and takes less than 3 steps, it is better to NOT use this tool and just do the taks directly.
@@ -12223,20 +12416,20 @@ Writing todos takes time and tokens, use it when it is helpful for managing comp
12223
12416
  ## Important To-Do List Usage Notes to Remember
12224
12417
  - The \`write_todos\` tool should never be called multiple times in parallel.
12225
12418
  - Don't be afraid to revise the To-Do list as you go. New information may reveal new tasks that need to be done, or old tasks that are irrelevant.`;
12226
- var TodoStatus = import_zod49.z.enum(["pending", "in_progress", "completed"]).describe("Status of the todo");
12227
- var TodoSchema = import_zod49.z.object({
12228
- content: import_zod49.z.string().describe("Content of the todo item"),
12419
+ var TodoStatus = import_zod50.z.enum(["pending", "in_progress", "completed"]).describe("Status of the todo");
12420
+ var TodoSchema = import_zod50.z.object({
12421
+ content: import_zod50.z.string().describe("Content of the todo item"),
12229
12422
  status: TodoStatus
12230
12423
  });
12231
- var stateSchema = import_zod49.z.object({ todos: import_zod49.z.array(TodoSchema).default([]) });
12424
+ var stateSchema = import_zod50.z.object({ todos: import_zod50.z.array(TodoSchema).default([]) });
12232
12425
  function todoListMiddleware(options) {
12233
- const writeTodos = (0, import_langchain56.tool)(
12426
+ const writeTodos = (0, import_langchain58.tool)(
12234
12427
  ({ todos }, config) => {
12235
12428
  return new import_langgraph9.Command({
12236
12429
  update: {
12237
12430
  todos,
12238
12431
  messages: [
12239
- new import_langchain56.ToolMessage({
12432
+ new import_langchain58.ToolMessage({
12240
12433
  content: genUIMarkdown("todo_list", todos),
12241
12434
  tool_call_id: config.toolCall?.id
12242
12435
  })
@@ -12247,12 +12440,12 @@ function todoListMiddleware(options) {
12247
12440
  {
12248
12441
  name: "write_todos",
12249
12442
  description: options?.toolDescription ?? WRITE_TODOS_DESCRIPTION,
12250
- schema: import_zod49.z.object({
12251
- todos: import_zod49.z.array(TodoSchema).describe("List of todo items to update")
12443
+ schema: import_zod50.z.object({
12444
+ todos: import_zod50.z.array(TodoSchema).describe("List of todo items to update")
12252
12445
  })
12253
12446
  }
12254
12447
  );
12255
- return (0, import_langchain56.createMiddleware)({
12448
+ return (0, import_langchain58.createMiddleware)({
12256
12449
  name: "todoListMiddleware",
12257
12450
  stateSchema,
12258
12451
  tools: [writeTodos],
@@ -12304,13 +12497,13 @@ ${BASE_PROMPT}` : BASE_PROMPT;
12304
12497
  backend: filesystemBackend
12305
12498
  }),
12306
12499
  // Subagent middleware: Automatic conversation summarization when token limits are approached
12307
- (0, import_langchain57.summarizationMiddleware)({
12500
+ (0, import_langchain59.summarizationMiddleware)({
12308
12501
  model,
12309
12502
  trigger: { tokens: 17e4 },
12310
12503
  keep: { messages: 6 }
12311
12504
  }),
12312
12505
  // Subagent middleware: Anthropic prompt caching for improved performance
12313
- (0, import_langchain57.anthropicPromptCachingMiddleware)({
12506
+ (0, import_langchain59.anthropicPromptCachingMiddleware)({
12314
12507
  unsupportedModelBehavior: "ignore"
12315
12508
  }),
12316
12509
  // Subagent middleware: Patches tool calls for compatibility
@@ -12322,23 +12515,23 @@ ${BASE_PROMPT}` : BASE_PROMPT;
12322
12515
  generalPurposeAgent: true
12323
12516
  }),
12324
12517
  // Automatically summarizes conversation history when token limits are approached
12325
- (0, import_langchain57.summarizationMiddleware)({
12518
+ (0, import_langchain59.summarizationMiddleware)({
12326
12519
  model,
12327
12520
  trigger: { tokens: 17e4 },
12328
12521
  keep: { messages: 6 }
12329
12522
  }),
12330
12523
  // Enables Anthropic prompt caching for improved performance and reduced costs
12331
- (0, import_langchain57.anthropicPromptCachingMiddleware)({
12524
+ (0, import_langchain59.anthropicPromptCachingMiddleware)({
12332
12525
  unsupportedModelBehavior: "ignore"
12333
12526
  }),
12334
12527
  // Patches tool calls to ensure compatibility across different model providers
12335
12528
  createPatchToolCallsMiddleware()
12336
12529
  ];
12337
12530
  if (interruptOn) {
12338
- middleware.push((0, import_langchain57.humanInTheLoopMiddleware)({ interruptOn }));
12531
+ middleware.push((0, import_langchain59.humanInTheLoopMiddleware)({ interruptOn }));
12339
12532
  }
12340
12533
  middleware.push(...customMiddleware);
12341
- return (0, import_langchain57.createAgent)({
12534
+ return (0, import_langchain59.createAgent)({
12342
12535
  model,
12343
12536
  systemPrompt: finalSystemPrompt,
12344
12537
  tools,
@@ -12406,7 +12599,7 @@ var DeepAgentGraphBuilder = class {
12406
12599
  const tools = params.tools.map((t) => {
12407
12600
  const toolClient = getToolClient(t.key);
12408
12601
  return toolClient;
12409
- }).filter((tool50) => tool50 !== void 0);
12602
+ }).filter((tool51) => tool51 !== void 0);
12410
12603
  const subagents = await Promise.all(params.subAgents.map(async (sa) => {
12411
12604
  if (sa.client) {
12412
12605
  return {
@@ -12447,7 +12640,7 @@ var DeepAgentGraphBuilder = class {
12447
12640
 
12448
12641
  // src/agent_team/agent_team.ts
12449
12642
  var import_v35 = require("zod/v3");
12450
- var import_langchain60 = require("langchain");
12643
+ var import_langchain62 = require("langchain");
12451
12644
 
12452
12645
  // src/agent_team/types.ts
12453
12646
  var TaskStatus = /* @__PURE__ */ ((TaskStatus3) => {
@@ -12883,13 +13076,13 @@ var InMemoryMailboxStore = class {
12883
13076
 
12884
13077
  // src/agent_team/middleware/team.ts
12885
13078
  var import_v34 = require("zod/v3");
12886
- var import_langchain59 = require("langchain");
13079
+ var import_langchain61 = require("langchain");
12887
13080
  var import_langgraph11 = require("@langchain/langgraph");
12888
13081
  var import_uuid = require("uuid");
12889
13082
 
12890
13083
  // src/agent_team/middleware/teammate_tools.ts
12891
13084
  var import_v33 = require("zod/v3");
12892
- var import_langchain58 = require("langchain");
13085
+ var import_langchain60 = require("langchain");
12893
13086
  var import_langgraph10 = require("@langchain/langgraph");
12894
13087
 
12895
13088
  // src/agent_team/middleware/formatMessages.ts
@@ -12914,7 +13107,7 @@ ${meta}${body}`;
12914
13107
  // src/agent_team/middleware/teammate_tools.ts
12915
13108
  function createTeammateTools(options) {
12916
13109
  const { teamId, agentId, taskListStore, mailboxStore } = options;
12917
- const claimTaskTool = (0, import_langchain58.tool)(
13110
+ const claimTaskTool = (0, import_langchain60.tool)(
12918
13111
  async (input) => {
12919
13112
  const task = await taskListStore.claimTaskById(
12920
13113
  teamId,
@@ -12944,7 +13137,7 @@ function createTeammateTools(options) {
12944
13137
  })
12945
13138
  }
12946
13139
  );
12947
- const completeTaskTool = (0, import_langchain58.tool)(
13140
+ const completeTaskTool = (0, import_langchain60.tool)(
12948
13141
  async (input) => {
12949
13142
  const task = await taskListStore.completeTask(
12950
13143
  teamId,
@@ -12971,7 +13164,7 @@ function createTeammateTools(options) {
12971
13164
  })
12972
13165
  }
12973
13166
  );
12974
- const failTaskTool = (0, import_langchain58.tool)(
13167
+ const failTaskTool = (0, import_langchain60.tool)(
12975
13168
  async (input) => {
12976
13169
  const task = await taskListStore.failTask(
12977
13170
  teamId,
@@ -12998,7 +13191,7 @@ function createTeammateTools(options) {
12998
13191
  })
12999
13192
  }
13000
13193
  );
13001
- const sendMessageTool = (0, import_langchain58.tool)(
13194
+ const sendMessageTool = (0, import_langchain60.tool)(
13002
13195
  async (input) => {
13003
13196
  await mailboxStore.sendMessage(
13004
13197
  teamId,
@@ -13036,7 +13229,7 @@ function createTeammateTools(options) {
13036
13229
  read: msg.read
13037
13230
  }));
13038
13231
  };
13039
- const readMessagesTool = (0, import_langchain58.tool)(
13232
+ const readMessagesTool = (0, import_langchain60.tool)(
13040
13233
  async (input, config) => {
13041
13234
  const formatAndMarkAsRead = async (msgs2) => {
13042
13235
  for (const msg of msgs2) {
@@ -13048,7 +13241,7 @@ function createTeammateTools(options) {
13048
13241
  if (msgs.length > 0) {
13049
13242
  const formatted2 = await formatAndMarkAsRead(msgs);
13050
13243
  const relevantMsgs2 = await getRelevantMessagesForState();
13051
- const toolMessage2 = new import_langchain58.ToolMessage({
13244
+ const toolMessage2 = new import_langchain60.ToolMessage({
13052
13245
  content: formatted2,
13053
13246
  tool_call_id: config.toolCall?.id,
13054
13247
  name: "read_messages"
@@ -13073,7 +13266,7 @@ function createTeammateTools(options) {
13073
13266
  });
13074
13267
  const relevantMsgs = await getRelevantMessagesForState();
13075
13268
  if (msgs.length === 0) {
13076
- const toolMessage2 = new import_langchain58.ToolMessage({
13269
+ const toolMessage2 = new import_langchain60.ToolMessage({
13077
13270
  content: "No unread messages.",
13078
13271
  tool_call_id: config.toolCall?.id,
13079
13272
  name: "read_messages"
@@ -13083,7 +13276,7 @@ function createTeammateTools(options) {
13083
13276
  });
13084
13277
  }
13085
13278
  const formatted = await formatAndMarkAsRead(msgs);
13086
- const toolMessage = new import_langchain58.ToolMessage({
13279
+ const toolMessage = new import_langchain60.ToolMessage({
13087
13280
  content: formatted,
13088
13281
  tool_call_id: config.toolCall?.id,
13089
13282
  name: "read_messages"
@@ -13098,7 +13291,7 @@ function createTeammateTools(options) {
13098
13291
  schema: import_v33.z.object({})
13099
13292
  }
13100
13293
  );
13101
- const checkTasksTool = (0, import_langchain58.tool)(
13294
+ const checkTasksTool = (0, import_langchain60.tool)(
13102
13295
  async () => {
13103
13296
  const tasks = await taskListStore.getAllTasks(teamId);
13104
13297
  return formatTaskSummary(tasks);
@@ -13109,7 +13302,7 @@ function createTeammateTools(options) {
13109
13302
  schema: import_v33.z.object({})
13110
13303
  }
13111
13304
  );
13112
- const broadcastMessageTool = (0, import_langchain58.tool)(
13305
+ const broadcastMessageTool = (0, import_langchain60.tool)(
13113
13306
  async (input) => {
13114
13307
  const allAgents = await mailboxStore.getRegisteredAgents(teamId);
13115
13308
  const recipients = allAgents.filter((a) => a !== agentId);
@@ -13294,7 +13487,7 @@ You have access to these tools:
13294
13487
  - \`read_messages\`: Read messages from team_lead or teammates
13295
13488
  - \`check_tasks\`: Get current status of all tasks in the team`;
13296
13489
  const assistantId = getTeammateAssistantId(ctx.teamId, spec.name);
13297
- agent = (0, import_langchain59.createAgent)({
13490
+ agent = (0, import_langchain61.createAgent)({
13298
13491
  model: spec.model ?? ctx.defaultModel,
13299
13492
  systemPrompt: teammatePrompt,
13300
13493
  tools: allTools,
@@ -13363,12 +13556,12 @@ async function spawnTeammate(options) {
13363
13556
  function createTeamMiddleware(options) {
13364
13557
  const { teamConfig, taskListStore, mailboxStore, tenantId } = options;
13365
13558
  const defaultModel = teamConfig.model ?? "claude-sonnet-4-5-20250929";
13366
- const createTeamTool = (0, import_langchain59.tool)(
13559
+ const createTeamTool = (0, import_langchain61.tool)(
13367
13560
  async (input, config) => {
13368
13561
  const state = (0, import_langgraph11.getCurrentTaskInput)();
13369
13562
  if (state?.team?.teamId) {
13370
13563
  const existingId = state.team.teamId;
13371
- const msg = new import_langchain59.ToolMessage({
13564
+ const msg = new import_langchain61.ToolMessage({
13372
13565
  content: `A team is already active (id: ${existingId}). Use this team_id for \`check_tasks\`, \`read_messages\`, \`add_tasks\`, \`send_message\`, \`assign_task\`, \`set_task_status\`, and \`set_task_dependencies\`. Do not call \`create_team\` again unless you need a fresh team for a new objective.`,
13373
13566
  tool_call_id: config.toolCall?.id,
13374
13567
  name: "create_team"
@@ -13457,7 +13650,7 @@ Teammates are now working in the background. Keep calling \`check_tasks\` and \`
13457
13650
  \`\`\`json
13458
13651
  ${teamJson}
13459
13652
  \`\`\``;
13460
- const toolMessage = new import_langchain59.ToolMessage({
13653
+ const toolMessage = new import_langchain61.ToolMessage({
13461
13654
  content: summary,
13462
13655
  tool_call_id: config.toolCall?.id,
13463
13656
  name: "create_team"
@@ -13542,7 +13735,7 @@ After calling create_team, you MUST:
13542
13735
  if (state?.team?.teamId) return state.team.teamId;
13543
13736
  throw new Error("No team_id provided and no team in state. Call create_team first.");
13544
13737
  };
13545
- const addTasksTool = (0, import_langchain59.tool)(
13738
+ const addTasksTool = (0, import_langchain61.tool)(
13546
13739
  async (input, config) => {
13547
13740
  const teamId = resolveTeamId();
13548
13741
  const created = await taskListStore.addTasks(
@@ -13556,7 +13749,7 @@ After calling create_team, you MUST:
13556
13749
  }))
13557
13750
  );
13558
13751
  const summary = created.map((t) => `- ${t.id}: "${t.title}"`).join("\n");
13559
- return new import_langchain59.ToolMessage({
13752
+ return new import_langchain61.ToolMessage({
13560
13753
  content: `Added ${created.length} task(s) to team ${teamId}:
13561
13754
  ${summary}
13562
13755
  Sleeping teammates will wake up and claim these.`,
@@ -13607,20 +13800,20 @@ IMPORTANT: Assigning to a specific teammate
13607
13800
  })
13608
13801
  }
13609
13802
  );
13610
- const assignTaskTool = (0, import_langchain59.tool)(
13803
+ const assignTaskTool = (0, import_langchain61.tool)(
13611
13804
  async (input, config) => {
13612
13805
  const teamId = resolveTeamId();
13613
13806
  const task = await taskListStore.updateTask(teamId, input.task_id, {
13614
13807
  assignee: input.assignee
13615
13808
  });
13616
13809
  if (!task) {
13617
- return new import_langchain59.ToolMessage({
13810
+ return new import_langchain61.ToolMessage({
13618
13811
  content: `Task ${input.task_id} not found in team ${teamId}.`,
13619
13812
  tool_call_id: config.toolCall?.id,
13620
13813
  name: "assign_task"
13621
13814
  });
13622
13815
  }
13623
- return new import_langchain59.ToolMessage({
13816
+ return new import_langchain61.ToolMessage({
13624
13817
  content: `Task "${task.title}" (${task.id}) assigned to ${input.assignee}.`,
13625
13818
  tool_call_id: config.toolCall?.id,
13626
13819
  name: "assign_task"
@@ -13635,20 +13828,20 @@ IMPORTANT: Assigning to a specific teammate
13635
13828
  })
13636
13829
  }
13637
13830
  );
13638
- const setTaskStatusTool = (0, import_langchain59.tool)(
13831
+ const setTaskStatusTool = (0, import_langchain61.tool)(
13639
13832
  async (input, config) => {
13640
13833
  const teamId = resolveTeamId();
13641
13834
  const task = await taskListStore.updateTask(teamId, input.task_id, {
13642
13835
  status: input.status
13643
13836
  });
13644
13837
  if (!task) {
13645
- return new import_langchain59.ToolMessage({
13838
+ return new import_langchain61.ToolMessage({
13646
13839
  content: `Task ${input.task_id} not found in team ${teamId}.`,
13647
13840
  tool_call_id: config.toolCall?.id,
13648
13841
  name: "set_task_status"
13649
13842
  });
13650
13843
  }
13651
- return new import_langchain59.ToolMessage({
13844
+ return new import_langchain61.ToolMessage({
13652
13845
  content: `Task "${task.title}" (${task.id}) status set to ${input.status}.`,
13653
13846
  tool_call_id: config.toolCall?.id,
13654
13847
  name: "set_task_status"
@@ -13663,20 +13856,20 @@ IMPORTANT: Assigning to a specific teammate
13663
13856
  })
13664
13857
  }
13665
13858
  );
13666
- const setTaskDependenciesTool = (0, import_langchain59.tool)(
13859
+ const setTaskDependenciesTool = (0, import_langchain61.tool)(
13667
13860
  async (input, config) => {
13668
13861
  const teamId = resolveTeamId();
13669
13862
  const task = await taskListStore.updateTask(teamId, input.task_id, {
13670
13863
  dependencies: input.dependencies
13671
13864
  });
13672
13865
  if (!task) {
13673
- return new import_langchain59.ToolMessage({
13866
+ return new import_langchain61.ToolMessage({
13674
13867
  content: `Task ${input.task_id} not found in team ${teamId}.`,
13675
13868
  tool_call_id: config.toolCall?.id,
13676
13869
  name: "set_task_dependencies"
13677
13870
  });
13678
13871
  }
13679
- return new import_langchain59.ToolMessage({
13872
+ return new import_langchain61.ToolMessage({
13680
13873
  content: `Task "${task.title}" (${task.id}) dependencies set to [${input.dependencies.join(", ")}].`,
13681
13874
  tool_call_id: config.toolCall?.id,
13682
13875
  name: "set_task_dependencies"
@@ -13691,7 +13884,7 @@ IMPORTANT: Assigning to a specific teammate
13691
13884
  })
13692
13885
  }
13693
13886
  );
13694
- const checkTasksTool = (0, import_langchain59.tool)(
13887
+ const checkTasksTool = (0, import_langchain61.tool)(
13695
13888
  async (input, config) => {
13696
13889
  const teamId = resolveTeamId();
13697
13890
  const tasks = await taskListStore.getAllTasks(teamId);
@@ -13700,7 +13893,7 @@ IMPORTANT: Assigning to a specific teammate
13700
13893
  update: {
13701
13894
  tasks: tasksSnapshot,
13702
13895
  messages: [
13703
- new import_langchain59.ToolMessage({
13896
+ new import_langchain61.ToolMessage({
13704
13897
  content: formatTaskSummary(tasks),
13705
13898
  tool_call_id: config.toolCall?.id,
13706
13899
  name: "check_tasks"
@@ -13736,7 +13929,7 @@ Task Status Values:
13736
13929
  })
13737
13930
  }
13738
13931
  );
13739
- const sendMessageTool = (0, import_langchain59.tool)(
13932
+ const sendMessageTool = (0, import_langchain61.tool)(
13740
13933
  async (input, config) => {
13741
13934
  const teamId = resolveTeamId();
13742
13935
  await mailboxStore.sendMessage(
@@ -13746,7 +13939,7 @@ Task Status Values:
13746
13939
  input.content,
13747
13940
  "direct_message" /* DIRECT_MESSAGE */
13748
13941
  );
13749
- return new import_langchain59.ToolMessage({
13942
+ return new import_langchain61.ToolMessage({
13750
13943
  content: `Message sent to ${input.to}.`,
13751
13944
  tool_call_id: config.toolCall?.id,
13752
13945
  name: "send_message"
@@ -13761,7 +13954,7 @@ Task Status Values:
13761
13954
  })
13762
13955
  }
13763
13956
  );
13764
- const readMessagesTool = (0, import_langchain59.tool)(
13957
+ const readMessagesTool = (0, import_langchain61.tool)(
13765
13958
  async (input, config) => {
13766
13959
  const teamId = resolveTeamId();
13767
13960
  const formatAndMarkAsRead = async (msgs2) => {
@@ -13789,7 +13982,7 @@ Task Status Values:
13789
13982
  if (msgs.length > 0) {
13790
13983
  const formatted2 = await formatAndMarkAsRead(msgs);
13791
13984
  const allTeamMessages2 = await getAllTeamMessagesForState();
13792
- const toolMessage2 = new import_langchain59.ToolMessage({
13985
+ const toolMessage2 = new import_langchain61.ToolMessage({
13793
13986
  content: formatted2,
13794
13987
  tool_call_id: config.toolCall?.id,
13795
13988
  name: "read_messages"
@@ -13821,7 +14014,7 @@ Task Status Values:
13821
14014
  );
13822
14015
  const allTeamMessages = await getAllTeamMessagesForState();
13823
14016
  if (msgs.length === 0) {
13824
- const toolMessage2 = new import_langchain59.ToolMessage({
14017
+ const toolMessage2 = new import_langchain61.ToolMessage({
13825
14018
  content: "No unread messages from teammates.",
13826
14019
  tool_call_id: config.toolCall?.id,
13827
14020
  name: "read_messages"
@@ -13831,7 +14024,7 @@ Task Status Values:
13831
14024
  });
13832
14025
  }
13833
14026
  const formatted = await formatAndMarkAsRead(msgs);
13834
- const toolMessage = new import_langchain59.ToolMessage({
14027
+ const toolMessage = new import_langchain61.ToolMessage({
13835
14028
  content: formatted,
13836
14029
  tool_call_id: config.toolCall?.id,
13837
14030
  name: "read_messages"
@@ -13848,7 +14041,7 @@ Task Status Values:
13848
14041
  })
13849
14042
  }
13850
14043
  );
13851
- const disbandTeamTool = (0, import_langchain59.tool)(
14044
+ const disbandTeamTool = (0, import_langchain61.tool)(
13852
14045
  async (input, config) => {
13853
14046
  const teamId = resolveTeamId();
13854
14047
  await mailboxStore.broadcastMessage(
@@ -13858,7 +14051,7 @@ Task Status Values:
13858
14051
  "shutdown_request" /* SHUTDOWN_REQUEST */
13859
14052
  );
13860
14053
  await new Promise((r) => setTimeout(r, 2e3));
13861
- return new import_langchain59.ToolMessage({
14054
+ return new import_langchain61.ToolMessage({
13862
14055
  content: `Team ${teamId} has been disbanded. All teammates notified and resources cleaned up.`,
13863
14056
  tool_call_id: config.toolCall?.id,
13864
14057
  name: "disband_team"
@@ -13869,7 +14062,7 @@ Task Status Values:
13869
14062
  description: "Disband a team when all work is done. Before calling: (1) Call check_tasks to verify no tasks are still pending/in_progress; (2) if any are, discuss with the team via read_messages and broadcast_message/send_message whether to continue or stop/cancel them; (3) only after alignment (all tasks completed/failed or explicitly stopped), then call this tool. This will: 1) Send a shutdown message to all teammates, 2) Wait briefly for them to clean up, 3) Clear all tasks and messages. Omit team_id to use the active team from state."
13870
14063
  }
13871
14064
  );
13872
- const broadcastMessageTool = (0, import_langchain59.tool)(
14065
+ const broadcastMessageTool = (0, import_langchain61.tool)(
13873
14066
  async (input, config) => {
13874
14067
  const teamId = resolveTeamId();
13875
14068
  await mailboxStore.broadcastMessage(
@@ -13878,7 +14071,7 @@ Task Status Values:
13878
14071
  input.content,
13879
14072
  "broadcast" /* BROADCAST */
13880
14073
  );
13881
- return new import_langchain59.ToolMessage({
14074
+ return new import_langchain61.ToolMessage({
13882
14075
  content: `Broadcast message sent to all teammates.`,
13883
14076
  tool_call_id: config.toolCall?.id,
13884
14077
  name: "broadcast_message"
@@ -13892,7 +14085,7 @@ Task Status Values:
13892
14085
  })
13893
14086
  }
13894
14087
  );
13895
- return (0, import_langchain59.createMiddleware)({
14088
+ return (0, import_langchain61.createMiddleware)({
13896
14089
  name: "teamMiddleware",
13897
14090
  tools: [
13898
14091
  createTeamTool,
@@ -14001,7 +14194,7 @@ function createAgentTeam(config) {
14001
14194
  ];
14002
14195
  const systemPrompt = config.systemPrompt + "\n\n" + TEAM_LEAD_BASE_PROMPT;
14003
14196
  const stateSchema2 = createReactAgentSchema(TEAM_STATE_SCHEMA);
14004
- return (0, import_langchain60.createAgent)({
14197
+ return (0, import_langchain62.createAgent)({
14005
14198
  model: config.model ?? "claude-sonnet-4-5-20250929",
14006
14199
  systemPrompt,
14007
14200
  tools: [],
@@ -14031,7 +14224,7 @@ var TeamAgentGraphBuilder = class {
14031
14224
  const tools = params.tools.map((t) => {
14032
14225
  const toolClient = getToolClient(t.key);
14033
14226
  return toolClient;
14034
- }).filter((tool50) => tool50 !== void 0);
14227
+ }).filter((tool51) => tool51 !== void 0);
14035
14228
  const teammates = params.subAgents.map((sa) => {
14036
14229
  const baseConfig = sa.config;
14037
14230
  return {
@@ -14756,6 +14949,9 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
14756
14949
  buffer2.expiresAt = Date.now() + this.config.ttl;
14757
14950
  buffer2.status = "active" /* ACTIVE */;
14758
14951
  }
14952
+ async ensureThread(threadId) {
14953
+ this.getOrCreateBuffer(threadId);
14954
+ }
14759
14955
  async completeThread(threadId) {
14760
14956
  const buffer2 = this.getBufferIfValid(threadId);
14761
14957
  if (buffer2) {
@@ -16900,10 +17096,10 @@ var McpLatticeManager = class _McpLatticeManager extends BaseLatticeManager {
16900
17096
  }
16901
17097
  const tools = await this.getAllTools();
16902
17098
  console.log(`[MCP] Registering ${tools.length} tools to Tool Lattice...`);
16903
- for (const tool50 of tools) {
16904
- const toolKey = prefix ? `${prefix}_${tool50.name}` : tool50.name;
16905
- tool50.name = toolKey;
16906
- toolLatticeManager.registerExistingTool(toolKey, tool50);
17099
+ for (const tool51 of tools) {
17100
+ const toolKey = prefix ? `${prefix}_${tool51.name}` : tool51.name;
17101
+ tool51.name = toolKey;
17102
+ toolLatticeManager.registerExistingTool(toolKey, tool51);
16907
17103
  console.log(`[MCP] Registered tool: ${toolKey}`);
16908
17104
  }
16909
17105
  console.log(`[MCP] Successfully registered ${tools.length} tools to Tool Lattice`);
@@ -16921,7 +17117,7 @@ var QueueMode = /* @__PURE__ */ ((QueueMode2) => {
16921
17117
 
16922
17118
  // src/services/Agent.ts
16923
17119
  var import_langgraph12 = require("@langchain/langgraph");
16924
- var import_langchain61 = require("langchain");
17120
+ var import_langchain63 = require("langchain");
16925
17121
  var import_uuid2 = require("uuid");
16926
17122
  var ThreadStatus2 = /* @__PURE__ */ ((ThreadStatus3) => {
16927
17123
  ThreadStatus3["IDLE"] = "idle";
@@ -17127,7 +17323,7 @@ var Agent = class {
17127
17323
  });
17128
17324
  const humanContent = p.content;
17129
17325
  const input = {
17130
- messages: [new import_langchain61.HumanMessage({ id: humanContent.id, content: humanContent.message })]
17326
+ messages: [new import_langchain63.HumanMessage({ id: humanContent.id, content: humanContent.message })]
17131
17327
  };
17132
17328
  if (files) {
17133
17329
  input.files = files;
@@ -17193,7 +17389,7 @@ var Agent = class {
17193
17389
  remainingPendings.forEach((p) => {
17194
17390
  this.queueStore?.markProcessing(p.id);
17195
17391
  const humanContent = p.content;
17196
- userMessages.push(new import_langchain61.HumanMessage({ id: humanContent.id, content: humanContent.message }));
17392
+ userMessages.push(new import_langchain63.HumanMessage({ id: humanContent.id, content: humanContent.message }));
17197
17393
  this.publish("message:started", {
17198
17394
  type: "message:started",
17199
17395
  messageId: humanContent.id,
@@ -17267,7 +17463,7 @@ var Agent = class {
17267
17463
  if (signal?.aborted) break;
17268
17464
  await this.queueStore?.markProcessing(p.id);
17269
17465
  const humanContent = p.content;
17270
- const message = new import_langchain61.HumanMessage({ id: humanContent.id, content: humanContent.message });
17466
+ const message = new import_langchain63.HumanMessage({ id: humanContent.id, content: humanContent.message });
17271
17467
  const startTime = Date.now();
17272
17468
  this.publish("message:started", {
17273
17469
  type: "message:started",
@@ -17410,7 +17606,7 @@ var Agent = class {
17410
17606
  const messageId = (0, import_uuid2.v4)();
17411
17607
  const input = {
17412
17608
  ...queueMessage.input,
17413
- messages: [new import_langchain61.HumanMessage({ id: messageId, content: queueMessage.input.message })]
17609
+ messages: [new import_langchain63.HumanMessage({ id: messageId, content: queueMessage.input.message })]
17414
17610
  };
17415
17611
  const inputMessage = { ...queueMessage, input };
17416
17612
  return this.agentExecutor(inputMessage, signal);
@@ -17510,6 +17706,7 @@ var Agent = class {
17510
17706
  id: messageId
17511
17707
  });
17512
17708
  }
17709
+ await this.chunkBuffer.ensureThread(this.thread_id);
17513
17710
  this.startQueueProcessorIfNeeded().catch((err) => {
17514
17711
  console.error("Failed to start queue processor:", err);
17515
17712
  });
@@ -17584,7 +17781,7 @@ var Agent = class {
17584
17781
  async getCurrentMessages() {
17585
17782
  const state = await this.getCurrentState();
17586
17783
  const messages = state.values.messages || [];
17587
- const filteredMessages = (0, import_langchain61.filterMessages)(messages, {
17784
+ const filteredMessages = (0, import_langchain63.filterMessages)(messages, {
17588
17785
  includeTypes: ["ai", "human", "tool"]
17589
17786
  //["human", "ai", "tool"],
17590
17787
  });
@@ -17643,12 +17840,16 @@ var Agent = class {
17643
17840
  /**
17644
17841
  * Abort the current agent execution
17645
17842
  * This will cancel any ongoing invoke or stream operations
17843
+ * and clear all queued messages (pending + processing)
17646
17844
  */
17647
- abort() {
17845
+ async abort() {
17648
17846
  if (this.abortController) {
17649
17847
  this.abortController.abort();
17650
17848
  this.abortController = null;
17651
17849
  }
17850
+ await this.chunkBuffer.abortThread(this.thread_id);
17851
+ const store = this.getQueueStore();
17852
+ await store.clearMessages(this.thread_id);
17652
17853
  }
17653
17854
  /**
17654
17855
  * Check if the agent is currently being aborted
@@ -17957,6 +18158,7 @@ function clearEncryptionKeyCache() {
17957
18158
  createQueryTablesListTool,
17958
18159
  createTeamMiddleware,
17959
18160
  createTeammateTools,
18161
+ createUnknownToolHandlerMiddleware,
17960
18162
  createWidgetMiddleware,
17961
18163
  decrypt,
17962
18164
  describeCronExpression,