Persist active run event history
This commit is contained in:
@@ -285,6 +285,52 @@ class AgentRuntimeTests(unittest.TestCase):
|
||||
self.assertGreaterEqual(len(result.transcript), 5)
|
||||
self.assertGreaterEqual(len(result.file_history), 0)
|
||||
|
||||
def test_agent_persists_max_turns_explanation_after_tool_result(self) -> None:
|
||||
responses = [
|
||||
{
|
||||
'choices': [
|
||||
{
|
||||
'message': {
|
||||
'role': 'assistant',
|
||||
'content': '我先读取文件。',
|
||||
'tool_calls': [
|
||||
{
|
||||
'id': 'call_1',
|
||||
'type': 'function',
|
||||
'function': {
|
||||
'name': 'read_file',
|
||||
'arguments': '{"path": "hello.txt"}',
|
||||
},
|
||||
}
|
||||
],
|
||||
},
|
||||
'finish_reason': 'tool_calls',
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
workspace = Path(tmp_dir)
|
||||
(workspace / 'hello.txt').write_text('hello world\n', encoding='utf-8')
|
||||
with patch(
|
||||
'src.openai_compat.request.urlopen',
|
||||
side_effect=make_urlopen_side_effect(responses),
|
||||
):
|
||||
agent = LocalCodingAgent(
|
||||
model_config=ModelConfig(
|
||||
model='Qwen/Qwen3-Coder-30B-A3B-Instruct',
|
||||
base_url='http://127.0.0.1:8000/v1',
|
||||
),
|
||||
runtime_config=AgentRuntimeConfig(cwd=workspace, max_turns=1),
|
||||
)
|
||||
result = agent.run('Inspect hello.txt')
|
||||
|
||||
self.assertEqual(result.stop_reason, 'max_turns')
|
||||
self.assertIn('最大步骤上限', result.final_output)
|
||||
self.assertEqual(result.transcript[-1]['role'], 'assistant')
|
||||
self.assertEqual(result.transcript[-1]['stop_reason'], 'max_turns')
|
||||
self.assertIn('最大步骤上限', result.transcript[-1]['content'])
|
||||
|
||||
def test_agent_stops_after_data_agent_goal_requires_review(self) -> None:
|
||||
responses = [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user