A turn is a single message in a conversational thread. After a session is open, every message – whether from the user, the assistant, the system, or a tool – is recorded as a turn. Spectron processes each turn synchronously through an extraction pipeline and returns a structured diff of everything that was learned or changed.
The turns endpoint
The request blocks until extraction is complete, then returns the structured result. Extraction is synchronous by design: the caller can use the returned diff to update application state, drive real-time UI, or trigger downstream logic without polling.
Roles
| Role | When to use |
|---|---|
user | Messages from the human participant. Extraction is most active on user turns. |
assistant | Responses generated by the LLM. Recording assistant turns preserves the full conversational context and allows Spectron to track what the assistant has stated or committed to. |
system | System prompt or instruction turns. Spectron extracts behavioural instructions and constraints from system turns. |
tool | Results returned from tool calls. Spectron extracts factual content from tool results and attributes it to the tool source. |
All four roles participate in provenance. Each turn is stored with its role, and every fact extracted from it carries a source_turn reference regardless of role.
Extraction pipeline
When a turn arrives, Spectron runs the following steps synchronously before returning:
Named entity recognition – identifies people, organisations, locations, products, and custom entity types configured in your context.
Attribute extraction – extracts scalar properties of entities (job title, location, preference, status, and so on).
Relation extraction – identifies directed relationships between entities.
Instruction detection – recognises statements that express user preferences, behavioural instructions, or explicit requests about how the agent should behave.
Uncertainty flagging – marks statements that are speculative, negated, or otherwise of low confidence.
Reconciliation – compares newly extracted facts against existing memory. Facts that contradict prior records are resolved and a correction record is produced. See Reconciliation and supersession for the full correction model.
Python SDK
JavaScript SDK
Extraction result
The response from a turn submission contains the full extraction diff for that turn.
turn_id
The stable identifier for this turn. Store it if you need to request a diff from /state/diff?since={turn_id} later.
entities
Entities named or implied in the turn content. Each entity carries:
id– stable record identifiertype– entity type (e.g.person,organisation,project)label– the canonical display namesource_turn– the turn that first introduced this entity
An entity record is created once and then referenced by subsequent attributes and relations. If an entity was already known, the existing record is returned rather than a duplicate.
attributes
Scalar facts about entities. Each attribute carries:
entity– the entity the attribute belongs tokey– the attribute name (e.g.job_title,location,preference)value– the extracted valuevalid_from– when the attribute became valid (defaults to the turn timestamp)valid_until– when the attribute ceased to be valid, if knownsource_turn– the turn that produced this attribute
Attributes are versioned. If the same key already exists for an entity and the new value differs, the prior attribute is superseded rather than overwritten. The supersession chain is preserved so the history of a fact is always queryable.
relations
Directed relationships between two entities. Each relation carries:
from– source entityto– target entitytype– relationship type (e.g.works_at,manages,owns)source_turn– the turn that established the relation
instructions
Behavioural directives extracted from the turn. These are statements where the user or system is expressing a persistent preference or rule, such as "always reply in French" or "never mention competitors by name." Instructions are surfaced in the context payload and injected into prompts automatically when using the managed chat loop.
Each instruction carries:
text– the normalised instruction textpriority– extracted priority level (high,medium,low)source_turn– the turn that introduced the instruction
uncertainties
Statements extracted from the turn that Spectron cannot assert with confidence – negated claims, speculative language, conflicting signals, or information that requires human verification. These are stored separately from confirmed attributes and are surfaced in the state under unknowns.
corrections
When reconciliation finds that a newly extracted fact contradicts an existing attribute, a correction record is produced. Each correction carries:
attribute– the attribute identifier that was correctedprevious– the prior value and its source turncurrent– the new value and this turn as sourcetimestamp– when the correction occurred
Corrections are the mechanism through which Spectron handles conversational drift – for example, when a user corrects a name, updates their role, or revises a stated preference. See Reconciliation and supersession for how the supersession chain works.
Using the extraction result for real-time UI
Because the extraction result returns synchronously with the turn response, you can use it to drive application state immediately after each message is submitted.
A common pattern is to compare the returned arrays against your local state and highlight changes in the UI:
Recording assistant turns
When you are driving the LLM loop yourself (as opposed to using session.chat()), record the assistant's response as a turn after each generation:
Recording assistant turns preserves the full conversational record and allows Spectron to extract any facts the assistant stated – commitments, stated knowledge, or preferences expressed on behalf of the agent. Omitting assistant turns is permitted, but the resulting memory will have gaps that could reduce context quality on subsequent retrieval.
Listing turns
To retrieve all turns recorded in a session:
The response is an ordered list of turns with their roles, content, and timestamps. Extraction results are not re-included in this listing; use the /state endpoint to query the facts that were produced.