Skip to content

Build a playbook

A playbook is a drawing: steps (called nodes in the API) joined by lines (called edges). Each step says what to do and which agent does it. The drawing is saved as JSON on a playbook version; you can draw it on the dashboard canvas or send the JSON yourself.

{
  "nodes": [ { "id": "...", "kind": "instruction", "title": "...", "text": "...", "agent_uuid": "...", "x": 0, "y": 0 } ],
  "edges": [ { "from": "...", "to": "...", "name": "..." } ],
  "rules": [ { "step": "...", "title": "...", "rule": "...", "why": "..." } ]
}

rules is optional. It holds guidance the agent follows on this version; see Rules.


Create a playbook

A playbook has a name, an optional description, a time limit for a whole run, and one or more versions.

POST /playbooks
{
  "name": "Invoice check",
  "description": "Match invoices to purchase orders",
  "max_run_duration_sec": 1800,
  "version": "0.1.0"
}
Field Meaning
name Required, 1 to 200 characters.
description Optional.
max_run_duration_sec The longest one run may take, across all its agents: 60 to 86400 seconds. Leave out (or send 0) for the default of 1800.
version Name of the first, empty version. Leave out for 0.1.0.

Creating a playbook also creates its first version with an empty drawing. A version name is 1 to 64 characters: letters, digits, dot, underscore and dash, starting with a letter or digit.

PATCH /playbooks/{uuid} takes the same name, description and max_run_duration_sec and replaces all three; a max_run_duration_sec left out resets to 1800.


Steps

Every step has these fields.

Field Required Meaning
id yes Unique within the version. Lines refer to steps by id. Must not be empty.
kind yes instruction, condition or tool. There is no default; anything else is refused.
title no A short label for the canvas and the run view, up to 200 characters. Messages name the step by its title, or by its id when there is no title.
text yes For an instruction, what to do. For a condition, how to choose the path. For a tool step, what to pass to the tool and what to do with its result. Up to 8000 characters, and not empty.
agent_uuid yes The agent that performs the step. It must have Workforce settings and not be disabled. A condition that decides by rules has none.
decide_by no On a condition only: agent (the default) or rules. See Decide by rules.
tool tool steps Only on a tool step, and required there: the one tool the step uses. See Tool.
result_schema no Only on a last instruction or tool step: the JSON shape the agent must return. See Return a result as data and the Result schema reference.
x, y no Canvas position only. They have no effect on a run.

A drawing may hold up to 200 steps and 400 lines. Saving a drawing over these limits is refused with 400.

Instruction

An instruction is work for an agent. The agent reads the step's text, the instructions the run was started with, any input data, and what earlier steps produced; it may call the tools it was granted; and it ends the step by finishing with a short summary. That summary is what later steps see as earlier work. Notes the agent wrote in a step go along with its summary to the steps after it: the newest 5, each up to 500 characters. The think step's input records how many came from each earlier step as earlier_notes, not the notes themselves; see What a run records. A last step can instead return its answer as data; see Return a result as data.

Write the text the way you would brief a colleague: what to do, what a good result looks like, and when to stop and ask (see Questions).

Tool

A tool step makes its agent use one named tool. Use it when a step must do one specific thing, such as sending a message or looking something up, and you don't want to leave it to the agent's judgement. The step names its agent and one tool in tool, and its text says what to pass to the tool and what to do with the result.

{ "id": "send", "kind": "tool", "title": "Send it", "text": "Send the summary to the on-call channel.", "agent_uuid": "...", "tool": "..." }

tool is either the name of a platform tool, as it appears in an agent's tool list, or <app uuid>/<tool> for a tool of a Forge app.

  • On this step the agent uses only that tool. Its other tools wait for the steps that need them; put any lookup the tool call depends on in an earlier step.
  • The agent can only use tools it already has. Its grants, pinned arguments and approval rules apply as they do anywhere else. If the tool needs a person's approval, the step waits until someone decides.
  • The step cannot finish without the tool. The agent is reminded once if it replies without asking for it; if it still doesn't, the step fails. A call that is denied or fails still counts as asking.
  • The editor warns you when the step's agent can't use the tool, and a version in that state is refused on deploy. Give the agent the tool, or pick another agent.
  • A tool step is followed like an instruction: every line out of it is followed, and a last tool step may return a result. It cannot decide by rules.

