pub struct ConditionalAgent { /* private fields */ }Expand description
Rule-based conditional routing agent.
Executes one of two sub-agents based on a synchronous condition function.
For LLM-based intelligent routing, use crate::LlmConditionalAgent instead.
§Example
ⓘ
// Route based on session state flag
let router = ConditionalAgent::new(
"premium_router",
|ctx| ctx.session().state().get("is_premium").map(|v| v.as_bool()).flatten().unwrap_or(false),
Arc::new(premium_agent),
).with_else(Arc::new(basic_agent));Implementations§
Source§impl ConditionalAgent
impl ConditionalAgent
Sourcepub fn new<F>(
name: impl Into<String>,
condition: F,
if_agent: Arc<dyn Agent>,
) -> Self
pub fn new<F>( name: impl Into<String>, condition: F, if_agent: Arc<dyn Agent>, ) -> Self
Create a new conditional agent with a condition function and the if-branch agent.
Sourcepub fn with_description(self, desc: impl Into<String>) -> Self
pub fn with_description(self, desc: impl Into<String>) -> Self
Set the agent description.
Sourcepub fn with_else(self, else_agent: Arc<dyn Agent>) -> Self
pub fn with_else(self, else_agent: Arc<dyn Agent>) -> Self
Set the else-branch agent executed when the condition is false.
Sourcepub fn before_callback(self, callback: BeforeAgentCallback) -> Self
pub fn before_callback(self, callback: BeforeAgentCallback) -> Self
Add a before-agent callback.
Sourcepub fn after_callback(self, callback: AfterAgentCallback) -> Self
pub fn after_callback(self, callback: AfterAgentCallback) -> Self
Add an after-agent callback.
Sourcepub fn with_skills(self, index: SkillIndex) -> Self
pub fn with_skills(self, index: SkillIndex) -> Self
Set a preloaded skills index for this agent.
Sourcepub fn with_auto_skills(self) -> Result<Self>
pub fn with_auto_skills(self) -> Result<Self>
Auto-load skills from .skills/ in the current working directory.
Sourcepub fn with_skills_from_root(self, root: impl AsRef<Path>) -> Result<Self>
pub fn with_skills_from_root(self, root: impl AsRef<Path>) -> Result<Self>
Auto-load skills from .skills/ under a custom root directory.
Sourcepub fn with_skill_policy(self, policy: SelectionPolicy) -> Self
pub fn with_skill_policy(self, policy: SelectionPolicy) -> Self
Customize skill selection behavior.
Sourcepub fn with_skill_budget(self, max_chars: usize) -> Self
pub fn with_skill_budget(self, max_chars: usize) -> Self
Limit injected skill content length.
Trait Implementations§
Source§impl Agent for ConditionalAgent
impl Agent for ConditionalAgent
Source§fn description(&self) -> &str
fn description(&self) -> &str
Returns a human-readable description of this agent’s purpose.
Source§fn sub_agents(&self) -> &[Arc<dyn Agent>]
fn sub_agents(&self) -> &[Arc<dyn Agent>]
Returns the child agents managed by this agent.
Auto Trait Implementations§
impl Freeze for ConditionalAgent
impl !RefUnwindSafe for ConditionalAgent
impl Send for ConditionalAgent
impl Sync for ConditionalAgent
impl Unpin for ConditionalAgent
impl UnsafeUnpin for ConditionalAgent
impl !UnwindSafe for ConditionalAgent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more