@fortressllm/sybil 0.0.3
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/.env copy +91 -0
- package/.env.example +139 -0
- package/BROWSER_CONTROL.md +354 -0
- package/CLI_CHAT_FEATURE.md +224 -0
- package/CLI_GUIDE.md +359 -0
- package/DYNAMIC_SKILLS.md +345 -0
- package/DockerFile.sandbox +14 -0
- package/PROGRESS.md +249 -0
- package/README.md +281 -0
- package/RENAME_LOG.md +62 -0
- package/SIMPLIFIED_TELEGRAM_UX.md +273 -0
- package/SYBIL_SUMMARY.md +360 -0
- package/TASK11_NETWORK.md +202 -0
- package/TASK14_CLI.md +432 -0
- package/TASK8_SAFETY.md +317 -0
- package/TASK9_COMPLETION.md +186 -0
- package/TASK9_SUMMARY.md +201 -0
- package/TELEGRAM_OTP_AUTH.md +359 -0
- package/VECTOR_MEMORY.md +163 -0
- package/assets/logo.png +0 -0
- package/cypfq_code_search.md +287 -0
- package/cypfq_driver_search.md +297 -0
- package/cypfq_github_search.md +297 -0
- package/cypfq_repo_search.md +370 -0
- package/dist/agents/autonomous-agent.d.ts +61 -0
- package/dist/agents/autonomous-agent.d.ts.map +1 -0
- package/dist/agents/autonomous-agent.js +536 -0
- package/dist/agents/autonomous-agent.js.map +1 -0
- package/dist/agents/network.d.ts +1006 -0
- package/dist/agents/network.d.ts.map +1 -0
- package/dist/agents/network.js +1266 -0
- package/dist/agents/network.js.map +1 -0
- package/dist/cli/commands/backup.d.ts +3 -0
- package/dist/cli/commands/backup.d.ts.map +1 -0
- package/dist/cli/commands/backup.js +63 -0
- package/dist/cli/commands/backup.js.map +1 -0
- package/dist/cli/commands/config.d.ts +3 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +163 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +3 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/doctor.js +107 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/init.d.ts +3 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +138 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/logs.d.ts +3 -0
- package/dist/cli/commands/logs.d.ts.map +1 -0
- package/dist/cli/commands/logs.js +81 -0
- package/dist/cli/commands/logs.js.map +1 -0
- package/dist/cli/commands/otp.d.ts +3 -0
- package/dist/cli/commands/otp.d.ts.map +1 -0
- package/dist/cli/commands/otp.js +142 -0
- package/dist/cli/commands/otp.js.map +1 -0
- package/dist/cli/commands/restore.d.ts +3 -0
- package/dist/cli/commands/restore.d.ts.map +1 -0
- package/dist/cli/commands/restore.js +99 -0
- package/dist/cli/commands/restore.js.map +1 -0
- package/dist/cli/commands/start.d.ts +3 -0
- package/dist/cli/commands/start.d.ts.map +1 -0
- package/dist/cli/commands/start.js +65 -0
- package/dist/cli/commands/start.js.map +1 -0
- package/dist/cli/commands/status.d.ts +3 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +68 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/stop.d.ts +3 -0
- package/dist/cli/commands/stop.d.ts.map +1 -0
- package/dist/cli/commands/stop.js +62 -0
- package/dist/cli/commands/stop.js.map +1 -0
- package/dist/cli/commands/update.d.ts +3 -0
- package/dist/cli/commands/update.d.ts.map +1 -0
- package/dist/cli/commands/update.js +49 -0
- package/dist/cli/commands/update.js.map +1 -0
- package/dist/cli/commands/whatsapp.d.ts +3 -0
- package/dist/cli/commands/whatsapp.d.ts.map +1 -0
- package/dist/cli/commands/whatsapp.js +281 -0
- package/dist/cli/commands/whatsapp.js.map +1 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +58 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli.d.ts +9 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +750 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +109 -0
- package/dist/index.js.map +1 -0
- package/dist/mastra/index.d.ts +4 -0
- package/dist/mastra/index.d.ts.map +1 -0
- package/dist/mastra/index.js +37 -0
- package/dist/mastra/index.js.map +1 -0
- package/dist/mastra/memory.d.ts +9 -0
- package/dist/mastra/memory.d.ts.map +1 -0
- package/dist/mastra/memory.js +92 -0
- package/dist/mastra/memory.js.map +1 -0
- package/dist/processors/index.d.ts +74 -0
- package/dist/processors/index.d.ts.map +1 -0
- package/dist/processors/index.js +153 -0
- package/dist/processors/index.js.map +1 -0
- package/dist/processors/semantic-recall.d.ts +63 -0
- package/dist/processors/semantic-recall.d.ts.map +1 -0
- package/dist/processors/semantic-recall.js +216 -0
- package/dist/processors/semantic-recall.js.map +1 -0
- package/dist/processors/tool-search.d.ts +26 -0
- package/dist/processors/tool-search.d.ts.map +1 -0
- package/dist/processors/tool-search.js +41 -0
- package/dist/processors/tool-search.js.map +1 -0
- package/dist/skills/dynamic/skill-generator.d.ts +169 -0
- package/dist/skills/dynamic/skill-generator.d.ts.map +1 -0
- package/dist/skills/dynamic/skill-generator.js +488 -0
- package/dist/skills/dynamic/skill-generator.js.map +1 -0
- package/dist/tools/agent-delegation-tools.d.ts +142 -0
- package/dist/tools/agent-delegation-tools.d.ts.map +1 -0
- package/dist/tools/agent-delegation-tools.js +263 -0
- package/dist/tools/agent-delegation-tools.js.map +1 -0
- package/dist/tools/browser-tools.d.ts +374 -0
- package/dist/tools/browser-tools.d.ts.map +1 -0
- package/dist/tools/browser-tools.js +752 -0
- package/dist/tools/browser-tools.js.map +1 -0
- package/dist/tools/dynamic/registry.d.ts +61 -0
- package/dist/tools/dynamic/registry.d.ts.map +1 -0
- package/dist/tools/dynamic/registry.js +121 -0
- package/dist/tools/dynamic/registry.js.map +1 -0
- package/dist/tools/dynamic/tool-generator.d.ts +99 -0
- package/dist/tools/dynamic/tool-generator.d.ts.map +1 -0
- package/dist/tools/dynamic/tool-generator.js +367 -0
- package/dist/tools/dynamic/tool-generator.js.map +1 -0
- package/dist/tools/extended-tools.d.ts +176 -0
- package/dist/tools/extended-tools.d.ts.map +1 -0
- package/dist/tools/extended-tools.js +464 -0
- package/dist/tools/extended-tools.js.map +1 -0
- package/dist/tools/library/calendar/index.d.ts +134 -0
- package/dist/tools/library/calendar/index.d.ts.map +1 -0
- package/dist/tools/library/calendar/index.js +160 -0
- package/dist/tools/library/calendar/index.js.map +1 -0
- package/dist/tools/podman-workspace-mcp-cli.d.ts +3 -0
- package/dist/tools/podman-workspace-mcp-cli.d.ts.map +1 -0
- package/dist/tools/podman-workspace-mcp-cli.js +12 -0
- package/dist/tools/podman-workspace-mcp-cli.js.map +1 -0
- package/dist/tools/podman-workspace-mcp.d.ts +247 -0
- package/dist/tools/podman-workspace-mcp.d.ts.map +1 -0
- package/dist/tools/podman-workspace-mcp.js +1093 -0
- package/dist/tools/podman-workspace-mcp.js.map +1 -0
- package/dist/tools/podman-workspace.d.ts +148 -0
- package/dist/tools/podman-workspace.d.ts.map +1 -0
- package/dist/tools/podman-workspace.js +682 -0
- package/dist/tools/podman-workspace.js.map +1 -0
- package/dist/tools/telegram-file-tools.d.ts +78 -0
- package/dist/tools/telegram-file-tools.d.ts.map +1 -0
- package/dist/tools/telegram-file-tools.js +294 -0
- package/dist/tools/telegram-file-tools.js.map +1 -0
- package/dist/tools/tool-registry.d.ts +467 -0
- package/dist/tools/tool-registry.d.ts.map +1 -0
- package/dist/tools/tool-registry.js +156 -0
- package/dist/tools/tool-registry.js.map +1 -0
- package/dist/tools/web-tools.d.ts +77 -0
- package/dist/tools/web-tools.d.ts.map +1 -0
- package/dist/tools/web-tools.js +416 -0
- package/dist/tools/web-tools.js.map +1 -0
- package/dist/tools/whatsapp-autoreply-tools.d.ts +118 -0
- package/dist/tools/whatsapp-autoreply-tools.d.ts.map +1 -0
- package/dist/tools/whatsapp-autoreply-tools.js +503 -0
- package/dist/tools/whatsapp-autoreply-tools.js.map +1 -0
- package/dist/tools/whatsapp-tools.d.ts +175 -0
- package/dist/tools/whatsapp-tools.d.ts.map +1 -0
- package/dist/tools/whatsapp-tools.js +566 -0
- package/dist/tools/whatsapp-tools.js.map +1 -0
- package/dist/utils/logger.d.ts +65 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +307 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/model-config.d.ts +73 -0
- package/dist/utils/model-config.d.ts.map +1 -0
- package/dist/utils/model-config.js +366 -0
- package/dist/utils/model-config.js.map +1 -0
- package/dist/utils/semantic-memory.d.ts +82 -0
- package/dist/utils/semantic-memory.d.ts.map +1 -0
- package/dist/utils/semantic-memory.js +189 -0
- package/dist/utils/semantic-memory.js.map +1 -0
- package/dist/utils/system.d.ts +2 -0
- package/dist/utils/system.d.ts.map +1 -0
- package/dist/utils/system.js +24 -0
- package/dist/utils/system.js.map +1 -0
- package/dist/utils/telegram-auth.d.ts +54 -0
- package/dist/utils/telegram-auth.d.ts.map +1 -0
- package/dist/utils/telegram-auth.js +146 -0
- package/dist/utils/telegram-auth.js.map +1 -0
- package/dist/utils/telegram.d.ts +7 -0
- package/dist/utils/telegram.d.ts.map +1 -0
- package/dist/utils/telegram.js +1494 -0
- package/dist/utils/telegram.js.map +1 -0
- package/dist/utils/whatsapp-client.d.ts +166 -0
- package/dist/utils/whatsapp-client.d.ts.map +1 -0
- package/dist/utils/whatsapp-client.js +722 -0
- package/dist/utils/whatsapp-client.js.map +1 -0
- package/dist/workflows/planner-workflow.d.ts +39 -0
- package/dist/workflows/planner-workflow.d.ts.map +1 -0
- package/dist/workflows/planner-workflow.js +165 -0
- package/dist/workflows/planner-workflow.js.map +1 -0
- package/dist/workflows/skill-builder-workflow.d.ts +16 -0
- package/dist/workflows/skill-builder-workflow.d.ts.map +1 -0
- package/dist/workflows/skill-builder-workflow.js +157 -0
- package/dist/workflows/skill-builder-workflow.js.map +1 -0
- package/dist/workspace/index.d.ts +23 -0
- package/dist/workspace/index.d.ts.map +1 -0
- package/dist/workspace/index.js +64 -0
- package/dist/workspace/index.js.map +1 -0
- package/docs/README.md +140 -0
- package/docs/api/agents.md +481 -0
- package/docs/api/browser-tools.md +469 -0
- package/docs/api/memory.md +629 -0
- package/docs/architecture/agent-networks.md +586 -0
- package/docs/architecture/memory.md +579 -0
- package/docs/architecture/overview.md +436 -0
- package/docs/architecture/tools.md +637 -0
- package/docs/cli-tui.md +367 -0
- package/docs/guides/environment-variables.md +502 -0
- package/docs/guides/troubleshooting.md +882 -0
- package/docs/tutorials/agent-networks.md +432 -0
- package/docs/tutorials/dynamic-tools.md +469 -0
- package/docs/tutorials/getting-started.md +263 -0
- package/docs/tutorials/skills.md +561 -0
- package/docs/tutorials/web-browsing.md +329 -0
- package/mastra.db-shm +0 -0
- package/mastra.db-wal +0 -0
- package/package.json +71 -0
- package/plan.md +601 -0
- package/skills/code-review/SKILL.md +48 -0
- package/skills/task-planning/SKILL.md +55 -0
- package/skills/web-research/SKILL.md +79 -0
- package/skills/whatsapp-management/SKILL.md +78 -0
- package/src/agents/autonomous-agent.ts +626 -0
- package/src/agents/network.ts +1307 -0
- package/src/cli/commands/backup.ts +78 -0
- package/src/cli/commands/config.ts +176 -0
- package/src/cli/commands/doctor.ts +111 -0
- package/src/cli/commands/init.ts +150 -0
- package/src/cli/commands/logs.ts +94 -0
- package/src/cli/commands/otp.ts +162 -0
- package/src/cli/commands/restore.ts +118 -0
- package/src/cli/commands/start.ts +76 -0
- package/src/cli/commands/status.ts +81 -0
- package/src/cli/commands/stop.ts +68 -0
- package/src/cli/commands/update.ts +61 -0
- package/src/cli/commands/whatsapp.ts +322 -0
- package/src/cli/index.ts +69 -0
- package/src/cli.ts +830 -0
- package/src/index.ts +124 -0
- package/src/mastra/index.ts +49 -0
- package/src/mastra/memory.ts +99 -0
- package/src/mastra/public/workspace/plan.md +115 -0
- package/src/mastra/public/workspace/research/react-tailwind/skill.md +47 -0
- package/src/processors/index.ts +170 -0
- package/src/processors/semantic-recall.ts +277 -0
- package/src/processors/tool-search.ts +46 -0
- package/src/skills/dynamic/skill-generator.ts +568 -0
- package/src/tools/agent-delegation-tools.ts +301 -0
- package/src/tools/browser-tools.ts +792 -0
- package/src/tools/dynamic/registry.ts +144 -0
- package/src/tools/dynamic/tool-generator.ts +406 -0
- package/src/tools/extended-tools.ts +498 -0
- package/src/tools/library/calendar/index.ts +172 -0
- package/src/tools/podman-workspace-mcp-cli.ts +14 -0
- package/src/tools/podman-workspace-mcp.ts +1290 -0
- package/src/tools/podman-workspace.ts +858 -0
- package/src/tools/telegram-file-tools.ts +320 -0
- package/src/tools/tool-registry.ts +233 -0
- package/src/tools/web-tools.ts +461 -0
- package/src/tools/whatsapp-autoreply-tools.ts +616 -0
- package/src/tools/whatsapp-tools.ts +602 -0
- package/src/utils/logger.ts +368 -0
- package/src/utils/model-config.ts +437 -0
- package/src/utils/semantic-memory.ts +230 -0
- package/src/utils/system.ts +25 -0
- package/src/utils/telegram-auth.ts +201 -0
- package/src/utils/telegram.ts +1847 -0
- package/src/utils/whatsapp-client.ts +808 -0
- package/src/workflows/planner-workflow.ts +178 -0
- package/src/workflows/skill-builder-workflow.ts +175 -0
- package/src/workspace/index.ts +69 -0
- package/tsconfig.json +22 -0
- package/view-logs.sh +116 -0
- package/whatsapp-session.sh +197 -0
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
// agent-delegation-tools.ts - Tools for agents to delegate to other agents
|
|
2
|
+
import { createTool } from "@mastra/core/tools";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { mastra } from "../mastra/index.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Helper function to delegate to an agent
|
|
8
|
+
*/
|
|
9
|
+
async function delegateToAgent(
|
|
10
|
+
agentName: string,
|
|
11
|
+
task: string,
|
|
12
|
+
context: any,
|
|
13
|
+
timeout: number = 60000
|
|
14
|
+
) {
|
|
15
|
+
// Get thread/resource from request context if available
|
|
16
|
+
const threadId = context?.requestContext?.get("threadId") as string | undefined;
|
|
17
|
+
const resourceId = context?.requestContext?.get("resourceId") as string | undefined;
|
|
18
|
+
|
|
19
|
+
const startTime = Date.now();
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
// Map agent names to actual agent IDs
|
|
23
|
+
const agentIdMap: Record<string, string> = {
|
|
24
|
+
planner: "plannerAgent",
|
|
25
|
+
researcher: "researcherAgent",
|
|
26
|
+
executor: "executorAgent",
|
|
27
|
+
whatsapp: "whatsappAgent",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const targetAgentId = agentIdMap[agentName];
|
|
31
|
+
if (!targetAgentId) {
|
|
32
|
+
return {
|
|
33
|
+
success: false,
|
|
34
|
+
agentName,
|
|
35
|
+
result: "",
|
|
36
|
+
duration: "0ms",
|
|
37
|
+
error: `Unknown agent: ${agentName}. Available: planner, researcher, executor, whatsapp`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Get the target agent
|
|
42
|
+
const agent = mastra.getAgent(targetAgentId);
|
|
43
|
+
|
|
44
|
+
// Execute with timeout
|
|
45
|
+
const result = await Promise.race([
|
|
46
|
+
agent.generate(task, {
|
|
47
|
+
...(threadId && resourceId ? {
|
|
48
|
+
memory: {
|
|
49
|
+
thread: threadId,
|
|
50
|
+
resource: resourceId,
|
|
51
|
+
},
|
|
52
|
+
} : {}),
|
|
53
|
+
}),
|
|
54
|
+
new Promise<never>((_, reject) =>
|
|
55
|
+
setTimeout(() => reject(new Error("Delegation timeout")), timeout)
|
|
56
|
+
),
|
|
57
|
+
]);
|
|
58
|
+
|
|
59
|
+
const duration = Date.now() - startTime;
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
success: true,
|
|
63
|
+
agentName,
|
|
64
|
+
result: result.text,
|
|
65
|
+
duration: `${duration}ms`,
|
|
66
|
+
};
|
|
67
|
+
} catch (error: any) {
|
|
68
|
+
const duration = Date.now() - startTime;
|
|
69
|
+
return {
|
|
70
|
+
success: false,
|
|
71
|
+
agentName,
|
|
72
|
+
result: "",
|
|
73
|
+
duration: `${duration}ms`,
|
|
74
|
+
error: error.message || "Delegation failed",
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Tool: Delegate task to another agent
|
|
81
|
+
* Allows any agent to spawn a sub-agent to handle specific tasks
|
|
82
|
+
*/
|
|
83
|
+
export const delegateToAgentTool = createTool({
|
|
84
|
+
id: "delegate-to-agent",
|
|
85
|
+
description: "Delegate a task to another specialized agent. Use this when the current agent lacks the specific expertise needed for a sub-task. Available agents: planner (complex planning), researcher (information gathering), executor (code/actions), whatsapp (messaging and communication).",
|
|
86
|
+
inputSchema: z.object({
|
|
87
|
+
agentName: z.enum(["planner", "researcher", "executor", "whatsapp"]).describe("Which agent to delegate to"),
|
|
88
|
+
task: z.string().describe("Clear description of what the agent should do"),
|
|
89
|
+
context: z.string().optional().describe("Additional context or background information"),
|
|
90
|
+
timeout: z.number().optional().describe("Timeout in milliseconds (default: 60000)"),
|
|
91
|
+
}),
|
|
92
|
+
outputSchema: z.object({
|
|
93
|
+
success: z.boolean(),
|
|
94
|
+
agentName: z.string(),
|
|
95
|
+
result: z.string(),
|
|
96
|
+
duration: z.string(),
|
|
97
|
+
error: z.string().optional(),
|
|
98
|
+
}),
|
|
99
|
+
execute: async (inputData, context) => {
|
|
100
|
+
const { agentName, task, context: additionalContext, timeout = 60000 } = inputData;
|
|
101
|
+
|
|
102
|
+
// Build the prompt
|
|
103
|
+
let fullPrompt = task;
|
|
104
|
+
if (additionalContext) {
|
|
105
|
+
fullPrompt = `Context: ${additionalContext}\n\nTask: ${task}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return delegateToAgent(agentName, fullPrompt, context, timeout);
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Tool: Delegate to Planner Agent
|
|
114
|
+
* Specialized tool for planning tasks
|
|
115
|
+
*/
|
|
116
|
+
export const delegateToPlannerTool = createTool({
|
|
117
|
+
id: "delegate-to-planner",
|
|
118
|
+
description: "Delegate a planning task to the Planner Agent. Use for: breaking down complex goals, creating execution plans, identifying dependencies, estimating effort. Returns a structured plan with steps and timelines.",
|
|
119
|
+
inputSchema: z.object({
|
|
120
|
+
goal: z.string().describe("The goal or objective to plan"),
|
|
121
|
+
constraints: z.string().optional().describe("Any constraints, limitations, or requirements"),
|
|
122
|
+
complexity: z.enum(["simple", "medium", "complex"]).optional().describe("Expected complexity level"),
|
|
123
|
+
}),
|
|
124
|
+
outputSchema: z.object({
|
|
125
|
+
success: z.boolean(),
|
|
126
|
+
plan: z.string(),
|
|
127
|
+
estimatedTime: z.string().optional(),
|
|
128
|
+
error: z.string().optional(),
|
|
129
|
+
}),
|
|
130
|
+
execute: async (inputData, context) => {
|
|
131
|
+
const { goal, constraints, complexity } = inputData;
|
|
132
|
+
|
|
133
|
+
const task = `Create a ${complexity || "structured"} plan for: ${goal}${constraints ? `\n\nConstraints: ${constraints}` : ""}`;
|
|
134
|
+
|
|
135
|
+
const result = await delegateToAgent("planner", task, context, 60000);
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
success: result.success,
|
|
139
|
+
plan: result.result,
|
|
140
|
+
estimatedTime: result.success ? result.duration : undefined,
|
|
141
|
+
error: result.error,
|
|
142
|
+
};
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Tool: Delegate to Researcher Agent
|
|
148
|
+
* Specialized tool for research tasks
|
|
149
|
+
*/
|
|
150
|
+
export const delegateToResearcherTool = createTool({
|
|
151
|
+
id: "delegate-to-researcher",
|
|
152
|
+
description: "Delegate a research task to the Researcher Agent. Use for: gathering information, fact-checking, finding sources, comprehensive research. Returns findings with citations and confidence levels.",
|
|
153
|
+
inputSchema: z.object({
|
|
154
|
+
topic: z.string().describe("Topic or question to research"),
|
|
155
|
+
depth: z.enum(["quick", "standard", "deep"]).optional().describe("Research depth (default: standard)"),
|
|
156
|
+
sources: z.number().optional().describe("Number of sources to check (default: 5)"),
|
|
157
|
+
}),
|
|
158
|
+
outputSchema: z.object({
|
|
159
|
+
success: z.boolean(),
|
|
160
|
+
findings: z.string(),
|
|
161
|
+
sourcesChecked: z.number().optional(),
|
|
162
|
+
error: z.string().optional(),
|
|
163
|
+
}),
|
|
164
|
+
execute: async (inputData, context) => {
|
|
165
|
+
const { topic, depth = "standard", sources = 5 } = inputData;
|
|
166
|
+
|
|
167
|
+
const task = `Research: ${topic}\n\nRequirements:\n- Depth: ${depth}\n- Check ${sources} sources minimum\n- Cite all sources with confidence levels\n- Note any conflicting information`;
|
|
168
|
+
|
|
169
|
+
const result = await delegateToAgent("researcher", task, context, 60000);
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
success: result.success,
|
|
173
|
+
findings: result.result,
|
|
174
|
+
sourcesChecked: result.success ? sources : undefined,
|
|
175
|
+
error: result.error,
|
|
176
|
+
};
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Tool: Delegate to Executor Agent
|
|
182
|
+
* Specialized tool for execution tasks
|
|
183
|
+
*/
|
|
184
|
+
export const delegateToExecutorTool = createTool({
|
|
185
|
+
id: "delegate-to-executor",
|
|
186
|
+
description: "Delegate an execution task to the Executor Agent. Use for: writing code, running commands, file operations, browser automation, performing actions. Returns execution results and any output files.",
|
|
187
|
+
inputSchema: z.object({
|
|
188
|
+
task: z.string().describe("Specific task to execute (e.g., 'Write a Python script to...', 'Create a file that...')"),
|
|
189
|
+
deliverables: z.array(z.string()).optional().describe("Expected outputs or deliverables"),
|
|
190
|
+
verify: z.boolean().optional().describe("Whether to verify execution success (default: true)"),
|
|
191
|
+
}),
|
|
192
|
+
outputSchema: z.object({
|
|
193
|
+
success: z.boolean(),
|
|
194
|
+
result: z.string(),
|
|
195
|
+
filesCreated: z.array(z.string()).optional(),
|
|
196
|
+
error: z.string().optional(),
|
|
197
|
+
}),
|
|
198
|
+
execute: async (inputData, context) => {
|
|
199
|
+
const { task, deliverables, verify = true } = inputData;
|
|
200
|
+
|
|
201
|
+
let fullTask = task;
|
|
202
|
+
if (deliverables && deliverables.length > 0) {
|
|
203
|
+
fullTask += `\n\nDeliverables:\n${deliverables.map(d => `- ${d}`).join("\n")}`;
|
|
204
|
+
}
|
|
205
|
+
if (verify) {
|
|
206
|
+
fullTask += "\n\nVerify all deliverables were created successfully.";
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const result = await delegateToAgent("executor", fullTask, context, 60000);
|
|
210
|
+
|
|
211
|
+
// Extract file paths from result (simple heuristic)
|
|
212
|
+
const filesCreated: string[] = [];
|
|
213
|
+
if (result.success && result.result) {
|
|
214
|
+
const fileMatches = result.result.match(/(?:created|saved|wrote|generated).*?(?:file|to):?\s*['"`]?(\/[^\s'"`,]+)/gi);
|
|
215
|
+
if (fileMatches) {
|
|
216
|
+
fileMatches.forEach((match: string) => {
|
|
217
|
+
const path = match.match(/(\/[^\s'"`,]+)/)?.[1];
|
|
218
|
+
if (path && !filesCreated.includes(path)) {
|
|
219
|
+
filesCreated.push(path);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return {
|
|
226
|
+
success: result.success,
|
|
227
|
+
result: result.result,
|
|
228
|
+
filesCreated: filesCreated.length > 0 ? filesCreated : undefined,
|
|
229
|
+
error: result.error,
|
|
230
|
+
};
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Tool: Delegate to WhatsApp Agent
|
|
236
|
+
* Specialized tool for WhatsApp messaging and communication tasks
|
|
237
|
+
*/
|
|
238
|
+
export const delegateToWhatsAppTool = createTool({
|
|
239
|
+
id: "delegate-to-whatsapp",
|
|
240
|
+
description: "Delegate a messaging or communication task to the WhatsApp Agent. Use for: sending messages, managing chats, checking message status, handling WhatsApp-specific operations. Returns execution status and message details.",
|
|
241
|
+
inputSchema: z.object({
|
|
242
|
+
task: z.string().describe("Specific WhatsApp task to perform (e.g., 'Send message to...', 'Check status of...', 'List recent chats')"),
|
|
243
|
+
contact: z.string().optional().describe("Contact name or phone number (if applicable)"),
|
|
244
|
+
message: z.string().optional().describe("Message content to send (if applicable)"),
|
|
245
|
+
priority: z.enum(["low", "normal", "high"]).optional().describe("Task priority (default: normal)"),
|
|
246
|
+
}),
|
|
247
|
+
outputSchema: z.object({
|
|
248
|
+
success: z.boolean(),
|
|
249
|
+
result: z.string(),
|
|
250
|
+
messagesSent: z.number().optional(),
|
|
251
|
+
error: z.string().optional(),
|
|
252
|
+
}),
|
|
253
|
+
execute: async (inputData, context) => {
|
|
254
|
+
const { task, contact, message, priority = "normal" } = inputData;
|
|
255
|
+
|
|
256
|
+
let fullTask = task;
|
|
257
|
+
if (contact) {
|
|
258
|
+
fullTask += `\n\nContact: ${contact}`;
|
|
259
|
+
}
|
|
260
|
+
if (message) {
|
|
261
|
+
fullTask += `\n\nMessage: ${message}`;
|
|
262
|
+
}
|
|
263
|
+
if (priority !== "normal") {
|
|
264
|
+
fullTask += `\n\nPriority: ${priority}`;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const result = await delegateToAgent("whatsapp", fullTask, context, 60000);
|
|
268
|
+
|
|
269
|
+
// Extract message count from result (simple heuristic)
|
|
270
|
+
let messagesSent: number | undefined;
|
|
271
|
+
if (result.success && result.result) {
|
|
272
|
+
const sentMatch = result.result.match(/sent\s+(\d+)\s+message/i);
|
|
273
|
+
if (sentMatch) {
|
|
274
|
+
messagesSent = parseInt(sentMatch[1], 10);
|
|
275
|
+
} else if (result.result.toLowerCase().includes("message sent") || result.result.toLowerCase().includes("sent successfully")) {
|
|
276
|
+
messagesSent = 1;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return {
|
|
281
|
+
success: result.success,
|
|
282
|
+
result: result.result,
|
|
283
|
+
messagesSent,
|
|
284
|
+
error: result.error,
|
|
285
|
+
};
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
// Export all delegation tools
|
|
293
|
+
export const agentDelegationTools = {
|
|
294
|
+
delegateToAgent: delegateToAgentTool,
|
|
295
|
+
delegateToPlanner: delegateToPlannerTool,
|
|
296
|
+
delegateToResearcher: delegateToResearcherTool,
|
|
297
|
+
delegateToExecutor: delegateToExecutorTool,
|
|
298
|
+
delegateToWhatsApp: delegateToWhatsAppTool,
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
export default agentDelegationTools;
|