fix: ensure researcher agent uses web search tool instead of generating URLs (#702) (#704)

* fix: ensure researcher agent uses web search tool instead of generating URLs (#702)

- Add enforce_researcher_search configuration option (default: True) to control web search requirement
- Strengthen researcher prompts in both English and Chinese with explicit instructions to use web_search tool
- Implement validate_web_search_usage function to detect if web search tool was used during research
- Add validation logic that warns when researcher doesn't use web search tool
- Enhance logging for web search tools with special markers for easy tracking
- Skip validation during unit tests to avoid test failures
- Update _execute_agent_step to accept config parameter for proper configuration access

This addresses issue #702 where the researcher agent was generating URLs on its own instead of using the web search tool.

* fix: addressed the code review comment

* fix the unit test error and update the code
This commit is contained in:
Willem Jiang
2025-11-24 20:07:28 +08:00
committed by GitHub
parent cc9414f978
commit 478291df07
6 changed files with 84 additions and 11 deletions

View File

@@ -950,7 +950,7 @@ async def test_execute_agent_step_basic(mock_state_with_steps, mock_agent):
assert "messages" in result.update
assert "observations" in result.update
# The new observation should be appended
assert result.update["observations"][-1] == "result content"
assert result.update["observations"][-1] == "result content" + "\n\n[WARNING] This research was completed without using the web_search tool. " + "Please verify that the information provided is accurate and up-to-date." + "\n\n[VALIDATION WARNING] Researcher did not use the web_search tool as recommended."
# The step's execution_res should be updated
assert (
mock_state_with_steps["current_plan"].steps[1].execution_res
@@ -1004,7 +1004,7 @@ async def test_execute_agent_step_with_resources_and_researcher(mock_step):
result = await _execute_agent_step(state, agent, "researcher")
assert isinstance(result, Command)
assert result.goto == "research_team"
assert result.update["observations"][-1] == "resource result"
assert result.update["observations"][-1] == "resource result" + "\n\n[WARNING] This research was completed without using the web_search tool. " + "Please verify that the information provided is accurate and up-to-date." + "\n\n[VALIDATION WARNING] Researcher did not use the web_search tool as recommended."
@pytest.mark.asyncio
@@ -1124,7 +1124,7 @@ def patch_create_agent():
@pytest.fixture
def patch_execute_agent_step():
async def fake_execute_agent_step(state, agent, agent_type):
async def fake_execute_agent_step(state, agent, agent_type, config=None):
return "EXECUTED"
with patch(