From 710d42d6b91f15524fc45764ee15e6197aeac374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=A9=98?= Date: Mon, 18 May 2026 16:14:13 +0000 Subject: [PATCH] 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 --- packages/uwf-agent-hermes/src/hermes.ts | 14 ++++++++------ packages/uwf-agent-kit/src/context.ts | 14 ++++++-------- packages/uwf-agent-kit/src/types.ts | 9 +++------ scripts/mock-agent.ts | 2 +- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/packages/uwf-agent-hermes/src/hermes.ts b/packages/uwf-agent-hermes/src/hermes.ts index dd71806..bb27661 100644 --- a/packages/uwf-agent-hermes/src/hermes.ts +++ b/packages/uwf-agent-hermes/src/hermes.ts @@ -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); } diff --git a/packages/uwf-agent-kit/src/context.ts b/packages/uwf-agent-kit/src/context.ts index c3c61e4..df3f5d5 100644 --- a/packages/uwf-agent-kit/src/context.ts +++ b/packages/uwf-agent-kit/src/context.ts @@ -143,14 +143,13 @@ export async function buildContext(threadId: ThreadId, role: string): Promise { - 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);