1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! Middleware system for Deep Agents.
//!
//! Middleware hooks run before/after model calls and tool executions,
//! allowing pluggable behaviour such as filesystem access, memory
//! injection, and context summarization.
//!
//! Built-in middleware:
//! - [`filesystem::FilesystemMiddleware`] — file read, write, edit, ls, glob, grep
//! - [`memory::MemoryMiddleware`] — inject persistent memory into context
//! - [`subagent::SubAgentMiddleware`] — isolated sub-agent delegation
//! - [`summarization::SummarizationMiddleware`] — context window management
//! - [`skills::SkillsMiddleware`] — custom skill loading
//! - [`patch_tool_calls::PatchToolCallsMiddleware`] — tool call correction
//! - [`rate_limiter::RateLimiterMiddleware`] — token bucket rate limiting with cost tracking
//! - [`logging::LoggingMiddleware`] — structured logging with redaction
//! - [`context::ContextMiddleware`] — dynamic context injection
//! - [`planning::PlanningMiddleware`] — plan-then-execute support with step tracking, dependencies, and status injection
use async_trait;
use Value;
use crateDeepAgentError;
/// Result type for middleware operations.
pub type Result<T> = Result;
/// A mutable reference to the agent state (a JSON object with at least a `"messages"` key).
pub type AgentState = Value;
/// Trait for pluggable middleware in the Deep Agent pipeline.
///
/// All methods have default no-op implementations so that concrete
/// middleware only needs to override the hooks it cares about.