Skip to content

feat(xai): add x_search tool — search X via xAI Responses API#12528

Closed
Julientalbot wants to merge 2 commits into
NousResearch:mainfrom
Julientalbot:jt/xai-x-search
Closed

feat(xai): add x_search tool — search X via xAI Responses API#12528
Julientalbot wants to merge 2 commits into
NousResearch:mainfrom
Julientalbot:jt/xai-x-search

Conversation

@Julientalbot

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds a new standalone x_search tool that queries X (Twitter) posts using xAI's built-in x_search Responses API tool. This is the smallest, most self-contained chunk extracted from Jaaneek's PR #10600 / Teknium's split PR #10786 and ships cleanly against current main.

Related

Type of Change

  • 🐛 Bug fix
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (6 new tests)
  • ♻️ Refactor
  • 🎯 New skill

Why standalone

PR #10786 bundles x_search with video_generation and image_generation xAI backend changes (~2k LOC across 8 files). Its CI currently fails on a mix of unrelated test drift (Discord/Telegram harness) and xai_media mock assertions that need rebasing against evolving main. Shipping x_search alone:

  • Unblocks 351 LOC of new functionality without waiting for the full media tooling rebase.
  • Keeps the review surface small (4 files, +566/-1).
  • Preserves authorship credit for Jaaneek and Teknium via Co-authored-by trailers.

Media tools (video_generation_tool.py, image_generation_tool.py xAI backend) intentionally not in this PR — happy to send follow-ups once #10786 lands or once the community decides on its rebase path.

Changes

File Change
tools/x_search_tool.py New — 351 LOC, tool implementation
tests/tools/test_x_search_tool.py New — 207 LOC, 6 tests
toolsets.py Add x_search to _HERMES_CORE_TOOLS + new TOOLSETS entry. browser_cdp preserved (unlike the #10786 diff which accidentally dropped it — that entry was added to main after the PR branched).
hermes_cli/tools_config.py Add x_search entry to CONFIGURABLE_TOOLSETS

How to test

Requires XAI_API_KEY in ~/.hermes/.env (get one at https://console.x.ai/).

source venv/bin/activate
pytest tests/tools/test_x_search_tool.py -v
# 6 passed

End-to-end:

> use x_search to find posts about "grok 4.20 reasoning"

Verify the response includes an answer with citations to X posts.

hermes tools configurator should show "🐦 X (Twitter) Search" entry.

Configuration

Optional x_search section in user config:

x_search:
  model: grok-4.20-reasoning    # default
  timeout_seconds: 180          # default (min 30)
  retries: 2                    # default

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this feature (no unrelated commits)
  • I've run pytest and all relevant tests pass (x_search: 6/6, toolsets: 126/126, tools_config: 91/91)
  • I've added tests for the new tool
  • I've tested on my platform: macOS (darwin arm64, Python 3.11)

Documentation & Housekeeping

  • I've updated relevant documentation — intentional follow-up PR in website/docs/ covering x_search + the feat(xai): upgrade to Responses API, add TTS provider #10783 xAI additions
  • I've updated hermes_cli/tools_config.py for the new toolset entry
  • I've considered cross-platform impact — pure HTTP + stdlib, no platform-specific code
  • I've added a tool schema description for x_search

Co-authored-by: Jaaneek Jaaneek@users.noreply.github.com
Co-authored-by: Teknium 127238744+teknium1@users.noreply.github.com

Extracted and standalone-ified from Jaaneek's PR NousResearch#10600 / Teknium's split
PR NousResearch#10786. The x_search tool is the smallest, most self-contained piece
of that work and doesn't depend on image/video generation changes, so it
ships cleanly on its own while NousResearch#10786 rebases.

## What

New tool `x_search` backed by xAI's built-in `x_search` Responses API
tool. Searches X (Twitter) posts with configurable model, timeout, retry
count, handle filtering, and citation extraction.

## Why split

PR NousResearch#10786 bundles x_search + video_generation + image_generation xAI
backend in ~2k lines across 8 files. Tests on that branch currently
regress (mostly unrelated flake from Discord/Telegram suites on CI, plus
xai_media asserts drifted vs evolving main). Shipping x_search alone
gets 351 LOC of production + 207 LOC of tests into main while the heavier
media pieces are rebased. Co-authored credit preserved.

## Scope

- tools/x_search_tool.py — tool implementation (351 LOC)
- tests/tools/test_x_search_tool.py — unit tests (207 LOC, 6 tests)
- toolsets.py — add x_search to _HERMES_CORE_TOOLS + new TOOLSETS entry
- hermes_cli/tools_config.py — add x_search to CONFIGURABLE_TOOLSETS

Deliberately **not** changing: image_generation_tool.py, video_generation_tool.py,
browser_cdp (preserved), xAI TTS wiring (already on main via NousResearch#10783).

## Tests

- tests/tools/test_x_search_tool.py — 6 passed
- tests/ -k toolset — 126 passed, 4 skipped
- tests/ -k tools_config — 91 passed, 4 skipped
- Registry smoke: x_search registered, browser_cdp preserved

## Config

Reads optional `x_search` section from user config:
```yaml
x_search:
  model: grok-4.20-reasoning    # default
  timeout_seconds: 180          # default
  retries: 2                    # default
```

## Requirements

Gated on `XAI_API_KEY` (already wired by PR NousResearch#10783).

Co-authored-by: Jaaneek <Jaaneek@users.noreply.github.com>
Co-authored-by: Teknium <127238744+teknium1@users.noreply.github.com>
Add a short subsection under xAI provider docs explaining how to enable
the x_search toolset, its optional config (model/timeout/retries), and
what it returns. Co-located with the other xAI wiring docs.

Co-authored-by: Jaaneek <Jaaneek@users.noreply.github.com>
@Julientalbot

Copy link
Copy Markdown
Contributor Author

Heads up on CI — build-and-push is failing with a Docker-image infra issue (mkdir: cannot create directory '/opt/data/cron': Permission denied when the entrypoint runs inside the freshly built image). Same failure is currently affecting PRs #12521, #12519, #12516, #12515 on main — unrelated to this change. Happy to rebase once the Docker image / entrypoint permission issue is fixed upstream if helpful.

@Julientalbot

Copy link
Copy Markdown
Contributor Author

Closing as superseded — #10786 by @teknium1 is already the canonical vehicle for this scope (x_search + video_gen + image_gen xAI). No value added by carrying a parallel slice while #10786 is still open. Happy to revisit if #10786 is abandoned.

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.

2 participants