Skip to main content

7 of 16

Scenarios and task corpora

Test an architecture with given inputs and scripted outside parts, and check the events it should record.

docs/scenarios.md

Scenarios and task corpora

A scenario tests one architecture with given inputs. It puts the inputs at the architecture's border, scripts the parts outside it (the model, the build tool, a person's reply), and lists the events it expects, named as the building blocks name them. agenticspec sim scenario run drives the simulator with it on a virtual clock and checks each expected event.

A task corpus lists inputs taken from real sessions, each with the outcome it had. agenticspec sim corpus run runs every entry and prints the outcome the simulator predicts beside the one the entry expects. A behaviour profile can also draw its tasks from a corpus.

The examples for the workstation architecture are in scenarios/workstation/.

Commands​

agenticspec sim scenario check scenarios/workstation/question-answered.scenario.yaml
agenticspec sim scenario run scenarios/workstation/question-answered.scenario.yaml --out target/scenarios/question
agenticspec sim corpus run scenarios/workstation/workstation.corpus.yaml
commandwhat it doesprints
sim scenario check <scenario>reads the scenario and checks it against its architecture and profilethe scenario name, the architecture, the number of inputs and of expectations
sim scenario run <scenario> --out <dir>checks the scenario, runs it and writes <dir>/scenario-result.jsonthe same, with the verdict, the predicted class and the counts of expectations held, failed and not checked
sim corpus run <corpus>runs every entry of the corpusthe rows as JSON; the table goes to standard error
blocks scenario <session> ...writes a draft scenario of a session (below)the file, the counts, the inputs left unjoined or unmapped

task check:scenarios runs every scenarios/*/*.scenario.yaml and every scenarios/*/*.corpus.yaml.

A refused command exits 1 and prints <code>: <detail> to standard error:

codewhen
document_unreadablea file cannot be read or is not YAML
scenario_invalidthe scenario is not a valid agenticspec-scenario/1 document; every problem is named by its path, such as when.0.atx: unknown key
architecture_digest_mismatcharchitecture.digest is not the sha256 of the architecture file; scenario run refuses before the simulation starts
profile_digest_mismatchprofile.digest is not the sha256 of the profile file
architecture_refusedthe architecture itself is refused, with the rules sim check names
input_not_at_borderan input is at a part the architecture's border does not list
invalid_rowa given row does not fit its entity (below)
fixture_without_parta fixture names a part the architecture does not have
unknown_eventan expected event is no event a block declares, such as agentic.resource.ClaimGrantd
unknown_refusalan expected refusal is no command a block declares, or its error is no error that command is refused with
scenario_refusedthe scenario does not fit its architecture in another way: an author names no part, a fixture names a part of the wrong block, an unavailable entry or a part of then.parts names no part or no dependency, a view, command or error is not declared by a block; or it has problems of more than one code

A check names every problem, each after its code. When all of them have one code, the command exits with that code; when their codes differ, with scenario_refused. | out_missing | scenario run without --out | | out_unwritable | scenario-result.json cannot be written | | expectation_failed | an expected event or a KPI bound failed; scenario-result.json is written first | | corpus_invalid | the corpus is not a valid agenticspec-corpus/1 document, or an entry's digest, kind or input digest does not match its scenario | | corpus_failed | an entry's expectations failed, or it predicts another class than it expects |

A scenario​

format: agenticspec-scenario/1
scenario: question-answered
summary: The worker asks a question only the owner can answer; the owner picks B.
architecture: { ref: ../../architectures/workstation.yaml, digest: 9f48c790a19597559396e9cb96d13e753d6d7b427c48eaf6bd9a91cd49fdfe99 }
profile: { ref: ../../fields/coding/profiles/coding.yaml, digest: f8f5d0007605f7d4b4da01c9996165d3a93e7e3e81ca23168412fc508bf83335 }
seed: 1
horizon: 2h

when:
- { at: operator, kind: prompt, author: owner, text: "Rename the config key the release script reads." }

