Improve agent long-task resilience
This commit is contained in:
@@ -65,6 +65,48 @@ class AgentSkillTests(unittest.TestCase):
|
||||
],
|
||||
)
|
||||
|
||||
def test_truncated_workspace_answer_falls_back_to_each_search_excerpt(self) -> None:
|
||||
task = (
|
||||
"ابحث في ملفات مساحة العمل للعثور على: "
|
||||
"1) heartbeat، 2) مهلة Flutter، 3) مهلة استدعاء النموذج، ثم لخّص."
|
||||
)
|
||||
queries = _explicit_workspace_search_queries(task)
|
||||
matches = {
|
||||
queries[0]: [("app/main.py", "50: AGENT_STREAM_HEARTBEAT_SECONDS = 15.0")],
|
||||
queries[1]: [
|
||||
(
|
||||
"flutter_app/lib/core/network/api_repository.dart",
|
||||
"570: timeout(const Duration(minutes: 10))",
|
||||
)
|
||||
],
|
||||
queries[2]: [("app/main.py", "2272: timeout_seconds=600.0")],
|
||||
}
|
||||
incomplete = {"choices": [{"message": {"content": "إليك النتائج:\n\n1. **"}}]}
|
||||
with (
|
||||
patch(
|
||||
"app.main.workspace.retrieve",
|
||||
side_effect=lambda query, _root, limit=3: matches[query],
|
||||
) as search,
|
||||
patch("app.main.get_completion", new=AsyncMock(return_value=incomplete)),
|
||||
):
|
||||
result = asyncio.run(
|
||||
_execute_agent(
|
||||
AgentRequest(
|
||||
task=task,
|
||||
workspace_path=self.workspace,
|
||||
skill_id="code_explain",
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
self.assertEqual(search.call_count, 3)
|
||||
self.assertIn("توقفت صياغة النموذج قبل اكتمال الجواب", result["result"])
|
||||
self.assertIn("AGENT_STREAM_HEARTBEAT_SECONDS = 15.0", result["result"])
|
||||
self.assertIn("timeout(const Duration(minutes: 10))", result["result"])
|
||||
self.assertIn("timeout_seconds=600.0", result["result"])
|
||||
self.assertIn("app/main.py", result["files"])
|
||||
self.assertIn("flutter_app/lib/core/network/api_repository.dart", result["files"])
|
||||
|
||||
def test_numbered_workspace_searches_are_prefetched_separately(self) -> None:
|
||||
task = (
|
||||
"استخدم أداة البحث في مساحة العمل ثلاث مرات منفصلة للعثور على: "
|
||||
|
||||
Reference in New Issue
Block a user