Skip to content

Add opt-in SpecStream search for OfficeQA rollouts - #514

Open
SpecStream (Specstreamai) wants to merge 1 commit into
microsoft:mainfrom
Specstreamai:feat/officeqa-specstream-search
Open

SpecStream (Specstreamai) wants to merge 1 commit into
microsoft:mainfrom
Specstreamai:feat/officeqa-specstream-search

Conversation

@Specstreamai

Copy link
Copy Markdown

Adds env.search_mode=specstream, an opt-in web search mode for the OfficeQA controller search loop. It has the same shape as the Keenable mode from #368, and it includes the #381 follow-ups from the start. It runs only when you select it and set SPECSTREAM_API_KEY. The default and auto stay offline, and the other modes do not change.

I work on SpecStream. SpecStream runs this API. Search costs $1 per 1,000 fast searches, billed to the key's account. This PR always sends speed=fast.

This is search only. The OfficeQA loop has no page reader slot, so there is no extract call.

Conditions from #352

  • Opt-in only: _normalize_search_mode returns specstream only when it is spelled out. The default, auto and unknown values stay offline. Tests: test_auto_and_other_modes_never_select_specstream, and test_fresh_config_never_calls_specstream. In that test a key is set and the model asks for search under auto and offline, and the mock transport must see zero requests.
  • No bundled key, credential or account: SPECSTREAM_API_KEY is read from the environment only. If it is missing or blank, _run_custom_search_process fails the rollout before the first model call. specstream_search also refuses to run without it, before any request.
  • No new dependency: plain JSON over the core httpx. pyproject.toml, lockfiles and CI do not change.
  • Service errors fail the rollout, no fallback: non-200 responses, invalid JSON, a body without the {"data": {"sources": [...]}} envelope, bad evidence and timeouts all raise. The 401, 402, 429 and 503 tests patch the custom, Parallel and Keenable paths to fail if reached.
  • Redirects are not followed: follow_redirects=False. A followed 307 would resend the query body to another origin, and to a same-origin target it would also resend the bearer key. A test returns a 307 and checks that one request was made.
  • Data boundary: "SpecStream search (opt-in)" in docs/reference/config.md lists what a request carries: a JSON body with q, num (env.search_max_num_results) and "speed": "fast", the key in an Authorization: Bearer header, and SkillOpt's User-Agent. The task question is not sent. The section says a generated query can still repeat text from the question, the document context or the skill. It has the comparability caveat about the paper's Google-backed search setting.
  • Neutral wording: the docs and CHANGELOG describe the mode, the endpoint, the data sent and billing only. There are no performance or quality claims.
  • Inert HTTP boundary in tests: tests/test_officeqa_specstream_search.py (58 tests) runs the client against httpx.MockTransport and asserts the exact request. Nothing reaches the live service.
  • One focused PR: five files, the same set as Add opt-in keyless Keenable search for OfficeQA rollouts #368.

Follow-ups from #368 and #381, built in

  1. Key in error text. The client reads error.message from {"error": {...}}, or else the raw body. It replaces the key with [redacted] before the 1000 character cut. Tests cover a key echoed in error.message (checked in fail_reason and conversation.json), one in a plain text body, and one straddling the cut.
  2. Round deadline. One search_timeout_seconds deadline covers all queries of a round. time.monotonic() > deadline is checked again after each response, so a slow last query fails the round too.
  3. Tests that catch regressions. I changed the code one way at a time and checked that each change fails at least one test:
    • follow_redirects=True
    • no openai_chat/qwen_chat backend check
    • invalid JSON read as no results
    • no key redaction
    • no deadline check after the response
    • auto or offline selecting SpecStream
    • no missing key check, in the rollout or in the client
    • payload["sources"] read instead of payload["data"]["sources"]
    • the task question added to the request body
    • speed other than fast
    • the raw body used instead of error.message
  4. Minor. search_max_num_results is per query here, as for Keenable, so the config table notes 16 results per round with the defaults. It is capped at 50. A missing or non-string title falls back to the URL. A source without a url is skipped. An empty snippet falls back to the joined highlights.

Files

  • skillopt/envs/officeqa/specstream_search.py: the client. It mirrors keenable_search.py: one keyed POST per query, the same rendering, the same deadline and the same error rules.
  • skillopt/envs/officeqa/rollout.py: the specstream mode constant, its _normalize_search_mode branch, the four controller mode sets, the missing key check and the dispatch branch.
  • docs/reference/config.md: the table rows and the data boundary section.
  • CHANGELOG.md: one entry under Unreleased.
  • tests/test_officeqa_specstream_search.py: the tests.

Tested

All commands ran with SPECSTREAM_API_KEY unset.

  • python -m pytest -q tests/test_officeqa_specstream_search.py tests/test_officeqa_keenable_search.py tests/test_officeqa_parallel_search.py: 132 passed on Python 3.10, 3.11 and 3.12 (.[dev,parallel]).
  • Full python -m pytest -q: 2688 passed, 11 skipped, 4 xfailed on Python 3.10, 3.11 and 3.12 (.[dev,parallel], with SKILLOPT_TEST_REAL_OPENCODE=0 and SKILLOPT_TEST_REAL_OPENCODE_SOURCE=0 as in CI).
  • python -m mkdocs build --strict: passes.
  • ruff check on the three changed Python files: clean.

No live SpecStream or model call was made.

To turn it off, remove env.search_mode=specstream or unset SPECSTREAM_API_KEY. To remove it, revert this one commit.

env.search_mode=specstream runs the OfficeQA controller search loop on
SpecStream's web search API, beside the Parallel and Keenable modes. It is
never selected automatically: the default and auto stay offline.

Each generated query is one POST to /v1/web-search with q, num and
speed=fast as JSON, and SPECSTREAM_API_KEY in an Authorization: Bearer
header. The task question is not sent. No key, credential or account is
bundled; a missing key fails the rollout before the first model call and
before any request. It uses the core httpx dependency, so no extra is
needed.

Service errors fail the rollout without falling back, with the API's
error.message and the key redacted before the text is cut. Redirects are
not followed. One deadline (search_timeout_seconds) covers all queries of
a round and is checked again after each response.

The config reference gets a data-boundary section listing exactly what a
request carries, plus the comparability caveat about the paper's
Google-backed search setting.

This branch has not been deployed

No deployments
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.

1 participant