Skip to content

Qwen Provider Specification

Scope

This package owns Qwen provider behavior for Robota when Qwen models are served through Alibaba Cloud Model Studio / DashScope OpenAI-compatible endpoints. It composes agent-provider-openai-compatible for Chat Completions message conversion, tool conversion, response parsing, streaming assembly, and endpoint probing while owning Qwen/DashScope defaults, setup labels, Responses API built-in web tools, and error framing.

Boundaries

  • Does not own generic OpenAI-compatible transport conversion, parser behavior, stream assembly, or endpoint probing. Those belong to agent-provider-openai-compatible.
  • Does not own OpenAI-branded account semantics or OpenAI default models. Those belong to agent-provider-openai.
  • Does not own Google Gemini/Gemma marker projection. That behavior belongs to provider packages for those model families.
  • Owns the Qwen Responses API slice for provider-side web_search and web_extractor. Broader native DashScope behavior and non-web Responses built-in tools remain future work.
  • Does not own CLI routing, session persistence, tool execution, or SDK orchestration.

Research

Official Qwen / Alibaba Cloud Model Studio documentation describes OpenAI-compatible Chat Completions as the mature migration path for Qwen chat, streaming, and tool-calling integration. It separately documents OpenAI-compatible Responses API support for built-in tools, including web_search and web_extractor. Web extractor documentation recommends Responses API for new integrations and says it exposes intermediate tool execution status. The documented base URLs are region-specific, and API keys are region-bound. This package therefore defaults to the international Singapore compatible endpoints and exposes provider-specific Responses options through the generic provider-definition options bag instead of adding CLI branches.

Sources:

Architecture Overview

src/
  index.ts                # public exports
  defaults.ts             # Qwen documented defaults and region base URLs
  provider.ts             # QwenProvider
  provider-definition.ts  # provider definition for CLI/runtime composition
  responses-converter.ts  # Qwen Responses API input/tool conversion
  responses-parser.ts     # Qwen Responses API response/event parsing
  types.ts                # provider options and option value types

QwenProvider is a provider shell over OpenAI-compatible Chat Completions plus a Qwen-owned Responses API path. Normal chat uses agent-provider-openai-compatible. When builtInWebTools.webSearch or builtInWebTools.webFetch is enabled, the provider switches to Responses API, sends provider-side built-in tool declarations, parses provider-side tool events, and records provenance in assistant-message metadata. createQwenProviderDefinition() returns an IProviderDefinition so CLI and SDK composition can inject Qwen without provider-specific branches.

Type Ownership

TypeLocationPurpose
IQwenProviderOptionssrc/types.tsConstructor options for QwenProvider.
TQwenProviderOptionValuesrc/types.tsValid provider option value union.
TQwenProviderRegionsrc/defaults.tsSupported documented Qwen OpenAI-compatible regions.
TQwenProviderResponsesRegionsrc/defaults.tsSupported documented Qwen Responses API regions.
QWEN_PROVIDER_BASE_URLSsrc/defaults.tsRegion to base URL map owned by this package.
QWEN_PROVIDER_RESPONSES_BASE_URLSsrc/defaults.tsRegion to Responses API base URL map owned by this package.
IQwenBuiltInWebToolsOptionssrc/types.tsQwen-owned switch for provider-side web search/fetch tools.
DEFAULT_QWEN_PROVIDER_MODELsrc/defaults.tsPackage-owned default Qwen model for setup definition.
DEFAULT_QWEN_PROVIDER_API_KEY_ENVsrc/defaults.tsPackage-owned default API-key environment variable name.
DEFAULT_QWEN_PROVIDER_API_KEY_REFERENCEsrc/defaults.ts$ENV: provider profile reference for the default API key.
DEFAULT_QWEN_PROVIDER_BASE_URLsrc/defaults.tsPackage-owned default OpenAI-compatible base URL.

Public API Surface

ExportKindDescription
QwenProviderclassPrimary provider class; extends AbstractAIProvider.
createQwenProviderDefinitionfunctionReturns an IProviderDefinition for branch-free CLI/runtime composition.
QWEN_PROVIDER_BASE_URLSconstantDocumented Qwen OpenAI-compatible base URLs by region.
QWEN_PROVIDER_RESPONSES_BASE_URLSconstantDocumented Qwen Responses API base URLs by region.
DEFAULT_QWEN_PROVIDER_MODELconstantDefault setup model owned by this package.
DEFAULT_QWEN_PROVIDER_API_KEY_ENVconstantDefault API-key environment variable name.
DEFAULT_QWEN_PROVIDER_API_KEY_REFERENCEconstantDefault $ENV: API-key reference for settings.
DEFAULT_QWEN_PROVIDER_BASE_URLconstantDefault setup base URL owned by this package.
DEFAULT_QWEN_PROVIDER_RESPONSES_BASE_URLconstantDefault Responses API base URL owned by this package.
IQwenBuiltInWebToolsOptionsinterfaceProvider-side web search/fetch configuration.
IQwenProviderOptionsinterfaceProvider constructor options.
TQwenProviderOptionValuetype aliasValid provider option values.
TQwenProviderRegiontype aliasSupported region keys for QWEN_PROVIDER_BASE_URLS.

Extension Points

  • Consumers can provide a preconfigured OpenAI SDK client for custom Qwen-compatible endpoint behavior.
  • Consumers can provide apiKey, baseURL, responsesBaseURL, timeout, defaultModel, and builtInWebTools.
  • Consumers can provide an executor to delegate provider execution without direct API calls.
  • Consumers such as agent-cli can inject createQwenProviderDefinition() alongside other provider definitions. The CLI and SDK must not special-case Qwen by type string or model name.
  • Future native DashScope or non-web Responses API support must be added as explicit Qwen-owned transport capability, not as generic CLI/SDK branches.

Built-in Web Tools

Qwen built-in web tools are provider-side capabilities, not Robota local tools. When enabled:

  • builtInWebTools.webSearch: true sends web_search.
  • builtInWebTools.webFetch: true sends both web_search and web_extractor, matching Alibaba's Responses API web extractor guidance.
  • builtInWebTools.enableThinking maps to Qwen's enable_thinking request field.
  • Provider-side tool usage is recorded in assistant metadata as providerToolMode, providerBuiltInToolsEnabled, providerBuiltInToolsUsed, qwenWebSearchCalls, and qwenWebExtractorCalls.

code_interpreter is intentionally unsupported in this package slice. If Qwen returns unsupported provider-side tool metadata, the parser records it as qwenUnsupportedProviderToolTypes; it does not execute or emulate that tool locally.

Error Taxonomy

ConditionError patternSource
Missing client, apiKey, and executorEither Qwen client, apiKey, or executor is requiredprovider.ts constructor
Missing API key in provider setupProvider qwen requires apiKeyprovider-definition.ts
Missing modelQwen chat/stream failed: Model is required...provider.ts
Client unavailableQwen client not available...provider.ts
Responses client unavailableQwen Responses client not available...provider.ts
Chat failureQwen chat failed: <message>provider.ts
Streaming failureQwen stream failed: <message>provider.ts
Responses failureQwen responses failed: <message>provider.ts

Test Strategy

  • Unit tests verify createQwenProviderDefinition() exposes Qwen defaults, setup steps, endpoint probing, and provider creation behavior.
  • Unit tests verify QwenProvider constructs an OpenAI SDK client with explicit or default Qwen base URL, API key, and timeout.
  • Unit tests verify non-streaming chat sends OpenAI-compatible messages/tools and parses native tool calls into universal assistant messages.
  • Unit tests verify streaming assembly emits onTextDelta values and returns the final assembled assistant response.
  • Unit tests verify direct chatStream yields universal assistant stream chunks.
  • Unit tests verify Responses API requests include web_search and web_extractor according to provider options.
  • Unit tests verify streamed response.output_text.delta events emit visible deltas and final metadata records provider-side tool provenance.
  • Unit tests verify Responses API function_call output remains a local Robota tool call and is not logged as provider-side built-in tool execution.
  • Unit tests verify upstream chat and streaming failures are wrapped with Qwen-owned error messages.
  • CLI tests verify Qwen is available through injected default provider definitions without CLI provider-specific branches.
  • CLI tests verify provider-owned options are passed through the generic provider config bag.

Class Contract Registry

Interface Implementations

None.

Inheritance Chains

Base (Owner)DerivedLocationNotes
AbstractAIProvider (agent-core)QwenProvidersrc/provider.tsQwen provider using OpenAI-compatible Chat Completions.

Cross-Package Port Consumers

Port (Owner)AdapterLocation
AbstractAIProvider (agent-core)QwenProvidersrc/provider.ts
IProviderDefinition (agent-core)createQwenProviderDefinitionsrc/provider-definition.ts
TUniversalMessage (agent-core)QwenProvidersrc/provider.ts
OpenAI-compatible transport primitivesQwenProvidersrc/provider.ts
OpenAI-compatible endpoint probecreateQwenProviderDefinitionsrc/provider-definition.ts
Qwen Responses API conversion/parsingQwenProvidersrc/responses-*.ts

Released under the MIT License.