Skip to content

feat: re-add web search with robust dual-source routing (#283) - #284

Merged
ASuresh0524 merged 4 commits into
mainfrom
fix/react-dual-source-283
Mar 30, 2026
Merged

feat: re-add web search with robust dual-source routing (#283)#284
ASuresh0524 merged 4 commits into
mainfrom
fix/react-dual-source-283

Conversation

@ASuresh0524

Copy link
Copy Markdown
Collaborator

Summary

Re-introduces web search (Serper API) and page fetching (Jina Reader) to the ReAct agent, replacing the reverted PR #232 with robust error handling and dual-source routing.

Key improvements over the original:

  • Dynamic prompt adapts tool list based on whether SERPER_API_KEY is configured
  • Graceful fallback when web_search is called without an API key (guides LLM to use leann_search)
  • Error responses from Serper (401, rate limits, etc.) handled without crashing the agent
  • visit_page errors (404, network failures) caught and surfaced as observations
  • search_history entries now include a source field ("local" or "web") for debugging
  • CLI gains --serper-api-key and --jina-api-key flags

Files changed:

  • packages/leann-core/src/leann/web_search.py — re-added with typo fix
  • packages/leann-core/src/leann/react_agent.py — dual-source routing, dynamic prompts, error handling
  • packages/leann-core/src/leann/cli.py — new CLI args, source tags in search history display
  • tests/test_react_dual_source.py — 13 tests covering all scenarios from issue ReAct agent: verify dual-source routing (local vs web) end-to-end #283

Test plan

  • Prompt includes all 3 tools when Serper key is present
  • Prompt shows only leann_search when no key
  • Local-only routing works correctly
  • Web-only routing works correctly (mocked)
  • Mixed routing (local → web) works correctly
  • Web results properly formatted as observations
  • visit_page content truncated to 15k chars
  • Local search results include scores
  • No API key → graceful fallback message, no crash
  • Invalid API key → error handled, agent continues
  • 404 page → error string, agent continues
  • Max iterations with mixed sources → still produces answer
  • search_history entries include source field

All 13 tests pass locally (193s).

Closes #283

Re-introduces web search (Serper API) and page fetching (Jina Reader)
to the ReAct agent with improvements over the reverted PR #232:

- Dynamic prompt adapts tool list based on API key availability
- Graceful fallback when web_search is called without SERPER_API_KEY
- Error responses from Serper (401, etc.) handled without crashing
- visit_page errors (404, network) caught and surfaced to the LLM
- search_history entries include 'source' field (local/web)
- CLI gains --serper-api-key and --jina-api-key flags
- 13 comprehensive tests covering all routing and edge case scenarios

Closes #283

Made-with: Cursor
@ASuresh0524

Copy link
Copy Markdown
Collaborator Author

if passes, this is good

@ASuresh0524
ASuresh0524 merged commit f2b446f into main Mar 30, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReAct agent: verify dual-source routing (local vs web) end-to-end

1 participant