Menu
popagent
publicLatest change 6726bbcb1e8a68b297a0e59825c4d913d4b9aab8 - Run autonomous improvements continuously by Ólafur Búi Ólafsson
import { expect, test } from "bun:test";
import type { AutonomySettings, EvolutionSignal } from "./api-types";
import { reflectWithAgent } from "./evolution-runtime";
const settings: AutonomySettings = {
enabled: true,
reflectionIntervalMs: 60_000,
batchSize: 1,
maxAttempts: 3,
autoApplyStrategies: true,
autoCreateSkills: true,
selfUpdateEnabled: true,
selfUpdateCron: "0 3 * * *",
idleImprovementEnabled: false,
idleDeploymentEnabled: false,
idleWorkspaceIds: [],
updatedAt: new Date().toISOString(),
};
test("reflection consumes the streaming structured object required by 9Router", async () => {
const evidenceId = crypto.randomUUID();
const signal: EvolutionSignal = {
id: evidenceId,
sessionId: "reflection-stream-contract",
turnId: crypto.randomUUID(),
traceId: crypto.randomUUID().replaceAll("-", ""),
agentId: "orchistrator",
workspaceId: "default",
kind: "turn-success",
summary: "Goal: Cite evidence.\nClassification: success\nOutcome: Evidence cited.",
status: "pending",
attempts: 0,
nextAttemptAt: new Date().toISOString(),
processedAt: null,
error: null,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
};
let streamed = false;
const reflector = {
stream: async (_prompt: string, options: { structuredOutput?: unknown }) => {
streamed = true;
expect(options.structuredOutput).toBeDefined();
return {
object: Promise.resolve({
proposals: [{
agentId: "orchistrator" as const,
strategy: "evidence-first" as const,
rationale: "The result must cite evidence.",
evidenceIds: [evidenceId],
}],
}),
};
},
};
expect(await reflectWithAgent(reflector, [signal], settings)).toEqual({
proposals: [{
agentId: "orchistrator",
targetType: "skill",
targetKey: "learned-evidence-first",
content: "Before declaring completion or readiness, verify the observable result and report the exact evidence.",
rationale: "The result must cite evidence.",
evidenceIds: [evidenceId],
}],
});
expect(streamed).toBe(true);
});