Skip to main content
For a guided walkthrough, see SDK overview.

Turn input

Each Turn’s input is a list of one of these types. Resuming a Turn paused by mcp.auth_required needs no input - omit input or pass [].
User messages (UserMessage) cannot be mixed with tool approvals or client-side tool responses in the same input list. UserToolApprovalEvent and UserToolResponseEvent may be mixed together.

UserMessage

Start a new conversation or send the next user message. content is either a plain string or a list of content parts, letting you attach files alongside text.

UserMessageContentItem

A content part is one of: Text File

UserToolApprovalEvent

Sent to resume a turn paused by tool.approval_required. One item per pending tool call.

UserToolResponseEvent

Sent to resume a turn paused by tool.response_required. One item per pending tool call.

Reference

Prefer the high-level AgentSessionClient for application code — same prepare_turn / prepareTurnexecute model as Use an agent. Use the low-level TrueFoundryGateway client when you need raw Fern types or direct SSE control. High-level streaming yields { sequence_number, event } (Python) / { sequenceNumber, event } (TypeScript). Low-level create_turn / createTurn yields raw TurnStreamingEvent values. Turn input JSON shapes are the same in every language.

High-level (AgentSessionClient)

Import is_event_delta, merge_event_delta, and event types from truefoundry_gateway_sdk.agents. Import UserMessage and content-part types from truefoundry_gateway_sdk.types.

create_session

Create a conversation AgentSession for a saved agent.

list_sessions

List AgentSession objects for a saved agent, newest-first by default. The pager auto-paginates when iterated.

get_session

Fetch an existing session by ID.

AgentSession

The conversation context for a saved agent. Turns created within a session are chained automatically. Key members:

prepare_turn

Stage a turn in the session. Makes no network call and returns a PreparedTurn with no id yet. The turn is created server-side on the first execute() call:
  • execute(stream=True) — POST create_turn and stream SSE as TurnStreamData (sequence_number, event).
  • execute(stream=False, poll_interval_ms=...) — POST create_turn, then poll until the turn reaches a terminal state. Default / minimum poll interval is 3000 ms.
After execute() starts the turn, call stream(), refresh(), wait_for_completion(), list_events(), or cancel() on the same object. Calling those methods before execute() raises.

PreparedTurn

Output of prepare_turn(). Not yet started — no HTTP until execute(). Identity fields are None until started.

Turn

A started turn returned by list_turns(), get_turn(), or after PreparedTurn.execute(). Same methods as PreparedTurn except there is no execute() — the turn already exists server-side.

Low-level (TrueFoundryGateway)

Access methods via client.agents.sessions.*.

create

Create a conversation Session for a saved agent. The returned response wraps the session in .data.

list

List Sessions for a saved agent, newest-first by default. The pager auto-paginates when iterated.

get

Fetch an existing session by ID. The returned response wraps the session in .data.

cancel

Cancel the running turn for a session. Idempotent.

Session

The conversation context for a saved agent, returned by create and get in .data. Turns created within a session are chained automatically, so each turn sees the history of earlier ones. Key members:

create_turn

Start or continue a turn within a session. Responds with a Server-Sent Events stream. The first event is turn.created; the stream closes with turn.done.

list_turns

List turns in a session, newest-first. The pager auto-paginates when iterated.

get_turn

Fetch a single turn by ID. The returned response wraps the turn in .data.

Turn

A single request/response cycle within a session, returned by list_turns and get_turn in .data. Transitions: runningdone | cancelled | error.

subscribe_to_turn

Reconnect to a running turn’s live SSE stream. Pass after_sequence_number to resume after a known point. Closes when the turn reaches a terminal state. Use list_turn_events for completed turns.

list_turn_events

Return a paginated snapshot of stored events for a completed turn. Pass order="asc" to replay forward. The pager auto-paginates when iterated.

list_events

Return a paginated snapshot of stored events across turns in a session.
To define or configure the agent itself, see Create an agent.