pub mod approval_gate;
pub mod context;
pub mod filesystem;
pub mod logging;
pub mod memory;
pub mod patch_tool_calls;
pub mod pipeline;
pub mod planning;
pub mod prompt_caching;
pub mod rate_limiter;
pub mod skills;
pub mod subagent;
pub mod summarization;
pub mod todo;
use async_trait::async_trait;
use serde_json::Value;
use crate::agent::DeepAgentError;
pub type Result<T> = std::result::Result<T, DeepAgentError>;
pub type AgentState = Value;
#[derive(Debug, Clone)]
pub enum ToolGateDecision {
Continue,
Reject { observation: String },
}
impl ToolGateDecision {
pub fn is_rejected(&self) -> bool {
matches!(self, Self::Reject { .. })
}
}
#[async_trait]
pub trait Middleware: Send + Sync {
fn name(&self) -> &str;
async fn before_model(&self, _state: &mut AgentState) -> Result<()> {
Ok(())
}
async fn after_model(&self, _state: &mut AgentState) -> Result<()> {
Ok(())
}
async fn before_tool(&self, _state: &mut AgentState, _tool_name: &str) -> Result<()> {
Ok(())
}
async fn gate_tool(
&self,
_state: &mut AgentState,
_tool_name: &str,
_tool_input: &Value,
) -> Result<ToolGateDecision> {
Ok(ToolGateDecision::Continue)
}
async fn after_tool(
&self,
_state: &mut AgentState,
_tool_name: &str,
_result: &str,
) -> Result<()> {
Ok(())
}
}