Skip to content

feat: add ChatCompletionsTransport + wire all default paths - #27083

Closed
Master-Rensei wants to merge 1 commit into
NousResearch:mainfrom
Master-Rensei:feat/chat-completions-transport
Closed

feat: add ChatCompletionsTransport + wire all default paths#27083
Master-Rensei wants to merge 1 commit into
NousResearch:mainfrom
Master-Rensei:feat/chat-completions-transport

Conversation

@Master-Rensei

Copy link
Copy Markdown

Summary

PR 5 of the provider transport refactor (PR 1: #12975, PR 2: #13073, PR 3: #13366, PR 4: #13430).

Third concrete transport — handles the default chat_completions api_mode used by ~16 OpenAI-compatible providers. Extracts the 210-line kwargs construction block from run_agent.py with all 13 provider-specific conditionals.

What ships

agent/transports/chat_completions.py — ChatCompletionsTransport (314 lines)

All transport methods wired to production paths:

Method What it replaces
build_kwargs() 210-line else branch in _build_api_kwargs with 13 provider conditionals
validate_response() response.choices validation gate
extract_cache_stats() OpenRouter prompt_tokens_details.cached_tokens extraction
convert_messages() Codex field sanitization + developer role swap
convert_tools() Identity (already in OpenAI format)
normalize_response() Near-identity (response.choices[0].message → NormalizedResponse)

Provider-specific conditionals now in the transport:

  • Qwen Portal: message preprocessing, metadata, vl_high_resolution_images, max_tokens 65536
  • NVIDIA NIM: max_tokens 16384 default
  • Ollama: num_ctx, think=false for disabled reasoning
  • OpenRouter: provider preferences, Claude max_tokens from Anthropic adapter
  • Nous Portal: reasoning config, product attribution tags
  • GitHub Models: reasoning extra_body format
  • GPT-5/Codex: developer role swap
  • Custom providers: think=false for Qwen3 reasoning suppression

Impact

  • run_agent.py: -197 lines in _build_api_kwargs (12,054 → 11,948)
  • _get_chat_completions_transport() lazy singleton added

Test plan

  • 26 new tests (build_kwargs: 12, validate: 4, normalize: 2, cache: 3, convert: 3, registration: 2)
  • All transport tests pass
  • Provider parity tests pass (some flaky under xdist parallel — pass on re-run)

Add ChatCompletionsTransport for the default api_mode used by ~16
OpenAI-compatible providers (OpenRouter, Nous, NVIDIA, Qwen, Ollama,
DeepSeek, xAI, custom, etc.).

Wire ALL transport methods to production paths in run_agent.py:
- build_kwargs: extract 210-line else branch with 13 provider-specific
  conditionals (Qwen portal, NVIDIA NIM, Ollama, reasoning, developer
  role swap, provider preferences, max_tokens defaults)
- validate_response: response.choices validation gate
- extract_cache_stats: OpenRouter prompt_tokens_details extraction
- convert_messages: codex field sanitization (identity otherwise)
- convert_tools: identity (already in OpenAI format)
- normalize_response: near-identity wrapper returning NormalizedResponse

Agent gathers state (provider detection flags, temperature, preferences)
and passes as explicit params to transport.build_kwargs().

run_agent.py: -197 lines in _build_api_kwargs (12,054 -> 11,948).

26 new tests (build_kwargs: 12, validate: 4, normalize: 2, cache: 3,
convert: 3, registration: 2). All transport tests pass.

PR 5 of the provider transport refactor.
@alt-glitch alt-glitch added type/feature New feature or request P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/openai OpenAI / Codex Responses API provider/openrouter OpenRouter aggregator provider/ollama Ollama / local models provider/nvidia NVIDIA NIM provider/nous Nous Research API (OAuth) provider/qwen Qwen / Alibaba Cloud (OAuth) labels May 16, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #13805 (already merged). This PR reopens a previously closed fork branch, but the feature (ChatCompletionsTransport) was already landed via a salvage PR.

@Master-Rensei Master-Rensei closed this by deleting the head repository May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists provider/nous Nous Research API (OAuth) provider/nvidia NVIDIA NIM provider/ollama Ollama / local models provider/openai OpenAI / Codex Responses API provider/openrouter OpenRouter aggregator provider/qwen Qwen / Alibaba Cloud (OAuth) type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants