States
A state is something your agent builds and Faces keeps and watches. It holds your premises (named facts your agent declares, each with a status and what it depends on), the decisions faces made, the faces’ replies, and your own messages, linked by what rests on what. It is not a message log. When a premise is invalidated, everything that depends on it is too, and the response lists each status that changed instatus_changes. When a premise’s value changes,
decisions_made_under_old_values lists the decisions that rested on the old value. You can
read a state back and page through it at any time. A face’s cause is the one thing kept on the
server and never returned: the state keeps it so the face’s later turns build on it.
Hand a state to choices as state_id to have a face propose options
for the situation it describes.
A chat or decision request joins a state with
"conversation": "<id>". Send only what is
new on each turn: the state is put in front of it for you, and what a face decided is never
taken from the request, so it cannot be rewritten. Entries are items in OpenAI’s Responses item
format.
Not to be confused with the state field of a decision request, which
describes the situation being decided.
States were called conversations, and before that sessions.
/v1/conversations still works
as a deprecated alias of /v1/states: it answers with the old object names (conversation,
conversation.deleted) and the headers Deprecation: true and
Link: </v1/states/...>; rel="successor-version". It will be removed. /v1/sessions also
still works. The conversation request field, and its older name session, are unchanged.Create a state
Any other field is a
422 that names it.
A state as a proof
A state can also be built as a proof in progress: a tree of premises joined by AND and OR. Each premise is proved[x], open [ ] or refuted [-], and the state ends with a line that names
what still stands between you and a proved goal. Writing and reading this way is free, and every
write answers with that line.
Add a premise
POST /v1/states/{state_id}/premises adds one premise. It is a 409 if the key exists.
result says what changed, summary is the proof’s last line, text is both, and premise is
the premise as format=json returns it.
Change a premise
PATCH /v1/states/{state_id}/premises changes only the fields it is given. A test’s run is a
status with the candidate it ran on (tested) and what it showed (evidence). A failed run
refutes that candidate, and the next one is the one to try:
value, to (a new key; everything that named the old one follows), description,
await (none clears it), note, on, said, as, and refinement. A premise with children
is proved only once its refinement is complete: its children are all it needs. Set by hand,
the proof says so on that premise’s line, (marked complete by hand), and after its last line.
A tool that checked the children sends refined_by with it (refine or choices), and the
proof says nothing more.
Read the proof
GET /v1/states/{state_id}/proof returns the tree and its last line:
format=json returns each premise’s fields instead, format=problog the proof as a ProbLog
program, and format=dot as a Graphviz graph. query= lists the premises closest in meaning to
a question, best first. GET /v1/states/{state_id}/premise?key=... returns one premise and its
branch (depth=, or up=true for the premises it sits under), then every message linked to it.
POST /v1/states/{state_id}/note with key and text links a message to a premise.
DELETE /v1/states/{state_id}/premises?key=... removes one premise and its edges.
Several agents on one proof
POST /v1/states/{state_id}/claim with key and agent gives that premise and everything under
it to one agent, for ttl_seconds (default 1800). A write into the branch by anyone else is a
409:
as. POST /v1/states/{state_id}/release with key releases it, and
POST /v1/states/{state_id}/release-session with session releases every claim taken in that
session (writes name their session in the X-Headwaters-Session header).
Take a turn
Add"conversation": "<id>" to a request with a face on chat
(/v1/chat/completions, /v1/responses, /v1/messages) or decisions
(/v1/decisions, /v1/systemone). Send only what is new.
state_id. With a question, it adds the options
it proposes to the state (see Options in a state). Prose sent beside the
state_id is read for that one call and never saved: write anything that should persist as
premises with Add items.
Items
Each entry is an item, in OpenAI’s Responses item format, with anid (ci_1, ci_2, …)
in the order it was added.
A message. Yours have role: user. A face’s reply on chat has role: assistant, the
face’s name, the model that answered and shown, the items it read.
decision, in the same shape whichever route asked it
(source says which: decisions or systemone). The question has its name, type
(predicate, choice or score), instructions and options; the answer has the result
(the probability for a predicate, the chosen value for a choice, the number for a score), the
probabilities and the confidence. It also carries the face, the decision model, the
depends_on it declared, and its status. Its call_id is the
decision’s id.
function_call named decision and its function_call_output, until it expires.
A face’s tool call. A state may hold a face’s tool calls from chat turns: each a
function_call naming the face and the model, and its function_call_output.
function_call named premise holding the key, and its
function_call_output holding the value, its description, and the status and
depends_on you set.
role: user and premises. A face’s replies, decisions and tool
calls are added by the turns that produce them.
Premises
A premise is a fact your agent’s decisions depend on, named by akey, with a value and a plain description. The description is required
the first time a key is used, and kept after that.
A key is plain text of 1 to 120 characters on one line, such as costs under $100? or
Resolve "can eat". Spaces, quotes and punctuation are kept as written, and spaces at
either end are trimmed. A key cannot hold control characters (a tab or a newline among them),
line or paragraph separators, or the characters that reverse the direction of text. Name a
key in depends_on exactly as you wrote it.
Send premises with a turn as
premises, a list of these, or add them on their own (see
Add items).
A newer reading of a key replaces it from that point on. A newer reading without
depends_on keeps the earlier one; [] clears it. A newer reading without role,
origin or touches keeps the earlier one too; null clears it. Any other value is a 422.
role, origin and touches are kept with the state and returned when you read it; they do
not change what a face is shown. A goal premise marks an outcome your agent works toward,
for it to know when to stop. To have a face read a premise, name it in the call’s depends_on
(see What a face is shown). Every decision
is made with the premises in force when it was made, and the state keeps each reading, so you can always see what a
decision was made under.
And, or and weights
A depends_on B means B must be true for A to be true. Each entry of a premise’s
depends_on is a plain id or an edge:
A plain id is an
and edge with no weight. One premise’s or weights that do not sum to 1
are kept, and the write answers with warnings naming them. Support runs one way: a write
whose depends_on would make a loop between premises is a 422.
To confirm a reading, write the premise again with the weights you mean, such as p: 1 for
the confirmed alternative and p: 0 for the rest. The new weights apply from then on, and the
earlier readings keep theirs. Choices can propose the
alternatives, and decisions can weigh them. The weights do
not change what a face is shown.
Status
Each premise has the status your agent gave it, and each decision isdecided. What you read
back is the effective status: invalidated when the item’s own status is, when anything
it rests on through a plain id or an and edge is invalidated, or when every one of its or
alternatives is, directly or through other items; otherwise its own. Only invalidated
spreads. An item that declared no depends_on does not depend on anything.
Set an invalidated premise to another status and what depended on it is restored, unless it
still depends on something else that is invalidated.
A write answers with status_changes: every effective status that changed, and why:
A decision item carries
status (decided or invalidated) and because the same way.
Options in a state
Ask choices a question withstate_id and the options it proposes are added
to the state as one item. The response gives each option an id (opt_...) and the list its
own, choices_item (cho_...).
A premise or a decision names an option in its depends_on, like a premise key or a decision
id. A list’s choices_item names all of its options. A decision that rests on an option,
directly or through the premises and decisions it rests on, is shown why the face proposed it.
Options have no status: resting on one never invalidates anything.
Add items
POST /v1/states/{state_id}/items adds your messages and premises, at most 20
at a time, as items (a premise may be written {key, value, description}), as premises, or both.
Both are one write, items first, checked together: if anything in it is invalid, the write
is a 422 and nothing is written.
premises is each key’s current reading, with its status. status_changes
lists every effective status the write changed. decisions_made_under_old_values lists
every earlier decision that rested on a key whose value you just changed: the keys it
declared in depends_on, or every premise in force when it was made if it declared none,
and any decision resting on one of those, with via naming the decision that reached it.
Your agent decides which to revisit. Nothing is decided again for you.
Decisions in a state
A decision request in a state may senddepends_on: the premise keys, decision ids and option
ids the decision rests on, at most 200, each already in the state or sent as a premise in the same
request. The decision is shown those premises and decisions, in full, with the premises each
of them directly depends on, and is invalidated when one of them is. Without depends_on, it
rests on every premise in force when it is made.
What a face is shown
When a face reads a state, for choices or a decision, it is shown:- What the call names in
depends_on, and the premises each of those directly depends on, always and in full, however many premises the state holds, up to about 60,000 characters in all. Past that, the rest are shown like any other premise. - The premises the state rests on most: those the most other items depend on.
- The premises closest to the question, and what they depend on.
role never changes what a face is
shown, and neither does the wording of the question: to make sure a face reads a premise,
name it in depends_on.
The response adds decision_ids, each question’s decision id, to name in a later
depends_on, and decisions_reopened, the decisions the premises sent with it put in
question:
Several faces
A state opened withoutmodel takes any of your faces, each turn naming its face in
model. Each face reads its own replies as its own, and the others’ as someone else’s,
labelled with their name. Its steering reads their causes too, unless causes_visible is
false on the state or on the turn.
What to do next
GET /v1/states/{state_id}/synopsis reads the state as work to do. Add ?since=ci_N to list
what was written after item ci_N. GET /v1/states/{state_id}/items?synopsis=1 returns the
same, as synopsis, beside the items.
A premise is achieved when it is verified, or when it rests on other premises, each of
its and children is achieved, and the alternative its or split is committed to is achieved.
An or split is committed to the alternative a human stated (origin: human), or to a clear
winner (p of at least 0.6, ahead of the next by at least 0.2), or to the only alternative
still standing.
Several agents
The synopsis also gives the work for several agents at once:
An agent claims an item before it starts:
ttl_seconds is 1 to 86,400, 900 by default. A claim holds until it expires, until it is
released with DELETE /v1/states/{state_id}/claims/{claim_id}, or until the premise’s status
changes. While it holds, another agent’s claim on the same premise is a 409; the same agent
claiming again renews it.
Read a state
GET /v1/states/{state_id} returns the state, as on creation, with
items, turns and last_used_at up to date.
GET /v1/states/{state_id}/items lists the items a page at a time, like
OpenAI’s list of conversation items. Newest first by default. Each premise and decision
carries its effective status, as in Status.
has_more is true while there are more pages. With format=faces, every page also carries
the premises in force now, all of them.
format=openai returns only the item types and fields OpenAI defines, so you can pass them
to anything that reads OpenAI’s conversation items. Our own fields are left out: the face’s
name, the model and the premises. A decision becomes a call to a decision tool
followed by its result. Any other format is a 422.
Compact
POST /v1/states/{state_id}/compact writes one face’s position over the state, in the
face’s own terms, and keeps it on the server under a compaction_id. The text itself is not
returned. In a state open to any face, name the face in model (@alice).
"compaction": "<compaction_id>" to a later chat or decision request with the same face to
have its steering read the summary. A slow compaction is held open like a decision: see
Speed.
Close a state
DELETE /v1/states/{state_id} closes it:
{"id": "fs_STATE_ID", "object": "state.deleted", "deleted": true}. A closed
state takes no more turns and cannot be read. Its compactions stay usable until they
expire.
Cost
- Opening, reading, adding items to and closing a state are free. A turn costs what it costs without one.
- Compacting is billed at the compaction rate (
compactioninGET /v1/rates) on the tokens it reads and writes,usage.input_tokens + usage.output_tokens. On Connect and Pro it counts against the plan’s allowance. - Using a compaction adds its text to what the steering reads, and is billed with it.
Every state route takes
version, a body field on POST and a query parameter on GET:
23, the default, or 22, which reads and writes the same states without statuses,
depends_on, role or origin (sending them is a 422) and without status_changes.Expiry
A state expires 30 days after it was last used, and is then deleted with everything in it. A compaction expires 30 days after it is written. Closing your account deletes your states at once.Errors
detail is a string.