docs(query): document real-time input/output interleaving - #1179
Open
GautamSharma99 wants to merge 1 commit into
Open
docs(query): document real-time input/output interleaving#1179GautamSharma99 wants to merge 1 commit into
GautamSharma99 wants to merge 1 commit into
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.
Summary
Align the public
query()documentation with its actual concurrent streaming lifecycle and supported capabilities.ClaudeSDKClientcontrol methodsquery()supports SDK MCP tools and hookscan_use_toolrequires an async-iterable promptProblem
The
query()docstring described async-iterable operation as unidirectional and stated that all prompts were sent before any responses were received. The implementation does the opposite: it startsQuery.stream_input(prompt)in a background task and immediately consumesQuery.receive_messages().The README also said that
ClaudeSDKClientadditionally enabled custom tools and hooks.InternalClientalready extracts SDK MCP servers, converts hooks, and sends both through the initialize control request forquery().These inaccuracies could lead callers to make incorrect assumptions about producer timing, backpressure, exception ordering, and which API they need for in-process extensions.
Documentation changes
Concurrent single-call lifecycle
The docstring now describes an async prompt iterable as the input source for one call while responses are processed concurrently. Input and output may interleave; the iterable does not need to be exhausted before the first response is yielded.
The wording avoids conflating concurrency with the stateful client API:
query()owns one connection lifecyclequery()orinterrupt()methodClaudeSDKClientremains the right choice for explicit connection management, first-class follow-up calls, interrupts, and long-running interactive sessionsTools and hooks
The README and docstring now state that both public entry points support Python SDK MCP tools and hooks through
ClaudeAgentOptions.The streaming requirement is documented precisely: SDK MCP tools and hooks work through the internal control protocol, while a
can_use_toolcallback specifically requires anAsyncIterableprompt rather than a string prompt.Behavioral regression
The new test uses synchronization events instead of sleeps:
query()iterator yields that responseThis fails under the documented send-all-then-receive model and proves the current concurrent implementation deterministically.
Runtime compatibility
No runtime behavior changes. This PR corrects the public contract and locks the existing scheduling behavior with a regression test.
Validation
uv run --extra dev pytest -q— 1292 passed, 5 skippeduv run --extra dev ruff check src tests— passeduv run --extra dev ruff format --check src tests— passeduv run --extra dev mypy src— passedFixes #1169