feat: add tool_choice support

Adds first_turn_tool_choice and ensure_tool_usage options to
  ClaudeAgentOptions for controlling tool usage in agentic loops.
This commit is contained in:
Ash Prabaker 2025-11-03 13:17:48 +00:00
parent 5a4cc2f41a
commit 44c6f5503a
No known key found for this signature in database
2 changed files with 15 additions and 0 deletions

View file

@ -225,6 +225,14 @@ class SubprocessCLITransport(Transport):
["--max-thinking-tokens", str(self._options.max_thinking_tokens)]
)
if self._options.first_turn_tool_choice is not None:
cmd.extend(
["--first-turn-tool-choice", json.dumps(self._options.first_turn_tool_choice)]
)
if self._options.ensure_tool_usage:
cmd.append("--ensure-tool-usage")
# Check if command line is too long (Windows limitation)
cmd_str = " ".join(cmd)
if len(cmd_str) > _CMD_LENGTH_LIMIT and self._options.agents:

View file

@ -17,6 +17,9 @@ PermissionMode = Literal["default", "acceptEdits", "plan", "bypassPermissions"]
# Agent definitions
SettingSource = Literal["user", "project", "local"]
# Tool choice types
ToolChoice = Literal["auto", "any", "none"] | dict[str, str]
class SystemPromptPreset(TypedDict):
"""System prompt preset configuration."""
@ -557,6 +560,10 @@ class ClaudeAgentOptions:
plugins: list[SdkPluginConfig] = field(default_factory=list)
# Max tokens for thinking blocks
max_thinking_tokens: int | None = None
# Tool choice for first turn only
first_turn_tool_choice: ToolChoice | None = None
# Ensure at least one tool is used before conversation ends
ensure_tool_usage: bool = False
# SDK Control Protocol