Skip to main content

Overview

The State API provides the AgentState class for managing agent execution state, conversation history, and context. Each agent maintains its own state throughout its lifecycle.

AgentState

Manages the complete state of an agent including messages, iteration count, and execution metadata.

Constructor

str
default:"'Strix Agent'"
Human-readable name for the agent
int
default:"300"
Maximum number of iterations allowed before stopping
Example:

Properties

Identity

str
Unique identifier auto-generated as “agent_” + 8 random hex characters
str
default:"'Strix Agent'"
Agent display name
str | None
default:"None"
Parent agent ID if this is a sub-agent

Sandbox Information

str | None
default:"None"
Docker container ID for the sandbox environment
str | None
default:"None"
Authentication token for sandbox API
dict[str, Any] | None
default:"None"
Complete sandbox information including ports and URLs

Execution State

str
default:"''"
Current task description
int
default:"0"
Current iteration number
int
default:"300"
Maximum iterations allowed
bool
default:"False"
Whether execution is completed
bool
default:"False"
Whether stop has been requested
bool
default:"False"
Whether agent is waiting for input
bool
default:"False"
Whether LLM requests are failing
dict[str, Any] | None
default:"None"
Final result when completed

Data Storage

list[dict[str, Any]]
default:"[]"
Conversation history (role, content, thinking_blocks)
dict[str, Any]
default:"{}"
Additional context storage
list[dict[str, Any]]
default:"[]"
Record of all actions taken with timestamps
list[dict[str, Any]]
default:"[]"
Observations recorded during execution
list[str]
default:"[]"
Error messages

Timestamps

str
ISO 8601 timestamp when state was created
str
ISO 8601 timestamp of last update
datetime | None
default:"None"
When agent entered waiting state

Methods

Message Management

add_message

Adds a message to the conversation history.
str
required
Message role: “user” or “assistant”
Any
required
Message content (string or structured content)
list[dict[str, Any]] | None
Optional thinking blocks from reasoning models
Example:

get_conversation_history

Returns the full conversation history.
list[dict[str, Any]]
List of message dictionaries
Example:

Iteration Management

increment_iteration

Increments the iteration counter and updates timestamp. Example:

has_reached_max_iterations

Checks if max iterations reached.
bool
True if iteration >= max_iterations

is_approaching_max_iterations

Checks if approaching max iterations.
float
default:"0.85"
Percentage threshold (0.0 to 1.0)
bool
True if past threshold
Example:

Execution Control

set_completed

Marks the agent as completed.
dict[str, Any] | None
Final result data
Example:

request_stop

Requests the agent to stop execution. Example:

should_stop

Checks if agent should stop.
bool
True if stop_requested, completed, or max iterations reached

Waiting State

enter_waiting_state

Puts agent into waiting state.
bool
default:"False"
Whether entering wait due to LLM failure

resume_from_waiting

Resumes from waiting state.
str | None
Optional new task to set
Example:

is_waiting_for_input

Checks if agent is waiting for input.
bool
True if waiting

has_waiting_timeout

Checks if waiting timeout (600 seconds) has been reached.
bool
True if timeout reached

Data Recording

add_action

Records an action taken.
dict[str, Any]
required
Action data to record
Example:

add_observation

Records an observation.
dict[str, Any]
required
Observation data
Example:

add_error

Records an error message.
str
required
Error message
Example:

Context Management

update_context

Updates context storage.
str
required
Context key
Any
required
Context value
Example:

Summary

get_execution_summary

Returns a comprehensive execution summary.
dict[str, Any]
Dictionary containing:
  • agent_id, agent_name, parent_id
  • sandbox_id, sandbox_info
  • task, iteration, max_iterations
  • completed, final_result
  • start_time, last_updated
  • total_actions, total_observations, total_errors
  • has_errors, max_iterations_reached
Example:

has_empty_last_messages

Checks if last N messages are empty.
int
default:"3"
Number of messages to check
bool
True if last N messages are empty

Complete Example