Skip to content

Commit b37f558

Browse files
committed
fix(agentos-api): chat-sandbox + /run fall back to Mongo registry
Previously /agents/:name/chat-sandbox and /agents/:name/run looked up the target only in the in-memory list (opts.agents). Agents registered via the dashboard or via MongoTelemetry returned 404 UNKNOWN_AGENT — even though the dashboard listed them and showed their logs. Adds a resolveAgent() helper that tries in-memory first, then reads from agent_registry. Registry agents have no envs/gitToken persisted; the server's own env (forwarded by inheritEssentialHostEnv) supplies ANTHROPIC_API_KEY etc, so the harness boots normally. Smoke verified against the deployed enterprise.clawagent.sh: registering a new agent + clicking chat now returns HTTP 200 with a valid sandboxId.
1 parent d19ada7 commit b37f558

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

examples/agentos-api.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,32 @@ export function createAgentOSApp(opts: AgentOSOptions): Hono {
421421
// Builds the SAME sandbox config the Slack flow uses (Lyzr model, envs,
422422
// gitToken) server-side. Pass an existing sessionId to resume that thread's
423423
// conversation memory; otherwise a fresh console session is minted.
424+
// Look up an agent by name — in-memory first, then the Mongo registry.
425+
// Registry agents have no auth/envs persisted; the server's own env (forwarded
426+
// via inheritEssentialHostEnv) provides ANTHROPIC_API_KEY etc.
427+
async function resolveAgent(name: string): Promise<AgentDef | undefined> {
428+
const inMem = byName.get(name);
429+
if (inMem) return inMem;
430+
try {
431+
const doc = await (await registryColl()).findOne({ _id: name });
432+
if (!doc) return undefined;
433+
const srcStr = typeof doc.source === "string"
434+
? doc.source
435+
: (doc.source as { url?: string; path?: string })?.url ?? (doc.source as { path?: string })?.path ?? "";
436+
return {
437+
name: doc._id,
438+
label: doc.label ?? doc._id,
439+
harness: doc.harness ?? "claude-agent-sdk",
440+
source: srcStr,
441+
model: doc.model,
442+
};
443+
} catch {
444+
return undefined;
445+
}
446+
}
447+
424448
app.post("/agentos/api/agents/:name/chat-sandbox", async (c) => {
425-
const agent = byName.get(c.req.param("name"));
449+
const agent = await resolveAgent(c.req.param("name"));
426450
if (!agent) return c.json({ error: { code: "UNKNOWN_AGENT" } }, 404);
427451
if (!sandboxCapable(agent.harness)) {
428452
return c.json({ error: { code: "NO_SANDBOX", message: `${agent.label} runs one-shot — use /run` } }, 400);
@@ -450,7 +474,7 @@ export function createAgentOSApp(opts: AgentOSOptions): Hono {
450474
// Streams a fresh POST /run back to the browser. No conversation memory
451475
// across turns — each message is an independent run.
452476
app.post("/agentos/api/agents/:name/run", async (c) => {
453-
const agent = byName.get(c.req.param("name"));
477+
const agent = await resolveAgent(c.req.param("name"));
454478
if (!agent) return c.json({ error: { code: "UNKNOWN_AGENT" } }, 404);
455479
const body = await c.req.json().catch(() => ({})) as { message?: string };
456480
const runBody: Record<string, unknown> = {

0 commit comments

Comments
 (0)