White paper

What is a specification?

What KAOS teaches spec-driven development

Spec-driven development needs a precise notion of specification. A focused look at how KAOS defines a specification through operations.

Bernard Lambeau
November 2026

What is a specification?

What KAOS teaches spec-driven development

Central question What must a specification contain to regenerate a system and to judge the result?

Summary

Spec-driven development needs a precise notion of specification. If the code is disposable and the spec is what we keep, the spec must be precise enough to regenerate the system and to judge the result. In agile circles, many developers treat the tests as the spec. Tests are part of it, but they cannot stand in for it: they state no invariants, assign no responsibilities, and record no assumptions.

The most precise vocabulary for what a spec must contain that I know comes from KAOS, the goal-oriented requirements engineering method. KAOS is often misread as a waterfall process prescribing how to build software, but its abstractions capture the WHAT and WHY instead, and they hold however the code gets written. I do not claim KAOS is the method every team should adopt, but it is a sound foundation for anyone who wants to throw the code away and keep the spec.

This document is a focused cut of KAOS, centred on operations. Its examples come from one small system, the Splitter, introduced below. It gives a short reference I could not find online, and a practical test framework built on it.

What the industry calls a specification

Cheap code generation moves the value of a system out of its code. Chad Fowler’s Phoenix Architecture series states the position most sharply. A component should be rebuildable from its specification and evaluation criteria alone; if it cannot be, it is not well defined. In his words, “the code is not the asset”.

I take that direction seriously. It raises the stakes on a word the industry uses loosely. If the spec is the only durable artifact, a vague notion of spec gives a vague system.

In practice, “spec” means whatever a team happens to keep. Yesterday it was a page of prose in Confluence; today it is more likely a Markdown file in the repository, a list of user stories or Jira tickets, or the test suite. Each captures part of what the software should do. None of them says what a specification is made of, how complete it is, or how it relates to tests. Fowler’s own framing asks for a specification plus evaluation criteria precise enough to rebuild a component without institutional memory. That is a requirement on the spec, not yet a definition of it.

Let’s have a quick look at typical specification assets used in the industry.

User stories, user story mapping, and Gherkin scenarios

The best definition I know of a user story is “a promise for a conversation”. User stories have proved great at breaking a big piece of work into smaller milestones of manageable size. They put a focus on the user and their involvement, from both a functional and a delivery point of view.

They are hardly a precise specification, especially when used in a “No backlog” setting that is sometimes encouraged. In fact, taken as conversation enablers, user stories are almost entirely a process artifact (the HOW), not a specification (the WHAT and WHY).

User story mapping and Gherkin scenarios sometimes complement user stories by illustrating user journeys, making them more precise, and validating them with end-users. Such collections provide great documentation about workflows and end user needs. They are most of the time silent about what the software must and must not do, except when instrumented as test artifacts.

Tests are part of the spec, but not the whole of it

In Agile circles, it is not uncommon to consider that the tests are the spec. But a test only shows an example. A high-level test is one scenario: a start situation, a few actions, an expected outcome. A suite of them samples the behaviour we want. It never states that behaviour.

Three things are missing from a test suite taken alone:

  • The invariants. In the Splitter (introduced below), a test shows that Cy owed 30.00 once. It does not say that the balances must always sum to zero.
  • The responsibility. A test passes or fails for the system as a whole. It does not say which component must guarantee what.
  • The assumption. A test quietly relies on users, devices and third-party services behaving in a certain way. Nothing records that reliance.

The usual levels of testing each add a weakness of their own.

LevelStrengthWeakness as a spec
End-to-end and acceptance testsSystemic, hence possibly stableToo often too vague: they rarely pin down which state must hold
Integration tests, especially API testsFairly precise, and stable while the API isToo often check responses only, not the state reached
Unit and small-component testsPreciseToo often solution-oriented and brittle: they follow the current design, not the problem

