enact-core 0.0.2

Core agent runtime for Enact - Graph-Native AI agents
Documentation
//! Edge types for graph connections

/// Target for an edge - either a specific node or END
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum EdgeTarget {
    /// Target a specific node by name
    Node(String),
    /// End the graph execution
    End,
}

impl EdgeTarget {
    pub fn node(name: impl Into<String>) -> Self {
        Self::Node(name.into())
    }

    pub fn end() -> Self {
        Self::End
    }

    pub fn is_end(&self) -> bool {
        matches!(self, Self::End)
    }
}

/// Edge in the graph
#[derive(Debug, Clone)]
pub struct Edge {
    pub from: String,
    pub to: EdgeTarget,
}

impl Edge {
    pub fn new(from: impl Into<String>, to: EdgeTarget) -> Self {
        Self {
            from: from.into(),
            to,
        }
    }
}

/// Conditional edge - routes based on a function
#[derive(Clone)]
pub struct ConditionalEdge {
    pub from: String,
    pub router: ConditionalRouter,
}

/// Router function type
pub type ConditionalRouter = std::sync::Arc<dyn Fn(&str) -> EdgeTarget + Send + Sync>;

impl std::fmt::Debug for ConditionalEdge {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("ConditionalEdge")
            .field("from", &self.from)
            .field("router", &"<fn>")
            .finish()
    }
}