StatefulAgent class

A stateful AI agent that orchestrates LLM calls, tool execution, skill management, and context compression.

Constructors

StatefulAgent({required String name, List<String>? systemPrompts, required LLMClient client, required ModelConfig modelConfig, required AgentState state, List<Tool>? tools, ToolChoice? toolChoice, ContextCompressor? compressor, PlanMode? planMode, List<Skill>? skills, String? skillDirectoryPath, JavaScriptRuntime? javaScriptRuntime, JavaScriptBridgeRegistry? javaScriptBridgeRegistry, List<SubAgent>? subAgents, bool withGeneralPrinciples = true, dynamic autoSaveStateFunc(AgentState state)?, AgentController? controller, LoopDetector? loopDetector, bool isSubAgent = false, bool disableSubAgents = false, SystemCallback? systemCallback, int maxTurns = 20})

Properties

autoSaveStateFunc → dynamic Function(AgentState state)?
Optional callback for persisting state on changes.
final
client LLMClient
The LLM client used to communicate with AI providers.
final
compressor ContextCompressor?
Optional compressor for managing long contexts.
final
controller AgentController?
Controller for intercepting agent events.
final
disableSubAgents bool
Whether to disable sub-agent delegation.
final
hashCode int
The hash code for this object.
no setterinherited
id String
Unique identifier generated for this agent instance.
final
isSubAgent bool
Whether this agent is running as a sub-agent.
final
javaScriptBridgeRegistry JavaScriptBridgeRegistry?
final
javaScriptRuntime JavaScriptRuntime?
final
loopDetector LoopDetector
Mechanism for detecting infinite tool loops.
latefinal
maxTurns int
Maximum number of turns (LLM calls) allowed in a single run.
final
modelConfig ModelConfig
Configuration for the LLM (model, temperature, etc.).
final
name String
The human-readable name of the agent.
final
planMode PlanMode?
The planning mode (auto, must, or null to disable).
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
skillDirectoryPath String?
Directory-mode skills root path (SKILL.md).
final
skills List<Skill>?
Modular capabilities that can be activated/deactivated.
final
state AgentState
The current state of the agent.
final
subAgents List<SubAgent>?
Registered sub-agents for task delegation.
final
systemCallback SystemCallback?
Optional callback to dynamically modify LLM requests before they are sent.
final
systemPrompts List<String>
List of system prompts that define the agent's behavior.
final
toolChoice ToolChoice?
Explicit instructions for tool selection.
final
tools List<Tool>?
List of tools available to the agent.
final
withGeneralPrinciples bool
Whether to include general principles in the system message.
final

Methods

composeSystemMessage() SystemMessage?
composeTools() List<Tool>
isCancelled(Object error) bool
isSuspend(DioException error) bool
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerJavaScriptBridgeChannel(String channel, JavaScriptBridgeHandler handler) → void
resume({bool useStream = true}) Future<List<LLMMessage>>
resumeStream({bool useStream = true}) Stream<StreamingEvent>
run(List<LLMMessage> messages, {CancelToken? cancelToken, bool useStream = true, int? maxTurns}) Future<List<LLMMessage>>
runStream(List<LLMMessage> messages, {CancelToken? cancelToken, bool useStream = true, int? maxTurns}) Stream<StreamingEvent>
toString() String
A string representation of this object.
inherited
unregisterJavaScriptBridgeChannel(String channel) → void

Operators

operator ==(Object other) bool
The equality operator.
inherited