Skip to content

Commit 2a04b26

Browse files
committed
refactor(langgraph): migrate to AgentRunConverter class and enhance event handling
The AgentRunConverter has been updated to use a class-based approach for better state management. The conversion functions are now static methods of the AgentRunConverter class, providing improved tool call ID consistency and event sequencing. The deprecated conversion functions have been removed from the public API. The AGUI protocol handler has been enhanced with copilotkit compatibility mode to handle sequential tool calls and improved event ordering. New protocol configuration options have been added to support these features. Several tests have been updated to reflect these changes, including new test files for comprehensive event handling coverage. feat: add AGUIProtocolConfig with copilotkit compatibility option refactor: migrate convert functions to AgentRunConverter static methods refactor: enhance AGUI protocol handler with improved event sequencing test: add comprehensive tests for AgentRunConverter and AGUI protocol 重构 langgraph 事件转换器以使用 AgentRunConverter 类并增强事件处理 AgentRunConverter 已更新为使用基于类的方法,以实现更好的状态管理。转换函数现在是 AgentRunConverter 类的静态方法,提供改进的工具调用 ID 一致性和事件排序。已从公共 API 中删除了已弃用的转换函数。 AGUI 协议处理器已通过 copilotkit 兼容模式增强,以处理顺序工具调用和改进的事件排序。已添加新的协议配置选项以支持这些功能。 已更新多个测试以反映这些更改,包括为全面事件处理覆盖范围添加的新测试文件。 新功能: 添加带有 copilotkit 兼容性选项的 AGUIProtocolConfig 重构: 将转换函数迁移到 AgentRunConverter 静态方法 重构: 使用改进的事件排序增强 AGUI 协议处理器 测试: 为 AgentRunConverter 和 AGUI 协议添加全面测试 Change-Id: I9e73626b3bf17d6d5af90038d0f2eb229f93dee6 Signed-off-by: OhYee <oyohyee@oyohyee.com>
1 parent 568557b commit 2a04b26

26 files changed

+10160
-2584
lines changed

agentrun/integration/langchain/__init__.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,14 @@
1616
- agent.astream(input, stream_mode="updates") - 异步按节点输出
1717
"""
1818

19-
from agentrun.integration.langgraph.agent_converter import ( # 向后兼容
19+
from agentrun.integration.langgraph.agent_converter import (
2020
AgentRunConverter,
21-
AguiEventConverter,
22-
convert,
23-
to_agui_events,
24-
)
21+
) # 向后兼容
2522

2623
from .builtin import model, sandbox_toolset, toolset
2724

2825
__all__ = [
2926
"AgentRunConverter",
30-
"AguiEventConverter", # 向后兼容
31-
"to_agui_events", # 向后兼容
32-
"convert", # 向后兼容
3327
"model",
3428
"toolset",
3529
"sandbox_toolset",

agentrun/integration/langgraph/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,25 @@
1010
... for item in converter.convert(event):
1111
... yield item
1212
13+
或使用静态方法(无状态):
14+
15+
>>> from agentrun.integration.langgraph import AgentRunConverter
16+
>>>
17+
>>> async for event in agent.astream_events(input_data, version="v2"):
18+
... for item in AgentRunConverter.to_agui_events(event):
19+
... yield item
20+
1321
支持多种调用方式:
1422
- agent.astream_events(input, version="v2") - 支持 token by token
1523
- agent.stream(input, stream_mode="updates") - 按节点输出
1624
- agent.astream(input, stream_mode="updates") - 异步按节点输出
1725
"""
1826

19-
from .agent_converter import AguiEventConverter # 向后兼容
20-
from .agent_converter import AgentRunConverter, convert, to_agui_events
27+
from .agent_converter import AgentRunConverter
2128
from .builtin import model, sandbox_toolset, toolset
2229

2330
__all__ = [
2431
"AgentRunConverter",
25-
"AguiEventConverter", # 向后兼容
26-
"to_agui_events", # 向后兼容
27-
"convert", # 向后兼容
2832
"model",
2933
"toolset",
3034
"sandbox_toolset",

0 commit comments

Comments
 (0)