Skip to content

Conversation

@OhYee
Copy link
Member

@OhYee OhYee commented Jan 21, 2026

  • 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

Thank you for creating a pull request to contribute to Serverless Devs agentrun-sdk-python code! Before you open the request please answer the following questions to help it be more easily integrated. Please check the boxes "[ ]" with "[x]" when done too.
Please select one of the PR types below to complete


Fix bugs

Bug detail

The specific manifestation of the bug or the associated issue.

Pull request tasks

  • Add test cases for the changes
  • Passed the CI test

Update docs

Reason for update

Why do you need to update your documentation?

Pull request tasks

  • Update Chinese documentation
  • Update English documentation

Add contributor

Contributed content

  • Code
  • Document

Content detail

if content_type == 'code' || content_type == 'document':
    please tell us `PR url`,like: https://github.com/Serverless-Devs/agentrun-sdk-python/pull/1
else:
    please describe your contribution in detail

Others

Reason for update

Why do you need to update your documentation?

Copy link
Contributor

Copilot AI left a 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_events from a static-style API to an instance method, introduce has_on_chat_model_stream to gate on_chain_stream handling, 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.

Comment on lines 438 to 441
# 事件转换器(静态方法)
# =========================================================================

@staticmethod
def _convert_stream_updates_event(
Copy link

Copilot AI Jan 21, 2026

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.

Copilot uses AI. Check for mistakes.
@OhYee OhYee force-pushed the fix-langchain-message-duplication branch from 8a8b3ba to 7bd1fbc Compare January 21, 2026 06:20
- 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>
@OhYee OhYee force-pushed the fix-langchain-message-duplication branch from 7bd1fbc to 63d41ce Compare January 21, 2026 06:21
@OhYee OhYee merged commit 2950133 into main Jan 21, 2026
2 checks passed
@OhYee OhYee deleted the fix-langchain-message-duplication branch January 21, 2026 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants