Skip to content

fix: reject or reroute tool requests for non-tool-capable models #33

Closed

Description

@stackbilt-admin

Summary

Groq and Cerebras declare supportsTools = true at the provider level, but only some models support tools. When a caller provides tools for a non-tool-capable model, both providers silently omit tools and tool_choice from the upstream request instead of failing fast or falling back to a tool-capable model.

Cloudflare handles the same class of problem more explicitly by throwing ConfigurationError when tools are used with a model whose capabilities do not support tools.

Fractal Decomposition

Macro: Unified provider contract

  • The package promises "tool/function calling ... with unified response format".
  • Consumers should not need provider-specific knowledge to know whether a requested tool call will be honored.

Meso: Provider-level vs model-level capabilities

  • The public LLMProvider interface exposes a coarse supportsTools boolean.
  • Model capability tables contain per-model tool support.
  • The factory does not use model capabilities to route tool requests, so adapters are the last boundary where unsupported tool use can be caught.

Micro: Concrete code paths

  • src/providers/groq.ts:72-81: provider advertises supportsTools = true.
  • src/providers/groq.ts:337-350: tools are included only if TOOL_CAPABLE_MODELS.has(model); otherwise they are dropped silently.
  • src/providers/cerebras.ts:71-81: provider advertises supportsTools = true.
  • src/providers/cerebras.ts:341-354: tools are included only if TOOL_CAPABLE_MODELS.has(model); otherwise they are dropped silently.
  • src/providers/cloudflare.ts:314-327: Cloudflare detects unsupported tool use and throws.

Impact

  • A caller can request tools and receive a plain text response from a model that never saw the tool schema.
  • This can mask production bugs in agent/tool workflows because the request appears successful.
  • Factory-level routing cannot distinguish "provider supports tools generally" from "this selected model supports tools for this request".

Suggested Fix

  • Make behavior consistent across providers:
    • Fail fast with ConfigurationError when tools are requested on a non-tool-capable model, or
    • Have the factory route tool requests only to configured providers/models that support tools.
  • Consider adding a provider method such as getModelCapabilities(model) or a factory-visible capability resolver.
  • Add tests for Groq/Cerebras unsupported-tool requests that assert either explicit rejection or documented fallback behavior.

Verification

  • npm run typecheck passes.
  • npm test passes: 169 tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions