pub trait LearningAgent<E: Environment>: Checkpointable {
// Required methods
fn act(&mut self, obs: &E::Observation, mode: ActMode) -> E::Action;
fn observe(&mut self, experience: Experience<E::Observation, E::Action>);
fn total_steps(&self) -> usize;
// Provided methods
fn episode_extras(&self) -> HashMap<String, f64> { ... }
fn on_episode_start(&mut self) { ... }
}Expand description
An agent that can act, learn from experience, and report training stats.
Implemented by all algorithm agents (DqnAgent, future PpoAgent, etc.).
The agent owns its exploration RNG internally – no external RNG is needed
at call sites.
§Episode extras
Algorithms should maintain internal aggregators (e.g. Mean, Std, Max
from crate::stats) over per-step values during each episode, reset them
at episode start, and report summaries via episode_extras. These are
merged into crate::stats::EpisodeRecord::extras automatically by
crate::training::TrainingSession.
Example extras a DQN agent might report:
{ "epsilon": 0.12, "loss_mean": 0.043, "loss_std": 0.012, "loss_max": 0.21 }Required Methods§
Sourcefn act(&mut self, obs: &E::Observation, mode: ActMode) -> E::Action
fn act(&mut self, obs: &E::Observation, mode: ActMode) -> E::Action
Select an action for obs according to mode.
Sourcefn observe(&mut self, experience: Experience<E::Observation, E::Action>)
fn observe(&mut self, experience: Experience<E::Observation, E::Action>)
Record a transition and update the agent’s internal state.
Sourcefn total_steps(&self) -> usize
fn total_steps(&self) -> usize
Total number of observe calls since construction.
Provided Methods§
Sourcefn episode_extras(&self) -> HashMap<String, f64>
fn episode_extras(&self) -> HashMap<String, f64>
Per-episode aggregates of step-level values, reported at episode end.
The default implementation returns an empty map. Algorithms override this to expose training dynamics (loss statistics, epsilon, etc.).
Sourcefn on_episode_start(&mut self)
fn on_episode_start(&mut self)
Called by crate::training::TrainingSession at the start of each
episode so the agent can reset its per-episode aggregators.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.