Skip to main content

AgentValue

Enum AgentValue 

Source
pub enum AgentValue {
    Unit,
    Boolean(bool),
    Integer(i64),
    Number(f64),
    String(Arc<String>),
    Image(Arc<PhotonImage>),
    Array(Vector<AgentValue>),
    Object(HashMap<String, AgentValue>),
    Tensor(Arc<Vec<f32>>),
    Message(Arc<Message>),
    Error(Arc<AgentError>),
}
Expand description

The value type passed between agents.

Supports multiple data types with immutable data structures for efficient cloning. Large data (String, Image, Tensor, etc.) is wrapped in Arc for reference-counted sharing.

Variants§

§

Unit

Empty value. Used as a trigger signal.

§

Boolean(bool)

Boolean value.

§

Integer(i64)

64-bit signed integer.

§

Number(f64)

64-bit floating point number.

§

String(Arc<String>)

UTF-8 string wrapped in Arc for efficient cloning.

§

Image(Arc<PhotonImage>)

Image data (requires image feature).

§

Array(Vector<AgentValue>)

Ordered array of values.

§

Object(HashMap<String, AgentValue>)

Key-value map.

§

Tensor(Arc<Vec<f32>>)

Tensor data for embeddings, etc.

§

Message(Arc<Message>)

LLM chat message.

§

Error(Arc<AgentError>)

Error value for propagating errors through the workflow.

Implementations§

Source§

impl AgentValue

Source

pub fn unit() -> Self

Creates a Unit value.

Source

pub fn boolean(value: bool) -> Self

Creates a Boolean value.

Source

pub fn integer(value: i64) -> Self

Creates an Integer value.

Source

pub fn number(value: f64) -> Self

Creates a Number value.

Source

pub fn string(value: impl Into<String>) -> Self

Creates a String value.

Source

pub fn image(value: PhotonImage) -> Self

Creates an Image value from a PhotonImage.

Source

pub fn image_arc(value: Arc<PhotonImage>) -> Self

Creates an Image value from an Arc<PhotonImage>.

Source

pub fn array(value: Vector<AgentValue>) -> Self

Creates an Array value.

Source

pub fn object(value: AgentValueMap<String, AgentValue>) -> Self

Creates an Object value.

Source

pub fn tensor(value: Vec<f32>) -> Self

Creates a Tensor value from a Vec<f32>.

Source

pub fn message(value: Message) -> Self

Creates a Message value.

Source

pub fn boolean_default() -> Self

Creates a default Boolean value (false).

Source

pub fn integer_default() -> Self

Creates a default Integer value (0).

Source

pub fn number_default() -> Self

Creates a default Number value (0.0).

Source

pub fn string_default() -> Self

Creates a default String value (empty string).

Source

pub fn image_default() -> Self

Creates a default Image value (1x1 transparent pixel).

Source

pub fn array_default() -> Self

Creates a default Array value (empty array).

Source

pub fn object_default() -> Self

Creates a default Object value (empty object).

Source

pub fn tensor_default() -> Self

Creates a default Tensor value (empty vector).

Source

pub fn from_json(value: Value) -> Result<Self, AgentError>

Creates an AgentValue from a serde_json::Value.

§Errors

Returns InvalidValue if the JSON value cannot be converted.

Source

pub fn to_json(&self) -> Value

Converts to a serde_json::Value.

Source

pub fn from_serialize<T: Serialize>(value: &T) -> Result<Self, AgentError>

Create AgentValue from Serialize

Source

pub fn to_deserialize<T: for<'de> Deserialize<'de>>( &self, ) -> Result<T, AgentError>

Convert AgentValue to a Deserialize

Source

pub fn is_unit(&self) -> bool

Returns true if this is a Unit value.

Source

pub fn is_boolean(&self) -> bool

Returns true if this is a Boolean value.

Source

pub fn is_integer(&self) -> bool

Returns true if this is an Integer value.

Source

pub fn is_number(&self) -> bool

