agent-lyra 0.6.5 → 0.8.0

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.
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "memory-engine-local",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "description": "Standalone local memory engine (staging package)",
7
+ "engines": {
8
+ "node": ">=22.13.0"
9
+ },
10
+ "license": "MIT",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./standalone.d.ts",
14
+ "default": "./standalone.js"
15
+ },
16
+ "./bridge": "./bridge.js"
17
+ },
18
+ "bin": {
19
+ "memory-engine": "./bridge-cli.js"
20
+ },
21
+ "files": [
22
+ "standalone.js",
23
+ "standalone.d.ts",
24
+ "local-store.js",
25
+ "contract.json",
26
+ "validation.js",
27
+ "proposals.js",
28
+ "bridge.js",
29
+ "bridge-cli.js",
30
+ "LICENSE",
31
+ "README.md"
32
+ ]
33
+ }
@@ -53,6 +53,12 @@ export function proposalActions(db, transaction) {
53
53
  return get(id);
54
54
  });
55
55
  },
56
+ approvedSkills(context) {
57
+ if (!safeContext(context)) return [];
58
+ const sources = readSources(db, context);
59
+ return db.prepare("SELECT * FROM skill_proposals WHERE context=? AND status='approved' ORDER BY decided_at DESC,id LIMIT 100").all(context)
60
+ .map(present).filter(p => p.receipt && p.sources.every(s => sources.some(r => r.id === s.id && r.revision === s.revision && r.evidenceId === s.evidenceId)));
61
+ },
56
62
  proposal: get,
57
63
  proposals: () => db.prepare("SELECT * FROM skill_proposals ORDER BY created_at DESC,id LIMIT 100").all().map(present),
