@lleverage-ai/agent-sdk 0.0.2 → 0.0.4
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/README.md +141 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +528 -41
- package/dist/agent.js.map +1 -1
- package/dist/hooks.d.ts +28 -1
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +40 -0
- package/dist/hooks.js.map +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/middleware/apply.d.ts.map +1 -1
- package/dist/middleware/apply.js +8 -0
- package/dist/middleware/apply.js.map +1 -1
- package/dist/middleware/context.d.ts.map +1 -1
- package/dist/middleware/context.js +11 -0
- package/dist/middleware/context.js.map +1 -1
- package/dist/middleware/types.d.ts +8 -0
- package/dist/middleware/types.d.ts.map +1 -1
- package/dist/plugins/agent-teams/coordinator.d.ts +46 -0
- package/dist/plugins/agent-teams/coordinator.d.ts.map +1 -0
- package/dist/plugins/agent-teams/coordinator.js +255 -0
- package/dist/plugins/agent-teams/coordinator.js.map +1 -0
- package/dist/plugins/agent-teams/hooks.d.ts +29 -0
- package/dist/plugins/agent-teams/hooks.d.ts.map +1 -0
- package/dist/plugins/agent-teams/hooks.js +29 -0
- package/dist/plugins/agent-teams/hooks.js.map +1 -0
- package/dist/plugins/agent-teams/index.d.ts +59 -0
- package/dist/plugins/agent-teams/index.d.ts.map +1 -0
- package/dist/plugins/agent-teams/index.js +313 -0
- package/dist/plugins/agent-teams/index.js.map +1 -0
- package/dist/plugins/agent-teams/mermaid.d.ts +32 -0
- package/dist/plugins/agent-teams/mermaid.d.ts.map +1 -0
- package/dist/plugins/agent-teams/mermaid.js +66 -0
- package/dist/plugins/agent-teams/mermaid.js.map +1 -0
- package/dist/plugins/agent-teams/session-runner.d.ts +92 -0
- package/dist/plugins/agent-teams/session-runner.d.ts.map +1 -0
- package/dist/plugins/agent-teams/session-runner.js +166 -0
- package/dist/plugins/agent-teams/session-runner.js.map +1 -0
- package/dist/plugins/agent-teams/tools.d.ts +41 -0
- package/dist/plugins/agent-teams/tools.d.ts.map +1 -0
- package/dist/plugins/agent-teams/tools.js +289 -0
- package/dist/plugins/agent-teams/tools.js.map +1 -0
- package/dist/plugins/agent-teams/types.d.ts +164 -0
- package/dist/plugins/agent-teams/types.d.ts.map +1 -0
- package/dist/plugins/agent-teams/types.js +7 -0
- package/dist/plugins/agent-teams/types.js.map +1 -0
- package/dist/plugins.d.ts.map +1 -1
- package/dist/plugins.js +1 -0
- package/dist/plugins.js.map +1 -1
- package/dist/presets/production.d.ts.map +1 -1
- package/dist/presets/production.js +7 -7
- package/dist/presets/production.js.map +1 -1
- package/dist/prompt-builder/components.d.ts +149 -0
- package/dist/prompt-builder/components.d.ts.map +1 -0
- package/dist/prompt-builder/components.js +252 -0
- package/dist/prompt-builder/components.js.map +1 -0
- package/dist/prompt-builder/index.d.ts +248 -0
- package/dist/prompt-builder/index.d.ts.map +1 -0
- package/dist/prompt-builder/index.js +165 -0
- package/dist/prompt-builder/index.js.map +1 -0
- package/dist/task-manager.d.ts +15 -0
- package/dist/task-manager.d.ts.map +1 -1
- package/dist/task-manager.js +36 -0
- package/dist/task-manager.js.map +1 -1
- package/dist/testing/mock-agent.d.ts.map +1 -1
- package/dist/testing/mock-agent.js +6 -0
- package/dist/testing/mock-agent.js.map +1 -1
- package/dist/testing/recorder.d.ts.map +1 -1
- package/dist/testing/recorder.js +6 -0
- package/dist/testing/recorder.js.map +1 -1
- package/dist/tools/task.d.ts.map +1 -1
- package/dist/tools/task.js +6 -2
- package/dist/tools/task.js.map +1 -1
- package/dist/types.d.ts +178 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Teams plugin for multi-agent coordination.
|
|
3
|
+
*
|
|
4
|
+
* Enables dynamic agent team coordination via runtime tools.
|
|
5
|
+
* When `start_team` is called, team management tools are added to the
|
|
6
|
+
* primary agent at runtime. Independent teammates communicate via mailboxes,
|
|
7
|
+
* share a task list with dependencies, and self-organize work.
|
|
8
|
+
* When `end_team` is called, the team tools are removed.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
import { tool } from "ai";
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
import { createAgent } from "../../agent.js";
|
|
15
|
+
import { invokeCustomHook } from "../../hooks.js";
|
|
16
|
+
import { definePlugin } from "../../plugins.js";
|
|
17
|
+
import { InMemoryTeamCoordinator } from "./coordinator.js";
|
|
18
|
+
import { TEAM_HOOKS } from "./hooks.js";
|
|
19
|
+
import { HeadlessSessionRunner } from "./session-runner.js";
|
|
20
|
+
import { createLeadTools, createTeammateTools } from "./tools.js";
|
|
21
|
+
// Re-exports
|
|
22
|
+
export { InMemoryTeamCoordinator } from "./coordinator.js";
|
|
23
|
+
export { TEAM_HOOKS } from "./hooks.js";
|
|
24
|
+
export { tasksToMermaid } from "./mermaid.js";
|
|
25
|
+
export { HeadlessSessionRunner } from "./session-runner.js";
|
|
26
|
+
/** System prompt augmentation for teammates */
|
|
27
|
+
function buildTeammateSystemPrompt(basePrompt, role) {
|
|
28
|
+
const teammateInstructions = `
|
|
29
|
+
## Team Context
|
|
30
|
+
|
|
31
|
+
You are a teammate with role "${role}".
|
|
32
|
+
|
|
33
|
+
### Workflow
|
|
34
|
+
1. Check available tasks: team_task_list
|
|
35
|
+
2. Claim a task: team_task_claim
|
|
36
|
+
3. Do the work using your tools and capabilities
|
|
37
|
+
4. Mark the task as completed: team_task_complete
|
|
38
|
+
5. Check for messages: team_read_messages
|
|
39
|
+
6. Communicate with the lead or other teammates: team_message
|
|
40
|
+
|
|
41
|
+
### Guidelines
|
|
42
|
+
- Always claim a task before starting work
|
|
43
|
+
- Complete tasks thoroughly before claiming the next one
|
|
44
|
+
- Send a message to the lead when you finish important work
|
|
45
|
+
- Check for messages regularly in case the lead has updates
|
|
46
|
+
`;
|
|
47
|
+
return basePrompt
|
|
48
|
+
? `${basePrompt}\n\n${teammateInstructions}`
|
|
49
|
+
: teammateInstructions;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Build the activation message returned as the `start_team` tool result.
|
|
53
|
+
* This replaces the old leader system prompt augmentation — the information
|
|
54
|
+
* is delivered as a tool result so the primary agent knows what to do.
|
|
55
|
+
*/
|
|
56
|
+
function buildTeamActivationMessage(reason, teammates, initialTasks) {
|
|
57
|
+
const roleList = teammates
|
|
58
|
+
.map((t) => `- **${t.role}**: ${t.description}`)
|
|
59
|
+
.join("\n");
|
|
60
|
+
let message = `Team mode activated. Reason: ${reason}
|
|
61
|
+
|
|
62
|
+
## Available Teammate Roles
|
|
63
|
+
${roleList}
|
|
64
|
+
|
|
65
|
+
## Team Management Tools Now Available
|
|
66
|
+
You now have team management tools. Use them to coordinate work:
|
|
67
|
+
|
|
68
|
+
### Workflow
|
|
69
|
+
1. Break the work into clear tasks (team_task_create)
|
|
70
|
+
2. Spawn teammates for the roles needed (team_spawn)
|
|
71
|
+
3. Monitor progress (team_task_list, team_read_messages)
|
|
72
|
+
4. Communicate with teammates (team_message)
|
|
73
|
+
5. When all work is done, summarize results and end the team (end_team)
|
|
74
|
+
|
|
75
|
+
### Guidelines
|
|
76
|
+
- Create tasks before spawning teammates so they can immediately claim work
|
|
77
|
+
- Use task dependencies (blocked_by) to order dependent work
|
|
78
|
+
- Periodically check messages from teammates for questions or results
|
|
79
|
+
- When all tasks are completed, synthesize results and call end_team
|
|
80
|
+
`;
|
|
81
|
+
if (initialTasks && initialTasks.length > 0) {
|
|
82
|
+
message += "\n## Initial Tasks Created\n";
|
|
83
|
+
for (const task of initialTasks) {
|
|
84
|
+
message += `- ${task.subject}: ${task.description}\n`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return message;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Creates the Agent Teams plugin.
|
|
91
|
+
*
|
|
92
|
+
* This plugin adds a `start_team` tool to the primary agent. When called,
|
|
93
|
+
* team management tools are dynamically added to the agent via runtime tools.
|
|
94
|
+
* No agent handoff occurs — the primary agent itself becomes the team leader.
|
|
95
|
+
*
|
|
96
|
+
* @param options - Plugin configuration
|
|
97
|
+
* @returns An AgentPlugin that enables team coordination
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* import { createAgent } from "@lleverage-ai/agent-sdk";
|
|
102
|
+
* import { createAgentTeamsPlugin } from "@lleverage-ai/agent-sdk/plugins/agent-teams";
|
|
103
|
+
*
|
|
104
|
+
* const agent = createAgent({
|
|
105
|
+
* model: "anthropic/claude-sonnet-4",
|
|
106
|
+
* systemPrompt: "You are a helpful assistant.",
|
|
107
|
+
* plugins: [
|
|
108
|
+
* createAgentTeamsPlugin({
|
|
109
|
+
* teammates: [
|
|
110
|
+
* {
|
|
111
|
+
* role: "researcher",
|
|
112
|
+
* description: "Researches topics thoroughly",
|
|
113
|
+
* agentOptions: { systemPrompt: "You are a thorough researcher..." },
|
|
114
|
+
* },
|
|
115
|
+
* {
|
|
116
|
+
* role: "coder",
|
|
117
|
+
* description: "Writes clean, tested code",
|
|
118
|
+
* agentOptions: { systemPrompt: "You are a senior developer..." },
|
|
119
|
+
* },
|
|
120
|
+
* ],
|
|
121
|
+
* }),
|
|
122
|
+
* ],
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @category Agent Teams
|
|
127
|
+
*/
|
|
128
|
+
export function createAgentTeamsPlugin(options) {
|
|
129
|
+
const maxConcurrent = options.maxConcurrentTeammates ?? Infinity;
|
|
130
|
+
let primaryAgent;
|
|
131
|
+
// Active team session state (undefined when no team is active)
|
|
132
|
+
let coordinator;
|
|
133
|
+
let runners;
|
|
134
|
+
let activeToolNames;
|
|
135
|
+
return definePlugin({
|
|
136
|
+
name: "agent-teams",
|
|
137
|
+
description: "Enables dynamic agent team coordination via runtime tools",
|
|
138
|
+
hooks: options.hooks,
|
|
139
|
+
setup: async (agent) => {
|
|
140
|
+
primaryAgent = agent;
|
|
141
|
+
},
|
|
142
|
+
tools: {
|
|
143
|
+
start_team: tool({
|
|
144
|
+
description: "Start a team of specialized agents to work on a complex task in parallel. " +
|
|
145
|
+
"Use this when the task benefits from multiple agents working concurrently.",
|
|
146
|
+
inputSchema: z.object({
|
|
147
|
+
reason: z.string().describe("Why a team is needed for this task"),
|
|
148
|
+
initial_tasks: z
|
|
149
|
+
.array(z.object({
|
|
150
|
+
subject: z.string().describe("Brief task title"),
|
|
151
|
+
description: z.string().describe("Detailed task description"),
|
|
152
|
+
blocked_by: z.array(z.string()).optional().describe("Task subjects this depends on"),
|
|
153
|
+
}))
|
|
154
|
+
.optional()
|
|
155
|
+
.describe("Initial tasks to create for the team"),
|
|
156
|
+
}),
|
|
157
|
+
execute: async ({ reason, initial_tasks }) => {
|
|
158
|
+
if (!primaryAgent) {
|
|
159
|
+
throw new Error("Plugin not initialized");
|
|
160
|
+
}
|
|
161
|
+
if (coordinator) {
|
|
162
|
+
return "Team already active. Use end_team first.";
|
|
163
|
+
}
|
|
164
|
+
// Create a fresh coordinator for this team session
|
|
165
|
+
coordinator = options.coordinator ?? new InMemoryTeamCoordinator();
|
|
166
|
+
runners = new Map();
|
|
167
|
+
// Create initial tasks if provided
|
|
168
|
+
const taskIdMap = new Map();
|
|
169
|
+
if (initial_tasks) {
|
|
170
|
+
for (const task of initial_tasks) {
|
|
171
|
+
const blockedByIds = (task.blocked_by ?? [])
|
|
172
|
+
.map((subject) => taskIdMap.get(subject))
|
|
173
|
+
.filter((id) => id !== undefined);
|
|
174
|
+
const created = coordinator.createTask({
|
|
175
|
+
subject: task.subject,
|
|
176
|
+
description: task.description,
|
|
177
|
+
status: "pending",
|
|
178
|
+
createdBy: "lead",
|
|
179
|
+
blockedBy: blockedByIds,
|
|
180
|
+
});
|
|
181
|
+
taskIdMap.set(task.subject, created.id);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// Capture refs for closures
|
|
185
|
+
const currentCoordinator = coordinator;
|
|
186
|
+
const currentRunners = runners;
|
|
187
|
+
const agent = primaryAgent;
|
|
188
|
+
// Shared mutable ref for teammate tools (teammate agent created after tools)
|
|
189
|
+
const agentRef = { current: undefined };
|
|
190
|
+
// Function to spawn a teammate
|
|
191
|
+
const spawnTeammate = async (role, initialPrompt) => {
|
|
192
|
+
const def = options.teammates.find((t) => t.role === role);
|
|
193
|
+
if (!def) {
|
|
194
|
+
throw new Error(`Unknown teammate role: ${role}`);
|
|
195
|
+
}
|
|
196
|
+
const teammateId = `${role}-${Date.now().toString(36)}`;
|
|
197
|
+
const model = def.model ?? agent.options?.model;
|
|
198
|
+
if (!model) {
|
|
199
|
+
throw new Error("No model available for teammate. Provide a model in TeammateDefinition or the primary agent.");
|
|
200
|
+
}
|
|
201
|
+
// Create teammate tools (uses agentRef since teammate agent is created after)
|
|
202
|
+
const teammateToolSet = createTeammateTools({
|
|
203
|
+
teammateId,
|
|
204
|
+
coordinator: currentCoordinator,
|
|
205
|
+
hooks: options.hooks,
|
|
206
|
+
agentRef,
|
|
207
|
+
});
|
|
208
|
+
// Create teammate agent
|
|
209
|
+
const teammateAgent = createAgent({
|
|
210
|
+
...def.agentOptions,
|
|
211
|
+
model,
|
|
212
|
+
systemPrompt: buildTeammateSystemPrompt(def.agentOptions.systemPrompt, role),
|
|
213
|
+
tools: {
|
|
214
|
+
...(def.agentOptions.tools ?? {}),
|
|
215
|
+
...teammateToolSet,
|
|
216
|
+
},
|
|
217
|
+
permissionMode: "bypassPermissions",
|
|
218
|
+
});
|
|
219
|
+
// Set the ref so teammate tools can access the agent
|
|
220
|
+
agentRef.current = teammateAgent;
|
|
221
|
+
// Register teammate
|
|
222
|
+
const info = {
|
|
223
|
+
id: teammateId,
|
|
224
|
+
role,
|
|
225
|
+
description: def.description,
|
|
226
|
+
status: "idle",
|
|
227
|
+
spawnedAt: new Date().toISOString(),
|
|
228
|
+
};
|
|
229
|
+
currentCoordinator.registerTeammate(info);
|
|
230
|
+
// Create and start runner
|
|
231
|
+
const runner = new HeadlessSessionRunner({
|
|
232
|
+
agent: teammateAgent,
|
|
233
|
+
teammateId,
|
|
234
|
+
coordinator: currentCoordinator,
|
|
235
|
+
initialPrompt,
|
|
236
|
+
hooks: options.hooks,
|
|
237
|
+
maxTurns: def.maxTurns,
|
|
238
|
+
onError: options.onError,
|
|
239
|
+
idleTimeoutMs: options.idleTimeoutMs,
|
|
240
|
+
});
|
|
241
|
+
currentRunners.set(teammateId, runner);
|
|
242
|
+
// Start the runner in the background
|
|
243
|
+
runner.start().catch(async (err) => {
|
|
244
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
245
|
+
if (options.onError) {
|
|
246
|
+
options.onError(teammateId, error);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
console.error(`[team:${teammateId}] Runner error:`, err);
|
|
250
|
+
}
|
|
251
|
+
// Fire TeammateStopped hook
|
|
252
|
+
await invokeCustomHook(options.hooks, TEAM_HOOKS.TeammateStopped, { teammateId, error: error.message }, agent);
|
|
253
|
+
});
|
|
254
|
+
return teammateId;
|
|
255
|
+
};
|
|
256
|
+
// Create lead tools (pass agent directly — no AgentRef needed)
|
|
257
|
+
const leadTools = createLeadTools({
|
|
258
|
+
coordinator: currentCoordinator,
|
|
259
|
+
runners: currentRunners,
|
|
260
|
+
teammates: options.teammates,
|
|
261
|
+
hooks: options.hooks,
|
|
262
|
+
agent,
|
|
263
|
+
spawnTeammate,
|
|
264
|
+
maxConcurrentTeammates: maxConcurrent,
|
|
265
|
+
});
|
|
266
|
+
// Create end_team tool
|
|
267
|
+
const endTeamTool = tool({
|
|
268
|
+
description: "End the team session. Shuts down all active teammates and removes team tools. " +
|
|
269
|
+
"Call this when all team work is complete.",
|
|
270
|
+
inputSchema: z.object({
|
|
271
|
+
summary: z.string().describe("Summary of team results"),
|
|
272
|
+
}),
|
|
273
|
+
execute: async ({ summary }) => {
|
|
274
|
+
// Check for incomplete tasks before shutting down
|
|
275
|
+
const allTasks = currentCoordinator.listTasks();
|
|
276
|
+
const incomplete = allTasks.filter((t) => t.status !== "completed");
|
|
277
|
+
// Stop all active teammates
|
|
278
|
+
for (const [id, runner] of currentRunners) {
|
|
279
|
+
if (runner.isRunning()) {
|
|
280
|
+
runner.stop();
|
|
281
|
+
}
|
|
282
|
+
await invokeCustomHook(options.hooks, TEAM_HOOKS.TeammateStopped, { teammateId: id }, agent);
|
|
283
|
+
}
|
|
284
|
+
currentRunners.clear();
|
|
285
|
+
// Dispose the coordinator
|
|
286
|
+
currentCoordinator.dispose();
|
|
287
|
+
// Remove team tools from the primary agent
|
|
288
|
+
if (activeToolNames) {
|
|
289
|
+
agent.removeRuntimeTools(activeToolNames);
|
|
290
|
+
}
|
|
291
|
+
// Reset state
|
|
292
|
+
coordinator = undefined;
|
|
293
|
+
runners = undefined;
|
|
294
|
+
activeToolNames = undefined;
|
|
295
|
+
if (incomplete.length > 0) {
|
|
296
|
+
const warning = `Warning: ${incomplete.length} task(s) not completed:\n${incomplete.map((t) => `- ${t.id}: [${t.status}] ${t.subject}`).join("\n")}\n\n`;
|
|
297
|
+
return warning + summary;
|
|
298
|
+
}
|
|
299
|
+
return summary;
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
const teamTools = { ...leadTools, end_team: endTeamTool };
|
|
303
|
+
activeToolNames = Object.keys(teamTools);
|
|
304
|
+
// Add team tools to the primary agent at runtime
|
|
305
|
+
agent.addRuntimeTools(teamTools);
|
|
306
|
+
// Return team context as tool result
|
|
307
|
+
return buildTeamActivationMessage(reason, options.teammates, initial_tasks);
|
|
308
|
+
},
|
|
309
|
+
}),
|
|
310
|
+
},
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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oBAEjC,qCAAqC;oBACrC,OAAO,0BAA0B,CAAC,MAAM,EAAE,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;gBAC9E,CAAC;aACF,CAAC;SACH;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mermaid diagram generation for team task dependency graphs.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
import type { TeamTask } from "./types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Converts an array of team tasks into a mermaid `graph TD` diagram string.
|
|
9
|
+
*
|
|
10
|
+
* Nodes are labeled with the task subject and a status icon.
|
|
11
|
+
* Edges represent `blockedBy` dependencies (blocker → blocked).
|
|
12
|
+
* CSS classes are applied per status for visual styling.
|
|
13
|
+
*
|
|
14
|
+
* @param tasks - The tasks to visualize
|
|
15
|
+
* @returns A valid mermaid diagram string
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const tasks = coordinator.listTasks();
|
|
20
|
+
* const diagram = tasksToMermaid(tasks);
|
|
21
|
+
* console.log(diagram);
|
|
22
|
+
* // graph TD
|
|
23
|
+
* // task-1["Research TypeScript ✓"]
|
|
24
|
+
* // task-2["Write Code ⏳"]
|
|
25
|
+
* // task-1 --> task-2
|
|
26
|
+
* // ...
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @category Agent Teams
|
|
30
|
+
*/
|
|
31
|
+
export declare function tasksToMermaid(tasks: TeamTask[]): string;
|
|
32
|
+
//# sourceMappingURL=mermaid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mermaid.d.ts","sourceRoot":"","sources":["../../../src/plugins/agent-teams/mermaid.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,CAyCxD"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mermaid diagram generation for team task dependency graphs.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Converts an array of team tasks into a mermaid `graph TD` diagram string.
|
|
8
|
+
*
|
|
9
|
+
* Nodes are labeled with the task subject and a status icon.
|
|
10
|
+
* Edges represent `blockedBy` dependencies (blocker → blocked).
|
|
11
|
+
* CSS classes are applied per status for visual styling.
|
|
12
|
+
*
|
|
13
|
+
* @param tasks - The tasks to visualize
|
|
14
|
+
* @returns A valid mermaid diagram string
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const tasks = coordinator.listTasks();
|
|
19
|
+
* const diagram = tasksToMermaid(tasks);
|
|
20
|
+
* console.log(diagram);
|
|
21
|
+
* // graph TD
|
|
22
|
+
* // task-1["Research TypeScript ✓"]
|
|
23
|
+
* // task-2["Write Code ⏳"]
|
|
24
|
+
* // task-1 --> task-2
|
|
25
|
+
* // ...
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @category Agent Teams
|
|
29
|
+
*/
|
|
30
|
+
export function tasksToMermaid(tasks) {
|
|
31
|
+
if (tasks.length === 0)
|
|
32
|
+
return "graph TD\n empty[No tasks]";
|
|
33
|
+
const lines = ["graph TD"];
|
|
34
|
+
// Node definitions
|
|
35
|
+
for (const task of tasks) {
|
|
36
|
+
const statusIcon = task.status === "completed" ? " ✓" : task.status === "in_progress" ? " ⏳" : "";
|
|
37
|
+
const label = `${task.subject}${statusIcon}`.replace(/"/g, """);
|
|
38
|
+
lines.push(` ${task.id}["${label}"]`);
|
|
39
|
+
}
|
|
40
|
+
// Edges: blocker --> blocked
|
|
41
|
+
for (const task of tasks) {
|
|
42
|
+
for (const depId of task.blockedBy) {
|
|
43
|
+
lines.push(` ${depId} --> ${task.id}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Status-based styling
|
|
47
|
+
lines.push("");
|
|
48
|
+
lines.push(" classDef completed fill:#90EE90,stroke:#333");
|
|
49
|
+
lines.push(" classDef in_progress fill:#FFD700,stroke:#333");
|
|
50
|
+
lines.push(" classDef pending fill:#D3D3D3,stroke:#333");
|
|
51
|
+
const byStatus = {
|
|
52
|
+
completed: [],
|
|
53
|
+
in_progress: [],
|
|
54
|
+
pending: [],
|
|
55
|
+
};
|
|
56
|
+
for (const task of tasks) {
|
|
57
|
+
byStatus[task.status]?.push(task.id);
|
|
58
|
+
}
|
|
59
|
+
for (const [status, ids] of Object.entries(byStatus)) {
|
|
60
|
+
if (ids.length > 0) {
|
|
61
|
+
lines.push(` class ${ids.join(",")} ${status}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return lines.join("\n");
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=mermaid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mermaid.js","sourceRoot":"","sources":["../../../src/plugins/agent-teams/mermaid.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,cAAc,CAAC,KAAiB;IAC9C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,6BAA6B,CAAC;IAE7D,MAAM,KAAK,GAAa,CAAC,UAAU,CAAC,CAAC;IAErC,mBAAmB;IACnB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,UAAU,GACd,IAAI,CAAC,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,C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,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless session runner for teammate agents.
|
|
3
|
+
*
|
|
4
|
+
* Runs an AgentSession in the background without a human operator.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
import type { Agent, HookRegistration } from "../../types.js";
|
|
9
|
+
import type { TeamCoordinator } from "./types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Options for creating a HeadlessSessionRunner.
|
|
12
|
+
*
|
|
13
|
+
* @category Agent Teams
|
|
14
|
+
*/
|
|
15
|
+
export interface HeadlessSessionRunnerOptions {
|
|
16
|
+
/** The teammate agent */
|
|
17
|
+
agent: Agent;
|
|
18
|
+
/** Unique teammate ID */
|
|
19
|
+
teammateId: string;
|
|
20
|
+
/** Team coordinator for message checking */
|
|
21
|
+
coordinator: TeamCoordinator;
|
|
22
|
+
/** Initial prompt to send to the agent */
|
|
23
|
+
initialPrompt: string;
|
|
24
|
+
/** Hook registration for custom events */
|
|
25
|
+
hooks?: HookRegistration;
|
|
26
|
+
/** Maximum turns before stopping */
|
|
27
|
+
maxTurns?: number;
|
|
28
|
+
/** Callback for output text */
|
|
29
|
+
onOutput?: (text: string) => void;
|
|
30
|
+
/** Callback when teammate enters idle state */
|
|
31
|
+
onIdle?: (teammateId: string) => void;
|
|
32
|
+
/** Milliseconds to wait for messages before considering teammate idle. @default 30000 */
|
|
33
|
+
idleTimeoutMs?: number;
|
|
34
|
+
/** Callback when a session error occurs. If not provided, errors are logged to console. */
|
|
35
|
+
onError?: (teammateId: string, error: Error) => void;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Runs a teammate's AgentSession in the background without a human operator.
|
|
39
|
+
*
|
|
40
|
+
* The runner:
|
|
41
|
+
* 1. Creates an AgentSession with the agent
|
|
42
|
+
* 2. Sends the initial prompt
|
|
43
|
+
* 3. When the session waits for input, checks the coordinator mailbox
|
|
44
|
+
* 4. Injects messages as new prompts or waits for messages
|
|
45
|
+
*
|
|
46
|
+
* @category Agent Teams
|
|
47
|
+
*/
|
|
48
|
+
export declare class HeadlessSessionRunner {
|
|
49
|
+
private session;
|
|
50
|
+
private running;
|
|
51
|
+
private stopped;
|
|
52
|
+
private teammateId;
|
|
53
|
+
private coordinator;
|
|
54
|
+
private initialPrompt;
|
|
55
|
+
private hooks?;
|
|
56
|
+
private agent;
|
|
57
|
+
private maxTurns;
|
|
58
|
+
private onOutput?;
|
|
59
|
+
private onIdle?;
|
|
60
|
+
private idleTimeoutMs;
|
|
61
|
+
private onError?;
|
|
62
|
+
constructor(options: HeadlessSessionRunnerOptions);
|
|
63
|
+
/**
|
|
64
|
+
* Start the headless session runner.
|
|
65
|
+
*
|
|
66
|
+
* This runs the session loop, sending the initial prompt and then
|
|
67
|
+
* processing messages from the coordinator mailbox.
|
|
68
|
+
*/
|
|
69
|
+
start(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Send a message to the teammate by injecting it into the session.
|
|
72
|
+
*/
|
|
73
|
+
sendMessage(content: string): void;
|
|
74
|
+
/**
|
|
75
|
+
* Stop the headless session runner.
|
|
76
|
+
*/
|
|
77
|
+
stop(): void;
|
|
78
|
+
/**
|
|
79
|
+
* Check if the runner is currently active.
|
|
80
|
+
*/
|
|
81
|
+
isRunning(): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Format team messages for injection into the session.
|
|
84
|
+
* Marks each message as read and formats with sender info.
|
|
85
|
+
*/
|
|
86
|
+
private formatMessages;
|
|
87
|
+
/**
|
|
88
|
+
* Report an error via the onError callback, falling back to console.error.
|
|
89
|
+
*/
|
|
90
|
+
private reportError;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=session-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-runner.d.ts","sourceRoot":"","sources":["../../../src/plugins/agent-teams/session-runner.ts"],"names":[],"mappings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