Returns true if this is a Number value.

Source

pub fn is_string(&self) -> bool

Returns true if this is a String value.

Source

pub fn is_image(&self) -> bool

Returns true if this is an Image value.

Source

pub fn is_array(&self) -> bool

Returns true if this is an Array value.

Source

pub fn is_object(&self) -> bool

Returns true if this is an Object value.

Source

pub fn is_tensor(&self) -> bool

Returns true if this is a Tensor value.

Source

pub fn is_message(&self) -> bool

Returns true if this is a Message value.

Source

pub fn as_bool(&self) -> Option<bool>

Returns the inner boolean value if this is a Boolean, otherwise None.

Source

pub fn as_i64(&self) -> Option<i64>

Returns the value as i64 if this is an Integer or Number, otherwise None.

Source

pub fn as_f64(&self) -> Option<f64>

Returns the value as f64 if this is an Integer or Number, otherwise None.

Source

pub fn as_str(&self) -> Option<&str>

Returns a reference to the inner string if this is a String, otherwise None.

Source

pub fn as_image(&self) -> Option<&PhotonImage>

Returns a reference to the inner image if this is an Image, otherwise None.

Source

pub fn as_image_mut(&mut self) -> Option<&mut PhotonImage>

Returns a mutable reference to the inner image if this is an Image, otherwise None.

Source

pub fn into_image(self) -> Option<Arc<PhotonImage>>

Extracts the inner Arc<PhotonImage> if this is an Image, consuming self.

Source

pub fn as_message(&self) -> Option<&Message>

Returns a reference to the inner message if this is a Message, otherwise None.

Source

pub fn as_message_mut(&mut self) -> Option<&mut Message>

Returns a mutable reference to the inner message if this is a Message, otherwise None.

Source

pub fn into_message(self) -> Option<Arc<Message>>

Extracts the inner Arc<Message> if this is a Message, consuming self.

Source

pub fn to_boolean(&self) -> Option<bool>

Converts to a boolean with type coercion.

Conversion rules:

  • Boolean: returns the value
  • Integer: 0false, otherwise true
  • Number: 0.0false, otherwise true
  • String: parses “true”/“false”
Source

pub fn to_boolean_value(&self) -> Option<AgentValue>

Converts to AgentValue::Boolean or AgentValue::Array of booleans.

Source

pub fn to_integer(&self) -> Option<i64>

Converts to an integer (i64) with type coercion.

Source

pub fn to_integer_value(&self) -> Option<AgentValue>

Converts to AgentValue::Integer or AgentValue::Array of integers.

Source

pub fn to_number(&self) -> Option<f64>

Converts to a number (f64) with type coercion.

Source

pub fn to_number_value(&self) -> Option<AgentValue>

Converts to AgentValue::Number or AgentValue::Array of numbers.

Source

pub fn to_string(&self) -> Option<String>

Converts to a string with type coercion.

Source

pub fn to_string_value(&self) -> Option<AgentValue>

Converts to AgentValue::String or AgentValue::Array of strings.

Source

pub fn to_message(&self) -> Option<Message>

Converts to a Message.

Source

pub fn to_message_value(&self) -> Option<AgentValue>

Converts to AgentValue::Message or AgentValue::Array of messages.

If the value is an array, it recursively converts its elements.

Source

pub fn as_object(&self) -> Option<&AgentValueMap<String, AgentValue>>

Returns a reference to the inner object map if this is an Object, otherwise None.

Source

pub fn as_object_mut( &mut self, ) -> Option<&mut AgentValueMap<String, AgentValue>>

Returns a mutable reference to the inner object map if this is an Object, otherwise None.

Source

pub fn into_object(self) -> Option<AgentValueMap<String, AgentValue>>

Extracts the inner HashMap if this is an Object, consuming self.

Source

pub fn as_array(&self) -> Option<&Vector<AgentValue>>

Returns a reference to the inner array if this is an Array, otherwise None.

Source

