Skip to content

Commit 7c6902b

Browse files
authored
feat: add background, effort, permissionMode to AgentDefinition (#782)
## Summary Adds 3 fields to `AgentDefinition` that are present in the TS SDK's `AgentDefinitionSchema` (`coreSchemas.ts`) but missing from the Python SDK: - **`background: bool | None`** -- Run this agent as a background task (non-blocking, fire-and-forget) when invoked. This is the key addition: it enables parallel subagent execution without spawning multiple SDK sessions. - **`effort: Literal["low", "medium", "high", "max"] | int | None`** -- Reasoning effort level for the agent. Accepts either a named level or an integer. - **`permissionMode: PermissionMode | None`** -- Permission mode controlling how tool executions are handled for this agent. All three are optional pass-through fields that the CLI already supports via the `AgentDefinitionSchema` in the control protocol. The existing `asdict()` + None-filtering serialization in `_internal/client.py` handles them automatically -- no serialization changes needed. `permissionMode` reuses the existing `PermissionMode` type alias already defined in `types.py`. ## Tests Added 5 new tests in `TestAgentDefinition`: - `test_background_serializes_correctly` -- verifies boolean serialization - `test_effort_accepts_named_level` -- verifies string effort ("high") - `test_effort_accepts_integer` -- verifies integer effort (32000) - `test_permission_mode_serializes_as_camelcase` -- verifies camelCase key - `test_new_fields_omitted_when_none` -- verifies all 3 fields absent when unset All 44 tests pass. <\!-- CHANGELOG-SDK:START --> - Added `background`, `effort`, and `permissionMode` fields to `AgentDefinition` for TS SDK parity <\!-- CHANGELOG-SDK:END -->
1 parent b63e8f1 commit 7c6902b

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

src/claude_agent_sdk/types.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class AgentDefinition:
8282
mcpServers: list[str | dict[str, Any]] | None = None # noqa: N815
8383
initialPrompt: str | None = None # noqa: N815
8484
maxTurns: int | None = None # noqa: N815
85+
background: bool | None = None
86+
effort: Literal["low", "medium", "high", "max"] | int | None = None
87+
permissionMode: PermissionMode | None = None # noqa: N815
8588

8689

8790
# Permission Update types (matching TypeScript SDK)

tests/test_types.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,64 @@ def test_model_accepts_full_model_id(self):
538538
payload = self._serialize(agent)
539539

540540
assert payload["model"] == "claude-opus-4-5"
541+
542+
def test_background_serializes_correctly(self):
543+
from claude_agent_sdk import AgentDefinition
544+
545+
agent = AgentDefinition(
546+
description="test",
547+
prompt="p",
548+
background=True,
549+
)
550+
payload = self._serialize(agent)
551+
552+
assert payload["background"] is True
553+
554+
def test_effort_accepts_named_level(self):
555+
from claude_agent_sdk import AgentDefinition
556+
557+
agent = AgentDefinition(
558+
description="test",
559+
prompt="p",
560+
effort="high",
561+
)
562+
payload = self._serialize(agent)
563+
564+
assert payload["effort"] == "high"
565+
566+
def test_effort_accepts_integer(self):
567+
from claude_agent_sdk import AgentDefinition
568+
569+
agent = AgentDefinition(
570+
description="test",
571+
prompt="p",
572+
effort=32000,
573+
)
574+
payload = self._serialize(agent)
575+
576+
assert payload["effort"] == 32000
577+
578+
def test_permission_mode_serializes_as_camelcase(self):
579+
"""CLI expects ``permissionMode`` (camelCase)."""
580+
from claude_agent_sdk import AgentDefinition
581+
582+
agent = AgentDefinition(
583+
description="test",
584+
prompt="p",
585+
permissionMode="bypassPermissions",
586+
)
587+
payload = self._serialize(agent)
588+
589+
assert payload["permissionMode"] == "bypassPermissions"
590+
assert "permission_mode" not in payload
591+
592+
def test_new_fields_omitted_when_none(self):
593+
"""New optional fields should not appear in payload when unset."""
594+
from claude_agent_sdk import AgentDefinition
595+
596+
agent = AgentDefinition(description="test", prompt="p")
597+
payload = self._serialize(agent)
598+
599+
assert "background" not in payload
600+
assert "effort" not in payload
601+
assert "permissionMode" not in payload

0 commit comments

Comments
 (0)