Prepared Turn Context • AI Agent SDK
PreparedTurnContext: Immutable turn plan object for standardized runtime execution.
PreparedTurnContext
Defined in the Turn Context module.
AI Agent
Immutable turn plan object for standardized runtime execution.
This dataclass captures all the context needed for a single agent turn, prepared in a preflight step before run_attempt. It eliminates the scattered tool assembly and message building across different execution paths.
The context is read-only during execution – mutations must go through defined hooks only. This ensures consistent behavior across different runtime harnesses (native, plugin, managed, etc.).
Attributes: model_ref: Resolved model configuration and capabilities agent_runtime: The runtime protocol instance to execute with tools: Normalized tool schemas for the turn transcript: Prepared conversation window for the turn delivery: Streaming and output delivery configuration correlation: Session and tracing identifiers runtime_mode: Execution mode (sync/async/stream) turn_metadata: Additional turn-specific metadata created_at: Timestamp when context was prepared
Properties
ModelReferenceNo description available.
AgentProtocolNo description available.
Tuple[ToolSchema, ...]No description available.
TranscriptWindowNo description available.
DeliveryChannelsNo description available.
SessionCorrelationNo description available.
RuntimeModeNo description available.
Mapping[str, Any]No description available.
floatNo description available.
Methods
Get a tool by name from the prepared tools.
has_tools()Check if any tools are available for this turn.
has_system_prompt()Check if a system prompt is configured.
get_message_count()Get the number of messages in the transcript window.
Internal & Generic Methods
- to_dict: Convert to dictionary for logging and debugging.
Source
View on GitHubpraisonaiagents/runtime/turn_context.py at line 174