pub fn as_array_mut(&mut self) -> Option<&mut Vector<AgentValue>>

Returns a mutable reference to the inner array if this is an Array, otherwise None.

Source

pub fn into_array(self) -> Option<Vector<AgentValue>>

Extracts the inner Vector if this is an Array, consuming self.

Source

pub fn as_tensor(&self) -> Option<&Vec<f32>>

Returns a reference to the inner tensor if this is a Tensor, otherwise None.

Source

pub fn as_tensor_mut(&mut self) -> Option<&mut Vec<f32>>

Returns a mutable reference to the inner tensor if this is a Tensor, otherwise None.

Source

pub fn into_tensor(self) -> Option<Arc<Vec<f32>>>

Extracts the inner Arc<Vec<f32>> if this is a Tensor, consuming self.

Source

pub fn into_tensor_vec(self) -> Option<Vec<f32>>

Extracts the inner Vec<f32> if this is a Tensor, consuming self. Possibly O(n) copy.

Source

pub fn get(&self, key: &str) -> Option<&AgentValue>

Gets a value by key from an Object.

Source

pub fn get_mut(&mut self, key: &str) -> Option<&mut AgentValue>

Gets a mutable reference to a value by key from an Object.

Source

pub fn get_bool(&self, key: &str) -> Option<bool>

Gets a boolean value by key from an Object.

Source

pub fn get_i64(&self, key: &str) -> Option<i64>

Gets an i64 value by key from an Object.

Source

pub fn get_f64(&self, key: &str) -> Option<f64>

Gets an f64 value by key from an Object.

Source

pub fn get_str(&self, key: &str) -> Option<&str>

Gets a string reference by key from an Object.

Source

pub fn get_image(&self, key: &str) -> Option<&PhotonImage>

Gets an image reference by key from an Object.

Source

pub fn get_image_mut(&mut self, key: &str) -> Option<&mut PhotonImage>

Gets a mutable image reference by key from an Object.

Source

pub fn get_object( &self, key: &str, ) -> Option<&AgentValueMap<String, AgentValue>>

Gets an object reference by key from an Object.

Source

pub fn get_object_mut( &mut self, key: &str, ) -> Option<&mut AgentValueMap<String, AgentValue>>

Gets a mutable object reference by key from an Object.

Source

pub fn get_array(&self, key: &str) -> Option<&Vector<AgentValue>>

Gets an array reference by key from an Object.

Source

pub fn get_array_mut(&mut self, key: &str) -> Option<&mut Vector<AgentValue>>

Gets a mutable array reference by key from an Object.

Source

pub fn get_tensor(&self, key: &str) -> Option<&Vec<f32>>

Gets a tensor reference by key from an Object.

Source

pub fn get_tensor_mut(&mut self, key: &str) -> Option<&mut Vec<f32>>

Gets a mutable tensor reference by key from an Object.

Source

pub fn get_message(&self, key: &str) -> Option<&Message>

Gets a message reference by key from an Object.

Source

pub fn get_message_mut(&mut self, key: &str) -> Option<&mut Message>

Gets a mutable message reference by key from an Object.

Source

pub fn set(&mut self, key: String, value: AgentValue) -> Result<(), AgentError>

Sets a value by key in an Object.

§Errors

Returns InvalidValue if this is not an Object.

Trait Implementations§

Source§

impl Clone for AgentValue

Source§

fn clone(&self) -> AgentValue

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AgentValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AgentValue

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for AgentValue

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&str> for AgentValue

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<()> for AgentValue

Source§

fn from(_: ()) -> Self

Converts to this type from the input type.
Source§

impl From<AgentError> for AgentValue

Source§

fn from(value: AgentError) -> Self

Converts to this type from the input type.
Source§

impl From<Arc<Vec<f32>>> for AgentValue

Source§

fn from(value: Arc<Vec<f32>>) -> Self

Converts to this type from the input type.
Source§

impl From<HashMap<String, AgentValue>> for AgentValue

Source§

