@axiom-lattice/core 2.1.30 → 2.1.31
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +276 -134
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +318 -176
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -699,11 +699,11 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
|
|
|
699
699
|
* @param key Lattice键名
|
|
700
700
|
* @param tool 已有的StructuredTool实例
|
|
701
701
|
*/
|
|
702
|
-
registerExistingTool(key,
|
|
702
|
+
registerExistingTool(key, tool48) {
|
|
703
703
|
const config = {
|
|
704
|
-
name:
|
|
705
|
-
description:
|
|
706
|
-
schema:
|
|
704
|
+
name: tool48.name,
|
|
705
|
+
description: tool48.description,
|
|
706
|
+
schema: tool48.schema,
|
|
707
707
|
// StructuredTool的schema已经是Zod兼容的
|
|
708
708
|
needUserApprove: false
|
|
709
709
|
// MCP工具默认不需要用户批准
|
|
@@ -711,7 +711,7 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
|
|
|
711
711
|
const toolLattice = {
|
|
712
712
|
key,
|
|
713
713
|
config,
|
|
714
|
-
client:
|
|
714
|
+
client: tool48
|
|
715
715
|
};
|
|
716
716
|
this.register(key, toolLattice);
|
|
717
717
|
}
|
|
@@ -737,7 +737,7 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
|
|
|
737
737
|
};
|
|
738
738
|
var toolLatticeManager = ToolLatticeManager.getInstance();
|
|
739
739
|
var registerToolLattice = (key, config, executor) => toolLatticeManager.registerLattice(key, config, executor);
|
|
740
|
-
var registerExistingTool = (key,
|
|
740
|
+
var registerExistingTool = (key, tool48) => toolLatticeManager.registerExistingTool(key, tool48);
|
|
741
741
|
var getToolLattice = (key) => toolLatticeManager.getToolLattice(key);
|
|
742
742
|
var getToolDefinition = (key) => toolLatticeManager.getToolDefinition(key);
|
|
743
743
|
var getToolClient = (key) => toolLatticeManager.getToolClient(key);
|
|
@@ -749,11 +749,17 @@ registerToolLattice(
|
|
|
749
749
|
"get_current_date_time",
|
|
750
750
|
{
|
|
751
751
|
name: "get_current_date_time",
|
|
752
|
-
description: "
|
|
752
|
+
description: "Access the authoritative system clock to synchronize the real-world timeline. Essential for anchoring all relative time expressions (e.g., 'recent', 'last quarter', 'YTD') and establishing precise temporal filters for data retrieval, trend analysis, and decision-making logic. Avoid data hallucinations from training data.",
|
|
753
753
|
schema: import_zod.default.object({})
|
|
754
754
|
},
|
|
755
755
|
async () => {
|
|
756
|
-
|
|
756
|
+
const now = /* @__PURE__ */ new Date();
|
|
757
|
+
return JSON.stringify({
|
|
758
|
+
local_time: now.toLocaleString(),
|
|
759
|
+
iso_date: now.toISOString().split("T")[0],
|
|
760
|
+
// 方便直接用于 SQL: 2026-03-10
|
|
761
|
+
timestamp: now.toISOString()
|
|
762
|
+
});
|
|
757
763
|
}
|
|
758
764
|
);
|
|
759
765
|
|
|
@@ -2088,7 +2094,7 @@ ${lines.join("\n")}`;
|
|
|
2088
2094
|
);
|
|
2089
2095
|
};
|
|
2090
2096
|
|
|
2091
|
-
// src/tool_lattice/metrics/
|
|
2097
|
+
// src/tool_lattice/metrics/list_datasources.ts
|
|
2092
2098
|
var import_zod8 = __toESM(require("zod"));
|
|
2093
2099
|
var import_langchain6 = require("langchain");
|
|
2094
2100
|
var LIST_METRICS_DATASOURCES_DESCRIPTION = `List all available datasources from all configured metrics servers. Returns a table with Server Key, DataSource ID, and DataSource Name. Use this tool first to discover what datasources are available before querying metrics.`;
|
|
@@ -2160,7 +2166,7 @@ To view all available data sources, please clear the current selection or reopen
|
|
|
2160
2166
|
}
|
|
2161
2167
|
},
|
|
2162
2168
|
{
|
|
2163
|
-
name: "
|
|
2169
|
+
name: "list_datasources",
|
|
2164
2170
|
description: `${LIST_METRICS_DATASOURCES_DESCRIPTION}${availableServersText}`,
|
|
2165
2171
|
schema: import_zod8.default.object({})
|
|
2166
2172
|
}
|
|
@@ -3062,10 +3068,10 @@ When to Use This Tool:
|
|
|
3062
3068
|
|
|
3063
3069
|
When NOT to Use This Tool:
|
|
3064
3070
|
- For simple metric queries - use query_semantic_metric_data instead
|
|
3065
|
-
- When you haven't identified the correct datasource yet - use
|
|
3071
|
+
- When you haven't identified the correct datasource yet - use list_datasources first
|
|
3066
3072
|
|
|
3067
3073
|
Prerequisites:
|
|
3068
|
-
1. Call
|
|
3074
|
+
1. Call list_datasources to get available datasource IDs
|
|
3069
3075
|
2. Call query_tables_list to see available tables and their structures
|
|
3070
3076
|
3. Call query_table_definition to understand table columns before writing SQL
|
|
3071
3077
|
|
|
@@ -3084,7 +3090,7 @@ Example:
|
|
|
3084
3090
|
"params": {
|
|
3085
3091
|
"year": "2024"
|
|
3086
3092
|
},
|
|
3087
|
-
"limit":
|
|
3093
|
+
"limit": 100
|
|
3088
3094
|
}`;
|
|
3089
3095
|
var createExecuteSqlQueryTool = ({ serverKeys, serverDescriptions }) => {
|
|
3090
3096
|
const availableServersText = serverKeys.length > 0 ? `
|
|
@@ -3142,7 +3148,7 @@ ${serverKeys.map(
|
|
|
3142
3148
|
datasourceId: import_zod14.default.string().optional().describe("The data source ID to execute SQL against. Optional if configured in runConfig.metricsDataSource"),
|
|
3143
3149
|
customSql: import_zod14.default.string().describe("Custom SQL query string with named parameters (e.g., :year, :category). Use double quotes for identifiers."),
|
|
3144
3150
|
params: import_zod14.default.record(import_zod14.default.union([import_zod14.default.string(), import_zod14.default.number(), import_zod14.default.boolean()])).optional().describe("Optional parameters for the SQL query. Keys should match the :paramName placeholders in customSql."),
|
|
3145
|
-
limit: import_zod14.default.number().optional().describe("Maximum number of results to return (default:
|
|
3151
|
+
limit: import_zod14.default.number().optional().describe("Maximum number of results to return (default: 100).")
|
|
3146
3152
|
})
|
|
3147
3153
|
}
|
|
3148
3154
|
);
|
|
@@ -4515,7 +4521,7 @@ var createReactAgentSchema = (schema) => {
|
|
|
4515
4521
|
};
|
|
4516
4522
|
|
|
4517
4523
|
// src/agent_lattice/builders/ReActAgentGraphBuilder.ts
|
|
4518
|
-
var
|
|
4524
|
+
var import_langchain48 = require("langchain");
|
|
4519
4525
|
|
|
4520
4526
|
// src/deep_agent_new/backends/sandboxFiles.ts
|
|
4521
4527
|
var import_sandbox2 = require("@agent-infra/sandbox");
|
|
@@ -7272,7 +7278,7 @@ function createFilesystemMiddleware(options = {}) {
|
|
|
7272
7278
|
backend = async (stateAndStore) => new StateBackend(stateAndStore),
|
|
7273
7279
|
systemPrompt: customSystemPrompt = null,
|
|
7274
7280
|
customToolDescriptions = null,
|
|
7275
|
-
toolTokenLimitBeforeEvict =
|
|
7281
|
+
toolTokenLimitBeforeEvict = 1e5
|
|
7276
7282
|
} = options;
|
|
7277
7283
|
const systemPrompt = customSystemPrompt || FILESYSTEM_SYSTEM_PROMPT;
|
|
7278
7284
|
const tools = [
|
|
@@ -7307,7 +7313,24 @@ ${systemPrompt}` : systemPrompt;
|
|
|
7307
7313
|
return handler({ ...request, systemPrompt: newSystemPrompt });
|
|
7308
7314
|
} : void 0,
|
|
7309
7315
|
wrapToolCall: toolTokenLimitBeforeEvict ? (async (request, handler) => {
|
|
7310
|
-
|
|
7316
|
+
let result;
|
|
7317
|
+
try {
|
|
7318
|
+
result = await handler(request);
|
|
7319
|
+
} catch (error) {
|
|
7320
|
+
if (error instanceof import_langgraph4.GraphInterrupt) {
|
|
7321
|
+
throw error;
|
|
7322
|
+
}
|
|
7323
|
+
console.error(request.toolCall?.name, error);
|
|
7324
|
+
return new import_langgraph4.Command({
|
|
7325
|
+
update: {
|
|
7326
|
+
messages: [new import_langchain44.ToolMessage({
|
|
7327
|
+
content: error instanceof Error ? error.message : "Unknown error",
|
|
7328
|
+
tool_call_id: request.toolCall?.id,
|
|
7329
|
+
name: request.toolCall?.name
|
|
7330
|
+
})]
|
|
7331
|
+
}
|
|
7332
|
+
});
|
|
7333
|
+
}
|
|
7311
7334
|
async function processToolMessage(msg) {
|
|
7312
7335
|
if (typeof msg.content === "string" && msg.content.length > toolTokenLimitBeforeEvict * 4) {
|
|
7313
7336
|
const stateAndStore = {
|
|
@@ -7421,6 +7444,122 @@ function createMetricsMiddleware(params) {
|
|
|
7421
7444
|
});
|
|
7422
7445
|
}
|
|
7423
7446
|
|
|
7447
|
+
// src/middlewares/askUserClarifyMiddleware.ts
|
|
7448
|
+
var import_langchain47 = require("langchain");
|
|
7449
|
+
var import_langgraph5 = require("@langchain/langgraph");
|
|
7450
|
+
|
|
7451
|
+
// src/tool_lattice/ask_user_to_clarify/index.ts
|
|
7452
|
+
var import_langchain46 = require("langchain");
|
|
7453
|
+
var import_zod45 = __toESM(require("zod"));
|
|
7454
|
+
var questionSchema = import_zod45.default.object({
|
|
7455
|
+
question: import_zod45.default.string().describe("The question text to ask the user"),
|
|
7456
|
+
options: import_zod45.default.array(import_zod45.default.string()).describe("List of EXACT, selectable values. Maximum 3 options allowed. DO NOT include any 'placeholder' options that require the user to type (e.g., do NOT add 'Enter manual value'). If manual input is needed, set allowOther to true instead."),
|
|
7457
|
+
type: import_zod45.default.enum(["single", "multiple"]).describe("Whether the question allows single or multiple selections"),
|
|
7458
|
+
required: import_zod45.default.boolean().optional().default(false).describe("Whether this question must be answered"),
|
|
7459
|
+
allowOther: import_zod45.default.boolean().optional().default(true).describe("Set to true to append an 'Other' option that opens a free-text input field. Use this for open-ended answers or when the 3 options cannot cover all possibilities.")
|
|
7460
|
+
});
|
|
7461
|
+
var inputSchema = import_zod45.default.object({
|
|
7462
|
+
questions: import_zod45.default.array(questionSchema).min(1, "At least one question is required").describe("A structured sequence of clarification questions. Use these to gather missing parameters or disambiguate user intent before proceeding.")
|
|
7463
|
+
});
|
|
7464
|
+
function createAskUserToClarifyTool() {
|
|
7465
|
+
return (0, import_langchain46.tool)(
|
|
7466
|
+
async (input) => {
|
|
7467
|
+
return JSON.stringify(input);
|
|
7468
|
+
},
|
|
7469
|
+
{
|
|
7470
|
+
name: "ask_user_to_clarify",
|
|
7471
|
+
description: "Prompts the user to choose from a list of predefined values OR provide custom input. USE CASES: 1. Use 'options' ONLY for distinct, mutually exclusive choices (e.g., ['Standard', 'Express']). 2. Set 'allowOther: true' ONLY when you need to capture free-text information that doesn't fit into the predefined options. IMPORTANT: Never put placeholders like 'Please specify' or 'Other' inside the 'options' list. ",
|
|
7472
|
+
schema: inputSchema
|
|
7473
|
+
}
|
|
7474
|
+
);
|
|
7475
|
+
}
|
|
7476
|
+
|
|
7477
|
+
// src/middlewares/askUserClarifyMiddleware.ts
|
|
7478
|
+
function createAskUserClarifyMiddleware() {
|
|
7479
|
+
return (0, import_langchain47.createMiddleware)({
|
|
7480
|
+
name: "AskUserClarifyMiddleware",
|
|
7481
|
+
tools: [createAskUserToClarifyTool()],
|
|
7482
|
+
wrapToolCall: async (request, handler) => {
|
|
7483
|
+
const toolCall = request.toolCall;
|
|
7484
|
+
const toolName = toolCall?.name;
|
|
7485
|
+
if (toolName !== "ask_user_to_clarify") {
|
|
7486
|
+
try {
|
|
7487
|
+
return await handler(request);
|
|
7488
|
+
} catch (error) {
|
|
7489
|
+
if (error instanceof import_langgraph5.GraphInterrupt) {
|
|
7490
|
+
throw error;
|
|
7491
|
+
}
|
|
7492
|
+
console.error(`Error executing tool "${toolName}":`, error);
|
|
7493
|
+
return new import_langchain47.ToolMessage({
|
|
7494
|
+
content: `Error executing tool: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
7495
|
+
tool_call_id: toolCall?.id,
|
|
7496
|
+
name: toolName
|
|
7497
|
+
});
|
|
7498
|
+
}
|
|
7499
|
+
}
|
|
7500
|
+
const input = toolCall?.args;
|
|
7501
|
+
if (!input?.questions || input.questions.length === 0) {
|
|
7502
|
+
return new import_langchain47.ToolMessage({
|
|
7503
|
+
content: "No questions provided.",
|
|
7504
|
+
tool_call_id: toolCall?.id,
|
|
7505
|
+
name: toolName
|
|
7506
|
+
});
|
|
7507
|
+
}
|
|
7508
|
+
const uiData = {
|
|
7509
|
+
questions: input.questions.map((q) => ({
|
|
7510
|
+
question: q.question,
|
|
7511
|
+
options: q.options,
|
|
7512
|
+
type: q.type,
|
|
7513
|
+
required: q.required,
|
|
7514
|
+
allowOther: q.allowOther
|
|
7515
|
+
}))
|
|
7516
|
+
};
|
|
7517
|
+
const md = genUIMarkdown("clarify", uiData);
|
|
7518
|
+
const result = await (0, import_langgraph5.interrupt)(md);
|
|
7519
|
+
const response = result.data;
|
|
7520
|
+
if (!response?.answers || response.answers.length === 0) {
|
|
7521
|
+
return new import_langchain47.ToolMessage({
|
|
7522
|
+
content: "No clarification questions were answered.",
|
|
7523
|
+
tool_call_id: toolCall?.id,
|
|
7524
|
+
name: toolName
|
|
7525
|
+
});
|
|
7526
|
+
}
|
|
7527
|
+
const answeredQuestions = response.answers.filter(
|
|
7528
|
+
(answer) => answer.selectedOptions.length > 0 || answer.otherText && answer.otherText.trim() !== ""
|
|
7529
|
+
);
|
|
7530
|
+
if (answeredQuestions.length === 0) {
|
|
7531
|
+
return new import_langchain47.ToolMessage({
|
|
7532
|
+
content: "No clarification questions were answered.",
|
|
7533
|
+
tool_call_id: toolCall?.id,
|
|
7534
|
+
name: toolName
|
|
7535
|
+
});
|
|
7536
|
+
}
|
|
7537
|
+
const lines = ["## Clarification Questions Answered", ""];
|
|
7538
|
+
for (const answer of answeredQuestions) {
|
|
7539
|
+
const question = input.questions[answer.questionIndex];
|
|
7540
|
+
if (!question) continue;
|
|
7541
|
+
lines.push(`**Q${answer.questionIndex + 1}: ${question.question}**`);
|
|
7542
|
+
const parts = [];
|
|
7543
|
+
if (answer.selectedOptions.length > 0) {
|
|
7544
|
+
parts.push(...answer.selectedOptions);
|
|
7545
|
+
}
|
|
7546
|
+
if (answer.otherText && answer.otherText.trim() !== "") {
|
|
7547
|
+
parts.push(`Other: ${answer.otherText.trim()}`);
|
|
7548
|
+
}
|
|
7549
|
+
if (parts.length > 0) {
|
|
7550
|
+
lines.push(`A: ${parts.join(", ")}`);
|
|
7551
|
+
}
|
|
7552
|
+
lines.push("");
|
|
7553
|
+
}
|
|
7554
|
+
return new import_langchain47.ToolMessage({
|
|
7555
|
+
content: lines.join("\n"),
|
|
7556
|
+
tool_call_id: toolCall?.id,
|
|
7557
|
+
name: toolName
|
|
7558
|
+
});
|
|
7559
|
+
}
|
|
7560
|
+
});
|
|
7561
|
+
}
|
|
7562
|
+
|
|
7424
7563
|
// src/agent_lattice/builders/commonMiddleware.ts
|
|
7425
7564
|
function createCommonMiddlewares(middlewareConfigs, filesystemBackend) {
|
|
7426
7565
|
const middlewares = [];
|
|
@@ -7467,6 +7606,9 @@ function createCommonMiddlewares(middlewareConfigs, filesystemBackend) {
|
|
|
7467
7606
|
}
|
|
7468
7607
|
}
|
|
7469
7608
|
break;
|
|
7609
|
+
case "ask_user_to_clarify":
|
|
7610
|
+
middlewares.push(createAskUserClarifyMiddleware());
|
|
7611
|
+
break;
|
|
7470
7612
|
}
|
|
7471
7613
|
}
|
|
7472
7614
|
return middlewares;
|
|
@@ -7510,14 +7652,14 @@ var ReActAgentGraphBuilder = class {
|
|
|
7510
7652
|
*/
|
|
7511
7653
|
build(agentLattice, params) {
|
|
7512
7654
|
const tools = params.tools.map((t) => {
|
|
7513
|
-
const
|
|
7514
|
-
return
|
|
7515
|
-
}).filter((
|
|
7655
|
+
const tool48 = getToolClient(t.key);
|
|
7656
|
+
return tool48;
|
|
7657
|
+
}).filter((tool48) => tool48 !== void 0);
|
|
7516
7658
|
const stateSchema2 = createReactAgentSchema(params.stateSchema);
|
|
7517
7659
|
const middlewareConfigs = params.middleware || [];
|
|
7518
7660
|
const filesystemBackend = this.createFilesystemBackendFactory(middlewareConfigs);
|
|
7519
7661
|
const middlewares = createCommonMiddlewares(middlewareConfigs, filesystemBackend);
|
|
7520
|
-
return (0,
|
|
7662
|
+
return (0, import_langchain48.createAgent)({
|
|
7521
7663
|
model: params.model,
|
|
7522
7664
|
tools,
|
|
7523
7665
|
systemPrompt: params.prompt,
|
|
@@ -7530,16 +7672,16 @@ var ReActAgentGraphBuilder = class {
|
|
|
7530
7672
|
};
|
|
7531
7673
|
|
|
7532
7674
|
// src/deep_agent_new/agent.ts
|
|
7533
|
-
var
|
|
7675
|
+
var import_langchain52 = require("langchain");
|
|
7534
7676
|
|
|
7535
7677
|
// src/deep_agent_new/middleware/subagents.ts
|
|
7536
7678
|
var import_v32 = require("zod/v3");
|
|
7537
|
-
var
|
|
7538
|
-
var
|
|
7679
|
+
var import_langchain49 = require("langchain");
|
|
7680
|
+
var import_langgraph7 = require("@langchain/langgraph");
|
|
7539
7681
|
var import_messages = require("@langchain/core/messages");
|
|
7540
7682
|
|
|
7541
7683
|
// src/agent_worker/agent_worker_graph.ts
|
|
7542
|
-
var
|
|
7684
|
+
var import_langgraph6 = require("@langchain/langgraph");
|
|
7543
7685
|
|
|
7544
7686
|
// src/constants/agent_task_types.ts
|
|
7545
7687
|
var AGENT_TASK_EVENT = "agent:execute";
|
|
@@ -7828,41 +7970,41 @@ var AgentManager = class _AgentManager {
|
|
|
7828
7970
|
};
|
|
7829
7971
|
|
|
7830
7972
|
// src/agent_worker/agent_worker_graph.ts
|
|
7831
|
-
var AgentWorkerState =
|
|
7973
|
+
var AgentWorkerState = import_langgraph6.Annotation.Root({
|
|
7832
7974
|
// Input parameters
|
|
7833
|
-
assistant_id: (0,
|
|
7975
|
+
assistant_id: (0, import_langgraph6.Annotation)({
|
|
7834
7976
|
reducer: (x, y) => y ?? x,
|
|
7835
7977
|
default: () => ""
|
|
7836
7978
|
}),
|
|
7837
|
-
thread_id: (0,
|
|
7979
|
+
thread_id: (0, import_langgraph6.Annotation)({
|
|
7838
7980
|
reducer: (x, y) => y ?? x,
|
|
7839
7981
|
default: () => ""
|
|
7840
7982
|
}),
|
|
7841
|
-
input: (0,
|
|
7983
|
+
input: (0, import_langgraph6.Annotation)({
|
|
7842
7984
|
reducer: (x, y) => y ?? x,
|
|
7843
7985
|
default: () => ({})
|
|
7844
7986
|
}),
|
|
7845
|
-
command2: (0,
|
|
7987
|
+
command2: (0, import_langgraph6.Annotation)({
|
|
7846
7988
|
reducer: (x, y) => y ?? x,
|
|
7847
7989
|
default: () => void 0
|
|
7848
7990
|
}),
|
|
7849
7991
|
// RunConfig for passing configuration through the graph
|
|
7850
|
-
runConfig: (0,
|
|
7992
|
+
runConfig: (0, import_langgraph6.Annotation)({
|
|
7851
7993
|
reducer: (x, y) => y ?? x,
|
|
7852
7994
|
default: () => void 0
|
|
7853
7995
|
}),
|
|
7854
7996
|
// Execution result
|
|
7855
|
-
result: (0,
|
|
7997
|
+
result: (0, import_langgraph6.Annotation)({
|
|
7856
7998
|
reducer: (x, y) => y ?? x,
|
|
7857
7999
|
default: () => void 0
|
|
7858
8000
|
}),
|
|
7859
8001
|
// Interrupt data
|
|
7860
|
-
interruptValue: (0,
|
|
8002
|
+
interruptValue: (0, import_langgraph6.Annotation)({
|
|
7861
8003
|
reducer: (x, y) => y ?? x,
|
|
7862
8004
|
default: () => void 0
|
|
7863
8005
|
}),
|
|
7864
8006
|
// Final state to return
|
|
7865
|
-
finalState: (0,
|
|
8007
|
+
finalState: (0, import_langgraph6.Annotation)({
|
|
7866
8008
|
reducer: (x, y) => y ?? x,
|
|
7867
8009
|
default: () => void 0
|
|
7868
8010
|
})
|
|
@@ -7892,7 +8034,7 @@ async function interruptNode(state) {
|
|
|
7892
8034
|
"Interrupt node called but no interrupt value found in result"
|
|
7893
8035
|
);
|
|
7894
8036
|
}
|
|
7895
|
-
const response = await (0,
|
|
8037
|
+
const response = await (0, import_langgraph6.interrupt)(interruptValue);
|
|
7896
8038
|
return {
|
|
7897
8039
|
command2: {
|
|
7898
8040
|
resume: response
|
|
@@ -7919,7 +8061,7 @@ function endNode(state) {
|
|
|
7919
8061
|
};
|
|
7920
8062
|
}
|
|
7921
8063
|
function createAgentWorkerGraph() {
|
|
7922
|
-
const workflow = new
|
|
8064
|
+
const workflow = new import_langgraph6.StateGraph(AgentWorkerState);
|
|
7923
8065
|
workflow.addNode("execute", executeNode);
|
|
7924
8066
|
workflow.addNode("interrupt", interruptNode);
|
|
7925
8067
|
workflow.addNode("end", endNode);
|
|
@@ -7929,7 +8071,7 @@ function createAgentWorkerGraph() {
|
|
|
7929
8071
|
end: "end"
|
|
7930
8072
|
});
|
|
7931
8073
|
workflow.addEdge("interrupt", "execute");
|
|
7932
|
-
workflow.addEdge("end",
|
|
8074
|
+
workflow.addEdge("end", import_langgraph6.END);
|
|
7933
8075
|
return workflow.compile();
|
|
7934
8076
|
}
|
|
7935
8077
|
var agentWorkerGraph = createAgentWorkerGraph();
|
|
@@ -8091,11 +8233,11 @@ function returnCommandWithStateUpdate(result, toolCallId) {
|
|
|
8091
8233
|
const stateUpdate = filterStateForSubagent(result);
|
|
8092
8234
|
const messages = result.messages;
|
|
8093
8235
|
const lastMessage = messages?.[messages.length - 1];
|
|
8094
|
-
return new
|
|
8236
|
+
return new import_langgraph7.Command({
|
|
8095
8237
|
update: {
|
|
8096
8238
|
...stateUpdate,
|
|
8097
8239
|
messages: [
|
|
8098
|
-
new
|
|
8240
|
+
new import_langchain49.ToolMessage({
|
|
8099
8241
|
content: lastMessage?.content || "Task Failed to complete",
|
|
8100
8242
|
tool_call_id: toolCallId,
|
|
8101
8243
|
name: "task"
|
|
@@ -8120,10 +8262,10 @@ function getSubagents(options) {
|
|
|
8120
8262
|
const generalPurposeMiddleware = [...defaultSubagentMiddleware];
|
|
8121
8263
|
if (defaultInterruptOn) {
|
|
8122
8264
|
generalPurposeMiddleware.push(
|
|
8123
|
-
(0,
|
|
8265
|
+
(0, import_langchain49.humanInTheLoopMiddleware)({ interruptOn: defaultInterruptOn })
|
|
8124
8266
|
);
|
|
8125
8267
|
}
|
|
8126
|
-
const generalPurposeSubagent = (0,
|
|
8268
|
+
const generalPurposeSubagent = (0, import_langchain49.createAgent)({
|
|
8127
8269
|
model: defaultModel,
|
|
8128
8270
|
systemPrompt: DEFAULT_SUBAGENT_PROMPT,
|
|
8129
8271
|
tools: defaultTools,
|
|
@@ -8144,8 +8286,8 @@ function getSubagents(options) {
|
|
|
8144
8286
|
const middleware = agentParams.middleware ? [...defaultSubagentMiddleware, ...agentParams.middleware] : [...defaultSubagentMiddleware];
|
|
8145
8287
|
const interruptOn = agentParams.interruptOn || defaultInterruptOn;
|
|
8146
8288
|
if (interruptOn)
|
|
8147
|
-
middleware.push((0,
|
|
8148
|
-
agents[agentParams.key] = (0,
|
|
8289
|
+
middleware.push((0, import_langchain49.humanInTheLoopMiddleware)({ interruptOn }));
|
|
8290
|
+
agents[agentParams.key] = (0, import_langchain49.createAgent)({
|
|
8149
8291
|
model: agentParams.model ?? defaultModel,
|
|
8150
8292
|
systemPrompt: agentParams.systemPrompt,
|
|
8151
8293
|
tools: agentParams.tools ?? defaultTools,
|
|
@@ -8174,7 +8316,7 @@ function createTaskTool(options) {
|
|
|
8174
8316
|
generalPurposeAgent
|
|
8175
8317
|
});
|
|
8176
8318
|
const finalTaskDescription = taskDescription ? taskDescription : getTaskToolDescription(subagentDescriptions);
|
|
8177
|
-
return (0,
|
|
8319
|
+
return (0, import_langchain49.tool)(
|
|
8178
8320
|
async (input, config) => {
|
|
8179
8321
|
const { description, subagent_type } = input;
|
|
8180
8322
|
try {
|
|
@@ -8185,7 +8327,7 @@ function createTaskTool(options) {
|
|
|
8185
8327
|
);
|
|
8186
8328
|
}
|
|
8187
8329
|
const subagent = subagentGraphs[subagent_type];
|
|
8188
|
-
const currentState = (0,
|
|
8330
|
+
const currentState = (0, import_langgraph7.getCurrentTaskInput)();
|
|
8189
8331
|
const subagentState = filterStateForSubagent(currentState);
|
|
8190
8332
|
subagentState.messages = [new import_messages.HumanMessage({ content: description })];
|
|
8191
8333
|
const subagent_thread_id = config.configurable?.thread_id + "____" + subagent_type + "_" + config.toolCall.id;
|
|
@@ -8206,10 +8348,10 @@ function createTaskTool(options) {
|
|
|
8206
8348
|
}
|
|
8207
8349
|
return returnCommandWithStateUpdate(result, config.toolCall.id);
|
|
8208
8350
|
} catch (error) {
|
|
8209
|
-
return new
|
|
8351
|
+
return new import_langgraph7.Command({
|
|
8210
8352
|
update: {
|
|
8211
8353
|
messages: [
|
|
8212
|
-
new
|
|
8354
|
+
new import_langchain49.ToolMessage({
|
|
8213
8355
|
content: error instanceof Error ? error.message : "Task Failed to complete",
|
|
8214
8356
|
tool_call_id: config.toolCall.id,
|
|
8215
8357
|
name: "task"
|
|
@@ -8253,7 +8395,7 @@ function createSubAgentMiddleware(options) {
|
|
|
8253
8395
|
generalPurposeAgent,
|
|
8254
8396
|
taskDescription
|
|
8255
8397
|
});
|
|
8256
|
-
return (0,
|
|
8398
|
+
return (0, import_langchain49.createMiddleware)({
|
|
8257
8399
|
name: "subAgentMiddleware",
|
|
8258
8400
|
tools: [taskTool],
|
|
8259
8401
|
wrapModelCall: async (request, handler) => {
|
|
@@ -8273,11 +8415,11 @@ ${systemPrompt}` : systemPrompt;
|
|
|
8273
8415
|
}
|
|
8274
8416
|
|
|
8275
8417
|
// src/deep_agent_new/middleware/patch_tool_calls.ts
|
|
8276
|
-
var
|
|
8418
|
+
var import_langchain50 = require("langchain");
|
|
8277
8419
|
var import_messages2 = require("@langchain/core/messages");
|
|
8278
|
-
var
|
|
8420
|
+
var import_langgraph8 = require("@langchain/langgraph");
|
|
8279
8421
|
function createPatchToolCallsMiddleware() {
|
|
8280
|
-
return (0,
|
|
8422
|
+
return (0, import_langchain50.createMiddleware)({
|
|
8281
8423
|
name: "patchToolCallsMiddleware",
|
|
8282
8424
|
beforeAgent: async (state) => {
|
|
8283
8425
|
const messages = state.messages;
|
|
@@ -8288,15 +8430,15 @@ function createPatchToolCallsMiddleware() {
|
|
|
8288
8430
|
for (let i = 0; i < messages.length; i++) {
|
|
8289
8431
|
const msg = messages[i];
|
|
8290
8432
|
patchedMessages.push(msg);
|
|
8291
|
-
if (
|
|
8433
|
+
if (import_langchain50.AIMessage.isInstance(msg) && msg.tool_calls != null) {
|
|
8292
8434
|
for (const toolCall of msg.tool_calls) {
|
|
8293
8435
|
const correspondingToolMsg = messages.slice(i).find(
|
|
8294
|
-
(m) =>
|
|
8436
|
+
(m) => import_langchain50.ToolMessage.isInstance(m) && m.tool_call_id === toolCall.id
|
|
8295
8437
|
);
|
|
8296
8438
|
if (!correspondingToolMsg) {
|
|
8297
8439
|
const toolMsg = `Tool call ${toolCall.name} with id ${toolCall.id} was cancelled - another message came in before it could be completed.`;
|
|
8298
8440
|
patchedMessages.push(
|
|
8299
|
-
new
|
|
8441
|
+
new import_langchain50.ToolMessage({
|
|
8300
8442
|
content: toolMsg,
|
|
8301
8443
|
name: toolCall.name,
|
|
8302
8444
|
tool_call_id: toolCall.id
|
|
@@ -8308,7 +8450,7 @@ function createPatchToolCallsMiddleware() {
|
|
|
8308
8450
|
}
|
|
8309
8451
|
return {
|
|
8310
8452
|
messages: [
|
|
8311
|
-
new import_messages2.RemoveMessage({ id:
|
|
8453
|
+
new import_messages2.RemoveMessage({ id: import_langgraph8.REMOVE_ALL_MESSAGES }),
|
|
8312
8454
|
...patchedMessages
|
|
8313
8455
|
]
|
|
8314
8456
|
};
|
|
@@ -9408,9 +9550,9 @@ var MemoryBackend = class {
|
|
|
9408
9550
|
};
|
|
9409
9551
|
|
|
9410
9552
|
// src/deep_agent_new/middleware/todos.ts
|
|
9411
|
-
var
|
|
9412
|
-
var
|
|
9413
|
-
var
|
|
9553
|
+
var import_langgraph9 = require("@langchain/langgraph");
|
|
9554
|
+
var import_zod46 = require("zod");
|
|
9555
|
+
var import_langchain51 = require("langchain");
|
|
9414
9556
|
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.
|
|
9415
9557
|
It also helps the user understand the progress of the task and overall progress of their requests.
|
|
9416
9558
|
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.
|
|
@@ -9637,20 +9779,20 @@ Writing todos takes time and tokens, use it when it is helpful for managing comp
|
|
|
9637
9779
|
## Important To-Do List Usage Notes to Remember
|
|
9638
9780
|
- The \`write_todos\` tool should never be called multiple times in parallel.
|
|
9639
9781
|
- 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.`;
|
|
9640
|
-
var TodoStatus =
|
|
9641
|
-
var TodoSchema =
|
|
9642
|
-
content:
|
|
9782
|
+
var TodoStatus = import_zod46.z.enum(["pending", "in_progress", "completed"]).describe("Status of the todo");
|
|
9783
|
+
var TodoSchema = import_zod46.z.object({
|
|
9784
|
+
content: import_zod46.z.string().describe("Content of the todo item"),
|
|
9643
9785
|
status: TodoStatus
|
|
9644
9786
|
});
|
|
9645
|
-
var stateSchema =
|
|
9787
|
+
var stateSchema = import_zod46.z.object({ todos: import_zod46.z.array(TodoSchema).default([]) });
|
|
9646
9788
|
function todoListMiddleware(options) {
|
|
9647
|
-
const writeTodos = (0,
|
|
9789
|
+
const writeTodos = (0, import_langchain51.tool)(
|
|
9648
9790
|
({ todos }, config) => {
|
|
9649
|
-
return new
|
|
9791
|
+
return new import_langgraph9.Command({
|
|
9650
9792
|
update: {
|
|
9651
9793
|
todos,
|
|
9652
9794
|
messages: [
|
|
9653
|
-
new
|
|
9795
|
+
new import_langchain51.ToolMessage({
|
|
9654
9796
|
content: genUIMarkdown("todo_list", todos),
|
|
9655
9797
|
tool_call_id: config.toolCall?.id
|
|
9656
9798
|
})
|
|
@@ -9661,12 +9803,12 @@ function todoListMiddleware(options) {
|
|
|
9661
9803
|
{
|
|
9662
9804
|
name: "write_todos",
|
|
9663
9805
|
description: options?.toolDescription ?? WRITE_TODOS_DESCRIPTION,
|
|
9664
|
-
schema:
|
|
9665
|
-
todos:
|
|
9806
|
+
schema: import_zod46.z.object({
|
|
9807
|
+
todos: import_zod46.z.array(TodoSchema).describe("List of todo items to update")
|
|
9666
9808
|
})
|
|
9667
9809
|
}
|
|
9668
9810
|
);
|
|
9669
|
-
return (0,
|
|
9811
|
+
return (0, import_langchain51.createMiddleware)({
|
|
9670
9812
|
name: "todoListMiddleware",
|
|
9671
9813
|
stateSchema,
|
|
9672
9814
|
tools: [writeTodos],
|
|
@@ -9718,13 +9860,13 @@ ${BASE_PROMPT}` : BASE_PROMPT;
|
|
|
9718
9860
|
backend: filesystemBackend
|
|
9719
9861
|
}),
|
|
9720
9862
|
// Subagent middleware: Automatic conversation summarization when token limits are approached
|
|
9721
|
-
(0,
|
|
9863
|
+
(0, import_langchain52.summarizationMiddleware)({
|
|
9722
9864
|
model,
|
|
9723
9865
|
trigger: { tokens: 17e4 },
|
|
9724
9866
|
keep: { messages: 6 }
|
|
9725
9867
|
}),
|
|
9726
9868
|
// Subagent middleware: Anthropic prompt caching for improved performance
|
|
9727
|
-
(0,
|
|
9869
|
+
(0, import_langchain52.anthropicPromptCachingMiddleware)({
|
|
9728
9870
|
unsupportedModelBehavior: "ignore"
|
|
9729
9871
|
}),
|
|
9730
9872
|
// Subagent middleware: Patches tool calls for compatibility
|
|
@@ -9735,23 +9877,23 @@ ${BASE_PROMPT}` : BASE_PROMPT;
|
|
|
9735
9877
|
generalPurposeAgent: false
|
|
9736
9878
|
}),
|
|
9737
9879
|
// Automatically summarizes conversation history when token limits are approached
|
|
9738
|
-
(0,
|
|
9880
|
+
(0, import_langchain52.summarizationMiddleware)({
|
|
9739
9881
|
model,
|
|
9740
9882
|
trigger: { tokens: 17e4 },
|
|
9741
9883
|
keep: { messages: 6 }
|
|
9742
9884
|
}),
|
|
9743
9885
|
// Enables Anthropic prompt caching for improved performance and reduced costs
|
|
9744
|
-
(0,
|
|
9886
|
+
(0, import_langchain52.anthropicPromptCachingMiddleware)({
|
|
9745
9887
|
unsupportedModelBehavior: "ignore"
|
|
9746
9888
|
}),
|
|
9747
9889
|
// Patches tool calls to ensure compatibility across different model providers
|
|
9748
9890
|
createPatchToolCallsMiddleware()
|
|
9749
9891
|
];
|
|
9750
9892
|
if (interruptOn) {
|
|
9751
|
-
middleware.push((0,
|
|
9893
|
+
middleware.push((0, import_langchain52.humanInTheLoopMiddleware)({ interruptOn }));
|
|
9752
9894
|
}
|
|
9753
9895
|
middleware.push(...customMiddleware);
|
|
9754
|
-
return (0,
|
|
9896
|
+
return (0, import_langchain52.createAgent)({
|
|
9755
9897
|
model,
|
|
9756
9898
|
systemPrompt: finalSystemPrompt,
|
|
9757
9899
|
tools,
|
|
@@ -9809,7 +9951,7 @@ var DeepAgentGraphBuilder = class {
|
|
|
9809
9951
|
const tools = params.tools.map((t) => {
|
|
9810
9952
|
const toolClient = getToolClient(t.key);
|
|
9811
9953
|
return toolClient;
|
|
9812
|
-
}).filter((
|
|
9954
|
+
}).filter((tool48) => tool48 !== void 0);
|
|
9813
9955
|
const subagents = params.subAgents.map((sa) => {
|
|
9814
9956
|
if (sa.client) {
|
|
9815
9957
|
return {
|
|
@@ -9850,7 +9992,7 @@ var DeepAgentGraphBuilder = class {
|
|
|
9850
9992
|
|
|
9851
9993
|
// src/agent_team/agent_team.ts
|
|
9852
9994
|
var import_v35 = require("zod/v3");
|
|
9853
|
-
var
|
|
9995
|
+
var import_langchain55 = require("langchain");
|
|
9854
9996
|
|
|
9855
9997
|
// src/agent_team/types.ts
|
|
9856
9998
|
var TaskStatus = /* @__PURE__ */ ((TaskStatus3) => {
|
|
@@ -10286,14 +10428,14 @@ var InMemoryMailboxStore = class {
|
|
|
10286
10428
|
|
|
10287
10429
|
// src/agent_team/middleware/team.ts
|
|
10288
10430
|
var import_v34 = require("zod/v3");
|
|
10289
|
-
var
|
|
10290
|
-
var
|
|
10431
|
+
var import_langchain54 = require("langchain");
|
|
10432
|
+
var import_langgraph11 = require("@langchain/langgraph");
|
|
10291
10433
|
var import_uuid = require("uuid");
|
|
10292
10434
|
|
|
10293
10435
|
// src/agent_team/middleware/teammate_tools.ts
|
|
10294
10436
|
var import_v33 = require("zod/v3");
|
|
10295
|
-
var
|
|
10296
|
-
var
|
|
10437
|
+
var import_langchain53 = require("langchain");
|
|
10438
|
+
var import_langgraph10 = require("@langchain/langgraph");
|
|
10297
10439
|
|
|
10298
10440
|
// src/agent_team/middleware/formatMessages.ts
|
|
10299
10441
|
function formatMessagesAsMarkdown(msgs) {
|
|
@@ -10317,7 +10459,7 @@ ${meta}${body}`;
|
|
|
10317
10459
|
// src/agent_team/middleware/teammate_tools.ts
|
|
10318
10460
|
function createTeammateTools(options) {
|
|
10319
10461
|
const { teamId, agentId, taskListStore, mailboxStore } = options;
|
|
10320
|
-
const claimTaskTool = (0,
|
|
10462
|
+
const claimTaskTool = (0, import_langchain53.tool)(
|
|
10321
10463
|
async (input) => {
|
|
10322
10464
|
const task = await taskListStore.claimTaskById(
|
|
10323
10465
|
teamId,
|
|
@@ -10347,7 +10489,7 @@ function createTeammateTools(options) {
|
|
|
10347
10489
|
})
|
|
10348
10490
|
}
|
|
10349
10491
|
);
|
|
10350
|
-
const completeTaskTool = (0,
|
|
10492
|
+
const completeTaskTool = (0, import_langchain53.tool)(
|
|
10351
10493
|
async (input) => {
|
|
10352
10494
|
const task = await taskListStore.completeTask(
|
|
10353
10495
|
teamId,
|
|
@@ -10374,7 +10516,7 @@ function createTeammateTools(options) {
|
|
|
10374
10516
|
})
|
|
10375
10517
|
}
|
|
10376
10518
|
);
|
|
10377
|
-
const failTaskTool = (0,
|
|
10519
|
+
const failTaskTool = (0, import_langchain53.tool)(
|
|
10378
10520
|
async (input) => {
|
|
10379
10521
|
const task = await taskListStore.failTask(
|
|
10380
10522
|
teamId,
|
|
@@ -10401,7 +10543,7 @@ function createTeammateTools(options) {
|
|
|
10401
10543
|
})
|
|
10402
10544
|
}
|
|
10403
10545
|
);
|
|
10404
|
-
const sendMessageTool = (0,
|
|
10546
|
+
const sendMessageTool = (0, import_langchain53.tool)(
|
|
10405
10547
|
async (input) => {
|
|
10406
10548
|
await mailboxStore.sendMessage(
|
|
10407
10549
|
teamId,
|
|
@@ -10439,7 +10581,7 @@ function createTeammateTools(options) {
|
|
|
10439
10581
|
read: msg.read
|
|
10440
10582
|
}));
|
|
10441
10583
|
};
|
|
10442
|
-
const readMessagesTool = (0,
|
|
10584
|
+
const readMessagesTool = (0, import_langchain53.tool)(
|
|
10443
10585
|
async (input, config) => {
|
|
10444
10586
|
const formatAndMarkAsRead = async (msgs2) => {
|
|
10445
10587
|
for (const msg of msgs2) {
|
|
@@ -10451,12 +10593,12 @@ function createTeammateTools(options) {
|
|
|
10451
10593
|
if (msgs.length > 0) {
|
|
10452
10594
|
const formatted2 = await formatAndMarkAsRead(msgs);
|
|
10453
10595
|
const relevantMsgs2 = await getRelevantMessagesForState();
|
|
10454
|
-
const toolMessage2 = new
|
|
10596
|
+
const toolMessage2 = new import_langchain53.ToolMessage({
|
|
10455
10597
|
content: formatted2,
|
|
10456
10598
|
tool_call_id: config.toolCall?.id,
|
|
10457
10599
|
name: "read_messages"
|
|
10458
10600
|
});
|
|
10459
|
-
return new
|
|
10601
|
+
return new import_langgraph10.Command({
|
|
10460
10602
|
update: { team_mailbox: relevantMsgs2, messages: [toolMessage2] }
|
|
10461
10603
|
});
|
|
10462
10604
|
}
|
|
@@ -10476,22 +10618,22 @@ function createTeammateTools(options) {
|
|
|
10476
10618
|
});
|
|
10477
10619
|
const relevantMsgs = await getRelevantMessagesForState();
|
|
10478
10620
|
if (msgs.length === 0) {
|
|
10479
|
-
const toolMessage2 = new
|
|
10621
|
+
const toolMessage2 = new import_langchain53.ToolMessage({
|
|
10480
10622
|
content: "No unread messages.",
|
|
10481
10623
|
tool_call_id: config.toolCall?.id,
|
|
10482
10624
|
name: "read_messages"
|
|
10483
10625
|
});
|
|
10484
|
-
return new
|
|
10626
|
+
return new import_langgraph10.Command({
|
|
10485
10627
|
update: { team_mailbox: relevantMsgs, messages: [toolMessage2] }
|
|
10486
10628
|
});
|
|
10487
10629
|
}
|
|
10488
10630
|
const formatted = await formatAndMarkAsRead(msgs);
|
|
10489
|
-
const toolMessage = new
|
|
10631
|
+
const toolMessage = new import_langchain53.ToolMessage({
|
|
10490
10632
|
content: formatted,
|
|
10491
10633
|
tool_call_id: config.toolCall?.id,
|
|
10492
10634
|
name: "read_messages"
|
|
10493
10635
|
});
|
|
10494
|
-
return new
|
|
10636
|
+
return new import_langgraph10.Command({
|
|
10495
10637
|
update: { team_mailbox: relevantMsgs, messages: [toolMessage] }
|
|
10496
10638
|
});
|
|
10497
10639
|
},
|
|
@@ -10501,7 +10643,7 @@ function createTeammateTools(options) {
|
|
|
10501
10643
|
schema: import_v33.z.object({})
|
|
10502
10644
|
}
|
|
10503
10645
|
);
|
|
10504
|
-
const checkTasksTool = (0,
|
|
10646
|
+
const checkTasksTool = (0, import_langchain53.tool)(
|
|
10505
10647
|
async () => {
|
|
10506
10648
|
const tasks = await taskListStore.getAllTasks(teamId);
|
|
10507
10649
|
return formatTaskSummary(tasks);
|
|
@@ -10512,7 +10654,7 @@ function createTeammateTools(options) {
|
|
|
10512
10654
|
schema: import_v33.z.object({})
|
|
10513
10655
|
}
|
|
10514
10656
|
);
|
|
10515
|
-
const broadcastMessageTool = (0,
|
|
10657
|
+
const broadcastMessageTool = (0, import_langchain53.tool)(
|
|
10516
10658
|
async (input) => {
|
|
10517
10659
|
const allAgents = await mailboxStore.getRegisteredAgents(teamId);
|
|
10518
10660
|
const recipients = allAgents.filter((a) => a !== agentId);
|
|
@@ -10697,7 +10839,7 @@ You have access to these tools:
|
|
|
10697
10839
|
- \`read_messages\`: Read messages from team_lead or teammates
|
|
10698
10840
|
- \`check_tasks\`: Get current status of all tasks in the team`;
|
|
10699
10841
|
const assistantId = getTeammateAssistantId(ctx.teamId, spec.name);
|
|
10700
|
-
agent = (0,
|
|
10842
|
+
agent = (0, import_langchain54.createAgent)({
|
|
10701
10843
|
model: spec.model ?? ctx.defaultModel,
|
|
10702
10844
|
systemPrompt: teammatePrompt,
|
|
10703
10845
|
tools: allTools,
|
|
@@ -10755,12 +10897,12 @@ async function spawnTeammate(options) {
|
|
|
10755
10897
|
function createTeamMiddleware(options) {
|
|
10756
10898
|
const { teamConfig, taskListStore, mailboxStore } = options;
|
|
10757
10899
|
const defaultModel = teamConfig.model ?? "claude-sonnet-4-5-20250929";
|
|
10758
|
-
const createTeamTool = (0,
|
|
10900
|
+
const createTeamTool = (0, import_langchain54.tool)(
|
|
10759
10901
|
async (input, config) => {
|
|
10760
|
-
const state = (0,
|
|
10902
|
+
const state = (0, import_langgraph11.getCurrentTaskInput)();
|
|
10761
10903
|
if (state?.team?.teamId) {
|
|
10762
10904
|
const existingId = state.team.teamId;
|
|
10763
|
-
const msg = new
|
|
10905
|
+
const msg = new import_langchain54.ToolMessage({
|
|
10764
10906
|
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.`,
|
|
10765
10907
|
tool_call_id: config.toolCall?.id,
|
|
10766
10908
|
name: "create_team"
|
|
@@ -10845,7 +10987,7 @@ Teammates are now working in the background. Keep calling \`check_tasks\` and \`
|
|
|
10845
10987
|
\`\`\`json
|
|
10846
10988
|
${teamJson}
|
|
10847
10989
|
\`\`\``;
|
|
10848
|
-
const toolMessage = new
|
|
10990
|
+
const toolMessage = new import_langchain54.ToolMessage({
|
|
10849
10991
|
content: summary,
|
|
10850
10992
|
tool_call_id: config.toolCall?.id,
|
|
10851
10993
|
name: "create_team"
|
|
@@ -10866,7 +11008,7 @@ ${teamJson}
|
|
|
10866
11008
|
})),
|
|
10867
11009
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
10868
11010
|
};
|
|
10869
|
-
return new
|
|
11011
|
+
return new import_langgraph11.Command({
|
|
10870
11012
|
update: { team: teamState, messages: [toolMessage] }
|
|
10871
11013
|
});
|
|
10872
11014
|
},
|
|
@@ -10926,11 +11068,11 @@ After calling create_team, you MUST:
|
|
|
10926
11068
|
}
|
|
10927
11069
|
);
|
|
10928
11070
|
const resolveTeamId = () => {
|
|
10929
|
-
const state = (0,
|
|
11071
|
+
const state = (0, import_langgraph11.getCurrentTaskInput)();
|
|
10930
11072
|
if (state?.team?.teamId) return state.team.teamId;
|
|
10931
11073
|
throw new Error("No team_id provided and no team in state. Call create_team first.");
|
|
10932
11074
|
};
|
|
10933
|
-
const addTasksTool = (0,
|
|
11075
|
+
const addTasksTool = (0, import_langchain54.tool)(
|
|
10934
11076
|
async (input, config) => {
|
|
10935
11077
|
const teamId = resolveTeamId();
|
|
10936
11078
|
const created = await taskListStore.addTasks(
|
|
@@ -10944,7 +11086,7 @@ After calling create_team, you MUST:
|
|
|
10944
11086
|
}))
|
|
10945
11087
|
);
|
|
10946
11088
|
const summary = created.map((t) => `- ${t.id}: "${t.title}"`).join("\n");
|
|
10947
|
-
return new
|
|
11089
|
+
return new import_langchain54.ToolMessage({
|
|
10948
11090
|
content: `Added ${created.length} task(s) to team ${teamId}:
|
|
10949
11091
|
${summary}
|
|
10950
11092
|
Sleeping teammates will wake up and claim these.`,
|
|
@@ -10995,20 +11137,20 @@ IMPORTANT: Assigning to a specific teammate
|
|
|
10995
11137
|
})
|
|
10996
11138
|
}
|
|
10997
11139
|
);
|
|
10998
|
-
const assignTaskTool = (0,
|
|
11140
|
+
const assignTaskTool = (0, import_langchain54.tool)(
|
|
10999
11141
|
async (input, config) => {
|
|
11000
11142
|
const teamId = resolveTeamId();
|
|
11001
11143
|
const task = await taskListStore.updateTask(teamId, input.task_id, {
|
|
11002
11144
|
assignee: input.assignee
|
|
11003
11145
|
});
|
|
11004
11146
|
if (!task) {
|
|
11005
|
-
return new
|
|
11147
|
+
return new import_langchain54.ToolMessage({
|
|
11006
11148
|
content: `Task ${input.task_id} not found in team ${teamId}.`,
|
|
11007
11149
|
tool_call_id: config.toolCall?.id,
|
|
11008
11150
|
name: "assign_task"
|
|
11009
11151
|
});
|
|
11010
11152
|
}
|
|
11011
|
-
return new
|
|
11153
|
+
return new import_langchain54.ToolMessage({
|
|
11012
11154
|
content: `Task "${task.title}" (${task.id}) assigned to ${input.assignee}.`,
|
|
11013
11155
|
tool_call_id: config.toolCall?.id,
|
|
11014
11156
|
name: "assign_task"
|
|
@@ -11023,20 +11165,20 @@ IMPORTANT: Assigning to a specific teammate
|
|
|
11023
11165
|
})
|
|
11024
11166
|
}
|
|
11025
11167
|
);
|
|
11026
|
-
const setTaskStatusTool = (0,
|
|
11168
|
+
const setTaskStatusTool = (0, import_langchain54.tool)(
|
|
11027
11169
|
async (input, config) => {
|
|
11028
11170
|
const teamId = resolveTeamId();
|
|
11029
11171
|
const task = await taskListStore.updateTask(teamId, input.task_id, {
|
|
11030
11172
|
status: input.status
|
|
11031
11173
|
});
|
|
11032
11174
|
if (!task) {
|
|
11033
|
-
return new
|
|
11175
|
+
return new import_langchain54.ToolMessage({
|
|
11034
11176
|
content: `Task ${input.task_id} not found in team ${teamId}.`,
|
|
11035
11177
|
tool_call_id: config.toolCall?.id,
|
|
11036
11178
|
name: "set_task_status"
|
|
11037
11179
|
});
|
|
11038
11180
|
}
|
|
11039
|
-
return new
|
|
11181
|
+
return new import_langchain54.ToolMessage({
|
|
11040
11182
|
content: `Task "${task.title}" (${task.id}) status set to ${input.status}.`,
|
|
11041
11183
|
tool_call_id: config.toolCall?.id,
|
|
11042
11184
|
name: "set_task_status"
|
|
@@ -11051,20 +11193,20 @@ IMPORTANT: Assigning to a specific teammate
|
|
|
11051
11193
|
})
|
|
11052
11194
|
}
|
|
11053
11195
|
);
|
|
11054
|
-
const setTaskDependenciesTool = (0,
|
|
11196
|
+
const setTaskDependenciesTool = (0, import_langchain54.tool)(
|
|
11055
11197
|
async (input, config) => {
|
|
11056
11198
|
const teamId = resolveTeamId();
|
|
11057
11199
|
const task = await taskListStore.updateTask(teamId, input.task_id, {
|
|
11058
11200
|
dependencies: input.dependencies
|
|
11059
11201
|
});
|
|
11060
11202
|
if (!task) {
|
|
11061
|
-
return new
|
|
11203
|
+
return new import_langchain54.ToolMessage({
|
|
11062
11204
|
content: `Task ${input.task_id} not found in team ${teamId}.`,
|
|
11063
11205
|
tool_call_id: config.toolCall?.id,
|
|
11064
11206
|
name: "set_task_dependencies"
|
|
11065
11207
|
});
|
|
11066
11208
|
}
|
|
11067
|
-
return new
|
|
11209
|
+
return new import_langchain54.ToolMessage({
|
|
11068
11210
|
content: `Task "${task.title}" (${task.id}) dependencies set to [${input.dependencies.join(", ")}].`,
|
|
11069
11211
|
tool_call_id: config.toolCall?.id,
|
|
11070
11212
|
name: "set_task_dependencies"
|
|
@@ -11079,16 +11221,16 @@ IMPORTANT: Assigning to a specific teammate
|
|
|
11079
11221
|
})
|
|
11080
11222
|
}
|
|
11081
11223
|
);
|
|
11082
|
-
const checkTasksTool = (0,
|
|
11224
|
+
const checkTasksTool = (0, import_langchain54.tool)(
|
|
11083
11225
|
async (input, config) => {
|
|
11084
11226
|
const teamId = resolveTeamId();
|
|
11085
11227
|
const tasks = await taskListStore.getAllTasks(teamId);
|
|
11086
11228
|
const tasksSnapshot = tasks;
|
|
11087
|
-
return new
|
|
11229
|
+
return new import_langgraph11.Command({
|
|
11088
11230
|
update: {
|
|
11089
11231
|
tasks: tasksSnapshot,
|
|
11090
11232
|
messages: [
|
|
11091
|
-
new
|
|
11233
|
+
new import_langchain54.ToolMessage({
|
|
11092
11234
|
content: formatTaskSummary(tasks),
|
|
11093
11235
|
tool_call_id: config.toolCall?.id,
|
|
11094
11236
|
name: "check_tasks"
|
|
@@ -11124,7 +11266,7 @@ Task Status Values:
|
|
|
11124
11266
|
})
|
|
11125
11267
|
}
|
|
11126
11268
|
);
|
|
11127
|
-
const sendMessageTool = (0,
|
|
11269
|
+
const sendMessageTool = (0, import_langchain54.tool)(
|
|
11128
11270
|
async (input, config) => {
|
|
11129
11271
|
const teamId = resolveTeamId();
|
|
11130
11272
|
await mailboxStore.sendMessage(
|
|
@@ -11134,7 +11276,7 @@ Task Status Values:
|
|
|
11134
11276
|
input.content,
|
|
11135
11277
|
"direct_message" /* DIRECT_MESSAGE */
|
|
11136
11278
|
);
|
|
11137
|
-
return new
|
|
11279
|
+
return new import_langchain54.ToolMessage({
|
|
11138
11280
|
content: `Message sent to ${input.to}.`,
|
|
11139
11281
|
tool_call_id: config.toolCall?.id,
|
|
11140
11282
|
name: "send_message"
|
|
@@ -11149,7 +11291,7 @@ Task Status Values:
|
|
|
11149
11291
|
})
|
|
11150
11292
|
}
|
|
11151
11293
|
);
|
|
11152
|
-
const readMessagesTool = (0,
|
|
11294
|
+
const readMessagesTool = (0, import_langchain54.tool)(
|
|
11153
11295
|
async (input, config) => {
|
|
11154
11296
|
const teamId = resolveTeamId();
|
|
11155
11297
|
const formatAndMarkAsRead = async (msgs2) => {
|
|
@@ -11177,12 +11319,12 @@ Task Status Values:
|
|
|
11177
11319
|
if (msgs.length > 0) {
|
|
11178
11320
|
const formatted2 = await formatAndMarkAsRead(msgs);
|
|
11179
11321
|
const allTeamMessages2 = await getAllTeamMessagesForState();
|
|
11180
|
-
const toolMessage2 = new
|
|
11322
|
+
const toolMessage2 = new import_langchain54.ToolMessage({
|
|
11181
11323
|
content: formatted2,
|
|
11182
11324
|
tool_call_id: config.toolCall?.id,
|
|
11183
11325
|
name: "read_messages"
|
|
11184
11326
|
});
|
|
11185
|
-
return new
|
|
11327
|
+
return new import_langgraph11.Command({
|
|
11186
11328
|
update: { team_mailbox: allTeamMessages2, messages: [toolMessage2] }
|
|
11187
11329
|
});
|
|
11188
11330
|
}
|
|
@@ -11209,22 +11351,22 @@ Task Status Values:
|
|
|
11209
11351
|
);
|
|
11210
11352
|
const allTeamMessages = await getAllTeamMessagesForState();
|
|
11211
11353
|
if (msgs.length === 0) {
|
|
11212
|
-
const toolMessage2 = new
|
|
11354
|
+
const toolMessage2 = new import_langchain54.ToolMessage({
|
|
11213
11355
|
content: "No unread messages from teammates.",
|
|
11214
11356
|
tool_call_id: config.toolCall?.id,
|
|
11215
11357
|
name: "read_messages"
|
|
11216
11358
|
});
|
|
11217
|
-
return new
|
|
11359
|
+
return new import_langgraph11.Command({
|
|
11218
11360
|
update: { team_mailbox: allTeamMessages, messages: [toolMessage2] }
|
|
11219
11361
|
});
|
|
11220
11362
|
}
|
|
11221
11363
|
const formatted = await formatAndMarkAsRead(msgs);
|
|
11222
|
-
const toolMessage = new
|
|
11364
|
+
const toolMessage = new import_langchain54.ToolMessage({
|
|
11223
11365
|
content: formatted,
|
|
11224
11366
|
tool_call_id: config.toolCall?.id,
|
|
11225
11367
|
name: "read_messages"
|
|
11226
11368
|
});
|
|
11227
|
-
return new
|
|
11369
|
+
return new import_langgraph11.Command({
|
|
11228
11370
|
update: { team_mailbox: allTeamMessages, messages: [toolMessage] }
|
|
11229
11371
|
});
|
|
11230
11372
|
},
|
|
@@ -11236,7 +11378,7 @@ Task Status Values:
|
|
|
11236
11378
|
})
|
|
11237
11379
|
}
|
|
11238
11380
|
);
|
|
11239
|
-
const disbandTeamTool = (0,
|
|
11381
|
+
const disbandTeamTool = (0, import_langchain54.tool)(
|
|
11240
11382
|
async (input, config) => {
|
|
11241
11383
|
const teamId = resolveTeamId();
|
|
11242
11384
|
await mailboxStore.broadcastMessage(
|
|
@@ -11246,7 +11388,7 @@ Task Status Values:
|
|
|
11246
11388
|
"shutdown_request" /* SHUTDOWN_REQUEST */
|
|
11247
11389
|
);
|
|
11248
11390
|
await new Promise((r) => setTimeout(r, 2e3));
|
|
11249
|
-
return new
|
|
11391
|
+
return new import_langchain54.ToolMessage({
|
|
11250
11392
|
content: `Team ${teamId} has been disbanded. All teammates notified and resources cleaned up.`,
|
|
11251
11393
|
tool_call_id: config.toolCall?.id,
|
|
11252
11394
|
name: "disband_team"
|
|
@@ -11257,7 +11399,7 @@ Task Status Values:
|
|
|
11257
11399
|
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."
|
|
11258
11400
|
}
|
|
11259
11401
|
);
|
|
11260
|
-
const broadcastMessageTool = (0,
|
|
11402
|
+
const broadcastMessageTool = (0, import_langchain54.tool)(
|
|
11261
11403
|
async (input, config) => {
|
|
11262
11404
|
const teamId = resolveTeamId();
|
|
11263
11405
|
await mailboxStore.broadcastMessage(
|
|
@@ -11266,7 +11408,7 @@ Task Status Values:
|
|
|
11266
11408
|
input.content,
|
|
11267
11409
|
"broadcast" /* BROADCAST */
|
|
11268
11410
|
);
|
|
11269
|
-
return new
|
|
11411
|
+
return new import_langchain54.ToolMessage({
|
|
11270
11412
|
content: `Broadcast message sent to all teammates.`,
|
|
11271
11413
|
tool_call_id: config.toolCall?.id,
|
|
11272
11414
|
name: "broadcast_message"
|
|
@@ -11280,7 +11422,7 @@ Task Status Values:
|
|
|
11280
11422
|
})
|
|
11281
11423
|
}
|
|
11282
11424
|
);
|
|
11283
|
-
return (0,
|
|
11425
|
+
return (0, import_langchain54.createMiddleware)({
|
|
11284
11426
|
name: "teamMiddleware",
|
|
11285
11427
|
tools: [
|
|
11286
11428
|
createTeamTool,
|
|
@@ -11388,7 +11530,7 @@ function createAgentTeam(config) {
|
|
|
11388
11530
|
];
|
|
11389
11531
|
const systemPrompt = config.systemPrompt + "\n\n" + TEAM_LEAD_BASE_PROMPT;
|
|
11390
11532
|
const stateSchema2 = createReactAgentSchema(TEAM_STATE_SCHEMA);
|
|
11391
|
-
return (0,
|
|
11533
|
+
return (0, import_langchain55.createAgent)({
|
|
11392
11534
|
model: config.model ?? "claude-sonnet-4-5-20250929",
|
|
11393
11535
|
systemPrompt,
|
|
11394
11536
|
tools: [],
|
|
@@ -11418,7 +11560,7 @@ var TeamAgentGraphBuilder = class {
|
|
|
11418
11560
|
const tools = params.tools.map((t) => {
|
|
11419
11561
|
const toolClient = getToolClient(t.key);
|
|
11420
11562
|
return toolClient;
|
|
11421
|
-
}).filter((
|
|
11563
|
+
}).filter((tool48) => tool48 !== void 0);
|
|
11422
11564
|
const teammates = params.subAgents.map((sa) => {
|
|
11423
11565
|
const baseConfig = sa.config;
|
|
11424
11566
|
return {
|
|
@@ -14078,10 +14220,10 @@ var McpLatticeManager = class _McpLatticeManager extends BaseLatticeManager {
|
|
|
14078
14220
|
}
|
|
14079
14221
|
const tools = await this.getAllTools();
|
|
14080
14222
|
console.log(`[MCP] Registering ${tools.length} tools to Tool Lattice...`);
|
|
14081
|
-
for (const
|
|
14082
|
-
const toolKey = prefix ? `${prefix}_${
|
|
14083
|
-
|
|
14084
|
-
toolLatticeManager.registerExistingTool(toolKey,
|
|
14223
|
+
for (const tool48 of tools) {
|
|
14224
|
+
const toolKey = prefix ? `${prefix}_${tool48.name}` : tool48.name;
|
|
14225
|
+
tool48.name = toolKey;
|
|
14226
|
+
toolLatticeManager.registerExistingTool(toolKey, tool48);
|
|
14085
14227
|
console.log(`[MCP] Registered tool: ${toolKey}`);
|
|
14086
14228
|
}
|
|
14087
14229
|
console.log(`[MCP] Successfully registered ${tools.length} tools to Tool Lattice`);
|