Skip to main content

oris_kernel/kernel/
step.rs

1//! Step function: given state, decide next (emit events, do action, interrupt, or complete).
2//!
3//! Graph/Agent compile down to a StepFn.
4
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7
8use crate::kernel::action::Action;
9use crate::kernel::event::Event;
10use crate::kernel::state::KernelState;
11use crate::kernel::KernelError;
12
13/// Information attached to an interrupt (e.g. for human-in-the-loop).
14#[derive(Clone, Debug, Serialize, Deserialize)]
15pub struct InterruptInfo {
16    pub value: Value,
17}
18
19/// What to do next after a step.
20#[derive(Clone, Debug)]
21pub enum Next {
22    /// Emit internal events only (no external action).
23    Emit(Vec<Event>),
24    /// Request one external action (policy + executor; result becomes events).
25    Do(Action),
26    /// Pause for interrupt (e.g. human approval).
27    Interrupt(InterruptInfo),
28    /// Run is complete.
29    Complete,
30}
31
32/// Step function: given current state, returns the next action (emit / do / interrupt / complete).
33/// Graph and Agent are compiled to this interface.
34pub trait StepFn<S: KernelState>: Send + Sync {
35    fn next(&self, state: &S) -> Result<Next, KernelError>;
36}