feat(xai): xai_deferred_chat tool — long-running completions via submit + poll - #23329
Closed
Julientalbot wants to merge 3 commits into
Closed
feat(xai): xai_deferred_chat tool — long-running completions via submit + poll#23329Julientalbot wants to merge 3 commits into
Julientalbot wants to merge 3 commits into
Conversation
…submit + poll
xAI deferred mode (POST /v1/chat/completions with deferred=true,
then GET /v1/chat/deferred-completion/{request_id}) decouples the
HTTP connection lifecycle from the actual completion. Useful for
extended-thinking, large-context, or multi-agent reasoning calls
that exceed normal HTTP timeouts.
Changes:
- tools/xai_deferred_tool.py: self-contained tool implementation
- xai_deferred_chat(prompt, model, system, max_wait_seconds,
poll_interval_seconds, extra_messages, extra_body) — submits
in deferred mode and polls until ready or budget exhausted
- Configurable model / max_wait_seconds / poll_interval_seconds
via config.yaml under xai_deferred:
- Reuses tools.xai_http.hermes_xai_user_agent for User-Agent
- extra_body cannot override deferred=true (hard-coded)
- Self-registers via tools.registry.registry.register
- tests/tools/test_xai_deferred_tool.py: 24 unit tests covering
- check_xai_deferred_requirements (with/without/blank API key)
- schema (required prompt, optional params advertised)
- argument validation (empty prompt, missing key, negative
max_wait, negative poll_interval)
- submit semantics (deferred=true, default model, explicit
model, system message, extra_body merging, 4xx error,
missing request_id, network error)
- poll semantics (200 first, 202 then 200, 5xx error, timeout)
- headers (Authorization Bearer, User-Agent prefix)
- toolsets.py: add xai_deferred_chat to _HERMES_CORE_TOOLS and
new xai_deferred toolset
- hermes_cli/tools_config.py: add xai_deferred to CONFIGURABLE_TOOLSETS
- tests/tools/test_registry.py: add tools.xai_deferred_tool to the
manual builtin tool set snapshot
Requires XAI_API_KEY in ~/.hermes/.env.
This was referenced May 10, 2026
Contributor
|
Thanks for the contribution Julien. We're going to pass on this one. New agent-facing tools that issue side-channel chat completions to a specific provider duplicate what the main model/provider pipeline (and ) already does, but locked to xAI only. Every new model tool also bloats the tool schema sent on every API call. If there's a concrete workflow you can't reach via the normal model loop or delegate_task, happy to hear it — but as a generic capability we'd rather not add it. Closing with appreciation. |
Contributor
Author
|
@teknium1 I understand thank you for taking the time to answer to me ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
xai_deferred_chat— a tool that runs a long-running chat completion against xAI in deferred mode: submits toPOST /v1/chat/completionswithdeferred: true, pollsGET /v1/chat/deferred-completion/{request_id}(202 → still pending, 200 → done) until the response is ready or the per-call budget is exhausted.Why
xAI's deferred mode is built for completions that take many minutes (extended thinking, multi-agent reasoning, large-context calls) — long enough that holding an open HTTP connection is unreliable. Deferred decouples the request lifecycle from the network: the client can disconnect, crash, retry, or yield, and pick the result up later. This pairs naturally with Hermes' autonomous mode (long-running sessions) and with the
grok-4.20-multi-agent-0309model whose orchestrator legs can run several minutes.This tool is the smallest possible primitive: one tool that submits + polls and blocks the caller until done. A future, more sophisticated transport could layer parallelism / persistence / cross-session resumption on top of the same primitives, but the existing autonomous + delegation patterns already get most of the value out of this minimal shape.
Changes (5 files, +653/-0)
tools/xai_deferred_tool.py(new, ~350 LoC)Self-contained tool. Public surface:
tools.xai_http.hermes_xai_user_agentforUser-Agent.extra_bodycannot overridedeferred=true(the entire point of the tool).tools.registry.registry.registerwithcheck_fngating onXAI_API_KEY.config.yaml:tests/tools/test_xai_deferred_tool.py(new, ~280 LoC)24 unit tests, all using a tiny
_FakeHttpmonkeypatch (no real network):max_wait_seconds, negativepoll_interval_seconds.deferred=truealways set, default model resolution, explicit-model override, system message ordering,extra_bodymerging (cannot clobberdeferred), 4xx HTTP error, missingrequest_idin response, network error.time.monotonic).Authorization: Bearer <key>on both submit + poll,User-Agent: Hermes-Agent/<version>on submit.Wiring
toolsets.py:xai_deferred_chatadded to_HERMES_CORE_TOOLS; newxai_deferredtoolset.hermes_cli/tools_config.py: newxai_deferredentry inCONFIGURABLE_TOOLSETS.tests/tools/test_registry.py:tools.xai_deferred_tooladded to the manual snapshot list (same convention as feat(xai): add x_search tool — search X via xAI Responses API #14541, feat(xai): add video generation tool — generate/edit/extend via xAI grok-imagine-video #14543).Validation
pytest tests/tools/test_xai_deferred_tool.py tests/tools/test_registry.py→ 55/55 passing locally on top of currentmain.Backward compatibility
toolsets.py,tools_config.py, and the registry snapshot list.check_fn-gated onXAI_API_KEY— invisible to users without an xAI key.xai_deferredis not in the default toolset roster; users opt in viatools_configor by enabling the toolset in their profile.Follow-up scope (not in this PR)
request_idto disk, resume polling on next launch. Useful for autonomous sessions whose backing process gets restarted mid-thought.