pub struct ConditionalAgent { /* private fields */ }Available on crate feature
agents only.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>,
) -> ConditionalAgent
pub fn new<F>( name: impl Into<String>, condition: F, if_agent: Arc<dyn Agent>, ) -> ConditionalAgent
Create a new conditional agent with a condition function and the if-branch agent.
Sourcepub fn with_description(self, desc: impl Into<String>) -> ConditionalAgent
pub fn with_description(self, desc: impl Into<String>) -> ConditionalAgent
Set the agent description.
Sourcepub fn with_else(self, else_agent: Arc<dyn Agent>) -> ConditionalAgent
pub fn with_else(self, else_agent: Arc<dyn Agent>) -> ConditionalAgent
Set the else-branch agent executed when the condition is false.
Sourcepub fn before_callback(
self,
callback: Box<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Send + Sync>,
) -> ConditionalAgent
pub fn before_callback( self, callback: Box<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Send + Sync>, ) -> ConditionalAgent
Add a before-agent callback.
Sourcepub fn after_callback(
self,
callback: Box<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Send + Sync>,
) -> ConditionalAgent
pub fn after_callback( self, callback: Box<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Send + Sync>, ) -> ConditionalAgent
Add an after-agent callback.
Sourcepub fn with_skills(self, index: SkillIndex) -> ConditionalAgent
Available on crate feature skills only.
pub fn with_skills(self, index: SkillIndex) -> ConditionalAgent
skills only.Set a preloaded skills index for this agent.
Sourcepub fn with_auto_skills(self) -> Result<ConditionalAgent, AdkError>
Available on crate feature skills only.
pub fn with_auto_skills(self) -> Result<ConditionalAgent, AdkError>
skills only.Auto-load skills from .skills/ in the current working directory.
Sourcepub fn with_skills_from_root(
self,
root: impl AsRef<Path>,
) -> Result<ConditionalAgent, AdkError>
Available on crate feature skills only.
pub fn with_skills_from_root( self, root: impl AsRef<Path>, ) -> Result<ConditionalAgent, AdkError>
skills only.Auto-load skills from .skills/ under a custom root directory.
Sourcepub fn with_skill_policy(self, policy: SelectionPolicy) -> ConditionalAgent
Available on crate feature skills only.
pub fn with_skill_policy(self, policy: SelectionPolicy) -> ConditionalAgent
skills only.Customize skill selection behavior.
Sourcepub fn with_skill_budget(self, max_chars: usize) -> ConditionalAgent
Available on crate feature skills only.
pub fn with_skill_budget(self, max_chars: usize) -> ConditionalAgent
skills only.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.
Source§fn run<'life0, 'async_trait>(
&'life0 self,
ctx: Arc<dyn InvocationContext>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Event, AdkError>> + Send>>, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
ConditionalAgent: 'async_trait,
fn run<'life0, 'async_trait>(
&'life0 self,
ctx: Arc<dyn InvocationContext>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Event, AdkError>> + Send>>, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
ConditionalAgent: 'async_trait,
Executes the agent and returns a stream of events.
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