58
64
  decideProposal(id, decision, evidence) {
@@ -0,0 +1,50 @@
1
+ export type MemoryType = "episodic" | "semantic" | "procedural" | "corrective";
2
+ export type MemoryStatus = "candidate" | "verified" | "archived";
3
+ export interface MemoryInput { type: MemoryType; title: string; learning: string; evidence?: string[] }
4
+ export type MemoryAdapter = "coding" | "practice";
5
+ export type VerificationReceipt = { evidenceId: string; context: string } & (
6
+ { adapter: "coding"; test: string } | { adapter: "practice"; exercise: string }
7
+ );
8
+ export interface MemoryRecord extends MemoryInput {
9
+ id: string;
10
+ evidence: string[];
11
+ scope: "project";
12
+ status: MemoryStatus;
13
+ revision: number;
14
+ createdAt: string;
15
+ updatedAt: string;
16
+ verification?: VerificationReceipt;
17
+ }
18
+ export interface SkillProposalSource { id: string; revision: number; evidenceId: string }
19
+ export interface SkillProposalReceipt { evidenceId: string; context: string; result: "passed"; reviewed: true }
20
+ export interface SkillProposal {
21
+ id: string;
22
+ context: string;
23
+ title: string;
24
+ markdown: string;
25
+ sources: SkillProposalSource[];
26
+ status: "pending" | "approved" | "rejected" | "withdrawn";
27
+ createdAt: string;
28
+ decidedAt: string | null;
29
+ receipt: SkillProposalReceipt | null;
30
+ }
31
+ export interface MemoryStore {
32
+ readonly file: string;
33
+ consolidate(context: string): Array<{ title: string; learning: string; sources: SkillProposalSource[] }>;
34
+ propose(context: string, memoryId: string): SkillProposal;
35
+ proposal(id: string): SkillProposal | null;
36
+ proposals(): SkillProposal[];
37
+ approvedSkills(context: string): SkillProposal[];
38
+ decideProposal(id: string, decision: "approved" | "rejected" | "withdrawn", evidence?: SkillProposalReceipt): SkillProposal;
39
+ close(): void;
40
+ get(id: string): MemoryRecord | null;
41
+ list(limit?: number): MemoryRecord[];
42
+ record(value: MemoryInput): MemoryRecord;
43
+ search(query: string, limit?: number): MemoryRecord[];
44
+ stats(): { schemaVersion: number; search: "fts5" | "keyword" } & Record<MemoryStatus, number>;
45
+ verify(id: string, evidence: VerificationReceipt & { result: "passed"; reviewed: true }): MemoryRecord;
46
+ retrieve(query: string, context: string, adapter?: MemoryAdapter): MemoryRecord[];
47
+ archive(id: string): MemoryRecord | null;
48
+ forget(id: string): boolean;
49
+ }
50
+ export function openLocalMemoryStore(root?: string, options?: { forceKeyword?: boolean; namespace?: string }): Promise<MemoryStore>;
@@ -0,0 +1 @@
1
+ export { openLocalMemoryStore } from "./local-store.js";
@@ -2,6 +2,7 @@ import { mkdir, writeFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { parseArgs } from "node:util";
4
4
  import { withProjectMemory } from "../memory/lifecycle.js";
5
+ import { withGraphSnipContext } from "../intelligence/lifecycle.js";
5
6
  import { runAgent } from "./run-agent.js";
6
7
 
7
8
  export async function openStore(cwd) {
@@ -141,7 +142,7 @@ export async function runLocalCli(argv, {
141
142
  for (const { agentId, system } of stages) {
142
143
  const event = await runAgent({
143
144
  agentId,
144
- request: await withProjectMemory(cwd, { model: values.model, messages: [{ role: "system", content: system }, ...messages] }, { env }),
145
+ request: await withProjectMemory(cwd, await withGraphSnipContext(cwd, { model: values.model, messages: [{ role: "system", content: system }, ...messages] }, { env }), { env }),
145
146
  provider,
146
147
  store,
147
148
  onStarted: (runId) => diagnostics.write(teamCommand ? `${agentId} run ID: ${runId}\n` : `Run ID: ${runId}\n`),
@@ -1,22 +1,31 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
 
3
+ const frameworkFailures = {
4
+ FRAMEWORK_TIMEOUT: ["timeout", "Framework run timed out."],
5
+ FRAMEWORK_DEPENDENCY: ["missing_dependency", "Install the framework in the selected Python environment."],
6
+ FRAMEWORK_ENDPOINT: ["endpoint_error", "Check the local MDA server, assistant ID, and authorization."],
7
+ FRAMEWORK_OUTPUT: ["invalid_output", "Framework agent returned an invalid output."],
8
+ };
9
+
3
10
  /**
4
11
  * @param {{
5
12
  * agentId: string,
6
13
  * request: import("./contracts.js").ModelRequest,
7
14
  * provider: import("./contracts.js").ModelProvider,
8
15
  * store: import("./contracts.js").RunStore,
16
+ * traceId?: string, framework?: string, revision?: string,
9
17
  * onStarted?: (runId: string) => void,
10
18
  * }} options
11
19
  */
12
- export async function runAgent({ agentId, request, provider, store, onStarted }) {
20
+ export async function runAgent({ agentId, request, provider, store, onStarted, traceId, framework, revision }) {
13
21
  const runId = randomUUID();
22
+ const started = Date.now();
14
23
  /** @param {number} seq */
15
- const envelope = (seq) => ({ id: randomUUID(), run_id: runId, seq, ts: new Date().toISOString() });
24
+ const envelope = (seq) => ({ id: randomUUID(), run_id: runId, seq, ts: new Date().toISOString(), ...(traceId ? { schemaVersion: 1, trace_id: traceId } : {}) });
16
25
  await store.append({
17
26
  ...envelope(0),
18
27
  type: "run.started",
19
- data: { agentId, model: request.model },
28
+ data: { agentId, model: request.model, ...(framework ? { framework, revision, execution: "local" } : {}) },
20
29
  });
21
30
  onStarted?.(runId);
22
31
 
@@ -24,11 +33,13 @@ export async function runAgent({ agentId, request, provider, store, onStarted })
24
33
  let result;
25
34
  try {
26
35
  result = await provider.complete(request);
27
- } catch {
36
+ } catch (error) {
37
+ const [reason, message] = Object.hasOwn(frameworkFailures, error?.code)
38
+ ? frameworkFailures[error.code] : ["execution_error", "Framework execution failed."];
28
39
  const failed = /** @type {const} */ ({
29
40
  ...envelope(1),
30
41
  type: "run.failed",
31
- data: { message: "Model request failed." },
42
+ data: { message: framework ? message : "Model request failed.", ...(framework ? { durationMs: Date.now() - started, reason } : {}) },
32
43
  });
33
44
  await store.append(failed);
34
45
  return failed;
@@ -38,6 +49,6 @@ export async function runAgent({ agentId, request, provider, store, onStarted })
38
49
  type: "run.completed",
39
50
  data: { result },
40
51
  });
41
- await store.append(completed);
52
+ await store.append(framework ? { ...completed, data: { durationMs: Date.now() - started } } : completed);
42
53
  return completed;
43
54
  }
@@ -15,7 +15,7 @@ function dom(tag, props, ...children) {
15
15
  return node;
16
16
  }
17
17
 
18
- const agentSources = { local: "Local agent", cloud: "Cloud agent", python: "Python agent" };
18
+ const agentSources = { local: "Local agent", cloud: "Cloud agent", python: "Python agent", framework: "Registered framework agent" };
19
19
  const names = { heading:"Heading", text:"Text", input:"Text input", textarea:"Text area", button:"Run button", "agent-card":"Agent card", output:"Output" };
20
20
  let project = { layout: [], agents: [], workflows: [], teams: [], skills: [], models: [] };
21
21
  let selected, pending;
@@ -184,6 +184,10 @@ function renderCatalog() {
184
184
  const section = $("#" + id);
185
185
  section.replaceChildren();
186
186
  if (!rows.length) section.append(element("p", "None in this project."));
187
+ if (id === "agents" && project.frameworkCandidates?.length) {
188
+ section.append(element("p", "LangGraph candidates: " + project.frameworkCandidates.map(item => item.name).join(", ") +
189
+ ". Run agent-lyra agent discover, then register the entry you want."));
190
+ }
187
191
  for (const row of rows) {
188
192
  if (id === "agents") {
189
193
  const push = row.source === "local" && project.mode !== "standalone"
@@ -205,8 +209,17 @@ function renderCatalog() {
205
209
  } catch (error) { announce(error.message); }
206
210
  finally { pull.disabled = false; }
207
211
  });
208
- const actions = push ? dom("div", { className: "actions" }, push, pull) : undefined;
209
- section.append(renderAgentCard(dom, { name: row.name, source: agentSources[row.source], onRun: () => openRun([row.id]), extraAction: actions }));
212
+ const sync = row.source === "framework" && project.mode !== "standalone" && button("Sync registration", async () => {
213
+ try {
214
+ const id = row.id.slice("framework:".length);
215
+ const preview = await api("framework-preview", { id });
216
+ if (!window.confirm("Sync only this private registration?\n" + JSON.stringify(preview.payload, null, 2))) return;
217
+ await api("framework-sync", { id, fingerprint: preview.fingerprint });
218
+ announce("Registration synced. Open Cloud → Agents to view it.");
219
+ } catch (error) { announce(error.message); }
220
+ });
221
+ const actions = push ? dom("div", { className: "actions" }, push, pull) : sync;
222
+ section.append(renderAgentCard(dom, { name: row.name, source: row.framework ? row.framework + " · Local" : agentSources[row.source], onRun: () => openRun([row.id]), extraAction: actions }));
210
223
  continue;
211
224
  }
212
225
  const card = element("article");
@@ -263,7 +276,8 @@ $("#runner").onsubmit = async event => {
263
276
  $("#run-status").textContent = "Running workflow…";
264
277
  try {
265
278
  const { answers } = await api("run", { targets: pending.targets, buttonId: pending.buttonId, input: $("#prompt").value, model: $("#model").value });
266
- const text = answers.map(({ agent, output }) => agent + "\n" + output).join("\n\n");
279
+ const text = answers.map(({ agent, output, run }) => agent + "\n" + output +
280
+ (run ? "\nRun " + run.runId + " · Trace " + run.traceId : "")).join("\n\n");
267
281
  $("#run-result").textContent = text;
268
282
  if (pending.outputId) outputs.set(pending.outputId, answers.at(-1).output);
269
283
  renderCanvas();
@@ -280,7 +294,7 @@ $("#drawer").oncancel = event => { if ($("#run").disabled) event.preventDefault(
280
294
  async function load({ catalogOnly = false } = {}) {
281
295
  const next = await api("project");
282
296
  if (catalogOnly) {
283
- for (const key of ["agents", "workflows", "teams", "skills", "models", "mode"]) project[key] = next[key];
297
+ for (const key of ["agents", "workflows", "teams", "skills", "models", "mode", "frameworkCandidates"]) project[key] = next[key];
284
298
  } else {
285
299
  project = next;
286
300
  dirty = false;
@@ -7,7 +7,9 @@ const runtime = [
7
7
  "resource-files.js",
8
8
  "studio/server.js", "studio/memory-actions.js", "studio/memory-panel.js", "studio/project.js", "studio/sync.js", "studio/index.html",
9
9
  "studio/browser.js", "studio/studio.css", "studio/agent-ui.js", "studio/agent-ui.css", "app-builder/saved-app.js",
10
- "memory/index.js", "memory/validation.js", "memory/proposals.js", "memory/sync.js", "memory/lifecycle.js", "memory/contract.json",
10
+ "memory/index.js", "memory/local-store.js", "memory/cloud-sync-actions.js", "memory/validation.js", "memory/proposals.js", "memory/sync.js", "memory/lifecycle.js", "memory/contract.json",
11
+ "framework/agent.js", "framework/run.py", "framework/mda.js",
12
+ "intelligence/lifecycle.js", "intelligence/graphsnip-provider.js",
11
13
  "runtime/local-cli.js", "runtime/run-agent.js", "studio/session.js", "studio/push.js", "studio/workflow-sync.js", "studio/pull-agent.js", "studio/python-agent.js", "studio/python-agent.py",
12
14
  ];
13
15
 
@@ -41,6 +43,9 @@ export async function exportStudioApp(app, root, directory) {
41
43
  });
42
44
  }
43
45
  }
46
+ if ([...agents.values()].some(agent => agent.source === "framework")) {
47
+ throw new Error("Registered framework agents run from their source project. Use Studio or app preview there.");
48
+ }
44
49
  const name = typeof app.application?.name === "string" ? app.application.name : "Lyra app";
45
50
  const files = await Promise.all(runtime.map(async file => [
46
51
  "runtime/" + file, await readFile(new URL("../" + file, import.meta.url)),
@@ -2,6 +2,7 @@ import { createHash, randomUUID } from "node:crypto";
2
2
  import { lstat, mkdir, readFile, readdir, rename, writeFile } from "node:fs/promises";
3
3
  import { join, dirname, basename } from "node:path";
4
4
  import { resourceFiles } from "../resource-files.js";
5
+ import { frameworkDescriptor, runFrameworkAgent } from "../framework/agent.js";
5
6
  import { createSavedAgentClient } from "../app-builder/saved-app.js";
6
7
  import { createOpenAIProvider, openStore } from "../runtime/local-cli.js";
7
8
  import { readMode, readSdkKey, requireCloudMode } from "./session.js";
@@ -72,6 +73,12 @@ export async function readCatalog(root) {
72
73
  if (error instanceof SyntaxError) continue;
73
74
  throw error;
74
75
  }
76
+ const external = frameworkDescriptor(item);
77
+ if (external && name === join("coding", external.id + ".json")) {
78
+ const id = "framework:" + external.id;
79
+ agents.set(id, { ...external, id, source: "framework" });
80
+ continue;
81
+ }
75
82
  const descriptor = pythonDescriptor(item);
76
83
  if (!descriptor || typeof item.id !== "string" || !safeId.test(item.id) ||
77
84
  typeof item.name !== "string" || !item.name.trim()) continue;
@@ -183,7 +190,7 @@ export async function runSelection(root, { targets, input, model }, catalog) {
183
190
  if (!exported) requireCloudMode(await readMode(root));
184
191
  cloud = createSavedAgentClient(exported ? undefined : { key: await readSdkKey(root) });
185
192
  }
186
- const store = local ? await openStore(root) : null;
193
+ const store = local || sequence.some(step => step.agentId.startsWith("framework:")) ? await openStore(root) : null;
187
194
  const answers = [];
188
195
  const named = new Map();
189
196
  try {
@@ -192,10 +199,28 @@ export async function runSelection(root, { targets, input, model }, catalog) {
192
199
  const previous = step.input ? named.get(step.input) : answers.at(-1)?.output;
193
200
  const text = [step.task, input.trim(), previous && "Previous result: " + previous].filter(Boolean).join("\n\n").slice(0, 12_000);
194
201
  let output;
202
+ let run;
195
203
  if (agent.source === "cloud") {
196
204
  output = await cloud.invoke(agent.id.slice("cloud:".length), text);
197
205
  } else if (agent.source === "python") {
198
206
  output = await runPythonAgent(root, agent, text, exported);
207
+ } else if (agent.source === "framework") {
208
+ let payload = text;
209
+ if (agent.input === "json") {
210
+ try { payload = JSON.parse(previous ?? input); }
211
+ catch { throw new Error("Provide valid JSON for " + agent.name + "."); }
212
+ }
213
+ const traceId = randomUUID();
214
+ const revision = createHash("sha256").update(JSON.stringify(agent)).digest("hex");
215
+ const event = await runAgent({
216
+ agentId: agent.id, store, traceId, framework: agent.framework, revision,
217
+ request: { model: "framework-managed", messages: [] },
218
+ provider: { complete: async () => ({ text: await runFrameworkAgent(root, agent, payload, traceId) }) },
219
+ });
220
+ if (event.type !== "run.completed") throw new Error(event.data.message + " Run " + event.run_id + " · Trace " + traceId + ".");
221
+
222
+ output = event.data.result.text;
223
+ run = { runId: event.run_id, traceId, framework: agent.framework };
199
224
  } else {
200
225
  const request = { model, messages: [{ role: "system", content: agent.prompt }, { role: "user", content: text }] };
201
226
  const event = await runAgent({
@@ -206,7 +231,7 @@ export async function runSelection(root, { targets, input, model }, catalog) {
206
231
  output = event.data.result.text;
207
232
  }
208
233
  if (step.output) named.set(step.output, output);
209
- answers.push({ agent: agent.name, output });
234
+ answers.push({ agent: agent.name, output, ...(run ? { run } : {}) });
210
235
  }
211
236
  return { answers };
212
237
  } finally {
@@ -1,3 +1,4 @@
1
+ import { discoverFrameworkAgents, syncFrameworkAgent } from "../framework/agent.js";
1
2
  import { memoryActions } from "./memory-actions.js";
2
3
  import { createServer } from "node:http";
3
4
  import { readFile } from "node:fs/promises";
@@ -18,6 +19,11 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
18
19
 
19
20
  const updates = new Map([
20
21
  ...(appCatalog ? [] : memoryActions(root)),
22
+ ["/api/framework-preview", ({ id }) => syncFrameworkAgent(root, id)],
23
+ ["/api/framework-sync", ({ id, fingerprint }) => {
24
+ if (typeof fingerprint !== "string") throw new Error("Preview the registration before syncing.");
25
+ return syncFrameworkAgent(root, id, fingerprint);
26
+ }],
21
27
  ["/api/save", ({ layout, revision }) => saveLayout(root, layout, revision)],
22
28
  ["/api/pull", () => pull(root)],
23
29
  ["/api/push", ({ id }) => pushStudioAgent(root, id)],
@@ -53,7 +59,8 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
53
59
  ...await readLayout(root),
54
60
  exported: Boolean(appCatalog),
55
61
  mode: appCatalog ? undefined : await readMode(root),
56
- agents: [...catalog.agents.values()].map(({ id, name, source }) => ({ id, name, source })),
62
+ agents: [...catalog.agents.values()].map(({ id, name, source, framework }) => ({ id, name, source, framework })),
63
+ frameworkCandidates: appCatalog ? [] : await discoverFrameworkAgents(root).catch(() => []),
57
64
  workflows: catalog.workflows.map(({ id, name, runnable, source }) => ({ id, name, runnable, source })),
58
65
  skills: (catalog.skills ?? []).map(({ id, name, source }) => ({ id, name, source })),
59
66
  teams: catalog.teams.map(({ id, name, source }) => ({ id, name, source })),