Files
Evan Mattson 3c31ac28b5 Python: Fix HandoffBuilder dropping function-level middleware when cloning agents (#5220)
* Fix HandoffBuilder dropping function-level middleware when cloning agents (#5173)

_clone_chat_agent() was using agent.agent_middleware (agent-level only)
instead of agent.middleware (all types), which silently dropped any
function middleware registered on the original agent.

Changed to use agent.middleware to preserve all middleware types
(agent, function, and chat) during cloning.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Python: Fix HandoffBuilder dropping function-level middleware when cloning agents

Fixes #5173

* Fix false-positive middleware regression test (#5173)

The test used isinstance(m, FunctionMiddleware) which matched
_AutoHandoffMiddleware (always appended during build) instead of the
user's @function_middleware decorator. Assert directly that
tracking_middleware is present in the cloned agent's middleware list.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Address review feedback for #5173: Python: [Bug]: HandoffBuilder drops function-level middleware when cloning agents

---------

Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
3c31ac28b5 ยท 2026-04-14 04:52:03 +00:00
History
..