Condition

A condition chooses which way the playbook goes. Its text says how to choose. The agent on the step reads the text and the earlier work, then picks from the names of the lines leaving the step. A condition calls no tools.

The agent may choose one line, several lines, or none. A condition passes what it received on to the steps after it, along with its reason for choosing.

Decide by rules

When the choice follows from the data the run was started with, a condition can decide by rules instead of asking an agent. Set "decide_by": "rules" on the step. It has no agent and needs no text. Each line leaving it carries a when rule over input, or "otherwise": true for the one line followed when no rule is true.

{ "id": "route", "kind": "condition", "title": "Where does it go?", "decide_by": "rules" }
{ "from": "route", "to": "sef", "name": "sef", "when": "input.amount > 500 && input.currency == \"RSD\"" },
{ "from": "route", "to": "pdf", "name": "pdf", "otherwise": true }

The answer is the same for the same input, and costs no credits. See the Rules reference for the syntax, missing fields, limits and every message.


Lines

A line joins one step to another.

Field Required Meaning
from yes Id of the step the line leaves.
to yes Id of the step the line enters.
name on a condition's lines The label the condition chooses by. Ignored on lines leaving an instruction.
when on a rules condition's lines The rule that must be true to follow the line, in CEL syntax over input. Up to 1000 characters. See the Rules reference.
otherwise on a rules condition's lines true on the one line followed when no rule is true. Not together with when.

How a run follows the lines

  • The playbook has exactly one start: the one step no line enters. A run begins there.
  • When an instruction finishes, every line leaving it is followed. Steps that are ready at the same time run side by side.
  • When a condition finishes, only the lines it chose are followed. A line it did not choose is dead, and so is everything that can only be reached through it.
  • A step with several lines entering it runs once every one of them is either followed or dead, and at least one was followed. If all of them are dead, the step is dead too and is skipped.
  • A run is complete when nothing is left to run. Its summary is the result of each last step.
  • Lines may only go forward. A line that leads back to a step you have already passed is refused. To retry something, write it into the step's text instead of drawing a loop.
  • Only one line is allowed between a given pair of steps.

Approvals and questions

Approvals and questions are not step kinds. They happen inside a step, when the agent doing it needs a person.

Approvals

When an agent calls a tool whose approval is confirm, the step stops and waits for a person to approve or deny that call. You decide which calls need approval when you grant tools to the agent (see Put an agent to work), not in the playbook. A step waiting on a person holds only its own path; the rest of the playbook carries on.

A tool granted with never is refused outright. Nothing waits.

Questions

Every agent can ask a person a question and wait for the answer. Tell it when to ask in the step's text: for example, "if more than one customer matches, ask which one and offer the names as options". A question has text (up to 2000 characters) and optionally up to six short options.

