fa9163e462
BREAKING: Major architecture change. - RoleDefinition = pure data (systemPrompt + schema + dryRunMeta) - AgentFn = (ctx: ThreadContext) => Promise<string>, reads ctx.currentRole - WorkflowDefinition decoupled from agents, bound via AgentBinding at runtime - createWorkflow(def, binding, extract) replaces createRoleModerator - Meta extraction moved into engine loop - Delete workflow-util-role package (createRole, decorators, extract all gone) - Role packages become pure data exports - Agent packages updated to single-arg AgentFn 小橘 <xiaoju@shazhou.work>
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import { createWorkflow, END, type RoleDefinition } from "@uncaged/workflow";
|
|
import * as z from "zod/v4";
|
|
|
|
type Roles = {
|
|
greeter: { greeting: string };
|
|
};
|
|
|
|
const greeterMetaSchema = z.object({
|
|
greeting: z.string(),
|
|
});
|
|
|
|
export const descriptor = {
|
|
description: "A simple hello world workflow",
|
|
roles: {
|
|
greeter: {
|
|
description: "Generates a greeting",
|
|
schema: {
|
|
type: "object",
|
|
properties: { greeting: { type: "string" } },
|
|
required: ["greeting"],
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const greeter: RoleDefinition<Roles["greeter"]> = {
|
|
description: "Generates a greeting",
|
|
systemPrompt: "You greet the user briefly.",
|
|
schema: greeterMetaSchema,
|
|
dryRunMeta: { greeting: "Hello!" },
|
|
};
|
|
|
|
const extract = {
|
|
provider: { baseUrl: "http://127.0.0.1:9", apiKey: "", model: "" },
|
|
dryRun: true,
|
|
} as const;
|
|
|
|
export const run = createWorkflow<Roles>(
|
|
{
|
|
roles: { greeter },
|
|
moderator(ctx) {
|
|
return ctx.steps.length === 0 ? "greeter" : END;
|
|
},
|
|
},
|
|
{
|
|
agent: async (ctx) => `Hello, ${ctx.start.content}`,
|
|
},
|
|
extract,
|
|
);
|