refactor: extract wrapAgentAsAdapter to util-agent, support childThread in RoleFn (#222)
This commit is contained in:
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user