Answer structured questions based on custom context (state) or recent Session context to determine whether a task is complete, select a business branch, or score against predefined levels.
The Decision API is currently in Beta. Interface definitions, response structures, and behavior may change in subsequent versions. Follow documentation updates and verify compatibility before using it in production.
choice) and scoring questions (score). The create endpoint executes the judgment synchronously and saves the result. Records can then be retrieved by ID or listed with pagination.
Endpoints
| Method | Path | Description |
|---|---|---|
POST | /api/v1/forward/decisions | Create Decision |
GET | /api/v1/forward/decisions/{decision_id} | Get Decision |
GET | /api/v1/forward/decisions | List Decisions |
Choose an input mode
| Mode | Use case | Behavior |
|---|---|---|
state (custom context) | Use caller-provided text, structured data, and other content as the basis for judgment. | Supply a non-empty JSON object; no Session is required. |
session_id | Evaluate a Session's execution progress or results. | The server extracts the Session's recent available context. |
user.message, agent.message, session.error, and agent.artifact_delivered events. It does not read file contents, tool call processes, or subthread history. The judgment uses recent available context, which may not include the complete conversation history.
Oversized input returns 422 decision_context_too_large. Reduce the context or questions before retrying. A Session with no available context returns 422 decision_context_unavailable.
Decision object
Successful creation responses, detail queries, and listed records share the following structure.
| Field | Type | Description |
|---|---|---|
| id | string | Decision ID, prefixed with dec_. |
| session_id | string or null | The associated Session ID for Session input; null for explicit state input. |
| source | string | Currently fixed to api. |
| status | string | running, completed, or failed. |
| questions | array | The questions for this judgment. For the structure, see Create Decision. |
| answers | array | Answers in the order of the request questions; [] when unfinished or failed. |
| context | object | Input mode and context scope. See the table below. |
| error | object or null | Contains code and message on failure; otherwise null. |
| created_at | string | Creation time in RFC 3339 format. |
| completed_at | string or null | Execution end time in RFC 3339 format; null while running, and a timestamp after success or failure. |
state or a complete Session input snapshot.
Answer structure
| type | Result field | Description |
|---|---|---|
choice | value | Returns the selected option's original string or boolean value, preserving its JSON type. |
score | score | Returns the numeric score defined for the selected level, not a freely generated continuous score. |
name, its answer returns the same field. When omitted, questions and answers correspond by array position.
Context fields
The following fields are returned according to the input mode and execution progress. During execution or when input preparation fails, only mode may be present. Clients should tolerate missing optional fields and fields added in later versions.
| Field | Type | Description |
|---|---|---|
| mode | string | state or session. |
| anchor_event_id | string | The latest candidate event ID determined during this read. |
| first_event_id | string | The earliest valid event ID actually included in the judgment. |
| last_event_id | string | The latest valid event ID actually included in the judgment. |
| included_segment_count | integer | Number of included context segments. Returned only in Session mode. |
| included_event_count | integer | Number of included valid events. Returned only in Session mode. |
Workflow
- Prepare
stateor an accessiblesession_id, and define the questions and candidate answers. - Call the create endpoint. A fixed
Idempotency-Keyis recommended for each logical operation. See Idempotent retries. - Process choice or scoring results according to
answers[].type. - Save the Decision ID and track results with the detail or list endpoint. If creation returns an error containing
error.decision_id, use that ID to query the failed record as well.