fixtures:
model:
- { for: worker, outcome: question, turns: 3, options: [A, B], default: A, needs_owner: true }
principals:
- { part: owner, option: B, after: 10m }

then:
order: sequence
events:
- { event: agentic.work.RunStarted, part: worker, task: when.0 }
- { event: agentic.question.QuestionAsked, part: worker, task: when.0, options: [A, B] }
- { event: agentic.question.QuestionAsked, part: operator, task: when.0 }
- { event: agentic.channel.MessageSent, part: operator, channel: chat }
- { event: agentic.question.QuestionAnswered, part: owner, task: when.0, option: B }
- { event: agentic.work.TaskCompleted, part: worker, task: when.0 }
kpis:
questions_forwarded: { min: 1, max: 1 }
questions_defaulted: { max: 0 }
keyrequiredwhat
formatyesagenticspec-scenario/1
scenarioyesthe name
summarynoone paragraph
architectureyes{ ref, digest }: the architecture file, relative to the scenario, and the sha256 of its bytes (sha256sum <file>)
profileyes{ ref, digest }: the behaviour profile the simulator draws everything else from
seednothe seed of the run; 0 by default. The same scenario and seed give the same scenario-result.json, byte for byte
horizonnohow long the run lasts; 4h by default
givennorows that exist when the run starts
whenyesthe inputs, in order
fixturesnostand-ins for the parts outside the architecture
unavailablenothe parts and dependencies that are unavailable, and from when (below)
thennothe expected events, KPI bounds and what each part shows

Every key that is not in these tables is refused with its path. Durations are written 90s, 15m, 2h or 1d.

Inputs​

Each entry of when is one input at a border part:

keyrequiredwhat
atyesthe part that receives it; it must be listed in the architecture's border
kindyesprompt, order, message or control
authoryesthe part that sends it: a principal or another part of the architecture
actfor controlsend, pick, run, retry, dispatch, approve or reject. A prompt and a message send by default, an order dispatchs
proofnothe proof that the input comes from its author, such as client_record, process_identity or passkey; none counts as no proof
textnothe input as written; the simulator does not read it, a corpus entry holds its digest
afternothe time since the input before it (the first: since the start); 0s by default

The run admits an input or refuses it by a rule. Every input is a message to its border part, so a refused input is a refusal of agentic.channel.SendMessage:

rulerefused whencommandblock error
input_without_linkno link from the author to the part carries the input: a prompt needs a prompt link, an order an order link, a message or a control input any linkagentic.channel.SendMessageagentic.channel.NotAParty
control_without_authoritya control input comes from an author that is not the principal the part acts for (acts_for)agentic.channel.SendMessageagentic.delegation.NotTheDelegator
control_without_proofa control input carries no proofagentic.channel.SendMessagenone: no block refuses a message without proof
claim_conflicta copy claims a board entry another copy claimed firstagentic.channel.TakePostagentic.channel.PostAlreadyTaken
corpus_refuseda corpus entry a profile drew was refused, so it makes no taskagentic.channel.SendMessagenone
part_unavailablethe part, the author or the channel of the input is unavailable at its time, or the part is cut from the author or the channel (below)agentic.channel.SendMessagenone: no block declares one

An admitted prompt (send), order (send, dispatch) or control input (run, retry, dispatch) makes a task, named after the input: when.0 for the first. Other admitted inputs are delivered and change nothing else in the simulation.

Given rows​

given:
tasks:
- { id: backlog-1 }
questions:
- { id: q-1, asked_by: worker, addressee: owner, options: [A, B, C], default: C }

A given task waits in the backlog at the start. A given question is open at the start: a copy of asked_by holds it and waits for the answer of addressee. Neither records a creation event; the events that follow carry the row's id as their task.

rows holds rows of any block entity, such as the rows agenticspec blocks lift writes for a session (Queries):

