diff --git a/python/packages/claude/agent_framework_claude/_agent.py b/python/packages/claude/agent_framework_claude/_agent.py index e0224e76be0..fe2983eefdc 100644 --- a/python/packages/claude/agent_framework_claude/_agent.py +++ b/python/packages/claude/agent_framework_claude/_agent.py @@ -589,9 +589,11 @@ def _prepare_client_options(self, resume_session_id: str | None = None) -> SDKOp opts["cwd"] = cwd if permission_mode := self._settings.get("permission_mode"): opts["permission_mode"] = permission_mode - if max_turns := self._settings.get("max_turns"): + max_turns = self._settings.get("max_turns") + if max_turns is not None: opts["max_turns"] = max_turns - if max_budget_usd := self._settings.get("max_budget_usd"): + max_budget_usd = self._settings.get("max_budget_usd") + if max_budget_usd is not None: opts["max_budget_usd"] = max_budget_usd # Apply default options diff --git a/python/packages/claude/tests/test_claude_agent.py b/python/packages/claude/tests/test_claude_agent.py index cd62108ec51..d8af59a0b92 100644 --- a/python/packages/claude/tests/test_claude_agent.py +++ b/python/packages/claude/tests/test_claude_agent.py @@ -1157,6 +1157,25 @@ def test_prepare_client_options_with_settings(self, monkeypatch: pytest.MonkeyPa assert call_kwargs.get("model") == "opus" assert call_kwargs.get("max_turns") == 15 + def test_prepare_client_options_preserves_explicit_zero_limits(self) -> None: + """Test that explicit zero limit values are preserved.""" + agent = ClaudeAgent( + default_options={ + "max_turns": 0, + "max_budget_usd": 0.0, + } + ) + + with patch("agent_framework_claude._agent.SDKOptions") as mock_opts: + mock_opts.return_value = MagicMock() + agent._prepare_client_options() # type: ignore[reportPrivateUsage] + call_kwargs = mock_opts.call_args[1] + + assert "max_turns" in call_kwargs + assert call_kwargs["max_turns"] == 0 + assert "max_budget_usd" in call_kwargs + assert call_kwargs["max_budget_usd"] == 0.0 + def test_prepare_client_options_with_instructions(self) -> None: """Test building options with instructions parameter.""" agent = ClaudeAgent(instructions="Be helpful")