RFC-005: Separate Agent and Role — type-level refactor #267
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Refactor the workflow type system to cleanly separate Agent (pure execution capability) from Role (identity + purpose + structured output). This clarifies the layering and simplifies adapter integration.
Motivation
Current
Role<Meta>conflates two concerns:The current signature
(start: StartStep, messages: WorkflowMessage[]) => Promise<RoleResult<Meta>>leaks engine-level details (maxRounds, dryRun) into every role implementation. Adapter authors (hermes, cursor) have to destructure fields they don't care about.Design
Core Insight
New Types
Layering
AgentFnThreadContextstringRole<M>ThreadContext{ content, meta }Moderator<M>ThreadContextRole ↔ Agent Composition
A Role internally decides how to use the
ThreadContext:start + stepsinto a prompt string, pass toAgentFnthreadIdonly, let the agent usenerve threadCLI to progressively load context as needed — more efficient for large threadsKey Changes from Current Code
Role(start, messages)Role(ctx: ThreadContext)start.meta.dryRunin Rolestart.meta.maxRoundsin RoleAgentFnconceptAgentFn = (ThreadContext) => Promise<string>messages: WorkflowMessage[]steps: RoleStep[]in ThreadContextThreadContext fields
threadIdnerve thread show <id>for progressive loadingstartstepsMigration
AgentFntype +ThreadContexttype to@uncaged/nerve-coreRole<Meta>signature from(start, messages)to(ctx: ThreadContext)Moderatorto use sameThreadContext(already close —ModeratorContexthas{ start, steps }; just addthreadId)dryRunout ofStartStep.metainto adapter/engine configcreateRole(agent, identity)helper to@uncaged/nerve-workflow-utilsPhase Tracking
Non-goals