pub struct Agent { /* private fields */ }Expand description
Agent represents an AI-powered NPC in a game
Implementations§
Source§impl Agent
impl Agent
Sourcepub fn new(config: AgentConfig) -> Self
pub fn new(config: AgentConfig) -> Self
Sourcepub fn new_with_tts(config: AgentConfig) -> Self
pub fn new_with_tts(config: AgentConfig) -> Self
Create a new agent with TTS service
Sourcepub async fn speak(
&self,
text: &str,
emotions: &EmotionalState,
urgency: f32,
) -> Result<AudioData>
pub async fn speak( &self, text: &str, emotions: &EmotionalState, urgency: f32, ) -> Result<AudioData>
Generate speech for agent response
Sourcepub async fn state(&self) -> AgentState
pub async fn state(&self) -> AgentState
Get the agent’s current state
Sourcepub async fn emotional_state(&self) -> EmotionalState
pub async fn emotional_state(&self) -> EmotionalState
Get a copy of the agent’s current emotional state
Sourcepub async fn emotion_vector(&self) -> [f32; 8]
pub async fn emotion_vector(&self) -> [f32; 8]
Get the agent’s emotion vector as a float array
Sourcepub async fn update_emotion(&self, emotion: &str, delta: f32)
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)
Sourcepub async fn decay_emotions(&self)
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
Sourcepub async fn emotional_valence(&self) -> f32
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
Sourcepub async fn emotional_arousal(&self) -> f32
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
Sourcepub async fn add_behavior<B: Behavior + 'static>(&self, behavior: B)
pub async fn add_behavior<B: Behavior + 'static>(&self, behavior: B)
Sourcepub async fn add_boxed_behavior(&self, behavior: Box<dyn Behavior>)
pub async fn add_boxed_behavior(&self, behavior: Box<dyn Behavior>)
Sourcepub async fn update_context(&self, context: AgentContext)
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
Sourcepub async fn start(&self) -> Result<()>
pub async fn start(&self) -> Result<()>
Start the agent
This initializes the agent and prepares it for operation
Sourcepub async fn process_input(&self, input: &str) -> Result<String>
pub async fn process_input(&self, input: &str) -> Result<String>
Sourcepub fn on_event<F>(&self, event: AgentEvent, callback: F)
pub fn on_event<F>(&self, event: AgentEvent, callback: F)
Sourcepub fn register_callback<F>(&self, event: &str, callback: F)
👎Deprecated since 0.1.5: Use on_event() with AgentEvent enum instead
pub fn register_callback<F>(&self, event: &str, callback: F)
Register a callback for agent events (deprecated, use on_event)
§Arguments
event- Event name to trigger the callbackcallback- Callback function
Sourcepub fn clone_for_binding(&self) -> Self
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.
Sourcepub async fn add_memory(
&self,
category: MemoryCategory,
content: &str,
importance: f64,
tags: Option<Vec<String>>,
) -> Result<()>
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
Sourcepub async fn add_emotional_memory(
&self,
category: MemoryCategory,
content: &str,
importance: f64,
valence: f64,
intensity: f64,
tags: Option<Vec<String>>,
) -> Result<()>
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
Sourcepub async fn memory_count(&self) -> usize
pub async fn memory_count(&self) -> usize
Get the total number of memories stored
Sourcepub async fn clear_memories(&self) -> usize
pub async fn clear_memories(&self) -> usize
Clear all non-permanent memories
Sourcepub async fn get_memories_by_category(
&self,
category: MemoryCategory,
) -> Vec<Memory>
pub async fn get_memories_by_category( &self, category: MemoryCategory, ) -> Vec<Memory>
Get all memories of a specific category
Sourcepub async fn retrieve_relevant_memories(
&self,
query: &str,
limit: usize,
) -> Result<Vec<Memory>>
pub async fn retrieve_relevant_memories( &self, query: &str, limit: usize, ) -> Result<Vec<Memory>>
Retrieve memories relevant to a query
Sourcepub async fn forget_memory(&self, memory_id: &str) -> Result<()>
pub async fn forget_memory(&self, memory_id: &str) -> Result<()>
Forget a specific memory by ID
Sourcepub async fn forget_memories_by_category(
&self,
category: MemoryCategory,
) -> usize
pub async fn forget_memories_by_category( &self, category: MemoryCategory, ) -> usize
Forget all memories of a specific category
Sourcepub async fn has_memory(&self, memory_id: &str) -> bool
pub async fn has_memory(&self, memory_id: &str) -> bool
Check if a memory exists by ID
Sourcepub async fn get_memory(&self, memory_id: &str) -> Option<Memory>
pub async fn get_memory(&self, memory_id: &str) -> Option<Memory>
Get a specific memory by ID