titan-agent 5.5.13 → 5.5.14
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/agent/agent.js +5 -12
- package/dist/agent/agent.js.map +1 -1
- package/dist/agent/agentLoop.js +3 -28
- package/dist/agent/agentLoop.js.map +1 -1
- package/dist/providers/ollama.js +2 -2
- package/dist/providers/ollama.js.map +1 -1
- package/dist/utils/constants.js +1 -1
- package/dist/utils/constants.js.map +1 -1
- package/docs/VISIONARY-IDEAS-2026-05-07.md +163 -0
- package/package.json +1 -1
- package/dist/agent/swarm.js +0 -148
- package/dist/agent/swarm.js.map +0 -1
package/dist/agent/swarm.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { chat } from "../providers/router.js";
|
|
3
|
-
import { executeTools, getToolDefinitions } from "./toolRunner.js";
|
|
4
|
-
import logger from "../utils/logger.js";
|
|
5
|
-
const COMPONENT = "Swarm";
|
|
6
|
-
const domainMap = {
|
|
7
|
-
// File Domain
|
|
8
|
-
"read_file": "file",
|
|
9
|
-
"write_file": "file",
|
|
10
|
-
"edit_file": "file",
|
|
11
|
-
"list_dir": "file",
|
|
12
|
-
"filesystem": "file",
|
|
13
|
-
// Web Domain
|
|
14
|
-
"web_search": "web",
|
|
15
|
-
"web_fetch": "web",
|
|
16
|
-
"webhook": "web",
|
|
17
|
-
"browser": "web",
|
|
18
|
-
// System Domain
|
|
19
|
-
"shell": "system",
|
|
20
|
-
"cron": "system",
|
|
21
|
-
"process": "system",
|
|
22
|
-
// Memory Domain
|
|
23
|
-
"memory_skill": "memory"
|
|
24
|
-
};
|
|
25
|
-
function getSwarmRouterTools() {
|
|
26
|
-
return [
|
|
27
|
-
{
|
|
28
|
-
type: "function",
|
|
29
|
-
function: {
|
|
30
|
-
name: "delegate_to_file_agent",
|
|
31
|
-
description: "Delegate a file system task to the File Agent (reading, writing, listing directories)",
|
|
32
|
-
parameters: {
|
|
33
|
-
type: "object",
|
|
34
|
-
properties: {
|
|
35
|
-
instruction: { type: "string", description: "Detailed instruction of what the File Agent should do" }
|
|
36
|
-
},
|
|
37
|
-
required: ["instruction"]
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
type: "function",
|
|
43
|
-
function: {
|
|
44
|
-
name: "delegate_to_web_agent",
|
|
45
|
-
description: "Delegate a web task to the Web Agent (searching the web, fetching URLs, controlling a browser)",
|
|
46
|
-
parameters: {
|
|
47
|
-
type: "object",
|
|
48
|
-
properties: {
|
|
49
|
-
instruction: { type: "string", description: "Detailed instruction of what the Web Agent should do" }
|
|
50
|
-
},
|
|
51
|
-
required: ["instruction"]
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
type: "function",
|
|
57
|
-
function: {
|
|
58
|
-
name: "delegate_to_system_agent",
|
|
59
|
-
description: "Delegate an OS task to the System Agent (running shell commands, managing processes/cron)",
|
|
60
|
-
parameters: {
|
|
61
|
-
type: "object",
|
|
62
|
-
properties: {
|
|
63
|
-
instruction: { type: "string", description: "Detailed instruction of what the System Agent should do" }
|
|
64
|
-
},
|
|
65
|
-
required: ["instruction"]
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
type: "function",
|
|
71
|
-
function: {
|
|
72
|
-
name: "delegate_to_memory_agent",
|
|
73
|
-
description: "Delegate a memory task to the Memory Agent (saving facts or retrieving knowledge)",
|
|
74
|
-
parameters: {
|
|
75
|
-
type: "object",
|
|
76
|
-
properties: {
|
|
77
|
-
instruction: { type: "string", description: "Detailed instruction of what the Memory Agent should do" }
|
|
78
|
-
},
|
|
79
|
-
required: ["instruction"]
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
];
|
|
84
|
-
}
|
|
85
|
-
function getDomainTools(domain) {
|
|
86
|
-
const allTools = getToolDefinitions();
|
|
87
|
-
return allTools.filter((t) => (domainMap[t.function.name] || "file") === domain);
|
|
88
|
-
}
|
|
89
|
-
async function runSubAgent(domain, instruction, model) {
|
|
90
|
-
logger.info(COMPONENT, `[Swarm] Spawning ${domain.toUpperCase()} Sub-Agent to handle: "${instruction.slice(0, 50)}..."`);
|
|
91
|
-
const domainTools = getDomainTools(domain);
|
|
92
|
-
const messages = [
|
|
93
|
-
{ role: "system", content: `You are the ${domain.toUpperCase()} Sub-Agent of TITAN.
|
|
94
|
-
Your ONLY job is to execute the tools necessary to fulfill this instruction:
|
|
95
|
-
|
|
96
|
-
${instruction}
|
|
97
|
-
|
|
98
|
-
Return a final text summary of the results.` },
|
|
99
|
-
{ role: "user", content: instruction }
|
|
100
|
-
];
|
|
101
|
-
let finalContent = "";
|
|
102
|
-
for (let round = 0; round < 3; round++) {
|
|
103
|
-
logger.debug(COMPONENT, `[Sub-Agent ${domain}] Round ${round + 1} with ${domainTools.length} tools`);
|
|
104
|
-
try {
|
|
105
|
-
const response = await chat({
|
|
106
|
-
model,
|
|
107
|
-
messages,
|
|
108
|
-
tools: domainTools.length > 0 ? domainTools : void 0,
|
|
109
|
-
maxTokens: 4096,
|
|
110
|
-
temperature: 0.2
|
|
111
|
-
// Low temp for strictly clinical tool execution
|
|
112
|
-
});
|
|
113
|
-
if (!response.toolCalls || response.toolCalls.length === 0) {
|
|
114
|
-
finalContent = response.content || "Task completed silently.";
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
messages.push({
|
|
118
|
-
role: "assistant",
|
|
119
|
-
content: response.content || "",
|
|
120
|
-
toolCalls: response.toolCalls
|
|
121
|
-
});
|
|
122
|
-
const toolResults = await executeTools(response.toolCalls);
|
|
123
|
-
for (const result of toolResults) {
|
|
124
|
-
messages.push({
|
|
125
|
-
role: "tool",
|
|
126
|
-
// Include name — Gemini's Ollama adapter rejects
|
|
127
|
-
// function_response with empty name (HTTP 400).
|
|
128
|
-
name: result.name,
|
|
129
|
-
content: result.content,
|
|
130
|
-
toolCallId: result.toolCallId
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
if (round === 2) {
|
|
134
|
-
finalContent = "Max sub-agent rounds reached. Partial results returned.";
|
|
135
|
-
}
|
|
136
|
-
} catch (e) {
|
|
137
|
-
logger.error(COMPONENT, `[Sub-Agent ${domain}] Error: ${e.message}`);
|
|
138
|
-
return `Sub-Agent encountered an error: ${e.message}`;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return `[Sub-Agent Result / Domain: ${domain}]
|
|
142
|
-
${finalContent}`;
|
|
143
|
-
}
|
|
144
|
-
export {
|
|
145
|
-
getSwarmRouterTools,
|
|
146
|
-
runSubAgent
|
|
147
|
-
};
|
|
148
|
-
//# sourceMappingURL=swarm.js.map
|
package/dist/agent/swarm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/agent/swarm.ts"],"sourcesContent":["/**\n * TITAN — Kimi Swarm Architecture\n * \n * Intercepts requests meant for kimi-k2.5:cloud and routes them through specialized Sub-Agents.\n * By breaking the 23-tool monolith into small 3-4 tool domain chunks, we prevent Kimi from\n * suffering context collapse and timeouts.\n */\nimport { chat } from '../providers/router.js';\nimport { executeTools, getToolDefinitions } from './toolRunner.js';\nimport type { ChatMessage, ToolDefinition } from '../providers/base.js';\nimport logger from '../utils/logger.js';\n\nconst COMPONENT = 'Swarm';\n\nexport type Domain = 'file' | 'web' | 'system' | 'memory';\n\n// Map generic tools to their specific domains\nconst domainMap: Record<string, Domain> = {\n // File Domain\n 'read_file': 'file',\n 'write_file': 'file',\n 'edit_file': 'file',\n 'list_dir': 'file',\n 'filesystem': 'file',\n // Web Domain\n 'web_search': 'web',\n 'web_fetch': 'web',\n 'webhook': 'web',\n 'browser': 'web',\n // System Domain\n 'shell': 'system',\n 'cron': 'system',\n 'process': 'system',\n // Memory Domain\n 'memory_skill': 'memory',\n};\n\n/** Get the Swarm Router tools to present to the Main LLM */\nexport function getSwarmRouterTools(): ToolDefinition[] {\n return [\n {\n type: 'function',\n function: {\n name: 'delegate_to_file_agent',\n description: 'Delegate a file system task to the File Agent (reading, writing, listing directories)',\n parameters: {\n type: 'object',\n properties: {\n instruction: { type: 'string', description: 'Detailed instruction of what the File Agent should do' }\n },\n required: ['instruction']\n }\n }\n },\n {\n type: 'function',\n function: {\n name: 'delegate_to_web_agent',\n description: 'Delegate a web task to the Web Agent (searching the web, fetching URLs, controlling a browser)',\n parameters: {\n type: 'object',\n properties: {\n instruction: { type: 'string', description: 'Detailed instruction of what the Web Agent should do' }\n },\n required: ['instruction']\n }\n }\n },\n {\n type: 'function',\n function: {\n name: 'delegate_to_system_agent',\n description: 'Delegate an OS task to the System Agent (running shell commands, managing processes/cron)',\n parameters: {\n type: 'object',\n properties: {\n instruction: { type: 'string', description: 'Detailed instruction of what the System Agent should do' }\n },\n required: ['instruction']\n }\n }\n },\n {\n type: 'function',\n function: {\n name: 'delegate_to_memory_agent',\n description: 'Delegate a memory task to the Memory Agent (saving facts or retrieving knowledge)',\n parameters: {\n type: 'object',\n properties: {\n instruction: { type: 'string', description: 'Detailed instruction of what the Memory Agent should do' }\n },\n required: ['instruction']\n }\n }\n }\n ];\n}\n\n/** Get the exact subset of registered tools belonging to a specific domain */\nfunction getDomainTools(domain: Domain): ToolDefinition[] {\n const allTools = getToolDefinitions();\n // Default to 'file' domain for unrecognized tools to err on the side of caution\n return allTools.filter(t => (domainMap[t.function.name] || 'file') === domain);\n}\n\n/** \n * Spawns an ephemeral Sub-Agent with a restricted toolset. \n * This is executed sequentially by the Main Director.\n */\nexport async function runSubAgent(\n domain: Domain,\n instruction: string,\n model: string,\n): Promise<string> {\n logger.info(COMPONENT, `[Swarm] Spawning ${domain.toUpperCase()} Sub-Agent to handle: \"${instruction.slice(0, 50)}...\"`);\n\n const domainTools = getDomainTools(domain);\n\n // Mini agent loop (max 3 rounds)\n const messages: ChatMessage[] = [\n { role: 'system', content: `You are the ${domain.toUpperCase()} Sub-Agent of TITAN.\\nYour ONLY job is to execute the tools necessary to fulfill this instruction:\\n\\n${instruction}\\n\\nReturn a final text summary of the results.` },\n { role: 'user', content: instruction }\n ];\n\n let finalContent = '';\n\n for (let round = 0; round < 3; round++) {\n logger.debug(COMPONENT, `[Sub-Agent ${domain}] Round ${round + 1} with ${domainTools.length} tools`);\n\n try {\n const response = await chat({\n model,\n messages,\n tools: domainTools.length > 0 ? domainTools : undefined,\n maxTokens: 4096,\n temperature: 0.2, // Low temp for strictly clinical tool execution\n });\n\n if (!response.toolCalls || response.toolCalls.length === 0) {\n finalContent = response.content || 'Task completed silently.';\n break;\n }\n\n messages.push({\n role: 'assistant',\n content: response.content || '',\n toolCalls: response.toolCalls,\n });\n\n const toolResults = await executeTools(response.toolCalls);\n\n for (const result of toolResults) {\n messages.push({\n role: 'tool',\n // Include name — Gemini's Ollama adapter rejects\n // function_response with empty name (HTTP 400).\n name: result.name,\n content: result.content,\n toolCallId: result.toolCallId,\n });\n }\n\n if (round === 2) {\n finalContent = \"Max sub-agent rounds reached. Partial results returned.\";\n }\n\n } catch (e) {\n logger.error(COMPONENT, `[Sub-Agent ${domain}] Error: ${(e as Error).message}`);\n return `Sub-Agent encountered an error: ${(e as Error).message}`;\n }\n }\n\n return `[Sub-Agent Result / Domain: ${domain}]\\n${finalContent}`;\n}\n"],"mappings":";AAOA,SAAS,YAAY;AACrB,SAAS,cAAc,0BAA0B;AAEjD,OAAO,YAAY;AAEnB,MAAM,YAAY;AAKlB,MAAM,YAAoC;AAAA;AAAA,EAEtC,aAAa;AAAA,EACb,cAAc;AAAA,EACd,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,cAAc;AAAA;AAAA,EAEd,cAAc;AAAA,EACd,aAAa;AAAA,EACb,WAAW;AAAA,EACX,WAAW;AAAA;AAAA,EAEX,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,WAAW;AAAA;AAAA,EAEX,gBAAgB;AACpB;AAGO,SAAS,sBAAwC;AACpD,S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