1import { Dock, Lynk } from "docklee";
2const lynk = new Lynk({ engineId: "eng_playbooks", memorySpaceId: "space_agents" });
3const dock = new Dock({ memorySpaceId: "space_agents" });
4
5async function runTask(userId, taskDescription) {
6 const plan = await llm.plan(taskDescription);
7 const results = [];
8
9 for (const step of plan.steps) {
10
11
12 const [memories, docs] = await Promise.all([
13 lynk.recall(step, { endUser: userId, topK: 5 }),
14 lynk.retrieve(`${taskDescription}: ${step}`, { topK: 5 }),
15 ]);
16
17 const result = await llm.run({
18 messages: [
19 { role: "system", content: buildContext(memories, docs) },
20 { role: "user", content: `Task: ${taskDescription}\nStep: ${step}` },
21 ],
22 });
23
24
25 dock.capture(result.insights, { type: "event", endUser: userId });
26 results.push({ step, output: result.content });
27 }
28
29 await dock.flush();
30 return results;
31}