Repository navigation
Fix NameError: is_mcp_config on base install; strip reasoning_content for Groq - #420
Open
dajiaohuang wants to merge 2 commits into
Conversation
…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.
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
Keep ordinary tool schemas usable without the MCP extra (#329)
On a base installation without
mcp, a non-streamingclient.chat.completions.create(..., tools=[<OpenAI-format function schema>])reaches_process_mcp_configs()and raisesNameError: name 'is_mcp_config' is not definedbefore the provider request. An explicit MCP configuration also raises that NameError instead of the intended missing-extra ImportError.Importing
.mcp.configfirst executesaisuite/mcp/__init__.py, which imports.clientand 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
Messageto the next request.Message.model_dump(mode="json")includesreasoning_content, even when its value isNone; 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
66c7890c2d68c2d67f41723bc848bb6713d82a9cwith the original head1628188f0be993efb82a65b0af874c1e237fb34c; follow-upeac654b88e8a972e9e46087314fef31eb32b3cecadds 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).Client->GroqProvider-> real SDK serialization -> HTTPXMockTransport: manual schema tools fail with NameError on base and reach the offline HTTP boundary on head.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.tests/providers/test_groq_request_serialization.py(new regression), existingtests/providers/test_groq_provider.pyandtests/client/test_manual_tool_calling.py: 7 passed on the follow-up. These are offline/unit tests, not live-provider acceptance.git diff --checkpassed.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.