Skip to content

Encourage web search usage in GPT handler - #117

Merged
jamesoncollins merged 1 commit into
mainfrom
codex/improve-gpt-handler-web_search-usage
Jun 1, 2026
Merged

Encourage web search usage in GPT handler#117
jamesoncollins merged 1 commit into
mainfrom
codex/improve-gpt-handler-web_search-usage

Conversation

@jamesoncollins

Copy link
Copy Markdown
Owner

Motivation

  • Reduce incorrect reliance on model internal knowledge by steering the Responses API to prefer web searches for factual, time-sensitive, or entity-specific queries.

Description

  • Added a high-context WEB_SEARCH_TOOL, an allowed_tools WEB_SEARCH_TOOL_CHOICE, and expanded system guidance WEB_SEARCH_GUIDANCE to explicitly prefer web_search for facts and current information in handlers/gpt_handler.py.
  • Implemented should_force_web_search(user_input) heuristic to detect prompts that should require a web search on the first model turn (URLs, time-sensitive terms, recent years, and key prefixes).
  • Added build_response_create_kwargs(...) to centralize Responses API call construction and attach the tool_choice when force_web_search is true, and switched the handler to use this builder for initial and follow-up Responses calls.
  • Surface a Web Search Forced flag in the diagnostic footer for visibility and adjusted the web_search tool spec to use search_context_size: "high".
  • Added unit tests tests/test_gpt_handler.py covering the heuristic and kwargs builder.

Testing

  • Ran python -m py_compile handlers/gpt_handler.py tests/test_gpt_handler.py, which succeeded.
  • Ran python -m unittest tests/test_gpt_handler.py, which passed (all tests OK).
  • Ran full test discovery OPENAI_API_KEY="" python3 -m unittest discover -s tests -p "test_*.py", which failed due to external network/proxy errors contacting third-party services (yt-dlp, yfinance, etc.); these failures are environment/network-related and not caused by the GPT handler changes.

Codex Task

@jamesoncollins
jamesoncollins merged commit 36e9c2c into main Jun 1, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant