Fix/nsh mcp bind error 20250309#154
Merged
yhjun1026 merged 2 commits intoderisk-ai:mainfrom Mar 10, 2026
Merged
Conversation
added 2 commits
March 9, 2026 17:52
Root cause: when the LLM responded with plain text (no tool_calls) in a function-calling session, the next iteration still built history pairs of assistant(tool_calls=null) → tool(tool_call_id=...) which violates the OpenAI-compatible API contract and produces: "messages with role 'tool' must be a response to a preceeding message with 'tool_calls'" Fix (base_agent.py): - `function_callning_reply_messages`: skip appending tool-result messages when the preceding assistant message has no tool_calls, preventing the invalid sequence from being produced in the first place. - `_sanitize_tool_messages`: new helper that scrubs any remaining orphaned tool messages from the final LLM message list immediately before the API call, acting as a last-resort safety net.
… creation
When an MCP resource is rebound (deleted and recreated with a new code/name),
the old resource instance remains registered but no longer matches the new
configuration. Previously, this caused a ValueError to be thrown, breaking
the entire agent initialization.
Changes:
- When registered instances exist but none match the requested resource,
fall back to dynamic resource creation using the configuration value
- Properly catch MCPNotFoundError in both matching and dynamic creation
paths, returning None to allow graceful degradation
- Filter out None entries in build_resource() and a_build_resource() to
prevent unavailable MCPs from breaking agent loading
This ensures that when an MCP is rebound, the agent can still initialize
by creating a new resource instance from the updated configuration.
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.
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Snapshots:
Include snapshots for easier review.
Checklist: