@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.d.mts +57 -2
- package/dist/index.d.ts +57 -2
- package/dist/index.js +307 -105
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +368 -167
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -648,11 +648,11 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
|
|
|
648
648
|
* @param key Lattice键名
|
|
649
649
|
* @param tool 已有的StructuredTool实例
|
|
650
650
|
*/
|
|
651
|
-
registerExistingTool(key,
|
|
651
|
+
registerExistingTool(key, tool51) {
|
|
652
652
|
const config = {
|
|
653
|
-
name:
|
|
654
|
-
description:
|
|
655
|
-
schema:
|
|
653
|
+
name: tool51.name,
|
|
654
|
+
description: tool51.description,
|
|
655
|
+
schema: tool51.schema,
|
|
656
656
|
// StructuredTool的schema已经是Zod兼容的
|
|
657
657
|
needUserApprove: false
|
|
658
658
|
// MCP工具默认不需要用户批准
|
|
@@ -660,7 +660,7 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
|
|
|
660
660
|
const toolLattice = {
|
|
661
661
|
key,
|
|
662
662
|
config,
|
|
663
|
-
client:
|
|
663
|
+
client: tool51
|
|
664
664
|
};
|
|
665
665
|
this.register(key, toolLattice);
|
|
666
666
|
}
|
|
@@ -686,7 +686,7 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
|
|
|
686
686
|
};
|
|
687
687
|
var toolLatticeManager = ToolLatticeManager.getInstance();
|
|
688
688
|
var registerToolLattice = (key, config, executor) => toolLatticeManager.registerLattice(key, config, executor);
|
|
689
|
-
var registerExistingTool = (key,
|
|
689
|
+
var registerExistingTool = (key, tool51) => toolLatticeManager.registerExistingTool(key, tool51);
|
|
690
690
|
var getToolLattice = (key) => toolLatticeManager.getToolLattice(key);
|
|
691
691
|
var getToolDefinition = (key) => toolLatticeManager.getToolDefinition(key);
|
|
692
692
|
var getToolClient = (key) => toolLatticeManager.getToolClient(key);
|
|
@@ -9239,7 +9239,7 @@ function createShowWidgetTool() {
|
|
|
9239
9239
|
},
|
|
9240
9240
|
{
|
|
9241
9241
|
name: "show_widget",
|
|
9242
|
-
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.
|
|
9242
|
+
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.",
|
|
9243
9243
|
schema: ShowWidgetInputSchema
|
|
9244
9244
|
}
|
|
9245
9245
|
);
|
|
@@ -9770,9 +9770,198 @@ ${bootstrapSections.join("\n\n")}
|
|
|
9770
9770
|
});
|
|
9771
9771
|
}
|
|
9772
9772
|
|
|
9773
|
+
// src/middlewares/unknownToolHandlerMiddleware.ts
|
|
9774
|
+
import { createMiddleware as createMiddleware11 } from "langchain";
|
|
9775
|
+
import { AIMessage as AIMessage2, ToolMessage as ToolMessage3 } from "@langchain/core/messages";
|
|
9776
|
+
function createUnknownToolHandlerMiddleware(config = {}) {
|
|
9777
|
+
const {
|
|
9778
|
+
strategy = "error",
|
|
9779
|
+
errorMessageTemplate = (name, tools) => `Error: Tool "${name}" does not exist.
|
|
9780
|
+
|
|
9781
|
+
Available tools:
|
|
9782
|
+
` + tools.map((t) => ` - ${t}`).join("\n") + `
|
|
9783
|
+
|
|
9784
|
+
Please select a valid tool from the list above.`
|
|
9785
|
+
} = config;
|
|
9786
|
+
return createMiddleware11({
|
|
9787
|
+
name: "UnknownToolHandlerMiddleware",
|
|
9788
|
+
/**
|
|
9789
|
+
* wrapModelCall hook
|
|
9790
|
+
*
|
|
9791
|
+
* The only place to access request.tools (all available tools).
|
|
9792
|
+
* Identifies unknown tools and stores error info in metadata.
|
|
9793
|
+
*
|
|
9794
|
+
* Key: Preserve all tool_calls in original AIMessage, including unknown ones.
|
|
9795
|
+
* This allows the model to see what it selected in the next round.
|
|
9796
|
+
*/
|
|
9797
|
+
wrapModelCall: async (request, handler) => {
|
|
9798
|
+
const availableTools = request.tools || [];
|
|
9799
|
+
const availableToolNames = availableTools.map((t) => t.name);
|
|
9800
|
+
const availableToolSet = new Set(availableToolNames);
|
|
9801
|
+
const aiResponse = await handler(request);
|
|
9802
|
+
if (!aiResponse.tool_calls || aiResponse.tool_calls.length === 0) {
|
|
9803
|
+
return aiResponse;
|
|
9804
|
+
}
|
|
9805
|
+
const unknownToolCalls = [];
|
|
9806
|
+
for (const toolCall of aiResponse.tool_calls) {
|
|
9807
|
+
if (!availableToolSet.has(toolCall.name)) {
|
|
9808
|
+
unknownToolCalls.push(toolCall);
|
|
9809
|
+
}
|
|
9810
|
+
}
|
|
9811
|
+
if (unknownToolCalls.length === 0) {
|
|
9812
|
+
return aiResponse;
|
|
9813
|
+
}
|
|
9814
|
+
if (strategy === "strict") {
|
|
9815
|
+
const unknownNames = unknownToolCalls.map((t) => t.name).join(", ");
|
|
9816
|
+
throw new Error(
|
|
9817
|
+
`Unknown tools detected: ${unknownNames}. Available tools: ${availableToolNames.join(", ")}`
|
|
9818
|
+
);
|
|
9819
|
+
}
|
|
9820
|
+
const unknownToolErrors = unknownToolCalls.map((toolCall) => ({
|
|
9821
|
+
toolName: toolCall.name,
|
|
9822
|
+
toolCallId: toolCall.id,
|
|
9823
|
+
errorMessage: errorMessageTemplate(toolCall.name, availableToolNames)
|
|
9824
|
+
}));
|
|
9825
|
+
const modifiedResponse = new AIMessage2({
|
|
9826
|
+
content: aiResponse.content,
|
|
9827
|
+
tool_calls: aiResponse.tool_calls,
|
|
9828
|
+
// Key: preserve all tool_calls, don't delete unknown
|
|
9829
|
+
response_metadata: {
|
|
9830
|
+
...aiResponse.response_metadata,
|
|
9831
|
+
_unknownToolErrors: unknownToolErrors
|
|
9832
|
+
}
|
|
9833
|
+
});
|
|
9834
|
+
if (aiResponse.id) {
|
|
9835
|
+
modifiedResponse.id = aiResponse.id;
|
|
9836
|
+
}
|
|
9837
|
+
return modifiedResponse;
|
|
9838
|
+
},
|
|
9839
|
+
/**
|
|
9840
|
+
* afterModel hook
|
|
9841
|
+
*
|
|
9842
|
+
* Processes unknown tool errors stored in metadata.
|
|
9843
|
+
* Generates error ToolMessages and jumps back to model.
|
|
9844
|
+
*
|
|
9845
|
+
* Key: Uses jumpTo: "model" to form agent loop.
|
|
9846
|
+
* Without jumpTo, the graph would end after ToolNode without returning to model.
|
|
9847
|
+
*/
|
|
9848
|
+
afterModel: {
|
|
9849
|
+
canJumpTo: ["model"],
|
|
9850
|
+
hook: async (state) => {
|
|
9851
|
+
const { messages } = state;
|
|
9852
|
+
if (!messages || messages.length === 0) {
|
|
9853
|
+
return;
|
|
9854
|
+
}
|
|
9855
|
+
const lastMessage = messages[messages.length - 1];
|
|
9856
|
+
if (!AIMessage2.isInstance(lastMessage)) {
|
|
9857
|
+
return;
|
|
9858
|
+
}
|
|
9859
|
+
const unknownToolErrors = lastMessage.response_metadata?._unknownToolErrors;
|
|
9860
|
+
if (!unknownToolErrors || !Array.isArray(unknownToolErrors) || unknownToolErrors.length === 0) {
|
|
9861
|
+
return;
|
|
9862
|
+
}
|
|
9863
|
+
const errorToolMessages = unknownToolErrors.map(
|
|
9864
|
+
(error) => new ToolMessage3({
|
|
9865
|
+
content: error.errorMessage,
|
|
9866
|
+
name: error.toolName,
|
|
9867
|
+
tool_call_id: error.toolCallId,
|
|
9868
|
+
status: "error"
|
|
9869
|
+
})
|
|
9870
|
+
);
|
|
9871
|
+
delete lastMessage.response_metadata._unknownToolErrors;
|
|
9872
|
+
return {
|
|
9873
|
+
messages: errorToolMessages,
|
|
9874
|
+
jumpTo: "model"
|
|
9875
|
+
};
|
|
9876
|
+
}
|
|
9877
|
+
}
|
|
9878
|
+
});
|
|
9879
|
+
}
|
|
9880
|
+
|
|
9881
|
+
// src/deep_agent_new/middleware/date.ts
|
|
9882
|
+
import { createMiddleware as createMiddleware12, tool as tool46 } from "langchain";
|
|
9883
|
+
import { z as z47 } from "zod";
|
|
9884
|
+
function formatCurrentDate(timezone = "UTC") {
|
|
9885
|
+
const now = /* @__PURE__ */ new Date();
|
|
9886
|
+
let validTimezone = timezone;
|
|
9887
|
+
try {
|
|
9888
|
+
Intl.DateTimeFormat(void 0, { timeZone: timezone });
|
|
9889
|
+
} catch {
|
|
9890
|
+
validTimezone = "UTC";
|
|
9891
|
+
}
|
|
9892
|
+
const dateFormatOptions = {
|
|
9893
|
+
timeZone: validTimezone,
|
|
9894
|
+
year: "numeric",
|
|
9895
|
+
month: "2-digit",
|
|
9896
|
+
day: "2-digit"
|
|
9897
|
+
};
|
|
9898
|
+
return new Intl.DateTimeFormat("en-US", dateFormatOptions).format(now);
|
|
9899
|
+
}
|
|
9900
|
+
function generateDateContext(timezone = "UTC") {
|
|
9901
|
+
const formattedDate = formatCurrentDate(timezone);
|
|
9902
|
+
if (timezone === "UTC") {
|
|
9903
|
+
return `Current Date: ${formattedDate}`;
|
|
9904
|
+
}
|
|
9905
|
+
const utcDate = formatCurrentDate("UTC");
|
|
9906
|
+
return `Current Date: ${formattedDate} (UTC: ${utcDate})`;
|
|
9907
|
+
}
|
|
9908
|
+
function createDateMiddleware(options = {}) {
|
|
9909
|
+
const timezone = options.timezone || "UTC";
|
|
9910
|
+
const dateContext = generateDateContext(timezone);
|
|
9911
|
+
return createMiddleware12({
|
|
9912
|
+
name: "DateMiddleware",
|
|
9913
|
+
tools: [
|
|
9914
|
+
tool46(
|
|
9915
|
+
async () => {
|
|
9916
|
+
const now = /* @__PURE__ */ new Date();
|
|
9917
|
+
let validTimezone = timezone;
|
|
9918
|
+
try {
|
|
9919
|
+
Intl.DateTimeFormat(void 0, { timeZone: timezone });
|
|
9920
|
+
} catch {
|
|
9921
|
+
validTimezone = "UTC";
|
|
9922
|
+
}
|
|
9923
|
+
const localTimeOptions = {
|
|
9924
|
+
timeZone: validTimezone,
|
|
9925
|
+
year: "numeric",
|
|
9926
|
+
month: "2-digit",
|
|
9927
|
+
day: "2-digit",
|
|
9928
|
+
hour: "2-digit",
|
|
9929
|
+
minute: "2-digit",
|
|
9930
|
+
second: "2-digit",
|
|
9931
|
+
hour12: false
|
|
9932
|
+
};
|
|
9933
|
+
const localTime = new Intl.DateTimeFormat("en-US", localTimeOptions).format(now);
|
|
9934
|
+
return JSON.stringify({
|
|
9935
|
+
local_time: `${localTime} (${validTimezone})`,
|
|
9936
|
+
iso_date: now.toISOString().split("T")[0],
|
|
9937
|
+
timestamp: now.toISOString(),
|
|
9938
|
+
timezone: validTimezone
|
|
9939
|
+
});
|
|
9940
|
+
},
|
|
9941
|
+
{
|
|
9942
|
+
name: "get_current_date_time",
|
|
9943
|
+
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.",
|
|
9944
|
+
schema: z47.object({})
|
|
9945
|
+
}
|
|
9946
|
+
)
|
|
9947
|
+
],
|
|
9948
|
+
wrapModelCall: async (request, handler) => {
|
|
9949
|
+
const currentSystemPrompt = request.systemPrompt || "";
|
|
9950
|
+
const newSystemPrompt = currentSystemPrompt ? `${dateContext}
|
|
9951
|
+
|
|
9952
|
+
${currentSystemPrompt}` : dateContext;
|
|
9953
|
+
return handler({
|
|
9954
|
+
...request,
|
|
9955
|
+
systemPrompt: newSystemPrompt
|
|
9956
|
+
});
|
|
9957
|
+
}
|
|
9958
|
+
});
|
|
9959
|
+
}
|
|
9960
|
+
|
|
9773
9961
|
// src/agent_lattice/builders/commonMiddleware.ts
|
|
9774
9962
|
async function createCommonMiddlewares(middlewareConfigs, filesystemBackend) {
|
|
9775
9963
|
const middlewares = [];
|
|
9964
|
+
middlewares.push(createUnknownToolHandlerMiddleware());
|
|
9776
9965
|
middlewares.push(createModelSelectorMiddleware());
|
|
9777
9966
|
const filesystemConfig = middlewareConfigs.find((m) => m.type === "filesystem");
|
|
9778
9967
|
if (filesystemConfig?.enabled && filesystemBackend) {
|
|
@@ -9833,6 +10022,9 @@ async function createCommonMiddlewares(middlewareConfigs, filesystemBackend) {
|
|
|
9833
10022
|
}));
|
|
9834
10023
|
}
|
|
9835
10024
|
break;
|
|
10025
|
+
case "date":
|
|
10026
|
+
middlewares.push(createDateMiddleware(config.config));
|
|
10027
|
+
break;
|
|
9836
10028
|
}
|
|
9837
10029
|
}
|
|
9838
10030
|
return middlewares;
|
|
@@ -9886,9 +10078,9 @@ var ReActAgentGraphBuilder = class {
|
|
|
9886
10078
|
*/
|
|
9887
10079
|
async build(agentLattice, params) {
|
|
9888
10080
|
const tools = params.tools.map((t) => {
|
|
9889
|
-
const
|
|
9890
|
-
return
|
|
9891
|
-
}).filter((
|
|
10081
|
+
const tool51 = getToolClient(t.key);
|
|
10082
|
+
return tool51;
|
|
10083
|
+
}).filter((tool51) => tool51 !== void 0);
|
|
9892
10084
|
const stateSchema2 = createReactAgentSchema(params.stateSchema);
|
|
9893
10085
|
const middlewareConfigs = params.middleware || [];
|
|
9894
10086
|
const filesystemBackend = this.createFilesystemBackendFactory(middlewareConfigs, agentLattice);
|
|
@@ -9914,12 +10106,12 @@ import {
|
|
|
9914
10106
|
} from "langchain";
|
|
9915
10107
|
|
|
9916
10108
|
// src/deep_agent_new/middleware/subagents.ts
|
|
9917
|
-
import { z as
|
|
10109
|
+
import { z as z48 } from "zod/v3";
|
|
9918
10110
|
import {
|
|
9919
|
-
createMiddleware as
|
|
10111
|
+
createMiddleware as createMiddleware13,
|
|
9920
10112
|
createAgent as createAgent2,
|
|
9921
|
-
tool as
|
|
9922
|
-
ToolMessage as
|
|
10113
|
+
tool as tool47,
|
|
10114
|
+
ToolMessage as ToolMessage4,
|
|
9923
10115
|
humanInTheLoopMiddleware
|
|
9924
10116
|
} from "langchain";
|
|
9925
10117
|
import { Command as Command2, getCurrentTaskInput as getCurrentTaskInput2, GraphInterrupt as GraphInterrupt3 } from "@langchain/langgraph";
|
|
@@ -10490,7 +10682,7 @@ function returnCommandWithStateUpdate(result, toolCallId) {
|
|
|
10490
10682
|
update: {
|
|
10491
10683
|
...stateUpdate,
|
|
10492
10684
|
messages: [
|
|
10493
|
-
new
|
|
10685
|
+
new ToolMessage4({
|
|
10494
10686
|
content: lastMessage?.content || "Task Failed to complete",
|
|
10495
10687
|
tool_call_id: toolCallId,
|
|
10496
10688
|
name: "task"
|
|
@@ -10572,7 +10764,7 @@ function createTaskTool(options) {
|
|
|
10572
10764
|
generalPurposeAgent
|
|
10573
10765
|
});
|
|
10574
10766
|
const finalTaskDescription = taskDescription ? taskDescription : getTaskToolDescription(subagentDescriptions);
|
|
10575
|
-
return
|
|
10767
|
+
return tool47(
|
|
10576
10768
|
async (input, config) => {
|
|
10577
10769
|
const { description, subagent_type } = input;
|
|
10578
10770
|
let assistant_id = subagent_type;
|
|
@@ -10626,7 +10818,7 @@ function createTaskTool(options) {
|
|
|
10626
10818
|
return new Command2({
|
|
10627
10819
|
update: {
|
|
10628
10820
|
messages: [
|
|
10629
|
-
new
|
|
10821
|
+
new ToolMessage4({
|
|
10630
10822
|
content: error instanceof Error ? error.message : "Task Failed to complete",
|
|
10631
10823
|
tool_call_id: config.toolCall.id,
|
|
10632
10824
|
name: "task"
|
|
@@ -10639,9 +10831,9 @@ function createTaskTool(options) {
|
|
|
10639
10831
|
{
|
|
10640
10832
|
name: "task",
|
|
10641
10833
|
description: finalTaskDescription,
|
|
10642
|
-
schema:
|
|
10643
|
-
description:
|
|
10644
|
-
subagent_type:
|
|
10834
|
+
schema: z48.object({
|
|
10835
|
+
description: z48.string().describe("The task to execute with the selected agent"),
|
|
10836
|
+
subagent_type: z48.string().describe(
|
|
10645
10837
|
`Name of the agent to use. Available: ${Object.keys(
|
|
10646
10838
|
subagentGraphs
|
|
10647
10839
|
).join(", ")}`
|
|
@@ -10670,7 +10862,7 @@ function createSubAgentMiddleware(options) {
|
|
|
10670
10862
|
generalPurposeAgent,
|
|
10671
10863
|
taskDescription
|
|
10672
10864
|
});
|
|
10673
|
-
return
|
|
10865
|
+
return createMiddleware13({
|
|
10674
10866
|
name: "subAgentMiddleware",
|
|
10675
10867
|
tools: [taskTool],
|
|
10676
10868
|
wrapModelCall: async (request, handler) => {
|
|
@@ -10691,14 +10883,14 @@ ${systemPrompt}` : systemPrompt;
|
|
|
10691
10883
|
|
|
10692
10884
|
// src/deep_agent_new/middleware/patch_tool_calls.ts
|
|
10693
10885
|
import {
|
|
10694
|
-
createMiddleware as
|
|
10695
|
-
ToolMessage as
|
|
10696
|
-
AIMessage as
|
|
10886
|
+
createMiddleware as createMiddleware14,
|
|
10887
|
+
ToolMessage as ToolMessage5,
|
|
10888
|
+
AIMessage as AIMessage3
|
|
10697
10889
|
} from "langchain";
|
|
10698
10890
|
import { RemoveMessage } from "@langchain/core/messages";
|
|
10699
10891
|
import { REMOVE_ALL_MESSAGES } from "@langchain/langgraph";
|
|
10700
10892
|
function createPatchToolCallsMiddleware() {
|
|
10701
|
-
return
|
|
10893
|
+
return createMiddleware14({
|
|
10702
10894
|
name: "patchToolCallsMiddleware",
|
|
10703
10895
|
beforeAgent: async (state) => {
|
|
10704
10896
|
const messages = state.messages;
|
|
@@ -10709,15 +10901,15 @@ function createPatchToolCallsMiddleware() {
|
|
|
10709
10901
|
for (let i = 0; i < messages.length; i++) {
|
|
10710
10902
|
const msg = messages[i];
|
|
10711
10903
|
patchedMessages.push(msg);
|
|
10712
|
-
if (
|
|
10904
|
+
if (AIMessage3.isInstance(msg) && msg.tool_calls != null) {
|
|
10713
10905
|
for (const toolCall of msg.tool_calls) {
|
|
10714
10906
|
const correspondingToolMsg = messages.slice(i).find(
|
|
10715
|
-
(m) =>
|
|
10907
|
+
(m) => ToolMessage5.isInstance(m) && m.tool_call_id === toolCall.id
|
|
10716
10908
|
);
|
|
10717
10909
|
if (!correspondingToolMsg) {
|
|
10718
10910
|
const toolMsg = `Tool call ${toolCall.name} with id ${toolCall.id} was cancelled - another message came in before it could be completed.`;
|
|
10719
10911
|
patchedMessages.push(
|
|
10720
|
-
new
|
|
10912
|
+
new ToolMessage5({
|
|
10721
10913
|
content: toolMsg,
|
|
10722
10914
|
name: toolCall.name,
|
|
10723
10915
|
tool_call_id: toolCall.id
|
|
@@ -11834,8 +12026,8 @@ var MemoryBackend = class {
|
|
|
11834
12026
|
|
|
11835
12027
|
// src/deep_agent_new/middleware/todos.ts
|
|
11836
12028
|
import { Command as Command3 } from "@langchain/langgraph";
|
|
11837
|
-
import { z as
|
|
11838
|
-
import { createMiddleware as
|
|
12029
|
+
import { z as z49 } from "zod";
|
|
12030
|
+
import { createMiddleware as createMiddleware15, tool as tool48, ToolMessage as ToolMessage6 } from "langchain";
|
|
11839
12031
|
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.
|
|
11840
12032
|
It also helps the user understand the progress of the task and overall progress of their requests.
|
|
11841
12033
|
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.
|
|
@@ -12062,20 +12254,20 @@ Writing todos takes time and tokens, use it when it is helpful for managing comp
|
|
|
12062
12254
|
## Important To-Do List Usage Notes to Remember
|
|
12063
12255
|
- The \`write_todos\` tool should never be called multiple times in parallel.
|
|
12064
12256
|
- 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.`;
|
|
12065
|
-
var TodoStatus =
|
|
12066
|
-
var TodoSchema =
|
|
12067
|
-
content:
|
|
12257
|
+
var TodoStatus = z49.enum(["pending", "in_progress", "completed"]).describe("Status of the todo");
|
|
12258
|
+
var TodoSchema = z49.object({
|
|
12259
|
+
content: z49.string().describe("Content of the todo item"),
|
|
12068
12260
|
status: TodoStatus
|
|
12069
12261
|
});
|
|
12070
|
-
var stateSchema =
|
|
12262
|
+
var stateSchema = z49.object({ todos: z49.array(TodoSchema).default([]) });
|
|
12071
12263
|
function todoListMiddleware(options) {
|
|
12072
|
-
const writeTodos =
|
|
12264
|
+
const writeTodos = tool48(
|
|
12073
12265
|
({ todos }, config) => {
|
|
12074
12266
|
return new Command3({
|
|
12075
12267
|
update: {
|
|
12076
12268
|
todos,
|
|
12077
12269
|
messages: [
|
|
12078
|
-
new
|
|
12270
|
+
new ToolMessage6({
|
|
12079
12271
|
content: genUIMarkdown("todo_list", todos),
|
|
12080
12272
|
tool_call_id: config.toolCall?.id
|
|
12081
12273
|
})
|
|
@@ -12086,12 +12278,12 @@ function todoListMiddleware(options) {
|
|
|
12086
12278
|
{
|
|
12087
12279
|
name: "write_todos",
|
|
12088
12280
|
description: options?.toolDescription ?? WRITE_TODOS_DESCRIPTION,
|
|
12089
|
-
schema:
|
|
12090
|
-
todos:
|
|
12281
|
+
schema: z49.object({
|
|
12282
|
+
todos: z49.array(TodoSchema).describe("List of todo items to update")
|
|
12091
12283
|
})
|
|
12092
12284
|
}
|
|
12093
12285
|
);
|
|
12094
|
-
return
|
|
12286
|
+
return createMiddleware15({
|
|
12095
12287
|
name: "todoListMiddleware",
|
|
12096
12288
|
stateSchema,
|
|
12097
12289
|
tools: [writeTodos],
|
|
@@ -12245,7 +12437,7 @@ var DeepAgentGraphBuilder = class {
|
|
|
12245
12437
|
const tools = params.tools.map((t) => {
|
|
12246
12438
|
const toolClient = getToolClient(t.key);
|
|
12247
12439
|
return toolClient;
|
|
12248
|
-
}).filter((
|
|
12440
|
+
}).filter((tool51) => tool51 !== void 0);
|
|
12249
12441
|
const subagents = await Promise.all(params.subAgents.map(async (sa) => {
|
|
12250
12442
|
if (sa.client) {
|
|
12251
12443
|
return {
|
|
@@ -12285,7 +12477,7 @@ var DeepAgentGraphBuilder = class {
|
|
|
12285
12477
|
};
|
|
12286
12478
|
|
|
12287
12479
|
// src/agent_team/agent_team.ts
|
|
12288
|
-
import { z as
|
|
12480
|
+
import { z as z52 } from "zod/v3";
|
|
12289
12481
|
import { createAgent as createAgent5 } from "langchain";
|
|
12290
12482
|
|
|
12291
12483
|
// src/agent_team/types.ts
|
|
@@ -12721,14 +12913,14 @@ var InMemoryMailboxStore = class {
|
|
|
12721
12913
|
};
|
|
12722
12914
|
|
|
12723
12915
|
// src/agent_team/middleware/team.ts
|
|
12724
|
-
import { z as
|
|
12725
|
-
import { createMiddleware as
|
|
12916
|
+
import { z as z51 } from "zod/v3";
|
|
12917
|
+
import { createMiddleware as createMiddleware16, createAgent as createAgent4, tool as tool50, ToolMessage as ToolMessage8 } from "langchain";
|
|
12726
12918
|
import { Command as Command5, getCurrentTaskInput as getCurrentTaskInput3 } from "@langchain/langgraph";
|
|
12727
12919
|
import { v4 as uuidv4 } from "uuid";
|
|
12728
12920
|
|
|
12729
12921
|
// src/agent_team/middleware/teammate_tools.ts
|
|
12730
|
-
import { z as
|
|
12731
|
-
import { tool as
|
|
12922
|
+
import { z as z50 } from "zod/v3";
|
|
12923
|
+
import { tool as tool49, ToolMessage as ToolMessage7 } from "langchain";
|
|
12732
12924
|
import { Command as Command4 } from "@langchain/langgraph";
|
|
12733
12925
|
|
|
12734
12926
|
// src/agent_team/middleware/formatMessages.ts
|
|
@@ -12753,7 +12945,7 @@ ${meta}${body}`;
|
|
|
12753
12945
|
// src/agent_team/middleware/teammate_tools.ts
|
|
12754
12946
|
function createTeammateTools(options) {
|
|
12755
12947
|
const { teamId, agentId, taskListStore, mailboxStore } = options;
|
|
12756
|
-
const claimTaskTool =
|
|
12948
|
+
const claimTaskTool = tool49(
|
|
12757
12949
|
async (input) => {
|
|
12758
12950
|
const task = await taskListStore.claimTaskById(
|
|
12759
12951
|
teamId,
|
|
@@ -12778,12 +12970,12 @@ function createTeammateTools(options) {
|
|
|
12778
12970
|
{
|
|
12779
12971
|
name: "claim_task",
|
|
12780
12972
|
description: "Pick a task to work on by task_id. Use check_tasks first to see all tasks; then call this with the task_id you choose. The task's assignee is set to you and you should focus on that task until you complete_task or fail_task it.",
|
|
12781
|
-
schema:
|
|
12782
|
-
task_id:
|
|
12973
|
+
schema: z50.object({
|
|
12974
|
+
task_id: z50.string().describe("ID of the task to claim (e.g. task-01). Use check_tasks to see IDs.")
|
|
12783
12975
|
})
|
|
12784
12976
|
}
|
|
12785
12977
|
);
|
|
12786
|
-
const completeTaskTool =
|
|
12978
|
+
const completeTaskTool = tool49(
|
|
12787
12979
|
async (input) => {
|
|
12788
12980
|
const task = await taskListStore.completeTask(
|
|
12789
12981
|
teamId,
|
|
@@ -12804,13 +12996,13 @@ function createTeammateTools(options) {
|
|
|
12804
12996
|
{
|
|
12805
12997
|
name: "complete_task",
|
|
12806
12998
|
description: "Mark a claimed task as completed with a result summary. Call this after you have finished working on a task.",
|
|
12807
|
-
schema:
|
|
12808
|
-
task_id:
|
|
12809
|
-
result:
|
|
12999
|
+
schema: z50.object({
|
|
13000
|
+
task_id: z50.string().describe("ID of the task to complete"),
|
|
13001
|
+
result: z50.string().describe("Summary of the task result")
|
|
12810
13002
|
})
|
|
12811
13003
|
}
|
|
12812
13004
|
);
|
|
12813
|
-
const failTaskTool =
|
|
13005
|
+
const failTaskTool = tool49(
|
|
12814
13006
|
async (input) => {
|
|
12815
13007
|
const task = await taskListStore.failTask(
|
|
12816
13008
|
teamId,
|
|
@@ -12831,13 +13023,13 @@ function createTeammateTools(options) {
|
|
|
12831
13023
|
{
|
|
12832
13024
|
name: "fail_task",
|
|
12833
13025
|
description: "Mark a claimed task as failed with an error description. Call this if you cannot complete the task.",
|
|
12834
|
-
schema:
|
|
12835
|
-
task_id:
|
|
12836
|
-
error:
|
|
13026
|
+
schema: z50.object({
|
|
13027
|
+
task_id: z50.string().describe("ID of the task to fail"),
|
|
13028
|
+
error: z50.string().describe("Description of why the task failed")
|
|
12837
13029
|
})
|
|
12838
13030
|
}
|
|
12839
13031
|
);
|
|
12840
|
-
const sendMessageTool =
|
|
13032
|
+
const sendMessageTool = tool49(
|
|
12841
13033
|
async (input) => {
|
|
12842
13034
|
await mailboxStore.sendMessage(
|
|
12843
13035
|
teamId,
|
|
@@ -12851,11 +13043,11 @@ function createTeammateTools(options) {
|
|
|
12851
13043
|
{
|
|
12852
13044
|
name: "send_message",
|
|
12853
13045
|
description: 'Send a message to the team lead or another teammate via the mailbox. Use "team_lead" to message the team lead. Use this to report discoveries, request guidance, or suggest new tasks.',
|
|
12854
|
-
schema:
|
|
12855
|
-
to:
|
|
13046
|
+
schema: z50.object({
|
|
13047
|
+
to: z50.string().describe(
|
|
12856
13048
|
'Recipient agent name (e.g. "team_lead" or a teammate name)'
|
|
12857
13049
|
),
|
|
12858
|
-
content:
|
|
13050
|
+
content: z50.string().describe("Message content")
|
|
12859
13051
|
})
|
|
12860
13052
|
}
|
|
12861
13053
|
);
|
|
@@ -12875,7 +13067,7 @@ function createTeammateTools(options) {
|
|
|
12875
13067
|
read: msg.read
|
|
12876
13068
|
}));
|
|
12877
13069
|
};
|
|
12878
|
-
const readMessagesTool =
|
|
13070
|
+
const readMessagesTool = tool49(
|
|
12879
13071
|
async (input, config) => {
|
|
12880
13072
|
const formatAndMarkAsRead = async (msgs2) => {
|
|
12881
13073
|
for (const msg of msgs2) {
|
|
@@ -12887,7 +13079,7 @@ function createTeammateTools(options) {
|
|
|
12887
13079
|
if (msgs.length > 0) {
|
|
12888
13080
|
const formatted2 = await formatAndMarkAsRead(msgs);
|
|
12889
13081
|
const relevantMsgs2 = await getRelevantMessagesForState();
|
|
12890
|
-
const toolMessage2 = new
|
|
13082
|
+
const toolMessage2 = new ToolMessage7({
|
|
12891
13083
|
content: formatted2,
|
|
12892
13084
|
tool_call_id: config.toolCall?.id,
|
|
12893
13085
|
name: "read_messages"
|
|
@@ -12912,7 +13104,7 @@ function createTeammateTools(options) {
|
|
|
12912
13104
|
});
|
|
12913
13105
|
const relevantMsgs = await getRelevantMessagesForState();
|
|
12914
13106
|
if (msgs.length === 0) {
|
|
12915
|
-
const toolMessage2 = new
|
|
13107
|
+
const toolMessage2 = new ToolMessage7({
|
|
12916
13108
|
content: "No unread messages.",
|
|
12917
13109
|
tool_call_id: config.toolCall?.id,
|
|
12918
13110
|
name: "read_messages"
|
|
@@ -12922,7 +13114,7 @@ function createTeammateTools(options) {
|
|
|
12922
13114
|
});
|
|
12923
13115
|
}
|
|
12924
13116
|
const formatted = await formatAndMarkAsRead(msgs);
|
|
12925
|
-
const toolMessage = new
|
|
13117
|
+
const toolMessage = new ToolMessage7({
|
|
12926
13118
|
content: formatted,
|
|
12927
13119
|
tool_call_id: config.toolCall?.id,
|
|
12928
13120
|
name: "read_messages"
|
|
@@ -12934,10 +13126,10 @@ function createTeammateTools(options) {
|
|
|
12934
13126
|
{
|
|
12935
13127
|
name: "read_messages",
|
|
12936
13128
|
description: "Read unread messages from the mailbox. Returns immediately if messages exist, otherwise waits for up to 3 minutes for new messages.",
|
|
12937
|
-
schema:
|
|
13129
|
+
schema: z50.object({})
|
|
12938
13130
|
}
|
|
12939
13131
|
);
|
|
12940
|
-
const checkTasksTool =
|
|
13132
|
+
const checkTasksTool = tool49(
|
|
12941
13133
|
async () => {
|
|
12942
13134
|
const tasks = await taskListStore.getAllTasks(teamId);
|
|
12943
13135
|
return formatTaskSummary(tasks);
|
|
@@ -12945,10 +13137,10 @@ function createTeammateTools(options) {
|
|
|
12945
13137
|
{
|
|
12946
13138
|
name: "check_tasks",
|
|
12947
13139
|
description: "Use this tool to get the current status of all tasks in a team. This is your primary way to monitor task progress.",
|
|
12948
|
-
schema:
|
|
13140
|
+
schema: z50.object({})
|
|
12949
13141
|
}
|
|
12950
13142
|
);
|
|
12951
|
-
const broadcastMessageTool =
|
|
13143
|
+
const broadcastMessageTool = tool49(
|
|
12952
13144
|
async (input) => {
|
|
12953
13145
|
const allAgents = await mailboxStore.getRegisteredAgents(teamId);
|
|
12954
13146
|
const recipients = allAgents.filter((a) => a !== agentId);
|
|
@@ -12967,8 +13159,8 @@ function createTeammateTools(options) {
|
|
|
12967
13159
|
{
|
|
12968
13160
|
name: "broadcast_message",
|
|
12969
13161
|
description: "Send a message to everyone in the team except yourself. Use this to share updates or information with all teammates and the team lead at once.",
|
|
12970
|
-
schema:
|
|
12971
|
-
content:
|
|
13162
|
+
schema: z50.object({
|
|
13163
|
+
content: z50.string().describe("Message content to broadcast to others")
|
|
12972
13164
|
})
|
|
12973
13165
|
}
|
|
12974
13166
|
);
|
|
@@ -13202,12 +13394,12 @@ async function spawnTeammate(options) {
|
|
|
13202
13394
|
function createTeamMiddleware(options) {
|
|
13203
13395
|
const { teamConfig, taskListStore, mailboxStore, tenantId } = options;
|
|
13204
13396
|
const defaultModel = teamConfig.model ?? "claude-sonnet-4-5-20250929";
|
|
13205
|
-
const createTeamTool =
|
|
13397
|
+
const createTeamTool = tool50(
|
|
13206
13398
|
async (input, config) => {
|
|
13207
13399
|
const state = getCurrentTaskInput3();
|
|
13208
13400
|
if (state?.team?.teamId) {
|
|
13209
13401
|
const existingId = state.team.teamId;
|
|
13210
|
-
const msg = new
|
|
13402
|
+
const msg = new ToolMessage8({
|
|
13211
13403
|
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.`,
|
|
13212
13404
|
tool_call_id: config.toolCall?.id,
|
|
13213
13405
|
name: "create_team"
|
|
@@ -13296,7 +13488,7 @@ Teammates are now working in the background. Keep calling \`check_tasks\` and \`
|
|
|
13296
13488
|
\`\`\`json
|
|
13297
13489
|
${teamJson}
|
|
13298
13490
|
\`\`\``;
|
|
13299
|
-
const toolMessage = new
|
|
13491
|
+
const toolMessage = new ToolMessage8({
|
|
13300
13492
|
content: summary,
|
|
13301
13493
|
tool_call_id: config.toolCall?.id,
|
|
13302
13494
|
name: "create_team"
|
|
@@ -13357,20 +13549,20 @@ After calling create_team, you MUST:
|
|
|
13357
13549
|
2. When messages indicate task changes, call check_tasks to get full task status
|
|
13358
13550
|
3. Continue until all tasks show "completed" or "failed"
|
|
13359
13551
|
4. Do NOT assume tasks are done - always verify with check_tasks`,
|
|
13360
|
-
schema:
|
|
13361
|
-
tasks:
|
|
13362
|
-
|
|
13363
|
-
id:
|
|
13364
|
-
title:
|
|
13365
|
-
description:
|
|
13366
|
-
dependencies:
|
|
13552
|
+
schema: z51.object({
|
|
13553
|
+
tasks: z51.array(
|
|
13554
|
+
z51.object({
|
|
13555
|
+
id: z51.string().describe("Task ID in format task-01, task-02, etc."),
|
|
13556
|
+
title: z51.string().describe("Short task title"),
|
|
13557
|
+
description: z51.string().describe("Detailed task description - what exactly needs to be done"),
|
|
13558
|
+
dependencies: z51.array(z51.string()).optional().default([]).describe('Array of task IDs that must complete before this task (e.g. ["task-01"])')
|
|
13367
13559
|
})
|
|
13368
13560
|
).describe("List of tasks for teammates to work on. Each task needs unique ID (task-01, task-02, etc.)."),
|
|
13369
|
-
teammates:
|
|
13370
|
-
|
|
13371
|
-
name:
|
|
13372
|
-
role:
|
|
13373
|
-
description:
|
|
13561
|
+
teammates: z51.array(
|
|
13562
|
+
z51.object({
|
|
13563
|
+
name: z51.string().describe("Teammate name (must match a pre-configured teammate type)"),
|
|
13564
|
+
role: z51.string().describe("Role category (e.g. researcher, writer, coder, reviewer)"),
|
|
13565
|
+
description: z51.string().describe("What this teammate will focus on - specific instructions for their work")
|
|
13374
13566
|
})
|
|
13375
13567
|
).describe("Teammate agents to create. Each should have a clear role and focus.")
|
|
13376
13568
|
})
|
|
@@ -13381,7 +13573,7 @@ After calling create_team, you MUST:
|
|
|
13381
13573
|
if (state?.team?.teamId) return state.team.teamId;
|
|
13382
13574
|
throw new Error("No team_id provided and no team in state. Call create_team first.");
|
|
13383
13575
|
};
|
|
13384
|
-
const addTasksTool =
|
|
13576
|
+
const addTasksTool = tool50(
|
|
13385
13577
|
async (input, config) => {
|
|
13386
13578
|
const teamId = resolveTeamId();
|
|
13387
13579
|
const created = await taskListStore.addTasks(
|
|
@@ -13395,7 +13587,7 @@ After calling create_team, you MUST:
|
|
|
13395
13587
|
}))
|
|
13396
13588
|
);
|
|
13397
13589
|
const summary = created.map((t) => `- ${t.id}: "${t.title}"`).join("\n");
|
|
13398
|
-
return new
|
|
13590
|
+
return new ToolMessage8({
|
|
13399
13591
|
content: `Added ${created.length} task(s) to team ${teamId}:
|
|
13400
13592
|
${summary}
|
|
13401
13593
|
Sleeping teammates will wake up and claim these.`,
|
|
@@ -13433,33 +13625,33 @@ IMPORTANT: Dependencies
|
|
|
13433
13625
|
|
|
13434
13626
|
IMPORTANT: Assigning to a specific teammate
|
|
13435
13627
|
- When you need a particular teammate to do the work, set assignee to that teammate's name (e.g. assignee: "researcher"). They can then claim or see the task as assigned to them.`,
|
|
13436
|
-
schema:
|
|
13437
|
-
tasks:
|
|
13438
|
-
|
|
13439
|
-
id:
|
|
13440
|
-
title:
|
|
13441
|
-
description:
|
|
13442
|
-
assignee:
|
|
13443
|
-
dependencies:
|
|
13628
|
+
schema: z51.object({
|
|
13629
|
+
tasks: z51.array(
|
|
13630
|
+
z51.object({
|
|
13631
|
+
id: z51.string().describe("Task ID in format task-01, task-02, etc. Must be unique."),
|
|
13632
|
+
title: z51.string().describe("Short task title"),
|
|
13633
|
+
description: z51.string().describe("Detailed task description - what needs to be done"),
|
|
13634
|
+
assignee: z51.string().optional().describe("Teammate name to assign this task to (use when you need that person to do the work)"),
|
|
13635
|
+
dependencies: z51.array(z51.string()).optional().default([]).describe("Array of task IDs that must complete before this task")
|
|
13444
13636
|
})
|
|
13445
13637
|
).describe("New tasks to add to the team")
|
|
13446
13638
|
})
|
|
13447
13639
|
}
|
|
13448
13640
|
);
|
|
13449
|
-
const assignTaskTool =
|
|
13641
|
+
const assignTaskTool = tool50(
|
|
13450
13642
|
async (input, config) => {
|
|
13451
13643
|
const teamId = resolveTeamId();
|
|
13452
13644
|
const task = await taskListStore.updateTask(teamId, input.task_id, {
|
|
13453
13645
|
assignee: input.assignee
|
|
13454
13646
|
});
|
|
13455
13647
|
if (!task) {
|
|
13456
|
-
return new
|
|
13648
|
+
return new ToolMessage8({
|
|
13457
13649
|
content: `Task ${input.task_id} not found in team ${teamId}.`,
|
|
13458
13650
|
tool_call_id: config.toolCall?.id,
|
|
13459
13651
|
name: "assign_task"
|
|
13460
13652
|
});
|
|
13461
13653
|
}
|
|
13462
|
-
return new
|
|
13654
|
+
return new ToolMessage8({
|
|
13463
13655
|
content: `Task "${task.title}" (${task.id}) assigned to ${input.assignee}.`,
|
|
13464
13656
|
tool_call_id: config.toolCall?.id,
|
|
13465
13657
|
name: "assign_task"
|
|
@@ -13468,26 +13660,26 @@ IMPORTANT: Assigning to a specific teammate
|
|
|
13468
13660
|
{
|
|
13469
13661
|
name: "assign_task",
|
|
13470
13662
|
description: "Assign a task to a specific teammate. Use when you need to reassign work to a different teammate. Omit team_id to use the active team from state.",
|
|
13471
|
-
schema:
|
|
13472
|
-
task_id:
|
|
13473
|
-
assignee:
|
|
13663
|
+
schema: z51.object({
|
|
13664
|
+
task_id: z51.string().describe("Task ID to assign"),
|
|
13665
|
+
assignee: z51.string().describe("Teammate name to assign this task to")
|
|
13474
13666
|
})
|
|
13475
13667
|
}
|
|
13476
13668
|
);
|
|
13477
|
-
const setTaskStatusTool =
|
|
13669
|
+
const setTaskStatusTool = tool50(
|
|
13478
13670
|
async (input, config) => {
|
|
13479
13671
|
const teamId = resolveTeamId();
|
|
13480
13672
|
const task = await taskListStore.updateTask(teamId, input.task_id, {
|
|
13481
13673
|
status: input.status
|
|
13482
13674
|
});
|
|
13483
13675
|
if (!task) {
|
|
13484
|
-
return new
|
|
13676
|
+
return new ToolMessage8({
|
|
13485
13677
|
content: `Task ${input.task_id} not found in team ${teamId}.`,
|
|
13486
13678
|
tool_call_id: config.toolCall?.id,
|
|
13487
13679
|
name: "set_task_status"
|
|
13488
13680
|
});
|
|
13489
13681
|
}
|
|
13490
|
-
return new
|
|
13682
|
+
return new ToolMessage8({
|
|
13491
13683
|
content: `Task "${task.title}" (${task.id}) status set to ${input.status}.`,
|
|
13492
13684
|
tool_call_id: config.toolCall?.id,
|
|
13493
13685
|
name: "set_task_status"
|
|
@@ -13496,26 +13688,26 @@ IMPORTANT: Assigning to a specific teammate
|
|
|
13496
13688
|
{
|
|
13497
13689
|
name: "set_task_status",
|
|
13498
13690
|
description: "Set a task's status. Use to reopen a task (set to pending), mark as failed, or correct status. Values: pending, claimed, in_progress, completed, failed. Omit team_id to use the active team from state.",
|
|
13499
|
-
schema:
|
|
13500
|
-
task_id:
|
|
13501
|
-
status:
|
|
13691
|
+
schema: z51.object({
|
|
13692
|
+
task_id: z51.string().describe("Task ID to update"),
|
|
13693
|
+
status: z51.enum(["pending", "claimed", "in_progress", "completed", "failed"]).describe("New status for the task")
|
|
13502
13694
|
})
|
|
13503
13695
|
}
|
|
13504
13696
|
);
|
|
13505
|
-
const setTaskDependenciesTool =
|
|
13697
|
+
const setTaskDependenciesTool = tool50(
|
|
13506
13698
|
async (input, config) => {
|
|
13507
13699
|
const teamId = resolveTeamId();
|
|
13508
13700
|
const task = await taskListStore.updateTask(teamId, input.task_id, {
|
|
13509
13701
|
dependencies: input.dependencies
|
|
13510
13702
|
});
|
|
13511
13703
|
if (!task) {
|
|
13512
|
-
return new
|
|
13704
|
+
return new ToolMessage8({
|
|
13513
13705
|
content: `Task ${input.task_id} not found in team ${teamId}.`,
|
|
13514
13706
|
tool_call_id: config.toolCall?.id,
|
|
13515
13707
|
name: "set_task_dependencies"
|
|
13516
13708
|
});
|
|
13517
13709
|
}
|
|
13518
|
-
return new
|
|
13710
|
+
return new ToolMessage8({
|
|
13519
13711
|
content: `Task "${task.title}" (${task.id}) dependencies set to [${input.dependencies.join(", ")}].`,
|
|
13520
13712
|
tool_call_id: config.toolCall?.id,
|
|
13521
13713
|
name: "set_task_dependencies"
|
|
@@ -13524,13 +13716,13 @@ IMPORTANT: Assigning to a specific teammate
|
|
|
13524
13716
|
{
|
|
13525
13717
|
name: "set_task_dependencies",
|
|
13526
13718
|
description: 'Set which task IDs must complete before this task can be claimed. Pass an array of task IDs (e.g. ["task-01", "task-02"]). Use to fix task order or add/remove dependencies. Omit team_id to use the active team from state.',
|
|
13527
|
-
schema:
|
|
13528
|
-
task_id:
|
|
13529
|
-
dependencies:
|
|
13719
|
+
schema: z51.object({
|
|
13720
|
+
task_id: z51.string().describe("Task ID to update"),
|
|
13721
|
+
dependencies: z51.array(z51.string()).describe("Task IDs that must complete before this task can be claimed")
|
|
13530
13722
|
})
|
|
13531
13723
|
}
|
|
13532
13724
|
);
|
|
13533
|
-
const checkTasksTool =
|
|
13725
|
+
const checkTasksTool = tool50(
|
|
13534
13726
|
async (input, config) => {
|
|
13535
13727
|
const teamId = resolveTeamId();
|
|
13536
13728
|
const tasks = await taskListStore.getAllTasks(teamId);
|
|
@@ -13539,7 +13731,7 @@ IMPORTANT: Assigning to a specific teammate
|
|
|
13539
13731
|
update: {
|
|
13540
13732
|
tasks: tasksSnapshot,
|
|
13541
13733
|
messages: [
|
|
13542
|
-
new
|
|
13734
|
+
new ToolMessage8({
|
|
13543
13735
|
content: formatTaskSummary(tasks),
|
|
13544
13736
|
tool_call_id: config.toolCall?.id,
|
|
13545
13737
|
name: "check_tasks"
|
|
@@ -13570,12 +13762,12 @@ Task Status Values:
|
|
|
13570
13762
|
- in_progress: Teammate is actively working on this task
|
|
13571
13763
|
- completed: Task finished successfully
|
|
13572
13764
|
- failed: Task encountered an error`,
|
|
13573
|
-
schema:
|
|
13574
|
-
team_id:
|
|
13765
|
+
schema: z51.object({
|
|
13766
|
+
team_id: z51.string().optional().describe("Team ID (omit to use active team)")
|
|
13575
13767
|
})
|
|
13576
13768
|
}
|
|
13577
13769
|
);
|
|
13578
|
-
const sendMessageTool =
|
|
13770
|
+
const sendMessageTool = tool50(
|
|
13579
13771
|
async (input, config) => {
|
|
13580
13772
|
const teamId = resolveTeamId();
|
|
13581
13773
|
await mailboxStore.sendMessage(
|
|
@@ -13585,7 +13777,7 @@ Task Status Values:
|
|
|
13585
13777
|
input.content,
|
|
13586
13778
|
"direct_message" /* DIRECT_MESSAGE */
|
|
13587
13779
|
);
|
|
13588
|
-
return new
|
|
13780
|
+
return new ToolMessage8({
|
|
13589
13781
|
content: `Message sent to ${input.to}.`,
|
|
13590
13782
|
tool_call_id: config.toolCall?.id,
|
|
13591
13783
|
name: "send_message"
|
|
@@ -13594,13 +13786,13 @@ Task Status Values:
|
|
|
13594
13786
|
{
|
|
13595
13787
|
name: "send_message",
|
|
13596
13788
|
description: "Send a message to a specific teammate in the team. Omit team_id to use the active team from state.",
|
|
13597
|
-
schema:
|
|
13598
|
-
to:
|
|
13599
|
-
content:
|
|
13789
|
+
schema: z51.object({
|
|
13790
|
+
to: z51.string().describe("Recipient teammate name"),
|
|
13791
|
+
content: z51.string().describe("Message content")
|
|
13600
13792
|
})
|
|
13601
13793
|
}
|
|
13602
13794
|
);
|
|
13603
|
-
const readMessagesTool =
|
|
13795
|
+
const readMessagesTool = tool50(
|
|
13604
13796
|
async (input, config) => {
|
|
13605
13797
|
const teamId = resolveTeamId();
|
|
13606
13798
|
const formatAndMarkAsRead = async (msgs2) => {
|
|
@@ -13628,7 +13820,7 @@ Task Status Values:
|
|
|
13628
13820
|
if (msgs.length > 0) {
|
|
13629
13821
|
const formatted2 = await formatAndMarkAsRead(msgs);
|
|
13630
13822
|
const allTeamMessages2 = await getAllTeamMessagesForState();
|
|
13631
|
-
const toolMessage2 = new
|
|
13823
|
+
const toolMessage2 = new ToolMessage8({
|
|
13632
13824
|
content: formatted2,
|
|
13633
13825
|
tool_call_id: config.toolCall?.id,
|
|
13634
13826
|
name: "read_messages"
|
|
@@ -13660,7 +13852,7 @@ Task Status Values:
|
|
|
13660
13852
|
);
|
|
13661
13853
|
const allTeamMessages = await getAllTeamMessagesForState();
|
|
13662
13854
|
if (msgs.length === 0) {
|
|
13663
|
-
const toolMessage2 = new
|
|
13855
|
+
const toolMessage2 = new ToolMessage8({
|
|
13664
13856
|
content: "No unread messages from teammates.",
|
|
13665
13857
|
tool_call_id: config.toolCall?.id,
|
|
13666
13858
|
name: "read_messages"
|
|
@@ -13670,7 +13862,7 @@ Task Status Values:
|
|
|
13670
13862
|
});
|
|
13671
13863
|
}
|
|
13672
13864
|
const formatted = await formatAndMarkAsRead(msgs);
|
|
13673
|
-
const toolMessage = new
|
|
13865
|
+
const toolMessage = new ToolMessage8({
|
|
13674
13866
|
content: formatted,
|
|
13675
13867
|
tool_call_id: config.toolCall?.id,
|
|
13676
13868
|
name: "read_messages"
|
|
@@ -13682,12 +13874,12 @@ Task Status Values:
|
|
|
13682
13874
|
{
|
|
13683
13875
|
name: "read_messages",
|
|
13684
13876
|
description: "Read unread messages from teammates. Returns immediately if messages exist, otherwise waits for up to 3 minutes for new messages.",
|
|
13685
|
-
schema:
|
|
13686
|
-
team_id:
|
|
13877
|
+
schema: z51.object({
|
|
13878
|
+
team_id: z51.string().optional().describe("Team ID (omit to use active team)")
|
|
13687
13879
|
})
|
|
13688
13880
|
}
|
|
13689
13881
|
);
|
|
13690
|
-
const disbandTeamTool =
|
|
13882
|
+
const disbandTeamTool = tool50(
|
|
13691
13883
|
async (input, config) => {
|
|
13692
13884
|
const teamId = resolveTeamId();
|
|
13693
13885
|
await mailboxStore.broadcastMessage(
|
|
@@ -13697,7 +13889,7 @@ Task Status Values:
|
|
|
13697
13889
|
"shutdown_request" /* SHUTDOWN_REQUEST */
|
|
13698
13890
|
);
|
|
13699
13891
|
await new Promise((r) => setTimeout(r, 2e3));
|
|
13700
|
-
return new
|
|
13892
|
+
return new ToolMessage8({
|
|
13701
13893
|
content: `Team ${teamId} has been disbanded. All teammates notified and resources cleaned up.`,
|
|
13702
13894
|
tool_call_id: config.toolCall?.id,
|
|
13703
13895
|
name: "disband_team"
|
|
@@ -13708,7 +13900,7 @@ Task Status Values:
|
|
|
13708
13900
|
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."
|
|
13709
13901
|
}
|
|
13710
13902
|
);
|
|
13711
|
-
const broadcastMessageTool =
|
|
13903
|
+
const broadcastMessageTool = tool50(
|
|
13712
13904
|
async (input, config) => {
|
|
13713
13905
|
const teamId = resolveTeamId();
|
|
13714
13906
|
await mailboxStore.broadcastMessage(
|
|
@@ -13717,7 +13909,7 @@ Task Status Values:
|
|
|
13717
13909
|
input.content,
|
|
13718
13910
|
"broadcast" /* BROADCAST */
|
|
13719
13911
|
);
|
|
13720
|
-
return new
|
|
13912
|
+
return new ToolMessage8({
|
|
13721
13913
|
content: `Broadcast message sent to all teammates.`,
|
|
13722
13914
|
tool_call_id: config.toolCall?.id,
|
|
13723
13915
|
name: "broadcast_message"
|
|
@@ -13726,12 +13918,12 @@ Task Status Values:
|
|
|
13726
13918
|
{
|
|
13727
13919
|
name: "broadcast_message",
|
|
13728
13920
|
description: "Send a message to all teammates at once. Use this to communicate with everyone in the team. Omit team_id to use the active team from state.",
|
|
13729
|
-
schema:
|
|
13730
|
-
content:
|
|
13921
|
+
schema: z51.object({
|
|
13922
|
+
content: z51.string().describe("Message content to broadcast to all teammates")
|
|
13731
13923
|
})
|
|
13732
13924
|
}
|
|
13733
13925
|
);
|
|
13734
|
-
return
|
|
13926
|
+
return createMiddleware16({
|
|
13735
13927
|
name: "teamMiddleware",
|
|
13736
13928
|
tools: [
|
|
13737
13929
|
createTeamTool,
|
|
@@ -13759,37 +13951,37 @@ ${TEAM_SYSTEM_PROMPT}` : TEAM_SYSTEM_PROMPT;
|
|
|
13759
13951
|
}
|
|
13760
13952
|
|
|
13761
13953
|
// src/agent_team/agent_team.ts
|
|
13762
|
-
var TeammateInfoSchema =
|
|
13763
|
-
name:
|
|
13764
|
-
role:
|
|
13765
|
-
description:
|
|
13954
|
+
var TeammateInfoSchema = z52.object({
|
|
13955
|
+
name: z52.string().describe("Teammate name"),
|
|
13956
|
+
role: z52.string().describe("Role category (e.g. research, writing, review)"),
|
|
13957
|
+
description: z52.string().describe("What this teammate focuses on")
|
|
13766
13958
|
});
|
|
13767
|
-
var TeamTaskInfoSchema =
|
|
13768
|
-
id:
|
|
13769
|
-
title:
|
|
13770
|
-
description:
|
|
13771
|
-
status:
|
|
13959
|
+
var TeamTaskInfoSchema = z52.object({
|
|
13960
|
+
id: z52.string(),
|
|
13961
|
+
title: z52.string(),
|
|
13962
|
+
description: z52.string(),
|
|
13963
|
+
status: z52.string().optional()
|
|
13772
13964
|
});
|
|
13773
|
-
var MailboxMessageSchema =
|
|
13774
|
-
id:
|
|
13775
|
-
from:
|
|
13776
|
-
to:
|
|
13777
|
-
content:
|
|
13778
|
-
timestamp:
|
|
13779
|
-
type:
|
|
13780
|
-
read:
|
|
13965
|
+
var MailboxMessageSchema = z52.object({
|
|
13966
|
+
id: z52.string().describe("Unique message identifier"),
|
|
13967
|
+
from: z52.string().describe("Sender agent name"),
|
|
13968
|
+
to: z52.string().describe("Recipient agent name"),
|
|
13969
|
+
content: z52.string().describe("Message content"),
|
|
13970
|
+
timestamp: z52.string().describe("ISO timestamp when the message was sent"),
|
|
13971
|
+
type: z52.nativeEnum(MessageType).describe("Message type"),
|
|
13972
|
+
read: z52.boolean().describe("Whether the recipient has read this message")
|
|
13781
13973
|
});
|
|
13782
|
-
var TeamInfoSchema =
|
|
13783
|
-
teamId:
|
|
13784
|
-
teamLeadId:
|
|
13785
|
-
teammates:
|
|
13786
|
-
tasks:
|
|
13787
|
-
createdAt:
|
|
13974
|
+
var TeamInfoSchema = z52.object({
|
|
13975
|
+
teamId: z52.string().describe("Unique team identifier"),
|
|
13976
|
+
teamLeadId: z52.string().default("team_lead").describe("Team lead agent ID"),
|
|
13977
|
+
teammates: z52.array(TeammateInfoSchema).describe("Active teammates in this team"),
|
|
13978
|
+
tasks: z52.array(TeamTaskInfoSchema).optional().describe("Initial tasks snapshot"),
|
|
13979
|
+
createdAt: z52.string().optional().describe("ISO timestamp when team was created")
|
|
13788
13980
|
});
|
|
13789
|
-
var TEAM_STATE_SCHEMA =
|
|
13981
|
+
var TEAM_STATE_SCHEMA = z52.object({
|
|
13790
13982
|
team: TeamInfoSchema.optional().describe("Team info: teamId, teamLeadId, teammates, tasks. Set when create_team succeeds."),
|
|
13791
|
-
tasks:
|
|
13792
|
-
team_mailbox:
|
|
13983
|
+
tasks: z52.array(TeamTaskInfoSchema).optional().describe("Current tasks snapshot from check_tasks. Updated on each check."),
|
|
13984
|
+
team_mailbox: z52.array(MailboxMessageSchema).optional().describe("All team mailbox messages for display")
|
|
13793
13985
|
});
|
|
13794
13986
|
var TEAM_LEAD_BASE_PROMPT = `You are a team lead that coordinates a team of specialized agents. In order to complete the objective that the user asks of you, you will need to:
|
|
13795
13987
|
|
|
@@ -13870,7 +14062,7 @@ var TeamAgentGraphBuilder = class {
|
|
|
13870
14062
|
const tools = params.tools.map((t) => {
|
|
13871
14063
|
const toolClient = getToolClient(t.key);
|
|
13872
14064
|
return toolClient;
|
|
13873
|
-
}).filter((
|
|
14065
|
+
}).filter((tool51) => tool51 !== void 0);
|
|
13874
14066
|
const teammates = params.subAgents.map((sa) => {
|
|
13875
14067
|
const baseConfig = sa.config;
|
|
13876
14068
|
return {
|
|
@@ -14603,6 +14795,9 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
|
14603
14795
|
buffer2.expiresAt = Date.now() + this.config.ttl;
|
|
14604
14796
|
buffer2.status = "active" /* ACTIVE */;
|
|
14605
14797
|
}
|
|
14798
|
+
async ensureThread(threadId) {
|
|
14799
|
+
this.getOrCreateBuffer(threadId);
|
|
14800
|
+
}
|
|
14606
14801
|
async completeThread(threadId) {
|
|
14607
14802
|
const buffer2 = this.getBufferIfValid(threadId);
|
|
14608
14803
|
if (buffer2) {
|
|
@@ -16756,10 +16951,10 @@ var McpLatticeManager = class _McpLatticeManager extends BaseLatticeManager {
|
|
|
16756
16951
|
}
|
|
16757
16952
|
const tools = await this.getAllTools();
|
|
16758
16953
|
console.log(`[MCP] Registering ${tools.length} tools to Tool Lattice...`);
|
|
16759
|
-
for (const
|
|
16760
|
-
const toolKey = prefix ? `${prefix}_${
|
|
16761
|
-
|
|
16762
|
-
toolLatticeManager.registerExistingTool(toolKey,
|
|
16954
|
+
for (const tool51 of tools) {
|
|
16955
|
+
const toolKey = prefix ? `${prefix}_${tool51.name}` : tool51.name;
|
|
16956
|
+
tool51.name = toolKey;
|
|
16957
|
+
toolLatticeManager.registerExistingTool(toolKey, tool51);
|
|
16763
16958
|
console.log(`[MCP] Registered tool: ${toolKey}`);
|
|
16764
16959
|
}
|
|
16765
16960
|
console.log(`[MCP] Successfully registered ${tools.length} tools to Tool Lattice`);
|
|
@@ -17366,6 +17561,7 @@ var Agent = class {
|
|
|
17366
17561
|
id: messageId
|
|
17367
17562
|
});
|
|
17368
17563
|
}
|
|
17564
|
+
await this.chunkBuffer.ensureThread(this.thread_id);
|
|
17369
17565
|
this.startQueueProcessorIfNeeded().catch((err) => {
|
|
17370
17566
|
console.error("Failed to start queue processor:", err);
|
|
17371
17567
|
});
|
|
@@ -17499,12 +17695,16 @@ var Agent = class {
|
|
|
17499
17695
|
/**
|
|
17500
17696
|
* Abort the current agent execution
|
|
17501
17697
|
* This will cancel any ongoing invoke or stream operations
|
|
17698
|
+
* and clear all queued messages (pending + processing)
|
|
17502
17699
|
*/
|
|
17503
|
-
abort() {
|
|
17700
|
+
async abort() {
|
|
17504
17701
|
if (this.abortController) {
|
|
17505
17702
|
this.abortController.abort();
|
|
17506
17703
|
this.abortController = null;
|
|
17507
17704
|
}
|
|
17705
|
+
await this.chunkBuffer.abortThread(this.thread_id);
|
|
17706
|
+
const store = this.getQueueStore();
|
|
17707
|
+
await store.clearMessages(this.thread_id);
|
|
17508
17708
|
}
|
|
17509
17709
|
/**
|
|
17510
17710
|
* Check if the agent is currently being aborted
|
|
@@ -17812,6 +18012,7 @@ export {
|
|
|
17812
18012
|
createQueryTablesListTool,
|
|
17813
18013
|
createTeamMiddleware,
|
|
17814
18014
|
createTeammateTools,
|
|
18015
|
+
createUnknownToolHandlerMiddleware,
|
|
17815
18016
|
createWidgetMiddleware,
|
|
17816
18017
|
decrypt,
|
|
17817
18018
|
describeCronExpression,
|