Skip to main content

InferenceAgent

Struct InferenceAgent 

Source
pub struct InferenceAgent {}

Implementations§

Source§

impl InferenceAgent

Source

pub fn new() -> Self

Examples found in repository?
examples/agent_loop.rs (line 55)
34fn main() -> Result<()> {
35    println!("Initializing Converge Analytics loop...");
36
37    // 0. Setup Dataset
38    let data_path = Path::new("california_housing_train.parquet");
39    // Ensure we can write to CWD or use a temp dir.
40    // In most CI/dev envs, CWD is writable.
41    download_dataset_if_missing(data_path)?;
42
43    // 1. Initialize Context
44    let mut ctx = Context::new();
45
46    // Seed with intent to analyze
47    ctx.add_fact(Fact::new(
48        ContextKey::Seeds,
49        "job-1",
50        "Analyze housing data",
51    ))?;
52
53    // 2. Initialize Agents
54    let feature_agent = FeatureAgent::new(Some(data_path.to_path_buf()));
55    let inference_agent = InferenceAgent::new();
56
57    let agents: Vec<Box<dyn Agent>> = vec![Box::new(feature_agent), Box::new(inference_agent)];
58
59    // 3. Run Loop (Simplified Engine)
60    // Real engine runs until convergence. Here we run fixed steps for demo.
61    println!("Starting execution loop...");
62    for cycle in 1..=3 {
63        println!("\n--- Cycle {} ---", cycle);
64        let mut changes = 0;
65
66        for agent in &agents {
67            if agent.accepts(&ctx) {
68                println!("Agent {} is active", agent.name());
69                let effect = agent.execute(&ctx);
70
71                if !effect.is_empty() {
72                    println!(
73                        "Agent {} produced {} facts, {} proposals",
74                        agent.name(),
75                        effect.facts.len(),
76                        effect.proposals.len()
77                    );
78
79                    // Emulate engine merging
80                    for fact in effect.facts {
81                        if ctx.add_fact(fact).unwrap_or(false) {
82                            changes += 1;
83                        }
84                    }
85
86                    // Emulate proposal validation (auto-promote for demo)
87                    for proposal in effect.proposals {
88                        // In real engine: validation logic.
89                        // Here: naive promotion.
90                        if let Ok(fact) = Fact::try_from(proposal) {
91                            if ctx.add_fact(fact).unwrap_or(false) {
92                                changes += 1;
93                            }
94                        }
95                    }
96                }
97            } else {
98                println!("Agent {} skipped", agent.name());
99            }
100        }
101
102        // Print state
103        for key in ctx.all_keys() {
104            let count = ctx.get(key).len();
105            println!("Context[{:?}] = {} facts", key, count);
106        }
107
108        if changes == 0 {
109            println!("Converged!");
110            break;
111        }
112    }
113
114    // 4. Verify Results
115    let hypotheses = ctx.get(ContextKey::Hypotheses);
116    if let Some(hypo) = hypotheses.first() {
117        println!("\nFinal Result: {}", hypo.content);
118    } else {
119        println!("\nNo hypothesis generated.");
120    }
121
122    Ok(())
123}

Trait Implementations§

Source§

impl Agent for InferenceAgent

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