Each level trades one weakness for another, and none records the invariants, responsibilities and assumptions above. So a regenerated implementation can pass every test and still break an invariant nobody wrote down. Closing that gap takes definitions from which tests can be derived, not the other way round.

Documents & prose

These days, generative artificial intelligence and LLMs resurrect the prose-driven way of building software.

Under the “spec-driven” umbrella, OpenSpec or SpecKit ground incremental software development in SKILL-assisted conversations between the developer and their AI-agents. Both rely on a massive use of markdown files to track everything during those conversations.

Such a record might prove valuable in a spec-driven rewrite assisted by AI. Yet, it inherits all attributes of document-driven software development, notably imprecision and lack of structure.

The running example: a splitter of shared expenses

The rest of the paper follows one system, so that each idea can be seen at work on something concrete. It is the Splitter, a small example shipped with opspicy, which keeps the shared expenses of a group.

Ann, Bob and Cy are the group, and each signs in with a name and a password. Whoever pays for something adds an expense, with its amount and the members who share it, and each of the others owes their share. Whoever owes pays back outside the Splitter, and says so in it. Each member’s balance is what they are owed, or what they owe when it is below zero. The Splitter never handles money itself.

At one moment, Ann has paid 90.00 for groceries shared by the three, and Bob has paid 12.00 for a taxi shared by Ann and Bob. Ann is owed 54.00, Bob owes 24.00 and Cy owes 30.00. Whatever happens next, the balances sum to zero.

Figure 1: The running example · two expenses, three balances, one invariant

Figure 1: The running example · two expenses, three balances, one invariant

From here on, the paper sees the Splitter as a black box, as Figure 2 shows: its inside is hidden, and I only look at its five operations at the front door and at the state they reveal.

Figure 2: The black box · five operations at the front door, the essential state inside

Figure 2: The black box · five operations at the front door, the essential state inside

What KAOS calls a specification

KAOS is a goal-oriented requirements engineering method. It is mostly known for its goal-decomposition & obstacle analysis formal mechanisms. KAOS is generally presented in a top-down setting: high-level goals are incrementally decomposed into sub-goals, which are eventually assigned to agents: devices, humans, and software components.

I’ll take an unusual bottom-up approach of KAOS here, with a strong focus on so-called Requirements and Operations. Requirements are defined as leaf goals assigned to software components (e.g. the shares of an expense are owed to the cent). Operations are the way these components meet their requirements: they correspond to verbs in software systems (e.g. AddExpense, ListBalances) together with execution constraints on states.

Figure 3: Goals and agents · three requirements on the Splitter, one expectation on the Member

Figure 3: Goals and agents · three requirements on the Splitter, one expectation on the Member

KAOS operations are great abstractions: they live at the boundary between goals (the WHY) and tangible software components (the WHAT), without being part of the implementation and its process (the HOW). In my opinion, they are the most promising level for those who seek “testable specifications for AI-assisted software rewrites”. I’ll come back to them in the next section.

Stateless and stateful software components

(This split is my own framing, not KAOS’s. It helps place the operations discussed below.)

As a developer, I find it convenient to split my abstractions in two: pure computations, and state management. Both must be specified and tested.

Pure computations are the easy part. They can be specified with mathematical formulas and proofs, or more pragmatically with input/output test cases (specification by example). The Splitter’s rule for shares is such a function: 40.00 shared by three gives 13.34, 13.33 and 13.33.

Pure functions are not sufficient, though. The practical interest of software, and most of its complexity, lie in states and state transitions. The Splitter keeps its expenses in database records and remembers who is signed in for the length of a session. A frontend is full of state too: every screen represents a continuously evolving state, enabling and disabling user actions. Physical devices are intrinsically stateful.

In a complex system, managing state means managing each agent’s own state, as well as the systemic state that spans several agents. Agents share no giant distributed memory, so the state users see outside the machine often has a more complex representation inside, and the same state ends up held in several places: state redundancy is unavoidable.

