Managing Journey States via Confident AI SDK
Overview
The Confident AI SDK exposes every State method on the platform. This page documents how to call these methods in all supported languages. See the introduction to install the SDK and set your API key.
Methods
Create State
Adds a state to a journey and returns its id. Send fromStateId and when to connect it from an existing state in the same call; retrieve the journey to read the edge that creates. State names are unique within a journey; reusing one returns a 409.
from confident_ai import ConfidentAI
client = ConfidentAI()
result = client.journeys.create_state(
journey_id="<JOURNEY-ID>",
name="Share Order Details",
instructions="Give order number 48213 and the email jane@example.com.",
from_state_id="<JOURNEY-STATE-ID>",
when="The assistant asks for your order number or email.",
)For async mode, call a_create_state and await it as shown below:
result = await client.journeys.a_create_state(...)Parameters
| Parameter | Type | Description |
|---|---|---|
journey_id | str | Required. The id of the journey. |
name | str | Required. The name of the state, unique within the journey. Name it for what the user does, in a few words. |
instructions | str | Required. What the simulated user says or does in this state, written to them in the second person. They keep acting it out until the app's reply matches an edge leaving the state. |
from_state_id | Optional[str] | The id of an existing state in this journey to connect the new state from. An edge from that state to the new one is created alongside it, and when is then required. Omit it to add an unconnected state. |
when | Optional[str] | What the app does or says in its reply that moves the simulated user from fromStateId into the new state; describe the app's reply, not the user. Required with fromStateId and ignored without it. An empty when keeps the edge out of the journey's paths until it is given one. |
import { ConfidentAI } from "confident-ai";
const client = new ConfidentAI();
const result = await client.journeys.createState(
"<JOURNEY-ID>",
"Share Order Details",
"Give order number 48213 and the email jane@example.com.",
"<JOURNEY-STATE-ID>",
"The assistant asks for your order number or email.",
);Parameters
| Parameter | Type | Description |
|---|---|---|
journeyId | string | Required. The id of the journey. |
name | string | Required. The name of the state, unique within the journey. Name it for what the user does, in a few words. |
instructions | string | Required. What the simulated user says or does in this state, written to them in the second person. They keep acting it out until the app's reply matches an edge leaving the state. |
fromStateId | string | The id of an existing state in this journey to connect the new state from. An edge from that state to the new one is created alongside it, and when is then required. Omit it to add an unconnected state. |
when | string | What the app does or says in its reply that moves the simulated user from fromStateId into the new state; describe the app's reply, not the user. Required with fromStateId and ignored without it. An empty when keeps the edge out of the journey's paths until it is given one. |
Returns
This method returns an object of type JourneyStateRef.
Update State
Renames a state or rewrites its instructions, and returns it. State names are unique within a journey; taking another state's name returns a 409.
from confident_ai import ConfidentAI
client = ConfidentAI()
result = client.journeys.update_state(
journey_id="<JOURNEY-ID>",
state_id="<JOURNEY-STATE-ID>",
name="Share Order Details",
instructions="Give order number 48213 and the email jane@example.com.",
)For async mode, call a_update_state and await it as shown below:
result = await client.journeys.a_update_state(...)Parameters
| Parameter | Type | Description |
|---|---|---|
journey_id | str | Required. The id of the journey the state belongs to. |
state_id | str | Required. The id of the state. |
name | Optional[str] | The name of the state, unique within the journey, for what the user does. Omit it to keep the current name. |
instructions | Optional[str] | What the simulated user says or does in this state, written to them in the second person. The text replaces the stored one outright, so send the whole of it. Omit it to keep the current instructions. |
import { ConfidentAI } from "confident-ai";
const client = new ConfidentAI();
const result = await client.journeys.updateState(
"<JOURNEY-ID>",
"<JOURNEY-STATE-ID>",
"Share Order Details",
"Give order number 48213 and the email jane@example.com.",
);Parameters
| Parameter | Type | Description |
|---|---|---|
journeyId | string | Required. The id of the journey the state belongs to. |
stateId | string | Required. The id of the state. |
name | string | The name of the state, unique within the journey, for what the user does. Omit it to keep the current name. |
instructions | string | What the simulated user says or does in this state, written to them in the second person. The text replaces the stored one outright, so send the whole of it. Omit it to keep the current instructions. |
Returns
This method returns an object of type JourneyState.
Delete State
Permanently deletes a state and its edges, along with every state that could only be reached through it, and returns the ids of all the states removed. Goldens generated for a path through any of them are kept but no longer belong to any path. The root state cannot be deleted; trying returns a 400.
from confident_ai import ConfidentAI
client = ConfidentAI()
result = client.journeys.delete_state(
journey_id="<JOURNEY-ID>",
state_id="<JOURNEY-STATE-ID>",
)For async mode, call a_delete_state and await it as shown below:
result = await client.journeys.a_delete_state(...)Parameters
| Parameter | Type | Description |
|---|---|---|
journey_id | str | Required. The id of the journey the state belongs to. |
state_id | str | Required. The id of the state. |
import { ConfidentAI } from "confident-ai";
const client = new ConfidentAI();
const result = await client.journeys.deleteState(
"<JOURNEY-ID>",
"<JOURNEY-STATE-ID>",
);Parameters
| Parameter | Type | Description |
|---|---|---|
journeyId | string | Required. The id of the journey the state belongs to. |
stateId | string | Required. The id of the state. |
Returns
This method returns an object of type DeleteJourneyStateResult.
Types
DeleteJourneyStateResult
The states removed by deleting a state from a journey.
class DeleteJourneyStateResult:
id: str
deleted_state_ids: List[str] = Field(alias="deletedStateIds")idstrRequired
The id of the state you deleted.
Example: "<JOURNEY-STATE-ID>"
deleted_state_idsList[str]Required
Every state removed: the one you deleted, then any state that could only be reached through it.
Example: ["<JOURNEY-STATE-ID>"]
interface DeleteJourneyStateResult {
id: string;
deletedStateIds: string[];
}idstringRequired
The id of the state you deleted.
Example: "<JOURNEY-STATE-ID>"
deletedStateIdsstring[]Required
Every state removed: the one you deleted, then any state that could only be reached through it.
Example: ["<JOURNEY-STATE-ID>"]
JourneyState
Something the simulated user does at one point in a journey, with the instructions it follows there.
class JourneyState:
id: str
name: str
instructions: str
golden_count: int = Field(alias="goldenCount")
created_at: str = Field(alias="createdAt")
updated_at: str = Field(alias="updatedAt")idstrRequired
The id of the state, generated by Confident AI.
Example: "<JOURNEY-STATE-ID>"
namestrRequired
The name of the state, unique within the journey.
Example: "Share Order Details"
instructionsstrRequired
What the simulated user says or does in this state, written to them in the second person.
Example: "Give order number 48213 and the email jane@example.com."
golden_countintRequired
The number of goldens generated for a path through this state.
Example: 10
created_atstrRequired
The time the state was created, as an ISO 8601 datetime.
Example: "2025-01-15T10:30:00+00:00"
updated_atstrRequired
The time the state was last changed, as an ISO 8601 datetime.
Example: "2025-01-16T09:12:00+00:00"
interface JourneyState {
id: string;
name: string;
instructions: string;
goldenCount: number;
createdAt: string;
updatedAt: string;
}idstringRequired
The id of the state, generated by Confident AI.
Example: "<JOURNEY-STATE-ID>"
namestringRequired
The name of the state, unique within the journey.
Example: "Share Order Details"
instructionsstringRequired
What the simulated user says or does in this state, written to them in the second person.
Example: "Give order number 48213 and the email jane@example.com."
goldenCountnumberRequired
The number of goldens generated for a path through this state.
Example: 10
createdAtstringRequired
The time the state was created, as an ISO 8601 datetime.
Example: "2025-01-15T10:30:00+00:00"
updatedAtstringRequired
The time the state was last changed, as an ISO 8601 datetime.
Example: "2025-01-16T09:12:00+00:00"
JourneyStateRef
A reference to a journey state by its id.
class JourneyStateRef:
id: stridstrRequired
The id of the state, generated by Confident AI.
Example: "<JOURNEY-STATE-ID>"
interface JourneyStateRef {
id: string;
}idstringRequired
The id of the state, generated by Confident AI.
Example: "<JOURNEY-STATE-ID>"
Last updated on