pub struct DeepAgentPromptMiddleware { /* private fields */ }Expand description
Deep Agent prompt middleware that injects comprehensive tool usage instructions and examples to force the LLM to actually call tools instead of just talking about them.
This middleware is inspired by Python’s deepagents package and Claude Code’s system prompt. It provides:
- Explicit tool usage rules with imperative language
- JSON examples of tool calling
- Workflow guidance for multi-step tasks
- Few-shot examples for common patterns
The middleware supports two modes:
- Default mode: Combines custom instructions with the Deep Agent system prompt
- Override mode: Uses a completely custom system prompt, bypassing the default
Implementations§
Source§impl DeepAgentPromptMiddleware
impl DeepAgentPromptMiddleware
pub fn new(custom_instructions: impl Into<String>) -> Self
Sourcepub fn with_override(system_prompt: impl Into<String>) -> Self
pub fn with_override(system_prompt: impl Into<String>) -> Self
Create a middleware with a completely custom system prompt that bypasses the default Deep Agent prompt.
Use this when you need full control over the agent’s system prompt.
Trait Implementations§
Source§impl AgentMiddleware for DeepAgentPromptMiddleware
impl AgentMiddleware for DeepAgentPromptMiddleware
Source§fn modify_model_request<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 mut MiddlewareContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn modify_model_request<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 mut MiddlewareContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Apply middleware-specific mutations to the pending model request.
Source§fn before_tool_execution<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_tool_name: &'life1 str,
_tool_args: &'life2 Value,
_call_id: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<Option<AgentInterrupt>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn before_tool_execution<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_tool_name: &'life1 str,
_tool_args: &'life2 Value,
_call_id: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<Option<AgentInterrupt>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Hook called before tool execution - can return an interrupt to pause execution. Read more
Auto Trait Implementations§
impl Freeze for DeepAgentPromptMiddleware
impl RefUnwindSafe for DeepAgentPromptMiddleware
impl Send for DeepAgentPromptMiddleware
impl Sync for DeepAgentPromptMiddleware
impl Unpin for DeepAgentPromptMiddleware
impl UnwindSafe for DeepAgentPromptMiddleware
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