trace artifact phase provider contract

This commit is contained in:
pewdiepie-archdaemon
2026-09-18 15:27:11 +00:00
parent 011daf9c38
commit afbab148f2
2 changed files with 21 additions and 0 deletions
+11
View File
@@ -4436,6 +4436,17 @@ async def stream_preview(*, endpoint_url, model, messages, headers, turn_contrac
streamed_round_text = False
request = search_tool_choice_request(request)
request = provider_compatible_tool_choice_request(request, model)
if artifact_write_phase and not successful_artifact_write:
yield event({
'type': 'provider_request_contract',
'round': round_number,
'artifact_write_phase': True,
'offered_tools': [
schema.get('function', {}).get('name')
for schema in request.get('tools', [])
],
'tool_choice': request.get('tool_choice'),
})
async with preview_model_response(client, endpoint_url, headers, request, context_recovery) as response:
response.raise_for_status()
async for line in response.aiter_lines():
+10
View File
@@ -4703,6 +4703,16 @@ async def test_native_stream_reserves_remaining_budget_for_required_artifact(mon
and event.get("reason") == "artifact_write_budget_reserved"
)
assert recovery["calls_used"] == module.NATIVE_ARTIFACT_RESEARCH_LIMIT
request_contract = next(
event for event in events
if event.get("type") == "provider_request_contract"
and event.get("artifact_write_phase") is True
)
assert "write_file" in request_contract["offered_tools"]
assert "web_search" not in request_contract["offered_tools"]
assert request_contract["tool_choice"] == {
"type": "function", "function": {"name": "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