Introducing Confident Voice: Watch the Launch Video Now

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

ParameterTypeDescription
journey_idstrRequired. The id of the journey.
namestrRequired. The name of the state, unique within the journey. Name it for what the user does, in a few words.
instructionsstrRequired. 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_idOptional[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.
whenOptional[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.

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

ParameterTypeDescription
journey_idstrRequired. The id of the journey the state belongs to.
state_idstrRequired. The id of the state.
nameOptional[str]The name of the state, unique within the journey, for what the user does. Omit it to keep the current name.
instructionsOptional[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.

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

ParameterTypeDescription
journey_idstrRequired. The id of the journey the state belongs to.
state_idstrRequired. 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>"]

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"

JourneyStateRef

A reference to a journey state by its id.

class JourneyStateRef:
    id: str

idstrRequired

The id of the state, generated by Confident AI.

Example: "<JOURNEY-STATE-ID>"

Building a production pipeline?Design a scalable API workflow for evals, datasets, traces, and promptsTalk to an engineer

Last updated on

Built byConfident AI