feat: support toolRestrictions on POST /api/chat (AI-3600) - #46
Draft
claude[bot] wants to merge 2 commits into
Draft
feat: support toolRestrictions on POST /api/chat (AI-3600)#46claude[bot] wants to merge 2 commits into
claude[bot] wants to merge 2 commits into
Conversation
Callers frequently need to constrain which tools the assistant may use for a given chat — for example running a read-only session, restricting to an allowlist of safe tools, or blocking specific write tools. The backend already accepts a `toolRestrictions` field on `POST /api/chat` (merged in keboola/ui#6267), but the Python SDK had no way to send it. This adds a `ToolRestrictions` model (allowed_tools / disallowed_tools / read_only_mode, serializing to allowedTools / disallowedTools / readOnlyMode) and an optional `tool_restrictions` parameter on `KaiClient.send_message`, plumbed through `ChatRequest`. When omitted, no `toolRestrictions` key is sent; unset sub-fields are omitted via exclude_none. Restrictions are first-message-wins: the backend persists them from the first message of a chat and ignores the field on follow-up messages. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MnbZpLRgq9gmFSWX8bvERm
Document the new tool_restrictions parameter on send_message so users can discover and use tool allowlists, denylists, and read-only mode without reading the source. Covers the three optional ToolRestrictions fields, the toolRestrictions serialization on POST /api/chat, and the first-message-wins persistence behavior. Updates the README usage examples, the kai-cli api-details reference, and the kai-js data-app skill (which builds the /api/chat payload directly). Pairs with backend PR keboola/ui#6267 (AI-3600). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MnbZpLRgq9gmFSWX8bvERm
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.
Requested by Jordan Burger · Slack thread
Before / After
Before:
KaiClient.send_message(...)had no way to constrain which tools the assistant could use. Every chat ran with the full tool set — you couldn't ask for a read-only session, an allowlist of safe tools, or block specific write tools from the client.After: Callers can pass an optional
tool_restrictionsargument tosend_message(...)to scope tool usage for a chat:How
ToolRestrictionsPydantic model with three optional fields —allowed_tools,disallowed_tools,read_only_mode— that serialize to the exact JSON keys the backend expects:allowedTools,disallowedTools,readOnlyMode.tool_restrictionsfield onChatRequest(src/kai_client/models.py), serializing totoolRestrictions.tool_restrictions: ToolRestrictions | None = Noneparameter onsend_message(src/kai_client/client.py), plumbed into theChatRequest.model_dump(by_alias=True, exclude_none=True), so whentool_restrictionsisNonethetoolRestrictionskey is omitted entirely, and any unset sub-fields are dropped from the payload.ToolRestrictionsis exported from the package's public API (kai_client.__init__).Behavioral note (documented, not enforced client-side): restrictions are first-message-wins — the backend persists them from the first message of a chat and silently ignores
toolRestrictionson follow-up messages of the same chat.Pairs with the already-merged backend PR keboola/ui#6267 and Linear AI-3600.
Generated by Claude Code