Fix issue 28 with tool use and improve the logic overall#141
Open
a-akimov wants to merge 2 commits into
Open
Conversation
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.
Motivation and Context
process_queryinmcp-client-python/client.pyso tool-use turns conform to the Anthropic Messages API: append the assistant's full content (preserving thetool_useblock) and reply with a propertool_resultblock carryingtool_use_id, replacing the previous plain-user-message workaround and the deadhasattr(content, "text")check that the API spec confirms can never be true.tool_useblocks and returning all matchingtool_resultblocks in one user message) and chained tool calls across turns (passingtoolson every follow-up request so the model can keep using them).MAX_TOOL_TURNS = 10cap to prevent unbounded tool-use loops; on cap-hit the client appends a[Stopped after N tool-use turns]notice and returns the accumulated output.chat_loopto exit cleanly onEOFError/KeyboardInterruptinstead of being swallowed by a broadexcept Exceptionand respinning forever. This also makes the python client smoke test pass reliably under non-tty stdin regardless of whetherANTHROPIC_API_KEYis set (previously the test hung whenever the key was loaded from.env).How Has This Been Tested?
tests/smoke-test.shpasses locally (all 5 tests green, no hangs) both with and withoutANTHROPIC_API_KEYset.client.pyagainstweather-server-pythonwith a realANTHROPIC_API_KEYand ask a query that triggers a single tool call (e.g. "What'sthe weather in NYC?") — verify the model receives the tool result and produces a final answer.
MAX_TOOL_TURNScap path by lowering the constant locally and confirming the[Stopped after N tool-use turns]notice appears.Query:prompt — verify the client exits cleanly instead of spinning.Breaking Changes
N/a
Types of changes
Checklist
Additional context
Fixes issue #28.