Agent constructor

Agent({
  1. Model? model,
  2. String? systemPrompt,
  3. List<Tool>? tools,
  4. List<Message>? messages,
  5. required StreamFunction streamFunction,
  6. ToolExecutor? toolExecutor,
  7. ToolRegistry? toolRegistry,
  8. BeforeToolCallHook? beforeToolCall,
  9. AfterToolCallHook? afterToolCall,
  10. TransformContextHook? transformContext,
  11. String? budgetLineProvider()?,
  12. PrepareNextTurnHook? prepareNextTurn,
  13. QueuedMessagesSource? externalSteeringSource,
  14. Future<bool> externalSteeringProbe()?,
  15. QueueMode steeringMode = QueueMode.oneAtATime,
  16. QueueMode followUpMode = QueueMode.oneAtATime,
  17. ToolExecutionMode toolExecution = ToolExecutionMode.parallel,
  18. int maxEmptyRetries = 1,
  19. Duration runIdleTimeout = defaultRunIdleTimeout,
  20. void onRunIdleTimeout(
    1. Object error
    )?,
  21. void onRunWatchdogPaused()?,
  22. int? contextWindowCap,
  23. bool wireDump = false,
  24. OverWindowRelief? overWindowRelief,
  25. ToolMisuseBreaker? toolMisuseBreaker,
  26. StuckToolConfig? stuckTool,
  27. bool finalizeGate = false,
  28. List<Skill> operativeSkills = const [],
  29. 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);
  };
}