Figure 4: Agents, computations and state · the two jobs of a developer

Figure 4: Agents, computations and state · the two jobs of a developer

This brings the necessity to specify and test stateful components, and that is where KAOS helps most.

State variables: controlled, monitored, essential

In the KAOS view, the state of a system is described by abstract state variables, and each one has an owner. Call them X, Y, Z. In the Splitter, they are the expenses kept, the balance of each member, and who is signed in.

Each state variable is controlled by exactly one agent, which can read and write it. It may be monitored by other agents, which can only read it. An agent’s interface is the set of variables it controls and the set it monitors.

Figure 5: State variables · controlled, monitored, accidental

Figure 5: State variables · controlled, monitored, accidental

Not every piece of mutable data deserves the name. The state variables I care about are those that explain the observable behaviour of agents. Call this essential state. A variable that no other agent can see, and that yields no observable behaviour, is accidental state. It is an implementation detail, and functional programming could often remove it (see previous section). It has no place in a specification. In the Splitter, the expenses and the balances are essential. The way passwords are stored, the numbering of expenses and the format of the session cookie are accidental: they explain no behaviour of the group.

Two distinctions are at play here, and they are not the same.

DistinctionIt is aboutThe two sides
Abstract or concreteHow state is describedAbstract: named in domain terms, as the end user sees it. Concrete: the copies agents actually hold, in a database, a cache or a screen
Essential or accidentalWhether state mattersEssential: explains observable behaviour. Accidental: explains none, an implementation detail

One abstract state variable may have several concrete representations, one per agent that holds it. Requirements and specifications talk about essential state only, ideally making clear how abstract variables map to the concrete states of components. In the Splitter, the expense Ann paid for groceries is abstract; the row that holds it in a database, and the line it takes on a phone’s screen, are concrete.

This filter is what makes a specification technology-agnostic. A cache, a session object or a table layout can change at every regeneration. The essential state variables cannot, because they belong to the problem to solve.

A requirement is a constraint on how state evolves

A component’s state changes over time, and a requirement restricts the ways it may change. Seen this way, a run of the system is a sequence of states, and a requirement accepts some sequences and rejects others. KAOS distinguishes two basic patterns (Letier and van Lamsweerde, 2002):

PatternIn wordsExample
MaintainIt is always true that some condition holdsThe balances of the group always sum to zero
AchieveIf something is true now, something else is true laterIf a member gives an expense, the Splitter eventually keeps it

Maintain constraints are invariants. Achieve constraints are promises about the future, often with a deadline.

A component cannot “be” an invariant. It can only act. The operational way to constrain state transitions is to constrain operations: they are the only things that act on a system, and what they do is precisely move it from one state to the next.

So each operation gets a PRE condition, what must be true of the state before it may run, and a POST condition, what is true of the state after it has run. If every operation respects its PRE and POST, only allowed transitions happen, and the requirements hold.

Figure 6: State over time · Maintain and Achieve · PRE and POST on AddExpense

Figure 6: State over time · Maintain and Achieve · PRE and POST on AddExpense

Domain conditions vs. required conditions

KAOS is more precise than a single PRE and POST per operation. It separates what an operation is from what the requirements demand of it (same source).

ConditionNatureWhat it captures
DomPRE and DomPOSTDescriptiveThe natural state transition: what the operation is intended to do, the very reason it exists
ReqPREPrescriptiveThe condition on state under which the operation may execute
ReqPOSTPrescriptiveThe condition on state the operation must guarantee
ReqTRIGPrescriptiveThe condition that obliges the agent to execute the operation

For the Splitter, the complete definition of AddExpense, by which a member adds an expense for the group, is:

ClauseCondition
DomPREThe expense is not kept yet
DomPOSTThe expense is kept
ReqPREThe requester is signed in, and the expense is shared only among members of the group
ReqPOSTThe expense is as given, paid by the requester; the balances still sum to zero; each sharer other than the payer owes their share more, to the cent
ReqTRIGA member decides to add the expense

