pub struct AgentBuilder { /* private fields */ }Implementations§
Source§impl AgentBuilder
impl AgentBuilder
pub fn new(client: Arc<dyn LlmProvider>) -> AgentBuilder
Sourcepub fn with_multi_agent(self, config: MultiAgentConfig) -> AgentBuilder
pub fn with_multi_agent(self, config: MultiAgentConfig) -> AgentBuilder
Enable multi-agent support with the given configuration.
Also sets the tool factory to create the 5 multi-agent tools.
Callers should use phi_kernel_tools::multi_agent::create_all_tools as the factory.
Sourcepub fn without_multi_agent(self) -> AgentBuilder
pub fn without_multi_agent(self) -> AgentBuilder
Disable multi-agent support.
Removes any previously set multi-agent configuration. No multi-agent tools will be registered and the system prompt will not mention multi-agent capabilities.
Sourcepub fn with_multi_agent_tool_factory(
self,
factory: Arc<dyn Fn(Arc<MultiAgentRuntime>) -> Vec<Arc<dyn Tool>> + Send + Sync>,
) -> AgentBuilder
pub fn with_multi_agent_tool_factory( self, factory: Arc<dyn Fn(Arc<MultiAgentRuntime>) -> Vec<Arc<dyn Tool>> + Send + Sync>, ) -> AgentBuilder
Set a custom factory for creating multi-agent tools.
The factory receives the MultiAgentRuntime and returns the tools to register.
If not set but multi-agent is enabled, no tools are registered (caller must
set this for multi-agent to work).
pub fn system_prompt(self, prompt: impl Into<String>) -> AgentBuilder
pub fn enable_thought(self, enable: bool) -> AgentBuilder
pub fn reasoning(self, config: ReasoningConfig) -> AgentBuilder
pub fn enable_thinking(self, enable: bool) -> AgentBuilder
pub fn thinking_budget(self, budget: u64) -> AgentBuilder
pub fn tool_timeout(self, timeout_ms: u64) -> AgentBuilder
pub fn max_tool_output_chars(self, max_chars: usize) -> AgentBuilder
pub fn max_sessions(self, max: usize) -> AgentBuilder
pub fn max_turns_per_session(self, max: usize) -> AgentBuilder
pub fn execution_max_turns(self, max: u32) -> AgentBuilder
pub fn max_message_tokens(self, max: usize) -> AgentBuilder
pub fn register_tool(self, tool: impl Tool + 'static) -> AgentBuilder
pub fn register_tool_arc(self, tool: Arc<dyn Tool>) -> AgentBuilder
pub fn approval_handler(self, handler: Arc<dyn ApprovalHandler>) -> AgentBuilder
pub fn tool_policy(self, policy: Arc<dyn ToolPolicy>) -> AgentBuilder
pub fn middleware(self, mw: impl Middleware + 'static) -> AgentBuilder
pub fn guard(self, guard: impl ReactLoopGuard + 'static) -> AgentBuilder
pub fn context_window(self, max_tokens: usize) -> AgentBuilder
pub fn context_window_manager( self, manager: ContextWindowManager, ) -> AgentBuilder
pub fn response_format(self, format: ResponseFormat) -> AgentBuilder
pub fn llm_retry(self, retry: RetryConfig) -> AgentBuilder
pub fn session_store(self, store: Arc<dyn SessionStore>) -> AgentBuilder
pub fn error_recovery( self, recovery: Arc<dyn ToolErrorRecovery>, ) -> AgentBuilder
pub fn tool_error_retry_prompt(self, prompt: impl Into<String>) -> AgentBuilder
pub fn language(self, language: Language) -> AgentBuilder
Sourcepub fn context_compactor(
self,
compactor: Arc<dyn ContextCompaction>,
) -> AgentBuilder
pub fn context_compactor( self, compactor: Arc<dyn ContextCompaction>, ) -> AgentBuilder
Set an inline context compactor for the react loop.
When set, the react loop will check token count after each tool turn and compact the session if it exceeds the configured threshold.
pub fn event_bus_capacity(self, capacity: usize) -> AgentBuilder
pub fn session_id_generator( self, generator: Arc<dyn SessionIdGenerator>, ) -> AgentBuilder
Sourcepub fn apply_if<T>(
self,
value: Option<T>,
f: impl FnOnce(AgentBuilder, T) -> AgentBuilder,
) -> AgentBuilder
pub fn apply_if<T>( self, value: Option<T>, f: impl FnOnce(AgentBuilder, T) -> AgentBuilder, ) -> AgentBuilder
Conditionally apply a transformation when value is Some.
This is a convenience for option-chaining builder patterns:
builder.apply_if(args.thinking_budget, |b, budget| b.thinking_budget(budget))Sourcepub fn agent_instructions_paths(self, paths: Vec<PathBuf>) -> AgentBuilder
pub fn agent_instructions_paths(self, paths: Vec<PathBuf>) -> AgentBuilder
Set paths to agent instruction files (e.g., CLAUDE.md, INSTRUCTIONS.md).
These files are read at build time and appended to the system prompt. Supports multiple paths (user-level + project-level); later entries have higher priority and appear first in the prompt.
Example:
use std::path::PathBuf;
use agent_works::AgentBuilder;
let builder = AgentBuilder::new();
let builder = builder.agent_instructions_paths(vec![
PathBuf::from("~/.claude/CLAUDE.md"), // user-level
PathBuf::from(".claude/CLAUDE.md"), // project-level
]);pub fn build(self) -> Result<AgentRuntime, AgentError>
Sourcepub fn build_with_ma(
self,
) -> Result<(AgentRuntime, Option<Arc<MultiAgentRuntime>>), AgentError>
pub fn build_with_ma( self, ) -> Result<(AgentRuntime, Option<Arc<MultiAgentRuntime>>), AgentError>
Build the runtime and return the multi-agent runtime (if enabled).
Same as build but also returns the MultiAgentRuntime
created during setup. Callers that need to start the watcher task or
access the mailbox should use this method.