pub struct AgentDefinition {
pub kind: String,
pub name: String,
pub title: Option<String>,
pub hide_title: bool,
pub description: Option<String>,
pub category: Option<String>,
pub inputs: Option<Vec<String>>,
pub outputs: Option<Vec<String>>,
pub configs: Option<AgentConfigSpecs>,
pub global_configs: Option<FnvIndexMap<String, AgentConfigSpec>>,
pub native_thread: bool,
pub new_boxed: Option<fn(ma: ModularAgent, id: String, spec: AgentSpec) -> Result<Box<dyn Agent>, AgentError>>,
}Expand description
The definition (blueprint) of an agent type.
An agent definition describes the metadata and capabilities of an agent type, including its ports, configuration options, and factory function. Multiple agent instances can be created from a single definition.
Fields§
§kind: StringThe kind/category identifier for this agent type (e.g., “Agent”, “Board”).
name: StringUnique name of this agent definition.
title: Option<String>Human-readable title for display in UI.
hide_title: boolWhether to hide the title in UI.
description: Option<String>Description of what this agent does.
category: Option<String>Category path for organizing agents (e.g., “Flow/Control”).
inputs: Option<Vec<String>>Default input port names.
outputs: Option<Vec<String>>Default output port names.
configs: Option<AgentConfigSpecs>Configuration specifications for this agent type.
global_configs: Option<FnvIndexMap<String, AgentConfigSpec>>Global configuration specifications (shared across instances).
native_thread: boolWhether to run this agent on a native OS thread instead of the async runtime.
new_boxed: Option<fn(ma: ModularAgent, id: String, spec: AgentSpec) -> Result<Box<dyn Agent>, AgentError>>Factory function to create new agent instances.
Implementations§
Source§impl AgentDefinition
impl AgentDefinition
Sourcepub fn new(
kind: impl Into<String>,
name: impl Into<String>,
new_boxed: Option<fn(ma: ModularAgent, id: String, spec: AgentSpec) -> Result<Box<dyn Agent>, AgentError>>,
) -> Self
pub fn new( kind: impl Into<String>, name: impl Into<String>, new_boxed: Option<fn(ma: ModularAgent, id: String, spec: AgentSpec) -> Result<Box<dyn Agent>, AgentError>>, ) -> Self
Creates a new agent definition.
§Arguments
kind- The kind/category identifier (e.g., “std”, “llm”)name- Unique name for this agent definitionnew_boxed- Optional factory function to create agent instances
Sourcepub fn title(self, title: &str) -> Self
pub fn title(self, title: &str) -> Self
Sets the display title. Returns self for method chaining.
Sourcepub fn hide_title(self) -> Self
pub fn hide_title(self) -> Self
Hides the title in UI. Returns self for method chaining.
Sourcepub fn description(self, description: &str) -> Self
pub fn description(self, description: &str) -> Self
Sets the description. Returns self for method chaining.
Sourcepub fn category(self, category: &str) -> Self
pub fn category(self, category: &str) -> Self
Sets the category path. Returns self for method chaining.
Sourcepub fn inputs(self, inputs: Vec<&str>) -> Self
pub fn inputs(self, inputs: Vec<&str>) -> Self
Sets the input port names. Returns self for method chaining.
Sourcepub fn outputs(self, outputs: Vec<&str>) -> Self
pub fn outputs(self, outputs: Vec<&str>) -> Self
Sets the output port names. Returns self for method chaining.
Sourcepub fn configs(self, configs: Vec<(&str, AgentConfigSpec)>) -> Self
pub fn configs(self, configs: Vec<(&str, AgentConfigSpec)>) -> Self
Sets all configuration specifications at once.
Sourcepub fn unit_config(self, key: &str) -> Self
pub fn unit_config(self, key: &str) -> Self
Adds a unit (trigger/signal) configuration.
Sourcepub fn unit_config_with<F>(self, key: &str, f: F) -> Self
pub fn unit_config_with<F>(self, key: &str, f: F) -> Self
Adds a unit configuration with customization callback.
Sourcepub fn boolean_config(self, key: &str, default: bool) -> Self
pub fn boolean_config(self, key: &str, default: bool) -> Self
Adds a boolean configuration with a default value.
Sourcepub fn boolean_config_with<F>(self, key: &str, default: bool, f: F) -> Self
pub fn boolean_config_with<F>(self, key: &str, default: bool, f: F) -> Self
Adds a boolean configuration with customization callback.
Sourcepub fn boolean_config_default(self, key: &str) -> Self
pub fn boolean_config_default(self, key: &str) -> Self
Adds a boolean configuration with default value false.
Sourcepub fn integer_config(self, key: &str, default: i64) -> Self
pub fn integer_config(self, key: &str, default: i64) -> Self
Adds an integer configuration with a default value.
Sourcepub fn integer_config_with<F>(self, key: &str, default: i64, f: F) -> Self
pub fn integer_config_with<F>(self, key: &str, default: i64, f: F) -> Self
Adds an integer configuration with customization callback.
Sourcepub fn integer_config_default(self, key: &str) -> Self
pub fn integer_config_default(self, key: &str) -> Self
Adds an integer configuration with default value 0.
Sourcepub fn number_config(self, key: &str, default: f64) -> Self
pub fn number_config(self, key: &str, default: f64) -> Self
Adds a number (f64) configuration with a default value.
Sourcepub fn number_config_with<F>(self, key: &str, default: f64, f: F) -> Self
pub fn number_config_with<F>(self, key: &str, default: f64, f: F) -> Self
Adds a number configuration with customization callback.
Sourcepub fn number_config_default(self, key: &str) -> Self
pub fn number_config_default(self, key: &str) -> Self
Adds a number configuration with default value 0.0.
Sourcepub fn string_config(self, key: &str, default: impl Into<String>) -> Self
pub fn string_config(self, key: &str, default: impl Into<String>) -> Self
Adds a string configuration with a default value.
Sourcepub fn string_config_with<F>(
self,
key: &str,
default: impl Into<String>,
f: F,
) -> Self
pub fn string_config_with<F>( self, key: &str, default: impl Into<String>, f: F, ) -> Self
Adds a string configuration with customization callback.
Sourcepub fn string_config_default(self, key: &str) -> Self
pub fn string_config_default(self, key: &str) -> Self
Adds a string configuration with empty default value.
Sourcepub fn text_config(self, key: &str, default: impl Into<String>) -> Self
pub fn text_config(self, key: &str, default: impl Into<String>) -> Self
Adds a multiline text configuration with a default value.
Sourcepub fn text_config_with<F>(
self,
key: &str,
default: impl Into<String>,
f: F,
) -> Self
pub fn text_config_with<F>( self, key: &str, default: impl Into<String>, f: F, ) -> Self
Adds a text configuration with customization callback.
Sourcepub fn text_config_default(self, key: &str) -> Self
pub fn text_config_default(self, key: &str) -> Self
Adds a text configuration with empty default value.
Sourcepub fn array_config(self, key: &str, default: impl Into<AgentValue>) -> Self
pub fn array_config(self, key: &str, default: impl Into<AgentValue>) -> Self
Adds an array configuration with a default value.
Sourcepub fn array_config_with<V: Into<AgentValue>, F>(
self,
key: &str,
default: V,
f: F,
) -> Self
pub fn array_config_with<V: Into<AgentValue>, F>( self, key: &str, default: V, f: F, ) -> Self
Adds an array configuration with customization callback.
Sourcepub fn array_config_default(self, key: &str) -> Self
pub fn array_config_default(self, key: &str) -> Self
Adds an array configuration with empty default value.
Sourcepub fn object_config<V: Into<AgentValue>>(self, key: &str, default: V) -> Self
pub fn object_config<V: Into<AgentValue>>(self, key: &str, default: V) -> Self
Adds an object configuration with a default value.
Sourcepub fn object_config_with<V: Into<AgentValue>, F>(
self,
key: &str,
default: V,
f: F,
) -> Self
pub fn object_config_with<V: Into<AgentValue>, F>( self, key: &str, default: V, f: F, ) -> Self
Adds an object configuration with customization callback.
Sourcepub fn object_config_default(self, key: &str) -> Self
pub fn object_config_default(self, key: &str) -> Self
Adds an object configuration with empty default value.
Sourcepub fn custom_config_with<V: Into<AgentValue>, F>(
self,
key: &str,
default: V,
type_: &str,
f: F,
) -> Self
pub fn custom_config_with<V: Into<AgentValue>, F>( self, key: &str, default: V, type_: &str, f: F, ) -> Self
Adds a custom-typed configuration with customization callback.
Sourcepub fn global_configs(self, configs: Vec<(&str, AgentConfigSpec)>) -> Self
pub fn global_configs(self, configs: Vec<(&str, AgentConfigSpec)>) -> Self
Sets all global configuration specifications at once.
Sourcepub fn boolean_global_config(self, key: &str, default: bool) -> Self
pub fn boolean_global_config(self, key: &str, default: bool) -> Self
Adds a boolean global configuration.
Sourcepub fn boolean_global_config_with<F>(
self,
key: &str,
default: bool,
f: F,
) -> Self
pub fn boolean_global_config_with<F>( self, key: &str, default: bool, f: F, ) -> Self
Adds a boolean global configuration with customization callback.
Sourcepub fn integer_global_config(self, key: &str, default: i64) -> Self
pub fn integer_global_config(self, key: &str, default: i64) -> Self
Adds an integer global configuration.
Sourcepub fn integer_global_config_with<F>(
self,
key: &str,
default: i64,
f: F,
) -> Self
pub fn integer_global_config_with<F>( self, key: &str, default: i64, f: F, ) -> Self
Adds an integer global configuration with customization callback.
Sourcepub fn number_global_config(self, key: &str, default: f64) -> Self
pub fn number_global_config(self, key: &str, default: f64) -> Self
Adds a number (f64) global configuration.
Sourcepub fn number_global_config_with<F>(self, key: &str, default: f64, f: F) -> Self
pub fn number_global_config_with<F>(self, key: &str, default: f64, f: F) -> Self
Adds a number global configuration with customization callback.
Sourcepub fn string_global_config(self, key: &str, default: impl Into<String>) -> Self
pub fn string_global_config(self, key: &str, default: impl Into<String>) -> Self
Adds a string global configuration.
Sourcepub fn string_global_config_with<F>(
self,
key: &str,
default: impl Into<String>,
f: F,
) -> Self
pub fn string_global_config_with<F>( self, key: &str, default: impl Into<String>, f: F, ) -> Self
Adds a string global configuration with customization callback.
Sourcepub fn text_global_config(self, key: &str, default: impl Into<String>) -> Self
pub fn text_global_config(self, key: &str, default: impl Into<String>) -> Self
Adds a multiline text global configuration.
Sourcepub fn text_global_config_with<F>(
self,
key: &str,
default: impl Into<String>,
f: F,
) -> Self
pub fn text_global_config_with<F>( self, key: &str, default: impl Into<String>, f: F, ) -> Self
Adds a text global configuration with customization callback.
Sourcepub fn array_global_config(
self,
key: &str,
default: impl Into<AgentValue>,
) -> Self
pub fn array_global_config( self, key: &str, default: impl Into<AgentValue>, ) -> Self
Adds an array global configuration.
Sourcepub fn array_global_config_with<V: Into<AgentValue>, F>(
self,
key: &str,
default: V,
f: F,
) -> Self
pub fn array_global_config_with<V: Into<AgentValue>, F>( self, key: &str, default: V, f: F, ) -> Self
Adds an array global configuration with customization callback.
Sourcepub fn array_global_config_default(self, key: &str) -> Self
pub fn array_global_config_default(self, key: &str) -> Self
Adds an array global configuration with empty default value.
Sourcepub fn object_global_config<V: Into<AgentValue>>(
self,
key: &str,
default: V,
) -> Self
pub fn object_global_config<V: Into<AgentValue>>( self, key: &str, default: V, ) -> Self
Adds an object global configuration.
Sourcepub fn object_global_config_with<V: Into<AgentValue>, F>(
self,
key: &str,
default: V,
f: F,
) -> Self
pub fn object_global_config_with<V: Into<AgentValue>, F>( self, key: &str, default: V, f: F, ) -> Self
Adds an object global configuration with customization callback.
Sourcepub fn custom_global_config_with<V: Into<AgentValue>, F>(
self,
key: &str,
default: V,
type_: &str,
f: F,
) -> Self
pub fn custom_global_config_with<V: Into<AgentValue>, F>( self, key: &str, default: V, type_: &str, f: F, ) -> Self
Adds a custom-typed global configuration with customization callback.
Sourcepub fn use_native_thread(self) -> Self
pub fn use_native_thread(self) -> Self
Configures this agent to run on a native OS thread.
Use this for agents that perform blocking I/O or CPU-intensive operations that would block the async runtime.
Sourcepub fn to_spec(&self) -> AgentSpec
pub fn to_spec(&self) -> AgentSpec
Creates a new agent specification from this definition.
Generates a unique ID and copies the definition’s ports and configs to create a new instance specification.
Sourcepub fn reconcile_spec(&self, spec: &mut AgentSpec)
pub fn reconcile_spec(&self, spec: &mut AgentSpec)
Reconciles an existing AgentSpec with this definition for backward compatibility.
When loading old JSON presets, the spec may not match the current definition. This method:
- Fills missing config keys with definition defaults
- Renames stale keys (not in definition) with
_prefix for lazy migration - Overwrites
config_specswith current definition metadata - Overwrites ports with current definition ports
Keys already starting with _ are skipped during rename (idempotency).
_-prefixed keys are cleaned up by AgentData::new().
Config names must not start with _ (reserved for stale key migration).
Trait Implementations§
Source§impl Clone for AgentDefinition
impl Clone for AgentDefinition
Source§fn clone(&self) -> AgentDefinition
fn clone(&self) -> AgentDefinition
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AgentDefinition
impl Debug for AgentDefinition
Source§impl Default for AgentDefinition
impl Default for AgentDefinition
Source§fn default() -> AgentDefinition
fn default() -> AgentDefinition
Source§impl<'de> Deserialize<'de> for AgentDefinition
impl<'de> Deserialize<'de> for AgentDefinition
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for AgentDefinition
impl RefUnwindSafe for AgentDefinition
impl Send for AgentDefinition
impl Sync for AgentDefinition
impl Unpin for AgentDefinition
impl UnsafeUnpin for AgentDefinition
impl UnwindSafe for AgentDefinition
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
Source§fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
Source§impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
Source§type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
Source§fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, Dst> ConvAsUtil<Dst> for T
impl<T, Dst> ConvAsUtil<Dst> for T
Source§impl<T> ConvUtil for T
impl<T> ConvUtil for T
Source§fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
Source§fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more