A visitor cannot add an expense, and the balances must still sum to zero afterwards.

Each required condition relates to a requirement, and through it to the high-level goals it serves. No line of a specification is arbitrary: each can be traced back to its reason.

KAOS’s definition of specification

With the restricted KAOS lens chosen here, an operational specification is one agent’s list of responsibilities. Each of its operations carries a PRE and POST over the essential state the agent monitors and controls, and a WHY clause that links to requirements.

This definition has three consequences.

A specification belongs to an agent, not to a system. The system has goals. Each agent I build has an operational specification. The link between the two is the goal decomposition: the operations of an agent, taken together, must guarantee the requirements assigned to it.

Agents I do not build have no specification. For a human or a third-party service I write expectations, not operations. I rely on them; I do not implement them. A member who owes money is one of them: the Splitter cannot make them pay back, it only records the repayments they report, so I write an expectation that members report their repayments.

Figure 7: One specification per agent · five operations for the Splitter, an expectation for the Member

Figure 7: One specification per agent · five operations for the Splitter, an expectation for the Member

A specification is checkable against its requirements. KAOS calls the step from requirements to operations operationalisation, and asks that it be complete, consistent and minimal: the operations guarantee the goal, do not contradict one another, and are no stronger than needed.

The terms used so far fit in one table:

TermDefinition
AgentAn active part of the system: a human, a device or a software component
State variableAn abstract variable that explains observable behaviour; controlled by one agent, monitored by others
GoalA Maintain or Achieve constraint on state, usually needing several agents
RequirementA leaf goal realisable by, and assigned to, one agent I build
ExpectationA leaf goal assigned to an agent I do not build
OperationThe only thing that changes state: one transition, guarded by a PRE and guaranteeing a POST
SpecificationThe operations of one agent, which together meet its requirements

A spec in this sense is exactly the input a regeneration needs: what the component may touch, what it must do, and what it must never break.

What it suggests for spec-driven and agentic development

If code is regenerated, the artifacts we keep must carry everything the code used to carry implicitly. The definitions above say what those artifacts are.

Artifact to keepWhat it recordsWhat it gives a coding agent
Essential state modelState variables, who controls and who monitors eachThe boundary of each component
Goal decompositionGoals, subgoals, requirements, expectationsThe reason for every requirement, and the assumptions it may rely on
Agent specificationsOperations with PRE and POSTA precise, checkable brief for one component
Pure function contractsInput and output examples or propertiesA brief for everything that is not state
ScenariosChains of operations with Given and Then statesAcceptance tests in domain terms

Three practical rules follow.

  1. Regenerate per agent. The unit of regeneration is the component that owns a specification, bounded by the variables it controls and monitors.
  2. Derive tests from the spec. Each operation yields many tests: some check its POST from states where its PRE holds, others check that a violated PRE is refused and the state left unchanged. Each scenario yields a chain test. A missing test then shows up as a gap.
  3. Keep state definitions abstract. Domain-phrased state keeps its tests valid across rewrites.

The next section describes opspicy, an Enspirit open-source library that provides a very concrete, yet limited, implementation of such a specification framework.

What is not covered here

This paper stops at the core vocabulary. KAOS goes further, and several of its techniques are left out:

  • The object model: the entities, relationships and attributes from which state variables are drawn.
  • Goal refinement patterns: reusable, proven ways to decompose a goal into subgoals.
  • State machines and scenarios: behaviour models of agents, which complement goals and scenarios.
  • Obstacle analysis: asking what could prevent a goal from being satisfied, and how to resolve it.
  • Conflict identification: detecting goals that cannot all hold together, and deciding between them.

The formal notation behind these techniques, a temporal logic, is left out as well.

Executable specifications: a concrete proposal & framework