The agent also has two ways to end its work early without failing: it can report that there is nothing to do (the run completes with that stop reason), or escalate to a person (the run completes with stop reason escalated, and the people the agent's escalation settings name are told).

How people see and answer all of this is on People in the loop.


Limits

Limit Where it is set Default When it is reached
Run duration Playbook: max_run_duration_sec 1800 s (range 60 to 86400) The run stops with budget_time
Steps per run Agent budget: max_steps_per_run 25 The run stops with budget_steps
Tool calls per run Agent budget: max_skill_calls_per_run 15 The run stops with budget_skill_calls
Tokens per run Agent budget: max_tokens_per_run none The run stops with budget_tokens
Duration per agent Agent budget: max_run_duration_sec 900 s The run stops with budget_time
Runs per day Agent budget: max_runs_per_day none The run does not start: budget_runs
Credits per day Agent budget: max_credits_per_day none The run stops: budget_credits

Things to know:

  • The agent limits count each agent's own work across the whole run. If two steps use the same agent, they share that agent's step and tool-call budget.
  • For a playbook run the clock is the earlier of the playbook's limit and the agent's own duration limit. Time spent waiting for a person does not count, so a run that waited a day for an approval is not out of time when the approval comes.
  • A run that hits a limit ends as completed with the matching stop reason. Its summary begins Stopped: and says which limit, then gives what the finished steps produced.
  • max_credits_per_day applies to the platform's credit allowance only, not to an agent using the project's own key. An agent on the project's own key must be given both max_tokens_per_run and max_runs_per_day when it is put to work, or it is refused with budget ceilings required for BYOK agent.
  • A scheduled run is not started at all when an agent on the playbook has reached its daily limits, so a capped schedule does not pile up refused runs.

Validation

Saving a drawing accepts any shape within the size limits: you can save a half-finished drawing. The drawing is checked when you validate it and when you deploy it. Deploy and rollback refuse a version with any problem.

POST /playbooks/{uuid}/versions/{version}/validate

answers 200 with the problems found; an empty list means the version can be deployed.

{
  "problems": [
    {
      "code": "condition_few_lines",
      "node_id": "route",
      "message": "Step \"Does it match?\" is a choice but has 1 line(s) out; it needs at least two."
    }
  ]
}

A deploy that is refused answers 422 with the same list:

{ "message": "workforce: playbook version has 1 problem(s)", "problems": [ ... ] }

Every problem has a code, a message and, when it belongs to one step, a node_id. A problem in a result schema also has a field. All problems are listed at once.

Code What it means How to fix it
no_nodes The drawing has no steps. Add at least one step.
empty_node_id A step has an empty id. Give every step a unique id.
duplicate_node Two steps share an id. Rename one.
unknown_node A line refers to a step that is not on the drawing. Fix the line's from or to, or add the step.
duplicate_line There is more than one line from one step to the same other step. Keep one. Branches to the same step need only one line.
no_start Every step has a line coming in, so there is nowhere to begin. Remove the line that enters the step the run should start at.
several_starts More than one step has no line coming in. Join the extra steps into the flow, or delete them.
unreachable A step cannot be reached from the start. Draw a line to it, or delete it.
empty_text A step has no text (a condition that decides by rules needs none). Write what to do (instruction) or how to choose (condition).
no_agent A step has no agent_uuid. Pick an agent.
agent_missing The step's agent has no Workforce settings (or no longer exists). Put the agent to work, or pick another.
agent_disabled The step's agent is disabled. Turn it back on, or pick another. A paused agent passes validation but cannot take part in a run until it is active.
bad_kind kind is not instruction, condition or tool. An empty kind is refused too. Set kind.
tool_missing A tool step has no tool. Message: Step "<title>" uses a tool, but no tool is chosen. Choose the tool, or change the step to an instruction.
tool_not_on_kind An instruction or condition has a tool. Remove tool, or make the step a tool step.
tool_invalid The tool is not one an agent can use: an app tool that is not written <app uuid>/<tool>, or a tool agents are never given. Use a platform tool name or a valid app tool.
tool_not_granted The step's agent can't use the tool: it is not one of the agent's tools, or the agent is never allowed to use it. Give the agent the tool (and don't set it to never), or pick another agent.
condition_few_lines A condition has fewer than two lines leaving it. Draw at least two lines out of it.
unnamed_line A line leaving a condition has no name. Name every line of a condition.
duplicate_line_name Two lines leaving one condition share a name. Give each line its own name.
result_schema_not_at_end A step with a line leaving it has a result_schema. Message: Only a last step can return a result. Move the schema to a last step, or remove it.
result_schema_invalid The schema breaks a rule of the result schema reference, or it is on a condition. Up to 20 are listed per step, each with a field (the path of the field, empty for the top level) and a message that starts with Step "<title>":; on a condition it is Step "<title>" is a choice and cannot return a result. Fix the schema as the message says, or move it to an instruction or tool last step.
rules_need_when, rules_when_invalid, rules_otherwise_twice, rules_when_and_otherwise, rules_no_agent, rules_too_many_lines, when_on_agent_condition, bad_decide_by A condition that decides by rules is not set up correctly. Each message says what is wrong. See Problems and fixes in the Rules reference.
rule_no_text, rule_too_long, rule_no_title, rule_title_too_long, rule_why_too_long, too_many_rules, rule_unknown_step, rule_on_rules_condition, rule_id_twice A rule in rules is not valid. See Rule problems.
cycle A line leads back to a step already on the way. A line from a step to itself counts. Remove the line; lines may only go forward.

