Ag2 Middleware

Intercept the AG2 agent loop with `BaseMiddleware` — wrap full turns (`on_turn`), each LLM call (`on_llm_call`), each tool execution (`on_tool_execution`), or each human-input request (`on_human_input`). Use for retry, logging, history trimming, request mutation, tool auditing, guardrails, or rate limiting. Built-ins: `LoggingMiddleware`, `RetryMiddleware`, `HistoryLimiter`, `TokenLimiter`, `TelemetryMiddleware` (see `ag2-telemetry`). For per-tool hooks see also `ag2-add-custom-tool` tool-middleware section.

ag2ai 8c9a8cb 2 files · 11.3 KB Updated

File contents

ag2ai/ag2-skills/tree/main/skills/ag2-middleware commit 8c9a8cb6a4

Frequently asked questions

npx skillmds@latest add ag2ai/ag2-middleware