steer
Function, in @jr2/orchestrator/src/steer.ts. It is an export of @jr2/orchestrator, in the Steering group of the Authoring surface page.
function steer<
TContext extends MachineContext,
TExpressionEvent extends EventObject,
TParams extends ParameterizedObject["params"] | undefined,
TEvent extends EventObject,
TActor extends ProvidedActor,
>(
agent: string,
text: string | ((args: SteerArgs<TContext, TExpressionEvent>) => string),
opts: { from?: Sender | ((args: SteerArgs<TContext, TExpressionEvent>) => Sender | undefined) } = {},
): ActionFunction<TContext, TExpressionEvent, TEvent, TParams, TActor, never, never, never, never>Send a Steering message to one Agent of this Machine: an action for a transition. The Agent hears the text once, without an interrupt. When a Turn of the Agent is open, its Harness adds the text at the Turn's next step boundary. Otherwise the text waits for the Agent's next Turn in this Machine instance. When this Machine instance ends first, the message is not delivered.
A Steering message is not an event: no guard reads it, and no Gate takes it. The Agent decides what to do with it, and acts on the workflow only by its picks.
Use it to relay what one Agent says to another. Give from the Sender of the event (the sender field that the Orchestrator writes on it): the Agent then reads the text as the word of a peer, not as an order. When the Sender is a Gate, the Agent reads the text as what the Gate received, not as an order. With no from, the Agent reads the text as the workflow's own.
agent is the name of an Agent in this Machine's actors. A text longer than 16 KiB is cut. The Machine can steer an Agent whose definition says steerable: false: that refuses Callers only.
Parameters
agenttextoptsfrom(optional):Sender | ((args: SteerArgs<TContext, TExpressionEvent>) => Sender | undefined)
Example
import { z } from "zod";
import { agent, defineEvent, jr2Setup, steer } from "@jr2/orchestrator";
const done = defineEvent({ name: "done", description: "The draft is ready.", input: z.object({}) });
const note = defineEvent({
name: "note",
description: "Send the draft back to the writer, with what to change.",
input: z.object({ text: z.string().min(1) }),
});
export const machine = jr2Setup({
events: [done, note],
actors: {
writer: agent({ model: "anthropic/claude-haiku-5-5", instructions: "You write.", workspace: "none" }),
reviewer: agent({ model: "anthropic/claude-haiku-5-5", instructions: "You review.", workspace: "none" }),
},
}).createMachine({
initial: "writing",
states: {
writing: {
invoke: { src: "writer", input: { prompt: "Write the notes.", continue: true } },
on: { done: "reviewing" },
},
reviewing: {
invoke: { src: "reviewer", input: { prompt: "Review the notes." } },
on: {
// The writer's next Turn hears the note as the reviewer's word, not as an order.
note: {
target: "writing",
actions: steer("writer", ({ event }) => event.text, { from: ({ event }) => event.sender }),
},
},
},
},
});See also