mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
cd0d38a073
## Description Fixes the LangGraph middleware "lying" to the agent about frontend tool execution (#4759). When a model turn calls a `useFrontendTool` handler, the middleware strips the FE tool calls so the backend `ToolNode` only runs calls it actually made, then rehydrates them afterward. Previously the rehydration could leave the restored AI message and its tool history inconsistent, so providers that require every tool call to have a matching result would break, and the agent saw an incorrect picture of what executed. ## Changes - `_restore_intercepted_tool_call_history` rebuilds the intercepted FE tool calls with synthetic `ToolMessage` results only for the restored model history (so providers that require every `tool_call` to have a result stay valid), and preserves the original AI message's `name`, `additional_kwargs`, and `response_metadata` on restore. - Tracks `original_tool_calls` in the CopilotKit private state so the original call set is restored exactly. ## Testing `uv run pytest tests/test_copilotkit_lg_middleware.py` — 68 passed, including new cases asserting the restored AI message keeps its tool-call ids, name, `additional_kwargs`, and `response_metadata`, and that tool results line up with their calls. Closes #4759 AI was used for assistance.
46 KiB
46 KiB