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_MAX_TURNS = 90;
function buildHistorySummary(history: AgentContext["history"]): string {
if (history.length === 0) {
function buildHistorySummary(steps: AgentContext["steps"]): string {
if (steps.length === 0) {
return "";
}
const lines: string[] = ["## Previous Steps"];
for (let i = 0; i < history.length; i++) {
const step = history[i];
for (let i = 0; i < steps.length; i++) {
const step = steps[i];
if (step === undefined) {
continue;
}
@@ -33,8 +33,10 @@ function buildHistorySummary(history: AgentContext["history"]): string {
/** Assemble system prompt, task, and prior step outputs for Hermes. */
export function buildHermesPrompt(ctx: AgentContext): string {
const parts: string[] = [ctx.systemPrompt, "", "## Task", ctx.prompt];
const historyBlock = buildHistorySummary(ctx.history);
const roleDef = ctx.workflow.roles[ctx.role];
const systemPrompt = roleDef?.systemPrompt ?? "";
const parts: string[] = [systemPrompt, "", "## Task", ctx.start.prompt];
const historyBlock = buildHistorySummary(ctx.steps);
if (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}"`);
}
const history = await buildHistory(store, chain.stepsNewestFirst);
const steps = await buildHistory(store, chain.stepsNewestFirst);
return {
threadId,
role,
systemPrompt: roleDef.systemPrompt,
prompt: chain.start.prompt,
history,
start: chain.start,
steps,
workflow,
store,
};
@@ -188,14 +187,13 @@ export async function buildContextWithMeta(
fail(`unknown role "${role}" in workflow "${workflow.name}"`);
}
const history = await buildHistory(store, chain.stepsNewestFirst);
const steps = await buildHistory(store, chain.stepsNewestFirst);
return {
threadId,
role,
systemPrompt: roleDef.systemPrompt,
prompt: chain.start.prompt,
history,
start: chain.start,
steps,
workflow,
store,
meta: { storageRoot, store, schemas, headHash, chain },
+3 -6
View File
@@ -1,14 +1,11 @@
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;
role: string;
systemPrompt: string;
prompt: string;
history: StepContext[];
workflow: WorkflowPayload;
store: Store;
workflow: WorkflowPayload;
};
export type AgentRunResult = {
+1 -1
View File
@@ -16,7 +16,7 @@ const MOCK_RAW_OUTPUT_SCHEMA: JSONSchema = {
const agent = createAgent({
name: "mock",
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;
await bootstrap(store);
const schemaHash = await putSchema(store, MOCK_RAW_OUTPUT_SCHEMA);