MCPcopy Create free account
hub / github.com/OpenDCAI/Paper2Any / test_react_mode_trajectory

Function test_react_mode_trajectory

tests/test_trajectory.py:94–145  ·  view source on GitHub ↗

测试 ReAct 模式轨迹

()

Source from the content-addressed store, hash-verified

92 log.info(f"✓ 已导出: {filepath}")
93
94def test_react_mode_trajectory():
95 """测试 ReAct 模式轨迹"""
96 log.info("=" * 60)
97 log.info("测试 2: ReAct 模式轨迹")
98 log.info("=" * 60)
99
100 manager = TrajectoryManager()
101 manager.start_recording(inputs={"query": "计算 123 + 456"})
102
103 collector = manager.get_collector()
104
105 # ReAct 循环
106 for i in range(2):
107 collector.on_node_start(f"agent_step_{i}", StepRole.AGENT.value)
108
109 # 思考
110 collector.on_thought(f"我需要使用计算器工具来计算 123 + 456")
111
112 # 动作
113 collector.on_action(
114 action_type=ActionType.TOOL_CALL.value,
115 action_payload={
116 "tool_name": "calculator",
117 "tool_args": {"expression": "123 + 456"}
118 }
119 )
120
121 # 观察
122 collector.on_observation("计算结果: 579")
123
124 collector.on_node_end(output={"result": 579})
125
126 # 创建状态
127 request = DFRequest(target="计算 123 + 456")
128 final_state = DFState(request=request)
129 final_state.agent_results = {
130 "agent": {"results": {"answer": "579"}}
131 }
132
133 trajectory = manager.stop_recording(final_state, "react_workflow")
134
135 # 验证 ReAct 特征
136 assert any(step.thought for step in trajectory.steps)
137 assert any(step.observation for step in trajectory.steps)
138 assert trajectory.mode == "react"
139
140 log.info(f"✓ 模式: {trajectory.mode}")
141 log.info(f"✓ 包含思考: {any(step.thought for step in trajectory.steps)}")
142
143 # 导出 SFT 格式
144 filepath = manager.export(trajectory, format="sft")
145 log.info(f"✓ 已导出 SFT 格式: {filepath}")
146
147def test_batch_export():
148 """测试批量导出"""

Callers 1

mainFunction · 0.85

Calls 12

start_recordingMethod · 0.95
get_collectorMethod · 0.95
stop_recordingMethod · 0.95
exportMethod · 0.95
TrajectoryManagerClass · 0.90
DFRequestClass · 0.90
DFStateClass · 0.90
on_node_startMethod · 0.80
on_thoughtMethod · 0.80
on_actionMethod · 0.80
on_observationMethod · 0.80
on_node_endMethod · 0.80

Tested by

no test coverage detected