Skip to main content

MonitoringAgent

Struct MonitoringAgent 

Source
pub struct MonitoringAgent;

Implementations§

Source§

impl MonitoringAgent

Source

pub fn new() -> Self

Examples found in repository?
examples/training_flow.rs (line 36)
14fn main() -> Result<()> {
15    println!("Initializing Converge Analytics training flow...");
16
17    // 1. Initialize Context
18    let mut ctx = Context::new();
19    ctx.add_fact(Fact::new(
20        ContextKey::Seeds,
21        "job-1",
22        "Train a baseline model on California Housing",
23    ))?;
24
25    // 2. Initialize Agents
26    let data_dir = PathBuf::from("data");
27    let model_dir = PathBuf::from("models");
28
29    let dataset_agent = DatasetAgent::new(data_dir);
30    let validator = DataValidationAgent::new();
31    let featurizer = FeatureEngineeringAgent::new();
32    let hyperparam = HyperparameterSearchAgent::new(12);
33    let trainer = ModelTrainingAgent::new(model_dir);
34    let evaluator = ModelEvaluationAgent::new();
35    let registry = ModelRegistryAgent::new();
36    let monitor = MonitoringAgent::new();
37    let inference = SampleInferenceAgent::new(5);
38    let deployment = DeploymentAgent::new();
39
40    let agents: Vec<Box<dyn Agent>> = vec![
41        Box::new(dataset_agent),
42        Box::new(validator),
43        Box::new(featurizer),
44        Box::new(hyperparam),
45        Box::new(trainer),
46        Box::new(evaluator),
47        Box::new(registry),
48        Box::new(monitor),
49        Box::new(inference),
50        Box::new(deployment),
51    ];
52
53    // 3. Run Loop (Convergence with quality gate)
54    println!("Starting execution loop...");
55    let mut iteration = 1usize;
56    let mut max_rows = 500usize;
57    let quality_threshold = 0.75;
58    let max_iterations = 5;
59    let mut last_iteration = iteration;
60
61    while iteration <= max_iterations {
62        let plan = TrainingPlan {
63            iteration,
64            max_rows,
65            train_fraction: 0.8,
66            val_fraction: 0.15,
67            infer_fraction: 0.05,
68            quality_threshold,
69        };
70        let plan_content = serde_json::to_string(&plan)?;
71        ctx.add_fact(Fact::new(
72            ContextKey::Constraints,
73            format!("training-plan-{}", iteration),
74            plan_content,
75        ))?;
76
77        println!(
78            "\n--- Iteration {} (max_rows={}) ---",
79            iteration, max_rows
80        );
81
82        for cycle in 1..=8 {
83            println!("Cycle {}", cycle);
84            let mut changes = 0;
85
86            for agent in &agents {
87                if agent.accepts(&ctx) {
88                    println!("Agent {} is active", agent.name());
89                    let effect = agent.execute(&ctx);
90
91                    if !effect.is_empty() {
92                        for fact in effect.facts {
93                            if ctx.add_fact(fact).unwrap_or(false) {
94                                changes += 1;
95                            }
96                        }
97                    }
98                }
99            }
100
101            if changes == 0 {
102                break;
103            }
104        }
105
106        let report = match latest_evaluation_for_iteration(&ctx, iteration) {
107            Some(report) => report,
108            None => {
109                println!("No evaluation report for iteration {}", iteration);
110                break;
111            }
112        };
113
114        println!(
115            "Validation MAE: {:.4} | success_ratio: {:.3} | val_rows: {}",
116            report.value, report.success_ratio, report.val_rows
117        );
118
119        if report.success_ratio >= quality_threshold {
120            println!("Quality threshold met. Converged.");
121            last_iteration = iteration;
122            break;
123        }
124
125        let total_rows = latest_total_rows(&ctx).unwrap_or(max_rows);
126        if max_rows >= total_rows {
127            println!("No more data available to improve quality.");
128            break;
129        }
130
131        max_rows = (max_rows * 2).min(total_rows);
132        println!("Quality below threshold, expanding training rows to {}", max_rows);
133        last_iteration = iteration;
134        iteration += 1;
135    }
136
137    if let Some(eval) = latest_evaluation_for_iteration(&ctx, last_iteration) {
138        println!("\nFinal evaluation: {:?}", eval);
139    }
140
141    if let Some(hypo) = ctx.get(ContextKey::Hypotheses).last() {
142        println!("\nInference sample: {}", hypo.content);
143    }
144
145    Ok(())
146}

Trait Implementations§

Source§

impl Agent for MonitoringAgent

Source§

fn name(&self) -> &str

Human-readable name for debugging and tracing.
Source§

fn dependencies(&self) -> &[ContextKey]

Context keys this agent depends on. Read more
Source§

fn accepts(&self, ctx: &Context) -> bool

Returns true if this agent should execute given the current context. Read more
Source§

fn execute(&self, ctx: &Context) -> AgentEffect

Execute the agent’s logic and return effects. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Adaptor<()> for T

Source§

fn adapt(&self)

Adapt the type to be passed to a metric.
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<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> 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> IntoComptime for T

Source§

fn comptime(self) -> Self

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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<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<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> PlanCallbackArgs for T

Source§

impl<T> PlanCallbackOut for T