This document provides a visual representation of the TaskState class structure from inspect_ai/src/inspect_ai/solver/_task_state.py
and all its referenced classes.
classDiagram
class TaskState {
+choices : Choices
+tool_choice : ToolChoice|None
+model : ModelName
+sample_id : int|str
+epoch : int
+input : str|list~ChatMessage~
+input_text : str
+user_prompt : ChatMessageUser
+metadata : dict~str,Any~
+messages : list~ChatMessage~
+output : ModelOutput
+store : Store
+tools : list~Tool~
+max_messages : int|None
+message_limit : int|None
+token_limit : int|None
+token_usage : int
+completed : bool
+target : Target
+scores : dict~str,Score~|None
+uuid : str
}
class Choice {
+value : str
+correct : bool|None
+original_position : int
}
class Choices {
}
class ModelName {
+api : str
+name : str
}
class Target {
+target : list~str~
+text : str
}
class ChatMessageBase {
+id : str|None
+content : str|list~Content~
+source : Literal~"input","generate"~|None
+metadata : dict~str,Any~|None
+text : str
}
class ChatMessageSystem {
+role : Literal~"system"~
}
class ChatMessageUser {
+role : Literal~"user"~
+tool_call_id : list~str~|None
}
class ChatMessageAssistant {
+role : Literal~"assistant"~
+tool_calls : list~ToolCall~|None
+model : str|None
}
class ChatMessageTool {
+role : Literal~"tool"~
+tool_call_id : str|None
+function : str|None
+error : ToolCallError|None
+tool_error : str|None
}
class ModelOutput {
+model : str
+choices : list~ChatCompletionChoice~
+completion : str
+usage : ModelUsage|None
+time : float|None
+metadata : dict~str,Any~|None
+error : str|None
+empty : bool
+stop_reason : StopReason
+message : ChatMessageAssistant
}
class ModelUsage {
+input_tokens : int
+output_tokens : int
+total_tokens : int
+input_tokens_cache_write : int|None
+input_tokens_cache_read : int|None
+reasoning_tokens : int|None
}
class ChatCompletionChoice {
+message : ChatMessageAssistant
+stop_reason : StopReason
+logprobs : Logprobs|None
}
class Store {
}
class Score {
+value : Value
+answer : str|None
+explanation : str|None
+metadata : dict~str,Any~|None
+text : str
}
class Tool {
}
class ToolFunction {
+name : str
}
TaskState *-- Choices : contains
Choices *-- Choice : contains
TaskState --> ModelName : uses
TaskState --> Target : uses
TaskState --> ChatMessageBase : uses
TaskState --> Tool : uses
TaskState --> ModelOutput : uses
TaskState --> Store : uses
TaskState --> Score : uses
TaskState --> ToolChoice : uses
ChatMessageSystem --|> ChatMessageBase : inherits
ChatMessageUser --|> ChatMessageBase : inherits
ChatMessageAssistant --|> ChatMessageBase : inherits
ChatMessageTool --|> ChatMessageBase : inherits
ModelOutput *-- ChatCompletionChoice : contains
ModelOutput *-- ModelUsage : contains
ChatCompletionChoice --> ChatMessageAssistant : uses
ToolChoice --|> ToolFunction : can be
The main class representing the internal state of a Task being run for a single Sample.
Public Properties:
choices
: Choices - Multiple choice options (if applicable)tool_choice
: ToolChoice|None - Tool choice directivemodel
: ModelName - Name of model being evaluatedsample_id
: int|str - Unique id for sampleepoch
: int - Epoch number for sampleinput
: str|list[ChatMessage] - Input from the Sample (immutable)input_text
: str - Convenience property for input as textuser_prompt
: ChatMessageUser - User prompt for this statemetadata
: dict[str,Any] - Metadata from the Samplemessages
: list[ChatMessage] - Chat conversation historyoutput
: ModelOutput - The 'final' model outputstore
: Store - Store for shared datatools
: list[Tool] - Tools available to the modelmax_messages
: int|None - Deprecated (use message_limit)message_limit
: int|None - Limit on total messages allowedtoken_limit
: int|None - Limit on total tokens allowedtoken_usage
: int - Total tokens used for current samplecompleted
: bool - Task completion statustarget
: Target - The scoring target for this Samplescores
: dict[str,Score]|None - Scores yielded by running taskuuid
: str - Globally unique identifier for sample run
Handle multiple choice question functionality:
Choice
: Represents individual choices with value, correctness, and positionChoices
: Collection wrapper with shuffling and prompting capabilities
ModelName
: Represents model API and name with pattern matchingModelOutput
: Complete model response with choices, usage, and metadataModelUsage
: Token usage statistics including caching and reasoning tokensChatCompletionChoice
: Individual completion choice with message and stop reason
ChatMessageBase
: Base class for all chat messages with content and metadataChatMessageSystem
: System messages with "system" roleChatMessageUser
: User messages with "user" role and optional tool call IDsChatMessageAssistant
: Assistant messages with "assistant" role and tool callsChatMessageTool
: Tool response messages with "tool" role and error handling
Target
: Sequence-like class for scoring targetsStore
: Key-value store for shared state with change trackingScore
: Scoring results with multiple access methods (str, int, float, bool, list, dict)Tool
: Protocol for tools that agents can useToolFunction
: Specific tool function specificationToolChoice
: Union type for tool selection ("auto", "any", "none", or specific function)
- Composition: TaskState contains Choices, ModelOutput contains ChatCompletionChoice and ModelUsage
- Inheritance: All chat message types inherit from ChatMessageBase
- Usage: TaskState references all major classes for comprehensive state management
- Polymorphism: ToolChoice can be either a string literal or ToolFunction instance