refactor(agent-kit): base AgentContext on ModeratorContext

AgentContext now extends ModeratorContext (start + steps) with threadId, role, store, and expanded workflow. Hermes and mock-agent read prompt/steps/systemPrompt from the new shape.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-18 16:14:13 +00:00
parent 072d900fcb
commit 710d42d6b9
4 changed files with 18 additions and 21 deletions
+8 -6
View File
@@ -12,14 +12,14 @@ import {
const HERMES_COMMAND = "hermes"; const HERMES_COMMAND = "hermes";
const HERMES_MAX_TURNS = 90; const HERMES_MAX_TURNS = 90;
function buildHistorySummary(history: AgentContext["history"]): string { function buildHistorySummary(steps: AgentContext["steps"]): string {
if (history.length === 0) { if (steps.length === 0) {
return ""; return "";
} }
const lines: string[] = ["## Previous Steps"]; const lines: string[] = ["## Previous Steps"];
for (let i = 0; i < history.length; i++) { for (let i = 0; i < steps.length; i++) {
const step = history[i]; const step = steps[i];
if (step === undefined) { if (step === undefined) {
continue; continue;
} }
@@ -33,8 +33,10 @@ function buildHistorySummary(history: AgentContext["history"]): string {
/** Assemble system prompt, task, and prior step outputs for Hermes. */ /** Assemble system prompt, task, and prior step outputs for Hermes. */
export function buildHermesPrompt(ctx: AgentContext): string { export function buildHermesPrompt(ctx: AgentContext): string {
const parts: string[] = [ctx.systemPrompt, "", "## Task", ctx.prompt]; const roleDef = ctx.workflow.roles[ctx.role];
const historyBlock = buildHistorySummary(ctx.history); const systemPrompt = roleDef?.systemPrompt ?? "";
const parts: string[] = [systemPrompt, "", "## Task", ctx.start.prompt];
const historyBlock = buildHistorySummary(ctx.steps);
if (historyBlock !== "") { if (historyBlock !== "") {
parts.push("", historyBlock); parts.push("", historyBlock);
} }
+6 -8
View File
@@ -143,14 +143,13 @@ export async function buildContext(threadId: ThreadId, role: string): Promise<Ag
fail(`unknown role "${role}" in workflow "${workflow.name}"`); fail(`unknown role "${role}" in workflow "${workflow.name}"`);
} }
const history = await buildHistory(store, chain.stepsNewestFirst); const steps = await buildHistory(store, chain.stepsNewestFirst);
return { return {
threadId, threadId,
role, role,
systemPrompt: roleDef.systemPrompt, start: chain.start,
prompt: chain.start.prompt, steps,
history,
workflow, workflow,
store, store,
}; };
@@ -188,14 +187,13 @@ export async function buildContextWithMeta(
fail(`unknown role "${role}" in workflow "${workflow.name}"`); fail(`unknown role "${role}" in workflow "${workflow.name}"`);
} }
const history = await buildHistory(store, chain.stepsNewestFirst); const steps = await buildHistory(store, chain.stepsNewestFirst);
return { return {
threadId, threadId,
role, role,
systemPrompt: roleDef.systemPrompt, start: chain.start,
prompt: chain.start.prompt, steps,
history,
workflow, workflow,
store, store,
meta: { storageRoot, store, schemas, headHash, chain }, meta: { storageRoot, store, schemas, headHash, chain },
+3 -6
View File
@@ -1,14 +1,11 @@
import type { Store } from "@uncaged/json-cas"; import type { Store } from "@uncaged/json-cas";
import type { StepContext, ThreadId, WorkflowPayload } from "@uncaged/uwf-protocol"; import type { ModeratorContext, ThreadId, WorkflowPayload } from "@uncaged/uwf-protocol";
export type AgentContext = { export type AgentContext = ModeratorContext & {
threadId: ThreadId; threadId: ThreadId;
role: string; role: string;
systemPrompt: string;
prompt: string;
history: StepContext[];
workflow: WorkflowPayload;
store: Store; store: Store;
workflow: WorkflowPayload;
}; };
export type AgentRunResult = { export type AgentRunResult = {
+1 -1
View File
@@ -16,7 +16,7 @@ const MOCK_RAW_OUTPUT_SCHEMA: JSONSchema = {
const agent = createAgent({ const agent = createAgent({
name: "mock", name: "mock",
run: async (ctx) => { run: async (ctx) => {
const output = `Mock output for role ${ctx.role}: task was "${ctx.prompt}"`; const output = `Mock output for role ${ctx.role}: task was "${ctx.start.prompt}"`;
const { store } = ctx; const { store } = ctx;
await bootstrap(store); await bootstrap(store);
const schemaHash = await putSchema(store, MOCK_RAW_OUTPUT_SCHEMA); const schemaHash = await putSchema(store, MOCK_RAW_OUTPUT_SCHEMA);