Skill 2.4.8
Design middleware for reusable capabilities across the solution, including logging, authorization, and exception handling
Key Concepts
Agent Framework provides agent middleware (around an agent run), function middleware (around each tool invocation) and chat middleware (around each model call). Each middleware receives a context, can inspect or modify it, call the next step or stop the pipeline. LangChain and LangGraph offer comparable callbacks and middleware hooks.
Typical middleware includes logging with correlation IDs and token counts, authorization that checks whether the current user may invoke a tool with given arguments, exception handling that converts errors into safe messages and retries transient failures, and policy checks such as PII redaction. Order matters: authorization runs before the tool, and logging wraps everything.