given:
rows:
- entity: agentic.question.Question
id: e77e1af7-84f9-f4c4-12b9-2c0d99596d5c
state: Answered
fields: { asked_by: 19faf7cc-c2aa-c558-1b93-cdd35cd4c467, addressee: c1582bfa-36f6-f8ad-4777-2e7feb7f5a80, text: { digest: cc780a105da069ae2ec1b36669e62f7891da7c136719992ea3752c419d572b56, length: 100, class: tool_input } }
not_recorded: [kind, options, default_option, deadline]
evidence: "lift-demo#16"
keyrequiredwhat
entityyesa block entity, by its full name
idyesits identifier
statenoa state of the entity's lifecycle
fieldsnofield values, each a field the entity declares, of its type
not_recordednorequired fields the record the row comes from does not hold
evidencenowhere the row comes from, such as a node of a session

scenario check refuses a row of an entity no block declares, a field the entity does not have, a value of the wrong type, a state outside its lifecycle, and a required field that is neither in fields nor in not_recorded, each by its path (given.rows.0.fields.pool_id). The simulator does not read rows.

Fixtures​

fixtures:
model:
- { for: worker, outcome: correct, turns: 4, builds: 1 }
- { outcome: question, options: [A, B], default: A, needs_owner: true }
tools:
- { tool: build, seconds: 2m }
principals:
- { part: owner, option: B, after: 10m }
fixturekeywhat
modeloutcomehow a run ends: correct, wrong (the run ends failed and the task is worked on again), false_completion (reported done, not correct) or question (one question, then correct)
foronly a run of this agent part takes it; any run by default
turnsthe model calls of the run; drawn from the profile when not given
buildsthe builds of the run; 0 by default
options, default, needs_ownerthe question's options, its default, and whether it needs the principal behind the agent it asks
toolstool, secondsbuild: how long the next build takes. The pool's job limit decides whether it ends or is killed
principalspart, after, optionthe next question that reaches this principal is answered after it arrives, with option (the question's default when not given)

Runs take the model fixtures in the order they start, builds take the tool fixtures in the order they start, and questions take the replies in the order they reach the principal. A run with no model fixture left, and a build with no tool fixture left, draws from the profile. A principal with no reply left does not answer, and the question takes its default after the architecture's question_default_after. The simulator scripts a run as a whole: outcome decides how the run ends, not each model call.

Expected events​

then:
order: sequence
events:
- { refusal: agentic.channel.SendMessage, part: operator, author: owner, rule: control_without_proof }
- { event: agentic.work.TaskCreated, absent: true }
kpis:
tasks_arrived: { max: 0 }

An expectation names one block event by its full name (event), or one refusal (refusal, error, rule, or any of them). order: sequence (the default) expects each after the one before it; order: set expects each on an event of its own, in any order. An expectation with absent: true holds when no event matches it.

keymatches
eventthe block event, as a block declares it: agentic.resource.ClaimGranted
refusalthe block command refused: agentic.resource.RequestClaim
errorthe block error of a refusal; it must be one the command is refused with: agentic.resource.NoTimeLimit
rulethe rule of the run that refused it (the table above)
partthe part the event is about
taskthe task: when.<n> for an input, the id of a given row
options, optionthe options of a question, the option of its answer or default
channel, authorthe channel and the sender of a message
processthe process the task follows; the simulator follows none, so this is never checked

scenario check refuses an event no block declares (unknown_event, with the nearest declared name when there is one) and a command or error no block declares for it (unknown_refusal). An expectation that names an event and a key of a refusal, or neither, is not a valid scenario.

The simulator records these block events:

block eventrecorded by the simulator
agentic.work.TaskCreatedyes
agentic.work.RunStartedyes
agentic.work.RunEndedyes, when a run ends failed
agentic.work.DeliverableSubmittedyes, when a reviewer receives it
agentic.work.AssignmentOfferedyes
agentic.work.TaskCompletedyes
agentic.work.DeliverableRejectedyes
agentic.work.TaskCancelledyes
agentic.gateway.CallDecidedyes, when the rate limit holds a call
agentic.resource.ClaimQueuedyes
agentic.resource.ClaimGrantedyes
agentic.resource.ClaimReleasedyes
agentic.question.QuestionAskedyes
agentic.channel.MessageSentyes
agentic.question.QuestionAnsweredyes
agentic.question.DefaultTakenyes
agentic.resource.ClaimKilledyes
agentic.channel.Postedyes
agentic.trigger.ScheduleAdvancedyes
agentic.trigger.TriggerFiredyes
agentic.trigger.FiringQueuedyes
agentic.trigger.FiringSkippedyes
agentic.trigger.FiringStartedyes
agentic.trigger.FiringFailedyes

It refuses only agentic.channel.SendMessage (an input) and agentic.channel.TakePost (a board claim). An expectation of any other block event, such as agentic.workspace.ChangeProposed, or of a refusal of any other command, is not_checked, not failed: a runtime that records it can check the same scenario. kpis bounds any KPI of a simulator run with min, max or both, inclusive.

Unavailable parts and dependencies​

A scenario can make a part unavailable, or only one dependency of a part: a store, a model route, an upstream it reaches over a link. then.parts then says what each remaining part shows. The same scenario runs on the simulator now and on a runtime later.

unavailable:
- { part: chat, from: 30m }
- { part: worker, dependency: builds, from: 0s }

then:
parts:
operator:
views:
- { view: agentic.channel.ChannelMessages, shows: error, error: agentic.channel.ChannelIsClosed }
rest: answers
worker:
commands:
- { command: agentic.resource.RequestClaim, shows: refused }
keyrequiredwhat
partyesthe part that is unavailable; with dependency, the part that loses it
dependencynoa part that part depends on: one its links go to or over, one in its egress, one that exists once per copy of it, or one any of those reach over their links. Only part loses it; the other parts still reach it
fromyeswhen it becomes unavailable; 0s is at the start, before the part listens
fornohow long it stays unavailable; to the end of the run by default

then.parts maps a part to what it shows. A part that is unavailable itself shows nothing and is refused there.

keywhat
viewsa list of { view, shows, error }. view is the block name of a view; shows is answer (no error, rows or none), empty (no rows, no error) or error; error, only with shows: error, is the block name of the error the view answers with, any error when left out
commandsa list of { command, shows, error }. command is the block name of a command; shows is accepted or refused; error, only with shows: refused, is the block name of the error it is refused with, any error when left out
exitsthe status, 1 to 255, the part's process exits with before it listens. Only for a part with a dependency unavailable from 0s, and with no views, commands or rest
restanswers: every view and command of the part that is not named answers as it does with nothing unavailable

check refuses, each by its path and name: a part or a dependency that is not in the architecture, a dependency the part does not reach, a part named as its own dependency, a from at or after the horizon, a view or a command that no block declares, an error that no block declares, and a view or command of a block that is neither the part's own nor one of a part it depends on. An agent part also shows the views and takes the commands of the blocks it works in: agentic.harness, agentic.work and agentic.question. A pack block covers every domain under it (scm covers agentic.scm.change and the others).

The four kinds of outcome, each with an example in scenarios/workstation/:

outcomehow it is writtenexample
an error inside one view while the rest answersviews: [{ view, shows: error, error }] and rest: answerschat-closed-view-error
an empty view with no errorviews: [{ view, shows: empty }]model-route-down-empty-view
the process exits with a status before it listensunavailable with from: 0s and exits: <status>operator-exits-without-gateway
a dependency only one command reaches: that command is refused, nothing else is missedcommands: [{ command, shows: refused }] and rest: answersbuild-pool-cut-claim-refused

On the simulator​

The simulator makes an entry unavailable where it can model it, and scenario-result.json says how in unavailable[].simulated:

simulatedwhenwhat the run does
faulta pool or a gateway, or a principal; a pool, gateway or principal only part reaches; a gateway's only modelthe pool or gateway falls to no capacity, the principal is away, for the window
inputs_refuseda channel; a border part, also one that exits at the start, when the scenario has no given rows; a border part cut from a channelthe inputs that reach the part, come from it or come over the channel in the window are refused by the rule part_unavailable
not_modeledanything else, or an inputs_refused entry while the simulation still records an event of the part or over the channel in the windownone of the expected events and bounds is checked: each is not_checked with the reason

The simulator serves no views, decides no commands of a part and starts no processes, so each observable of then.parts is not_checked on it, with the reason. The expected events and KPI bounds say what the simulator can see of the same outage: an input refused, a claim never granted, a task that does not complete while another one does.

On a runtime​

A conformance run of a runtime reads the same scenario and writes the same result document, with the observables checked:

  1. It starts the system with every entry that has from: 0s in force: the part is stopped, or the link from the part to its dependency is cut (the store, the model route, the upstream does not answer the part). The other entries come into force at from and end after for.
  2. A part with exits must exit with that status and must not listen: no port of it accepts a connection. Its status is held or failed.
  3. It sends the inputs of when at their times. An input the runtime refuses because a part or a link is unavailable counts as a refusal by part_unavailable.
  4. While the entries are in force it queries each named view of each part of then.parts and compares: answer holds when the view answers with no error; empty when it answers with no rows and no error; error when it answers with an error, the named one when error is given.
  5. It sends each named command with an input the scenario would accept with nothing unavailable: refused holds when the command is refused, with the named error when given; accepted when it is not refused.
  6. For rest: answers it queries every other view of the part's blocks: each must answer with no error. A command of the part that is not named must not be refused because of the entry.
  7. It checks the expected events and KPI bounds on the events it records, as the simulator does.

The result​

scenario-result.json (format agenticspec-scenario-result/1):

{
"format": "agenticspec-scenario-result/1",
"scenario": "question-answered",
"verdict": "held",
"predicted": "question",
"counts": { "held": 8, "failed": 0, "not_checked": 0 },
"expectations": [
{ "index": 4, "expect": { "event": "agentic.question.QuestionAnswered", "part": "owner", "task": "when.0", "option": "B" }, "status": "held", "trace": 6 }
],
"kpi_bounds": [ { "kpi": "questions_forwarded", "min": 1, "max": 1, "value": 1, "status": "held" } ],
"inputs": [ { "index": 0, "t_seconds": 0, "at": "operator", "kind": "prompt", "act": "send", "author": "owner", "status": "accepted", "rule": null } ],
"trace": [
{ "t_seconds": 654.63, "event": "agentic.question.QuestionAnswered", "part": "owner", "sim": "question_answered", "task": "when.0", "option": "B" }
],
"kpis": { "tasks_done": { "value": 1, "kind": "Quality" } }
}
fieldwhat
verdictheld when no expectation, no bound and no observable failed
predictedthe outcome class of the run (below)
expectationseach expected event with status held, failed or not_checked, the index of the trace event it matched, and the reason when it did not hold
kpi_boundseach bound with the measured value and its status
inputseach input, when it arrived, and whether it was accepted or refused by which rule
traceevery event of the run in block terms, in time order: the block event (refusal for a refusal, with its command, rule and error), the part, the task, and sim, the simulator's own event it comes from
kpisevery KPI of the run
unavailableeach unavailable entry, its window (from_seconds, until_seconds) and how the simulator made it unavailable: simulated is fault, inputs_refused or not_modeled with the reason
observableseach observable of then.parts: the part, observable (view, command, exits or rest), the expectation as written, its status and the reason when it was not checked

counts adds up the expected events, the bounds and the observables.

Outcome classes​

The class a run predicts is the first that applies:

classwhen
refusedan input was refused and no task was made
questiona question was asked
false_completiona task was reported done and is not correct
correcta task was completed and is correct
wronga run ended failed
opennone of these within the horizon

A task corpus​

format: agenticspec-corpus/1
corpus: workstation-examples
architecture: { ref: ../../architectures/workstation.yaml, digest: 9f48c790a19597559396e9cb96d13e753d6d7b427c48eaf6bd9a91cd49fdfe99 }
profile: { ref: ../../fields/coding/profiles/coding.yaml, digest: f8f5d0007605f7d4b4da01c9996165d3a93e7e3e81ca23168412fc508bf83335 }
seed: 1
horizon: 4h

entries:
- scenario: { ref: question-answered.scenario.yaml, digest: 6c675930da48357e350cc404d4a48704d3474261efbe9785eaa73d103524dd03 }
kind: prompt
input_digest: 674bead15a2e6fe07d6bffb0d9e6c35e414ddeb8701cd9b3521840636b2d3d62
expected: question
- { id: s-0042, kind: control, input_digest: 30c100fc28b40e6128c414cf0d212ffe1de6554a456e952020749b0eb0fc3071, expected: refused }
keywhat
format, corpus, summaryagenticspec-corpus/1, the name, one paragraph
architecture, profile, seed, horizonwhat inline entries run on; needed only when the corpus has inline entries
entriesone or more entries

An entry is a scenario reference or an inline entry:

keywhat
scenario{ ref, digest } of a scenario file, relative to the corpus
idthe entry's name; a reference is named after its file by default
kindthe kind of the input; for a reference it must be the kind of the scenario's first input
input_digestthe sha256 of the input's text; for a reference it must match the text of the scenario's first input
expectedthe outcome class: correct, wrong, false_completion, question, refused or open
weighthow often a profile draws the entry, against the others; 1 by default
at, author, act, proofan inline entry's input: at the architecture's border part (when it has one), from the principal that part acts for, unless given

sim corpus run runs a reference with its fixtures and expectations, and an inline entry as its one input with no fixtures, so the profile and the architecture decide what happens to it. An entry holds when none of its expectations failed and its predicted class is its expected class.

Drawing tasks from a corpus​

A behaviour profile draws the outcome of its tasks from a corpus:

load:
tasks_per_hour: 8
corpus: ../scenarios/workstation/workstation.corpus.yaml

Tasks still arrive at tasks_per_hour. Each arrival draws one entry by its weight, and the entry's class decides how the task's first run ends: correct, wrong, false_completion and question as the model fixture of that name, refused makes no task, and open leaves the run to the profile. The path is relative to the profile file.

A draft scenario from a session​

agenticspec blocks scenario <session>.jsonl --architecture architectures/workstation.yaml \
--profile fields/coding/profiles/coding.yaml --map main=operator,sub=worker --out drafts/session.scenario.yaml

blocks scenario lifts the session, writes each of its outside inputs as an entry of when, and the block events of the rows each input caused as then. An outside input is a prompt of the main agent by a human (kind prompt), a delegate or another session (kind message), with proof none and the time since the input before it. A prompt of the harness or a hook, such as a task notification, is no input. What an input caused is every row lifted from the turn that received it and from every step after it, up to the next input: a task makes agentic.work.TaskCreated, a run agentic.work.RunStarted, a question agentic.question.QuestionAsked (and agentic.question.QuestionAnswered), a sent message agentic.channel.MessageSent, each with the input's task, when.<n>. A comment beside each entry names the node it comes from.

--map names the part each side of the session plays, as key=part pairs:

keythe part of
mainthe main agent; required, and a border part of the architecture, where every input arrives
subevery sub-agent
humanthe human who prompts; the part main acts for when not given
delegatea delegate's prompts; the human's part when not given
peeranother session's messages

The draft is checked like any scenario before it is written; a draft the check refuses exits 1 with scenario_refused and writes nothing. It prints:

fieldwhat
out, scenariothe file written and the scenario's name (--name, or the file name)
inputs, expectationsthe entries of when and of then.events
unjoinedinputs no turn received, as when.<n> (<node>): in the scenario, with no expectation
unmappedinputs whose author plays no part, as <node> (<author>): left out of the scenario

Other refusals: transcript_unreadable, document_unreadable (the architecture or profile), map_invalid (a pair that is not key=part, an unknown key, no main) and out_unwritable.