Academic methods like KAOS sometimes look too theoretical and heavyweight to be used by software developers in practice. For this reason, Enspirit developed open-source libraries that developers can use on a daily basis, and that integrate nicely in continuous integration and delivery chains:

  • webspicy is a black-box test framework for web APIs. It models each API route as a KAOS operation with pre and post conditions and positive/negative test cases. It has been successfully used on tens of software projects at Enspirit during the last 15 years.

  • opspicy is a successor that revisits the black-box test framework, integrates a more powerful assertion language and comes with review tools for collaboration with AI agents. It supports Enspirit engineers who no longer test their own code, but inherit the code generated at scale by AI agents. This calls for getting architectural and specification insights, as well as skills and constraints on agents to fit Enspirit’s specification framework.

Black-box functional testing

In my experience, functional tests that target what the software must and must not do (the verbs) get little attention from developers. If we seek to regenerate the software from its specification, I argue that this is the most promising level for tests, especially if they are written per component and without coupling them to the implementation.

I call this black box component testing, and insist that assertions must be expressed in terms of domain-driven observable states, through data exchanges only, and not in terms of implementation artifacts.

As will appear in the next section, these test suites correspond to KAOS’s notion of operational specification, and the test plan therefore follows from the specification, and not the other way round.

(Note: this view is compatible with Test-Driven, Behavior-Driven Development and incremental software development. Arguing that it is reinventing the V-cycle is an example of the WHAT/HOW confusion mentioned in the introduction.)

Based on the distinction between stateless and stateful components introduced earlier, the testing habits proposed work as follows:

What is testedStartActionAssertion
A pure computationA controlled inputCall the functionThe output equals the expected one
One operation of one agentA state where PRE holdsRun the operationPOST holds in the reached state
Robustness of that operationA state where PRE is violatedRun the operationThe operation is refused and the state is unchanged
A chain of operationsA systemic state (the Given)Run a scenario across agentsThe Then holds in the reached systemic state

Computations are easy to test because nothing has to be set up. Component and systemic tests need more: a harness that can put each agent into a given state, and assert properties of the states reached. If both are expressed on abstract, essential state variables, the tests are stable and technology-agnostic, and they survive a rewrite of the code underneath.

Figure 8 shows typical tests of one operation, SettleUp, drawn from its PRE and POST.

Figure 8: From specification to tests · SettleUp

Figure 8: From specification to tests · SettleUp

Operation and chain tests written this way are as precise as a unit test, since they assert a POST on a known state, and as stable as an acceptance test, since the state they talk about belongs to the problem. Getting there means making the system’s state variables visible: named in domain terms, owned by an agent, and reachable by tests. This is probably close to what Domain-Driven Design aims at.

The necessary ingredients

For the approach to work, base ingredients are necessary. In opspicy all are defined in simple YAML data files, that AI agents can easily create from a SKILL-driven discussion.

  • The definition of an abstract state, with concrete observations. For instance, the Splitter’s state has the variable expense(id), observed through GET /api/expenses/:id, and the variable balance(who), observed through GET /api/balances.
- name: expenses
  item: expense(id)
  web:
    expenses: GET /api/expenses -> Expenses
    expense(id): GET /api/expenses/:id -> Expense

- name: balances
  item: balance(who)
  web: GET /api/balances -> Balances
  • An expression language to express PRE and POST conditions as well as test assertions, all in terms of the abstract state and data exchanges. I use Elo, a small purely functional expression language.
- name: owed(who)
  formaldef: balance(who).balance

- name: balanced
  formaldef: sum(map(balances, b ~> b.balance)) == 0
  • The full definition of operations: the input/output data exchange, their pre and post conditions, and positive/negative test cases. For instance, AddExpense, defined in its own YAML file, has the postcondition balanced. One of its positive cases is Cy paying the first expense of the group, which is accepted with 201. One of its negative cases is an expense whose amount is zero, which is refused with 400 expenses.amountNotPositive.