A drawing can be refused for size on save, before any of these: at most 200 steps, at most 400 lines, step text is at most 8000 characters, step title is at most 200 characters.


Rules

A version's rules are short pieces of guidance the agent follows while it works on this version. They belong to the version: a new version copies them, and deploy and rollback carry them along. Each rule is:

{ "id": "", "step": "pay", "title": "Pay the gross total", "rule": "Use the gross invoice total, never the net amount.", "why": "Suppliers are paid gross." }
Field Meaning
id Empty on a new rule (the server gives one); keep it when you resend a rule.
step The id of the step the rule is for. Empty means every step.
title Required, up to 120 characters.
rule Required, up to 1000 characters.
why Optional, up to 1000 characters.
source, added_by, added_at Set by the server; anything you send is ignored.

A version holds at most 20 rules. A save accepts up to 100 so you can keep a draft, but validate and deploy refuse more than 20. Rules are also made from feedback: see Feedback and rules.

Rule problems

Each problem has a field such as rules[1].rule (the place in the list, from 0).

code Message Fix
rule_no_text Rule 2 has no text. Write the rule.
rule_too_long Rule 2 is longer than 1000 characters. Shorten it.
rule_no_title Rule 2 has no title. Give it a title.
rule_title_too_long The title of rule 2 is longer than 120 characters. Shorten the title.
rule_why_too_long The reason on rule 2 is longer than 1000 characters. Shorten the reason.
too_many_rules There are 21 rules; at most 20 are allowed. Remove rules, or keep the most useful.
rule_unknown_step Rule 2 is for the step "x", but there is no such step. Use the id of a step in this drawing, or leave step empty.
rule_on_rules_condition Rule 2 is for <the step>, which decides by rules and never reads rules. Put the rule on another step, or on every step.
rule_id_twice Two rules share the id "x". Give each rule its own id, or leave it empty.

Examples

Replace the agent ids with agents of your own that are at work. Each example was checked against the rules above and passes validation.

A single agent

One step, no lines. The agent works with the tools it was granted and finishes with the digest.

{
  "nodes": [
    {
      "id": "digest",
      "kind": "instruction",
      "title": "Write the weekly digest",
      "text": "List the orders created in the last 7 days. Write a short digest: how many orders, the total value, and the three largest orders. Finish with the digest as your summary.",
      "agent_uuid": "11111111-1111-4111-8111-111111111111",
      "x": 80,
      "y": 80
    }
  ],
  "edges": []
}

A branch, with an approval

Two agents. The accounts agent checks the invoice, a condition chooses a path, and a payments agent schedules the payment only when the totals match.

{
  "nodes": [
    {
      "id": "check",
      "kind": "instruction",
      "title": "Check the invoice",
      "text": "Read the invoice from the input. Compare the total with the purchase order it names. Summarise any difference.",
      "agent_uuid": "22222222-2222-4222-8222-222222222222"
    },
    {
      "id": "route",
      "kind": "condition",
      "title": "Does it match?",
      "text": "Choose \"matches\" when the invoice total equals the purchase order total. Choose \"differs\" when it does not.",
      "agent_uuid": "22222222-2222-4222-8222-222222222222"
    },
    {
      "id": "pay",
      "kind": "instruction",
      "title": "Schedule the payment",
      "text": "Schedule the payment for the invoice total with the payments tool.",
      "agent_uuid": "33333333-3333-4333-8333-333333333333"
    },
    {
      "id": "flag",
      "kind": "instruction",
      "title": "Flag the difference",
      "text": "Write a note for the accounts team that names the invoice, both totals and the difference. Do not schedule a payment.",
      "agent_uuid": "22222222-2222-4222-8222-222222222222"
    }
  ],
  "edges": [
    { "from": "check", "to": "route" },
    { "from": "route", "to": "pay", "name": "matches" },
    { "from": "route", "to": "flag", "name": "differs" }
  ]
}

The approval does not appear in the drawing. It comes from the payments agent's settings: grant its payment tool with "approval": "confirm", and the Schedule the payment step stops at the call and waits for a person to approve it.

{ "tool": "payments_schedule", "approval": "confirm" }

