mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-09 00:12:21 +02:00
Bound research breadth recovery by attempts and completion state
This commit is contained in:
@@ -3939,6 +3939,7 @@ async def stream_preview(*, endpoint_url, model, messages, headers, turn_contrac
|
|||||||
empty_search_intents = {}
|
empty_search_intents = {}
|
||||||
successful_search_intents = []
|
successful_search_intents = []
|
||||||
web_search_attempts = 0
|
web_search_attempts = 0
|
||||||
|
breadth_recovery_attempted = False
|
||||||
empty_web_search_attempts = 0
|
empty_web_search_attempts = 0
|
||||||
successful_web_searches = 0
|
successful_web_searches = 0
|
||||||
successful_web_retrievals = 0
|
successful_web_retrievals = 0
|
||||||
@@ -4276,8 +4277,12 @@ async def stream_preview(*, endpoint_url, model, messages, headers, turn_contrac
|
|||||||
if (
|
if (
|
||||||
broad_current_web_request(direct_user_text)
|
broad_current_web_request(direct_user_text)
|
||||||
and successful_web_searches == 1
|
and successful_web_searches == 1
|
||||||
|
and web_search_attempts < 2
|
||||||
|
and not breadth_recovery_attempted
|
||||||
|
and not search_completion_attempted
|
||||||
and round_number < round_limit
|
and round_number < round_limit
|
||||||
):
|
):
|
||||||
|
breadth_recovery_attempted = True
|
||||||
force_web_search_next_round = True
|
force_web_search_next_round = True
|
||||||
replace_streamed_draft_on_finish = True
|
replace_streamed_draft_on_finish = True
|
||||||
history.pop()
|
history.pop()
|
||||||
|
|||||||
@@ -1188,7 +1188,8 @@ async def test_stream_bounds_research_to_two_searches_fetch_then_synthesis(monke
|
|||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.parametrize('embedded_article', [False, True])
|
@pytest.mark.parametrize('embedded_article', [False, True])
|
||||||
async def test_stream_retries_an_obviously_truncated_broad_web_answer(monkeypatch, embedded_article):
|
@pytest.mark.parametrize('empty_second_search', [False, True])
|
||||||
|
async def test_stream_retries_an_obviously_truncated_broad_web_answer(monkeypatch, embedded_article, empty_second_search):
|
||||||
"""Broad current research expands, retrieves evidence, then synthesizes."""
|
"""Broad current research expands, retrieves evidence, then synthesizes."""
|
||||||
import src.clean_agent_preview as module
|
import src.clean_agent_preview as module
|
||||||
|
|
||||||
@@ -1227,7 +1228,7 @@ async def test_stream_retries_an_obviously_truncated_broad_web_answer(monkeypatc
|
|||||||
)}}]},
|
)}}]},
|
||||||
]
|
]
|
||||||
article = packets[-1]['choices'][0]['delta']['content']
|
article = packets[-1]['choices'][0]['delta']['content']
|
||||||
if embedded_article:
|
if embedded_article or empty_second_search:
|
||||||
packets.pop(3)
|
packets.pop(3)
|
||||||
packets = iter(packets)
|
packets = iter(packets)
|
||||||
requests = []
|
requests = []
|
||||||
@@ -1249,7 +1250,14 @@ async def test_stream_retries_an_obviously_truncated_broad_web_answer(monkeypatc
|
|||||||
requests.append(kwargs['json'])
|
requests.append(kwargs['json'])
|
||||||
return Response(next(packets))
|
return Response(next(packets))
|
||||||
|
|
||||||
|
search_calls = 0
|
||||||
|
|
||||||
async def execute(block, **kwargs):
|
async def execute(block, **kwargs):
|
||||||
|
nonlocal search_calls
|
||||||
|
if block.tool_type == 'web_search':
|
||||||
|
search_calls += 1
|
||||||
|
if empty_second_search and search_calls == 2:
|
||||||
|
return block.tool_type, {'output': 'No matching results', 'exit_code': 0, 'evidence_status': 'empty'}
|
||||||
return block.tool_type, {
|
return block.tool_type, {
|
||||||
'output': '[1] AI News\n https://example.org/ai-news' + (
|
'output': '[1] AI News\n https://example.org/ai-news' + (
|
||||||
'\n[CONTENT 1] From: https://example.org/ai-news\nTitle: Report\n-----\n'
|
'\n[CONTENT 1] From: https://example.org/ai-news\nTitle: Report\n-----\n'
|
||||||
@@ -1274,11 +1282,11 @@ async def test_stream_retries_an_obviously_truncated_broad_web_answer(monkeypatc
|
|||||||
)]
|
)]
|
||||||
events = [json.loads(chunk[6:]) for chunk in raw if '[DONE]' not in chunk]
|
events = [json.loads(chunk[6:]) for chunk in raw if '[DONE]' not in chunk]
|
||||||
|
|
||||||
assert len(requests) == (4 if embedded_article else 5)
|
assert len(requests) == (4 if embedded_article or empty_second_search else 5)
|
||||||
assert requests[2]['tool_choice'] == {
|
assert requests[2]['tool_choice'] == {
|
||||||
'type': 'function', 'function': {'name': 'web_search'},
|
'type': 'function', 'function': {'name': 'web_search'},
|
||||||
}
|
}
|
||||||
if not embedded_article:
|
if not embedded_article and not empty_second_search:
|
||||||
assert requests[3]['tool_choice'] == {
|
assert requests[3]['tool_choice'] == {
|
||||||
'type': 'function', 'function': {'name': 'web_fetch'},
|
'type': 'function', 'function': {'name': 'web_fetch'},
|
||||||
}
|
}
|
||||||
@@ -1289,6 +1297,7 @@ async def test_stream_retries_an_obviously_truncated_broad_web_answer(monkeypatc
|
|||||||
and event.get('reason') == 'insufficient_research_breadth'
|
and event.get('reason') == 'insufficient_research_breadth'
|
||||||
for event in events
|
for event in events
|
||||||
)
|
)
|
||||||
|
assert sum(event.get('reason') == 'insufficient_research_breadth' for event in events) == 1
|
||||||
assert any(
|
assert any(
|
||||||
event.get('type') == 'final_response'
|
event.get('type') == 'final_response'
|
||||||
and 'fuller evidence-based briefing' in event.get('content', '')
|
and 'fuller evidence-based briefing' in event.get('content', '')
|
||||||
|
|||||||
Reference in New Issue
Block a user