fn from(value: HashMap<String, AgentValue>) -> Self

Converts to this type from the input type.
Source§

impl From<HashMap<String, AgentValue>> for AgentValue

Source§

fn from(value: HashMap<String, AgentValue>) -> Self

Converts to this type from the input type.
Source§

impl From<Message> for AgentValue

Source§

fn from(msg: Message) -> Self

Converts to this type from the input type.
Source§

impl From<Option<AgentValue>> for AgentValue

Source§

fn from(value: Option<AgentValue>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for AgentValue

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<ToolInfo> for AgentValue

Source§

fn from(info: ToolInfo) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<AgentValue>> for AgentValue

Source§

fn from(value: Vec<AgentValue>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Message>> for AgentValue

Source§

fn from(msgs: Vec<Message>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<f32>> for AgentValue

Source§

fn from(value: Vec<f32>) -> Self

Converts to this type from the input type.
Source§

impl From<Vector<AgentValue>> for AgentValue

Source§

fn from(value: Vector<AgentValue>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for AgentValue

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for AgentValue

Source§

fn from(value: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for AgentValue

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for AgentValue

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for AgentValue

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for AgentValue

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for AgentValue

Source§

fn from(value: usize) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for AgentValue

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for AgentValue

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<AgentValue> for Message

Source§

type Error = AgentError

The type returned in the event of a conversion error.
Source§

fn try_from(value: AgentValue) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: FloatComponent, Swp: WhitePoint, Dwp: WhitePoint, D: AdaptFrom<S, Swp, Dwp, T>,

Source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<Swp, Dwp, T>,

Convert the source color to the destination color using the specified method
Source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src
where Scheme: ApproxScheme,

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>

Convert the given value into an approximately equivalent representation.
Source§

impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src
where Dst: ApproxFrom<Src, Scheme>, Scheme: ApproxScheme,

Source§

type Err = <Dst as ApproxFrom<Src, Scheme>>::Err

The error type produced by a failed conversion.
Source§

fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>

Convert the subject into an approximately equivalent representation.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T, Dst> ConvAsUtil<Dst> for T

Source§

fn approx(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject with the default scheme.
Source§

fn approx_by<Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject with a specific scheme.
Source§

impl<T> ConvUtil for T

Source§

fn approx_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject to a given type with the default scheme.
Source§

fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject to a given type with a specific scheme.
Source§

fn into_as<Dst>(self) -> Dst
where Self: Sized + Into<Dst>,

Convert the subject to a given type.
Source§

fn try_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + TryInto<Dst>,

Attempt to convert the subject to a given type.
Source§

fn value_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ValueInto<Dst>,

Attempt a value conversion of the subject to a given type.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> IntoColor<U> for T
where U: FromColor<T>,

Source§

fn into_color(self) -> U

Convert into T with values clamped to the color defined bounds Read more
Source§

impl<T, U> IntoColorUnclamped<U> for T
where U: FromColorUnclamped<T>,

Source§

fn into_color_unclamped(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<Src> TryFrom<Src> for Src

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn try_from(src: Src) -> Result<Src, <Src as TryFrom<Src>>::Err>

Convert the given value into the subject type.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<Src, Dst> TryInto<Dst> for Src
where Dst: TryFrom<Src>,

Source§

type Err = <Dst as TryFrom<Src>>::Err

The error type produced by a failed conversion.
Source§

fn try_into(self) -> Result<Dst, <Src as TryInto<Dst>>::Err>

Convert the subject into the destination type.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> TryIntoColor<U> for T
where U: TryFromColor<T>,

Source§

fn try_into_color(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<Src> ValueFrom<Src> for Src

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>

Convert the given value into an exactly equivalent representation.
Source§

impl<Src, Dst> ValueInto<Dst> for Src
where Dst: ValueFrom<Src>,

Source§

type Err = <Dst as ValueFrom<Src>>::Err

The error type produced by a failed conversion.
Source§

fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>

Convert the subject into an exactly equivalent representation.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,