Threads, Turns, Events, and Items¶
Prerequisites: - Basic familiarity with request/response workflows
What you'll learn: - The core vocabulary of this SDK - How thread continuity works - How to reason about event and item payloads
Thread¶
A Thread represents a conversation session.
- Start new:
codex.start_thread() - Resume existing:
codex.resume_thread(thread_id)
thread.id is populated when thread.started event arrives.
Turn¶
A turn is one prompt submission plus all resulting events until completion or failure.
- Buffered mode:
thread.run(...)returnsTurn - Streaming mode:
thread.run_streamed(...)returns iterator of events
Events¶
Top-level stream records, e.g.:
- thread.started
- turn.started
- item.started / item.updated / item.completed
- turn.completed
- turn.failed
Items¶
Items are typed payloads inside item events, e.g.:
- agent_message
- reasoning
- command_execution
- file_change
- todo_list
Lifecycle Example¶
- Prompt sent
thread.started(new thread only)turn.started- one or more item events
turn.completedwith usage orturn.failedwith error
Failure modes:
- assuming thread.id exists before first turn starts
- assuming every stream includes all item categories