mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-17 12:22:21 +02:00
fix(agent): reserve artifact budget after scratch writes
This commit is contained in:
@@ -4268,7 +4268,7 @@ async def stream_preview(*, endpoint_url, model, messages, headers, turn_contrac
|
|||||||
yield event({'type': 'completion_recovery', 'reason': 'research_before_synthesis'})
|
yield event({'type': 'completion_recovery', 'reason': 'research_before_synthesis'})
|
||||||
if (
|
if (
|
||||||
required_artifacts
|
required_artifacts
|
||||||
and not successful_write
|
and not successful_artifact_write
|
||||||
and not artifact_write_phase
|
and not artifact_write_phase
|
||||||
and calls >= min(NATIVE_ARTIFACT_RESEARCH_LIMIT, tool_call_limit - 1)
|
and calls >= min(NATIVE_ARTIFACT_RESEARCH_LIMIT, tool_call_limit - 1)
|
||||||
):
|
):
|
||||||
|
|||||||
@@ -4551,13 +4551,19 @@ async def test_blocked_search_engine_browser_forces_native_web_search(monkeypatc
|
|||||||
async def test_native_stream_reserves_remaining_budget_for_required_artifact(monkeypatch):
|
async def test_native_stream_reserves_remaining_budget_for_required_artifact(monkeypatch):
|
||||||
import src.clean_agent_preview as module
|
import src.clean_agent_preview as module
|
||||||
|
|
||||||
payloads = [
|
payloads = [{"choices": [{"delta": {"tool_calls": [{
|
||||||
|
"index": 0, "id": "scratch-write",
|
||||||
|
"function": {"name": "python", "arguments": json.dumps({
|
||||||
|
"code": "open('/tmp_workspace/scratch.txt', 'w').write('notes')",
|
||||||
|
})},
|
||||||
|
}]}}]}]
|
||||||
|
payloads.extend([
|
||||||
{"choices": [{"delta": {"tool_calls": [{
|
{"choices": [{"delta": {"tool_calls": [{
|
||||||
"index": 0, "id": f"search-{index}",
|
"index": 0, "id": f"search-{index}",
|
||||||
"function": {"name": "web_search", "arguments": json.dumps({"query": f"topic {index}"})},
|
"function": {"name": "web_search", "arguments": json.dumps({"query": f"topic {index}"})},
|
||||||
}]}}]}
|
}]}}]}
|
||||||
for index in range(module.NATIVE_ARTIFACT_RESEARCH_LIMIT)
|
for index in range(module.NATIVE_ARTIFACT_RESEARCH_LIMIT - 1)
|
||||||
]
|
])
|
||||||
payloads.extend([
|
payloads.extend([
|
||||||
{"choices": [{"delta": {"tool_calls": [{
|
{"choices": [{"delta": {"tool_calls": [{
|
||||||
"index": 0, "id": "write",
|
"index": 0, "id": "write",
|
||||||
@@ -4594,7 +4600,7 @@ async def test_native_stream_reserves_remaining_budget_for_required_artifact(mon
|
|||||||
monkeypatch.setattr(module, "execute_tool_block", execute)
|
monkeypatch.setattr(module, "execute_tool_block", execute)
|
||||||
schemas = [
|
schemas = [
|
||||||
item for item in FUNCTION_TOOL_SCHEMAS
|
item for item in FUNCTION_TOOL_SCHEMAS
|
||||||
if item["function"]["name"] in {"web_search", "write_file"}
|
if item["function"]["name"] in {"python", "web_search", "write_file"}
|
||||||
]
|
]
|
||||||
contract = resolve_full_inventory_contract(schemas=schemas, policy=ToolPolicy())
|
contract = resolve_full_inventory_contract(schemas=schemas, policy=ToolPolicy())
|
||||||
raw = [chunk async for chunk in stream_preview(
|
raw = [chunk async for chunk in stream_preview(
|
||||||
@@ -4616,7 +4622,9 @@ async def test_native_stream_reserves_remaining_budget_for_required_artifact(mon
|
|||||||
and event.get("reason") == "artifact_write_budget_reserved"
|
and event.get("reason") == "artifact_write_budget_reserved"
|
||||||
)
|
)
|
||||||
assert recovery["calls_used"] == module.NATIVE_ARTIFACT_RESEARCH_LIMIT
|
assert recovery["calls_used"] == module.NATIVE_ARTIFACT_RESEARCH_LIMIT
|
||||||
assert [tool["function"]["name"] for tool in requests[12]["tools"]] == ["write_file"]
|
reserved_names = [tool["function"]["name"] for tool in requests[12]["tools"]]
|
||||||
|
assert "write_file" in reserved_names
|
||||||
|
assert "web_search" not in reserved_names
|
||||||
assert requests[12]["tool_choice"] == {
|
assert requests[12]["tool_choice"] == {
|
||||||
"type": "function", "function": {"name": "write_file"},
|
"type": "function", "function": {"name": "write_file"},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user