refactor: extract wrapAgentAsAdapter to util-agent, support childThread in RoleFn (#222)

This commit is contained in:
2026-05-13 02:37:32 +00:00
parent 1f4bd3f431
commit ec4599a230
16 changed files with 55 additions and 41 deletions
@@ -4,10 +4,8 @@
* All roles use cursor-agent with workspace auto-extracted from context.
*/
import { createCursorAgent } from "@uncaged/workflow-agent-cursor";
import { putContentNodeWithRefs } from "@uncaged/workflow-cas";
import type { AdapterFn, AgentContext, AgentFnResult, ThreadContext, WorkflowRuntime } from "@uncaged/workflow-runtime";
import { createWorkflow } from "@uncaged/workflow-runtime";
import type * as z from "zod/v4";
import { wrapAgentAsAdapter } from "@uncaged/workflow-util-agent";
import { buildDevelopDescriptor, developWorkflowDefinition } from "./src/index.js";
function requireEnv(name: string): string {
@@ -43,19 +41,6 @@ const agent = createCursorAgent({
llmProvider,
});
function wrapAgentAsAdapter(agentFn: (ctx: AgentContext) => Promise<AgentFnResult>): AdapterFn {
return <T>(prompt: string, schema: z.ZodType<T>) => {
return async (ctx: ThreadContext, runtime: WorkflowRuntime): Promise<T> => {
const agentCtx: AgentContext = { ...ctx, currentRole: { name: "agent", systemPrompt: prompt } };
const result = await agentFn(agentCtx);
const output = typeof result === "string" ? result : result.output;
const contentHash = await putContentNodeWithRefs(runtime.cas, output, []);
const extracted = await runtime.extract(schema as z.ZodType<Record<string, unknown>>, contentHash);
return extracted.meta as T;
};
};
}
const adapter = wrapAgentAsAdapter(agent);
const wf = createWorkflow(developWorkflowDefinition, { adapter, overrides: null });