pub struct Engine { /* private fields */ }Expand description
The Converge execution engine.
Owns agent registration, dependency indexing, and the convergence loop.
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn with_budget(budget: Budget) -> Self
pub fn with_budget(budget: Budget) -> Self
Creates a new engine with custom budget.
Sourcepub fn set_budget(&mut self, budget: Budget)
pub fn set_budget(&mut self, budget: Budget)
Sets the execution budget.
Sourcepub fn set_streaming(&mut self, callback: Arc<dyn StreamingCallback>)
pub fn set_streaming(&mut self, callback: Arc<dyn StreamingCallback>)
Sets a streaming callback for real-time fact emission.
When set, the callback will be invoked:
- At the start of each convergence cycle
- When each fact is added to the context
- At the end of each convergence cycle
§Example
ⓘ
use std::sync::Arc;
use converge_core::{Engine, StreamingCallback, Fact};
struct MyCallback;
impl StreamingCallback for MyCallback {
fn on_cycle_start(&self, cycle: u32) {
println!("[cycle:{}] started", cycle);
}
fn on_fact(&self, cycle: u32, fact: &Fact) {
println!("[cycle:{}] fact:{} | {}", cycle, fact.id, fact.content);
}
fn on_cycle_end(&self, cycle: u32, facts_added: usize) {
println!("[cycle:{}] ended with {} facts", cycle, facts_added);
}
}
let mut engine = Engine::new();
engine.set_streaming(Arc::new(MyCallback));Sourcepub fn clear_streaming(&mut self)
pub fn clear_streaming(&mut self)
Clears the streaming callback.
Sourcepub fn register_invariant(
&mut self,
invariant: impl Invariant + 'static,
) -> InvariantId
pub fn register_invariant( &mut self, invariant: impl Invariant + 'static, ) -> InvariantId
Registers an invariant (compiled Gherkin predicate).
Invariants are checked at different points depending on their class:
- Structural: after every merge
- Semantic: at end of each cycle
- Acceptance: when convergence is claimed
Sourcepub fn register(&mut self, agent: impl Agent + 'static) -> AgentId
pub fn register(&mut self, agent: impl Agent + 'static) -> AgentId
Registers an agent and returns its ID.
Agents are assigned monotonically increasing IDs. The dependency index is updated incrementally.
Sourcepub fn agent_count(&self) -> usize
pub fn agent_count(&self) -> usize
Returns the number of registered agents.
Sourcepub fn run(&mut self, context: Context) -> Result<ConvergeResult, ConvergeError>
pub fn run(&mut self, context: Context) -> Result<ConvergeResult, ConvergeError>
Runs the convergence loop until fixed point or budget exhaustion.
§Algorithm
initialize context
mark all keys as dirty (first cycle)
repeat:
clear dirty flags
find eligible agents (dirty deps + accepts)
execute eligible agents (parallel read)
merge effects (serial, deterministic order)
track which keys changed
until no keys changed OR budget exhausted§Errors
Returns ConvergeError::BudgetExhausted if:
max_cyclesis exceededmax_factsis exceeded
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Engine
impl !RefUnwindSafe for Engine
impl Send for Engine
impl Sync for Engine
impl Unpin for Engine
impl !UnwindSafe for Engine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more