import claude/client.{type Config} import claude/types/tool.{type Registry, type ToolChoice} import gleam/option.{type Option, None, Some} /// Configuration for the agent loop. pub type AgentConfig { AgentConfig( client: Config, model: String, max_tokens: Int, system: Option(String), tools: Registry, tool_choice: Option(ToolChoice), thinking: Option(Int), max_iterations: Int, tool_timeout_ms: Int, ) } /// Create a new AgentConfig with sensible defaults. /// /// Defaults: /// - model: config.default_model /// - max_tokens: config.default_max_tokens /// - max_iterations: 10 /// - tool_timeout_ms: 30_000 (30 seconds) pub fn new( client client: Config, tools tools: Registry, ) -> AgentConfig { AgentConfig( client: client, model: client.default_model, max_tokens: client.default_max_tokens, system: None, tools: tools, tool_choice: None, thinking: None, max_iterations: 10, tool_timeout_ms: 30_000, ) } /// Set the system prompt. pub fn with_system(config: AgentConfig, system: String) -> AgentConfig { AgentConfig(..config, system: Some(system)) } /// Set the maximum number of agent loop iterations. pub fn with_max_iterations(config: AgentConfig, max: Int) -> AgentConfig { AgentConfig(..config, max_iterations: max) } /// Set the model to use. pub fn with_model(config: AgentConfig, model: String) -> AgentConfig { AgentConfig(..config, model: model) } /// Enable extended thinking with a budget (in tokens). pub fn with_thinking(config: AgentConfig, budget: Int) -> AgentConfig { AgentConfig(..config, thinking: Some(budget)) } /// Set the per-tool execution timeout in milliseconds. pub fn with_tool_timeout(config: AgentConfig, timeout_ms: Int) -> AgentConfig { AgentConfig(..config, tool_timeout_ms: timeout_ms) } /// Set the max tokens for API calls. pub fn with_max_tokens(config: AgentConfig, max_tokens: Int) -> AgentConfig { AgentConfig(..config, max_tokens: max_tokens) } /// Set the tool choice strategy. pub fn with_tool_choice( config: AgentConfig, choice: ToolChoice, ) -> AgentConfig { AgentConfig(..config, tool_choice: Some(choice)) }