Agent

Struct Agent 

Source
pub struct Agent { /* private fields */ }
Expand description

Agent represents an AI-powered NPC in a game

Implementations§

Source§

impl Agent

Source

pub fn new(config: AgentConfig) -> Self

Create a new agent with the given configuration

§Arguments
  • config - Agent configuration
§Returns

A new Agent instance

Source

pub fn new_with_tts(config: AgentConfig) -> Self

Create a new agent with TTS service

Source

pub async fn speak( &self, text: &str, emotions: &EmotionalState, urgency: f32, ) -> Result<AudioData>

Generate speech for agent response

Source

pub fn id(&self) -> Uuid

Get the agent’s unique ID

Source

pub fn name(&self) -> &str

Get the agent’s name

Source

pub async fn state(&self) -> AgentState

Get the agent’s current state

Source

pub async fn emotional_state(&self) -> EmotionalState

Get a copy of the agent’s current emotional state

Source

pub async fn emotion_vector(&self) -> [f32; 8]

Get the agent’s emotion vector as a float array

Source

pub async fn update_emotion(&self, emotion: &str, delta: f32)

Update a specific emotion by a delta value

§Arguments
  • emotion - Name of the emotion to update (e.g., “joy”, “fear”)
  • delta - Amount to change the emotion by (-1.0 to 1.0)
Source

pub async fn decay_emotions(&self)

Apply emotional decay to all emotions

This should be called periodically (e.g., every frame or tick) to allow emotions to naturally fade over time

Source

pub async fn emotional_valence(&self) -> f32

Get the current emotional valence (-1.0 to 1.0)

Valence represents how positive or negative the agent feels

Source

pub async fn emotional_arousal(&self) -> f32

Get the current emotional arousal (0.0 to 1.0)

Arousal represents how intensely the agent is feeling

Source

pub async fn add_behavior<B: Behavior + 'static>(&self, behavior: B)

Add a behavior to the agent

§Arguments
  • behavior - A behavior to add to the agent
Source

pub async fn add_boxed_behavior(&self, behavior: Box<dyn Behavior>)

Add a boxed behavior to the agent

§Arguments
  • behavior - A boxed behavior to add to the agent
Source

pub async fn update_context(&self, context: AgentContext)

Update the agent’s context with new data

§Arguments
  • context - New context data to merge with existing context
Source

pub async fn start(&self) -> Result<()>

Start the agent

This initializes the agent and prepares it for operation

Source

pub async fn stop(&self) -> Result<()>

Stop the agent

Source

pub async fn process_input(&self, input: &str) -> Result<String>

Process player input and generate a response

§Arguments
  • input - Player input to process
§Returns

A result containing the agent’s response

Source

pub fn on_event<F>(&self, event: AgentEvent, callback: F)
where F: Fn(&Agent, &str) + Send + Sync + 'static,

Register a callback for agent events using typed events

§Arguments
  • event - Event type to trigger the callback
  • callback - Callback function
§Example
agent.on_event(AgentEvent::Start, |agent, data| {
    println!("Agent {} started: {}", agent.name(), data);
});
Source

pub fn register_callback<F>(&self, event: &str, callback: F)
where F: Fn(&Agent, &str) + Send + Sync + 'static,

👎Deprecated since 0.1.5: Use on_event() with AgentEvent enum instead

Register a callback for agent events (deprecated, use on_event)

§Arguments
  • event - Event name to trigger the callback
  • callback - Callback function
Source

pub fn clone_for_binding(&self) -> Self

Create a new agent with the same configuration but new state

This is a simplified clone method that creates a new agent with the same configuration but with fresh state. This is useful for creating copies of agents for engine bindings.

Source

pub async fn add_memory( &self, category: MemoryCategory, content: &str, importance: f64, tags: Option<Vec<String>>, ) -> Result<()>

Add a memory to the agent’s memory system

Source

pub async fn add_emotional_memory( &self, category: MemoryCategory, content: &str, importance: f64, valence: f64, intensity: f64, tags: Option<Vec<String>>, ) -> Result<()>

Add a memory with emotional context to the agent’s memory system

Source

pub async fn memory_count(&self) -> usize

Get the total number of memories stored

Source

pub async fn clear_memories(&self) -> usize

Clear all non-permanent memories

Source

pub async fn get_memories_by_category( &self, category: MemoryCategory, ) -> Vec<Memory>

Get all memories of a specific category

Source

pub async fn retrieve_relevant_memories( &self, query: &str, limit: usize, ) -> Result<Vec<Memory>>

Retrieve memories relevant to a query

Source

pub async fn forget_memory(&self, memory_id: &str) -> Result<()>

Forget a specific memory by ID

Source

pub async fn forget_memories_by_category( &self, category: MemoryCategory, ) -> usize

Forget all memories of a specific category

Source

pub async fn has_memory(&self, memory_id: &str) -> bool

Check if a memory exists by ID

Source

pub async fn get_memory(&self, memory_id: &str) -> Option<Memory>

Get a specific memory by ID

Trait Implementations§

Source§

impl Debug for Agent

Source§

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

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

impl From<&Agent> for UnityAgentState

Source§

fn from(agent: &Agent) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !Freeze for Agent

§

impl !RefUnwindSafe for Agent

§

impl Send for Agent

§

impl Sync for Agent

§

impl Unpin for Agent

§

impl !UnwindSafe for Agent

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

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
§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

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> ErasedDestructor for T
where T: 'static,