Skip to main content

praisonaiagents.hooks.middleware

Core SDK Middleware System for PraisonAI Agents. Provides wrap_model_call and wrap_tool_call patterns for intercepting and modifying agent behavior at model/tool call boundaries. Zero Performance Impact:
  • All middleware is optional
  • Empty middleware chain is O(1) fast path
  • No overhead when middleware not registered
Usage: from praisonaiagents.hooks import before_model, wrap_model_call, wrap_tool_call @before_model def add_context(request): request.messages.append({“role”: “system”, “content”: “Extra”}) return request @wrap_model_call def retry_on_error(request, call_next): for _ in range(3): try: return call_next(request) except Exception: pass raise RuntimeError(“All retries failed”) agent = Agent(name=“Test”, hooks=[add_context, retry_on_error])

Overview

This module provides components for middleware.

Classes

Functions

Constants

NameValue
TTypeVar('T')