Agent constructor
Agent({
- Model? model,
- String? systemPrompt,
- List<
Tool> ? tools, - List<
Message> ? messages, - required StreamFunction streamFunction,
- ToolExecutor? toolExecutor,
- ToolRegistry? toolRegistry,
- BeforeToolCallHook? beforeToolCall,
- AfterToolCallHook? afterToolCall,
- TransformContextHook? transformContext,
- String? budgetLineProvider()?,
- PrepareNextTurnHook? prepareNextTurn,
- QueuedMessagesSource? externalSteeringSource,
- Future<
bool> externalSteeringProbe()?, - QueueMode steeringMode = QueueMode.oneAtATime,
- QueueMode followUpMode = QueueMode.oneAtATime,
- ToolExecutionMode toolExecution = ToolExecutionMode.parallel,
- int maxEmptyRetries = 1,
- Duration runIdleTimeout = defaultRunIdleTimeout,
- void onRunIdleTimeout(
- Object error
- void onRunWatchdogPaused()?,
- int? contextWindowCap,
- bool wireDump = false,
- OverWindowRelief? overWindowRelief,
- ToolMisuseBreaker? toolMisuseBreaker,
- StuckToolConfig? stuckTool,
- bool finalizeGate = false,
- List<
Skill> operativeSkills = const [], - Set<
String> ? reportedOrphanKeys,
Creates an agent. See the library doc for the pi mapping.
toolExecutor is optional when a toolRegistry is provided: the
registry then supplies both the executor and (unless tools is given
explicitly) the tool list. Passing both toolExecutor and
toolRegistry is allowed; toolExecutor wins.
Implementation
Agent({
Model? model,
String? systemPrompt,
List<Tool>? tools,
List<Message>? messages,
required this.streamFunction,
ToolExecutor? toolExecutor,
ToolRegistry? toolRegistry,
this.beforeToolCall,
this.afterToolCall,
this.transformContext,
this.budgetLineProvider,
this.prepareNextTurn,
this.externalSteeringSource,
this.externalSteeringProbe,
QueueMode steeringMode = QueueMode.oneAtATime,
QueueMode followUpMode = QueueMode.oneAtATime,
this.toolExecution = ToolExecutionMode.parallel,
this.maxEmptyRetries = 1,
this.runIdleTimeout = defaultRunIdleTimeout,
this.onRunIdleTimeout,
this.onRunWatchdogPaused,
this.contextWindowCap,
this.wireDump = false,
this.overWindowRelief,
this.toolMisuseBreaker,
this.stuckTool,
this.finalizeGate = false,
this.operativeSkills = const [],
Set<String>? reportedOrphanKeys,
}) : toolExecutor =
toolExecutor ?? toolRegistry?.executor ?? _missingToolExecutor(),
_reportedOrphanKeys = reportedOrphanKeys ?? <String>{},
_state = AgentState(
model: model ?? _defaultModel,
systemPrompt: systemPrompt ?? '',
tools: tools ?? toolRegistry?.tools ?? const [],
messages: messages ?? const [],
),
_steeringQueue = _PendingMessageQueue(steeringMode),
_followUpQueue = _PendingMessageQueue(followUpMode) {
_steeringQueue.onEnqueue = () {
if (!_steeringArrived.isClosed) _steeringArrived.add(null);
};
}