Skip to content

Fix NameError: is_mcp_config on base install; strip reasoning_content for Groq - #420

Open
dajiaohuang wants to merge 2 commits into
andrewyng:mainfrom
dajiaohuang:dajiaohuang/fix-nameerror-is-mcp-config-and-reasoning-content
Open

dajiaohuang wants to merge 2 commits into
andrewyng:mainfrom
dajiaohuang:dajiaohuang/fix-nameerror-is-mcp-config-and-reasoning-content

Conversation

@dajiaohuang

@dajiaohuang dajiaohuang commented Oct 8, 2026 •

Copy link
Copy Markdown

Summary

Keep ordinary tool schemas usable without the MCP extra (#329)

On a base installation without mcp, a non-streaming client.chat.completions.create(..., tools=[<OpenAI-format function schema>]) reaches _process_mcp_configs() and raises NameError: name 'is_mcp_config' is not defined before the provider request. An explicit MCP configuration also raises that NameError instead of the intended missing-extra ImportError.

Importing .mcp.config first executes aisuite/mcp/__init__.py, which imports .client and fails when the external MCP package is absent. It is this package initialization failure that prevents the utility import from binding; a later failing import would not undo an already completed import. The patch allows package initialization without the optional dependency and imports the dependency-free configuration predicate outside the optional client import.

This does not mean every callable-tool invocation fails: with no dictionary tools the generator never evaluates the missing predicate. No streaming defect is claimed here.

Remove the internal reasoning field from OpenAI-compatible request conversion (#369, Bug 1)

The automatic tool loop appends its normalized Message to the next request. Message.model_dump(mode="json") includes reasoning_content, even when its value is None; it does not require a <think> response to reach this path. Groq rejects that field in assistant request messages as reported in #369. The converter removes it from normalized messages and dictionary messages, without removing it from the response object or mutating the caller's dictionary.

The change is in the shared OpenAI-compatible converter. The concrete rejection evidence is Groq; this PR does not claim live acceptance or model-quality validation for every provider using that converter, or resolve the other issues grouped in #369.

Validation

Compared current base 66c7890c2d68c2d67f41723bc848bb6713d82a9c with the original head 1628188f0be993efb82a65b0af874c1e237fb34c; follow-up eac654b88e8a972e9e46087314fef31eb32b3cec adds the SDK-boundary regression test and required formatting using an isolated Python 3.13 environment with no MCP package, Pydantic 2.14.1, HTTPX 0.28.1 and the real Groq SDK 0.37.1 (within the declared dependency ranges).

  • Production Client -> GroqProvider -> real SDK serialization -> HTTPX MockTransport: manual schema tools fail with NameError on base and reach the offline HTTP boundary on head.
  • The same production path with a callable and two automatic tool turns: base sends reasoning_content: null; head omits the field and preserves the executed tool result. The HTTP responses are explicit offline fixtures, not evidence of model behavior or server acceptance.
  • Explicit MCP configuration without the extra: base raises NameError; head raises the intended ImportError without starting an MCP server.
  • Dictionary conversion removes the field while leaving the input dictionary unchanged on head.
  • tests/providers/test_groq_request_serialization.py (new regression), existing tests/providers/test_groq_provider.py and tests/client/test_manual_tool_calling.py: 7 passed on the follow-up. These are offline/unit tests, not live-provider acceptance.
  • Black 24.4.2 checks passed for all three production files in this PR and the new test; git diff --check passed.

No real provider calls or credentials were used. The complete development dependency installation, full test suite and all-files pre-commit checks were not run; no CI pass is claimed.

dajiaohuang and others added 2 commits October 8, 2026 13:57
…andrewyng#329)

- Move is_mcp_config import outside the try/except block since it's a pure
  utility function with no external mcp dependency, so it's always available.
- Make mcp/__init__.py gracefully handle missing mcp package.

Also fix Groq reasoning_content error on multi-turn tool calls (andrewyng#369):

- Strip reasoning_content field from messages before sending to providers
  that don't support it (like Groq). reasoning_content is aisuite-internal
  metadata extracted from think tags, not a standard API field.
- Applied in OpenAICompliantMessageConverter.convert_request(), which is
  used by Groq, Ollama, and other OpenAI-compatible providers.
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.

1 participant