-
Notifications
You must be signed in to change notification settings - Fork 4
fix: resolve message duplication in LangChain integration #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR makes the LangGraph/LangChain → AG-UI conversion stateful per converter instance to avoid duplicate message emission across different event formats, and adds comprehensive integration and compatibility tests (including Python 3.10 vs 3.12 event shapes and multiple LangChain invoke patterns). It also updates AG-UI and OpenAI-protocol expectations in tests to match the new, de-duplicated streaming behavior.
Changes:
- Convert
AgentRunConverter.to_agui_eventsfrom a static-style API to an instance method, introducehas_on_chat_model_streamto gateon_chain_streamhandling, and adjust internal conversion helpers accordingly. - Update existing integration tests to construct a converter instance and expand coverage with new LangChain/LangGraph invoke-mode tests and Python 3.10/3.12 event-shape fixtures.
- Align e2e expectations (AG-UI and OpenAI streaming/non-streaming) with the new tool-call and text-message event ordering to ensure no duplicated tool or text outputs.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| agentrun/integration/langgraph/agent_converter.py | Makes the converter fully instance-based, adds has_on_chat_model_stream to suppress duplicate on_chain_stream handling, and wires all internal converters through self. |
| tests/unittests/integration/test_langgraph_to_agent_event.py | Switches tests to use AgentRunConverter() instances instead of the previous static-style to_agui_events calls. |
| tests/unittests/integration/test_langgraph_events.py | Same instance-based adjustment for LangGraph-focused converter tests. |
| tests/unittests/integration/test_langchain_convert.py | Updates existing LangChain conversion tests to the instance API and ensures streaming behavior assertions use a per-test converter instance. |
| tests/unittests/integration/test_agent_converter.py | Mirrors the instance-API refactor across the broader converter test suite. |
| tests/unittests/integration/langchain/test_convert.py | New unit tests that feed recorded 3.10 and 3.12 LangGraph/LangChain event sequences through AgentRunConverter.convert and assert de-duplicated final text. |
| tests/unittests/integration/langchain/test_agent_invoke_methods.py | New integration tests that spin up a mock OpenAI-compatible backend and verify AG-UI/OpenAI outputs across astream_events, astream, stream, invoke, and ainvoke for both plain text and tool-call flows. |
| tests/unittests/integration/conftest.py | Adjusts the shared convert_and_collect helper to use a converter instance per call, consistent with the new API. |
| tests/e2e/integration/langchain/test_agent_invoke_methods.py | Updates end-to-end AG-UI and OpenAI expectation fixtures to the new tool-call/text-message ordering and adds Python-version–specific conversion checks similar to the unit tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/unittests/integration/langchain/test_agent_invoke_methods.py
Outdated
Show resolved
Hide resolved
| # 事件转换器(静态方法) | ||
| # ========================================================================= | ||
|
|
||
| @staticmethod | ||
| def _convert_stream_updates_event( |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section header still labels the following helpers as "静态方法" and the examples further down the file still show calling AgentRunConverter.to_agui_events(event) on the class, but to_agui_events has been converted to an instance method. To avoid confusing users, please update the comment and examples to describe and demonstrate instance-based usage (for example, via a converter instance) instead of static calls.
8a8b3ba to
7bd1fbc
Compare
- Convert AgentRunConverter.to_agui_events() from static to instance method calls in tests - Add comprehensive integration tests for LangChain/LangGraph invoke methods - Add conversion tests for Python 3.10 and 3.12 compatibility - Ensure proper state management to prevent duplicate message output in streaming scenarios Change-Id: I113237eeb2cb73bf0e7b00e9e55882f2f32e6c10 Signed-off-by: OhYee <oyohyee@oyohyee.com>
7bd1fbc to
63d41ce
Compare
Change-Id: I113237eeb2cb73bf0e7b00e9e55882f2f32e6c10
Fix bugs
Bug detail
Pull request tasks
Update docs
Reason for update
Pull request tasks
Add contributor
Contributed content
Content detail
Others
Reason for update