(Use the real tool name from GET /skills or your app's tool list.)

A step that may ask a question

The first step tells the agent to ask when it cannot decide. When it asks, the run waits for the answer and then continues with the second step.

{
  "nodes": [
    {
      "id": "find",
      "kind": "instruction",
      "title": "Find the customer",
      "text": "Find the customer record that matches the name in the input. If more than one customer matches and you cannot tell which is meant, ask the person which one, and offer the matching names as options. Finish with the customer's id.",
      "agent_uuid": "44444444-4444-4444-8444-444444444444"
    },
    {
      "id": "reply",
      "kind": "instruction",
      "title": "Draft the reply",
      "text": "Draft a short, polite reply to the customer about the open question in the input. Finish with the draft.",
      "agent_uuid": "44444444-4444-4444-8444-444444444444"
    }
  ],
  "edges": [
    { "from": "find", "to": "reply" }
  ]
}

Return a result as data

By default a run answers in words: each last step finishes with a short summary. When a program needs to read the answer, give a last step a result schema. The agent then has to hand back JSON in exactly that shape, and the run carries it as data.

{
  "id": "reply",
  "kind": "instruction",
  "text": "Write the reply to the customer and rate how urgent the ticket is.",
  "agent_uuid": "55555555-5555-4555-8555-555555555555",
  "result_schema": {
    "type": "object",
    "properties": {
      "priority": { "type": "string", "enum": ["low", "high"] },
      "text": { "type": "string", "description": "The reply that was sent." }
    },
    "required": ["priority", "text"]
  }
}

Where a schema may go

  • Only on an instruction or tool step that is a last step: no line leaves it. A step with a line out cannot return a result, and a condition never can.
  • A playbook may have several last steps. Each may have its own schema, and each result is kept under the id of its step.

Schema rules

The schema is a small subset of JSON Schema: type, properties, required, items, enum, description and additionalProperties, nothing else. The top level is an object with at least one property, every field has a one-word type, an array has items, and a schema is at most 5 levels deep and 8 KB. Describe every field: the agent reads the descriptions to know what to write.

Every keyword, type and rule, with the exact message for each problem, common mistakes and worked examples, is in the Result schema reference. Problems are listed all at once when you validate, each with the path of the field.

What the agent does

A last step with a schema gives the agent a work_result tool. It must finish the step by calling it with JSON in the shape of the schema. The JSON is checked. If it does not match, the agent is told what is wrong and gets one more try. If it still does not match, the run ends failed with the stop reason result_invalid: the agent did not return the result in the shape the playbook asks for.

The prose summary is unchanged and still written. The run's result is separate: an object keyed by last-step id, for example { "reply": { "priority": "high", "text": "hello" } }. See Deploy and run.

A full example

Two steps. The first reads the ticket; the last returns a rating and the reply as data.

{
  "nodes": [
    {
      "id": "read",
      "kind": "instruction",
      "title": "Read the ticket",
      "text": "Read the support ticket in the input and summarise what the customer wants.",
      "agent_uuid": "55555555-5555-4555-8555-555555555555"
    },
    {
      "id": "reply",
      "kind": "instruction",
      "title": "Answer the ticket",
      "text": "Write a short, polite reply to the customer, and decide how urgent the ticket is: high if the customer cannot work at all, otherwise low.",
      "agent_uuid": "55555555-5555-4555-8555-555555555555",
      "result_schema": {
        "type": "object",
        "properties": {
          "priority": { "type": "string", "enum": ["low", "high"] },
          "text": { "type": "string", "description": "The reply that was sent." },
          "tags": { "type": "array", "items": { "type": "string" } }
        },
        "required": ["priority", "text"],
        "additionalProperties": false
      }
    }
  ],
  "edges": [
    { "from": "read", "to": "reply" }
  ]
}

A completed run of this playbook carries:

{ "reply": { "priority": "high", "text": "Thanks for getting in touch. We are on it.", "tags": ["login"] } }

Saving and versions

PATCH /playbooks/{uuid}/versions/{version}
{ "graph": { "nodes": [ ... ], "edges": [ ... ], "rules": [ ... ] }, "note": "Added the flag step" }

Saving replaces the whole drawing, rules included: send the rules you want to keep. note is optional and records what changed. The request body may be up to 1 MB. The version that is deployed to live cannot be edited: saving it answers 409 workforce: version is deployed to live. Make a new version instead; see Deploy and run.