name: AddExpense
entry: POST /api/expenses
input: ExpenseGiven
output: Expense
DomPost:
  - (x) the expense is kept: kept(output.id)
ReqPost:
  - (x) the balances still sum to zero: balanced
examples:
  - when: Cy pays the first expense of the group
    given: test/empty, as cy
    input: { label: Tickets, amount: 3000, sharedBy: [ann, bob, cy] }
    then: 201
    and:
      - Cy is owed 20.00, by Ann and Bob, 10.00 each: owed('cy') == 2000 && owed('ann') == -1000 && owed('bob') == -1000
counterexamples:
  - when: the amount is zero
    for: ExpenseGiven
    given: test/base, as ann
    input: { label: Nothing, amount: 0, sharedBy: [ann, bob] }
    then: 400 expenses.amountNotPositive
  • The data the operations exchange, typed in Elo. For instance, AddExpense takes an ExpenseGiven and returns an Expense, both defined from the types Who and Cents:
# A member of the group, known by their name.
Who = String
# An amount of money: a whole number of cents, above zero. The Splitter knows no other currency,
# and no fraction of a cent.
Cents = Int(c | c > 0)
# What is paid, for whom.
ExpenseGiven = { label: String, amount: Cents, sharedBy: [Who] }
# What somebody paid for the group.
Expense = { id: Int, label: String, amount: Cents, paidBy: Who, sharedBy: [Who] }

Only the entry door touches an implementation: here a web API, but it could as well be a database or a command-line tool. Everything else (the state, the operations, the scenarios and their checks) says what the Splitter knows and does, not how it does it. That is why the code can be thrown away and regenerated, while the specification and its tests stay.

The test runner

The runner executes each case against the running system through its front door, and reports what does not hold. Started with its fault, the Splitter fails on the 100.00 dinner shared by three, the one amount in the suite that does not split evenly.

The test runner reporting the failing dinner case

Screenshot · the runner on the Splitter with its fault

The spec explorer

The explorer is a wiki of the suite in one HTML file: the specification, the last run of each operation, and the formaldef of each clause. It needs neither the running system nor its configuration, so it can be opened and sent as a file.

The explorer's overview of the Splitter's suite

Screenshot · the explorer of the Splitter’s suite

Reviewing a specification is now a job for people and for AI agents alike. A reviewer’s notes on any operation or clause export as one Markdown file. Each note names its item by anchor, and by the file and line that declare it, so an agent can act on the file directly.

The explorer's review mode with a note on AddExpense

Screenshot · the review mode: a note on AddExpense and its review file

Read and run the example

The Splitter, its specification and its cases are in the opspicy repository. The training page serves the app and the explorer side by side.

The Splitter's app in analyst mode, signed in as Ann

Screenshot · the Splitter’s app in analyst mode, signed in as Ann

Each button is enabled exactly when its DomPre and ReqPre hold, so each precondition is visible in the app. A formal specification, yet a lightweight one, gives architectural insight of this kind: a practical route to software that is not only regenerable, but also correct by design.

Conclusion: why KAOS deserves attention

KAOS was built for high-assurance systems long before AI coding, by Axel van Lamsweerde and colleagues at UCLouvain.

Read as a waterfall process, as the introduction describes, KAOS misses what it offers. Its abstractions capture the WHAT: which agents exist, what state they control and monitor, which goals constrain that state, and which operations each agent is responsible for. This is a description of architecture, not of process, and it holds however the code gets written.

I am not arguing for the full method or its formal notation, only for its vocabulary and chain of reasoning: goals, agents, realisability, requirements and expectations, operations with PRE and POST.

The first place to apply it is legacy software about to be rebuilt with AI. Before launching such a rebuild, redocument its requirements and specifications in these terms. Today’s agents make that affordable, and the rebuild then starts from a precise WHAT, not from old code.

The industry is converging on “the spec is the source”. KAOS is a serious candidate for what that spec must say, and it is already there.

Sources