Skip to content

AgentDefinition

Base classes

Name Children Inherits
ClaudeCodeBaseModel
clawd_code_sdk.models.base
Base model for all Claude Code Pydantic models.

⋔ Inheritance diagram

graph TD
  3197581190["agents.AgentDefinition"]
  2604142835["base.ClaudeCodeBaseModel"]
  3879467795["main.BaseModel"]
  2751680898["builtins.object"]
  2604142835 --> 3197581190
  3879467795 --> 2604142835
  2751680898 --> 3879467795

🛈 DocStrings

Bases: ClaudeCodeBaseModel

User-facing agent definition configuration.

Accepts ergonomic Python inputs (e.g. dict-style mcp_servers) and converts to the wire format via to_wire().

Source code in src/clawd_code_sdk/models/agents.py
class AgentDefinition(ClaudeCodeBaseModel):
    """User-facing agent definition configuration.

    Accepts ergonomic Python inputs (e.g. dict-style mcp_servers)
    and converts to the wire format via ``to_wire()``.
    """

    description: str = Field(..., title="Agent Description", examples=["QA Assistant"])
    """A brief description of the agent's purpose."""

    prompt: str = Field(..., title="Agent Prompt", examples=["Do XY"])
    """The prompt to use for this agent."""

    tools: list[ToolName | str] | None = Field(default=None, title="Agent Tools", examples=["Bash"])
    """The tools this agent has access to."""

    model: ModelName | Literal["inherit"] | str | None = Field(  # noqa: PYI051
        default=None,
        title="Agent Model",
        examples=["sonnet"],
    )
    """The model to use for this agent."""

    memory: SettingSource | None = Field(
        default=None,
        title="Agent Memory",
        examples=["user", "project"],
    )
    """Persistent cross-session memory scope for this agent."""
    mcp_servers: Mapping[str, McpServerConfigForProcessTransport | None] | None = None
    """MCP servers for this agent.

    Maps server names to configs. Use ``None`` as the value to reference
    a server already configured in settings::
    """

    disallowed_tools: list[ToolName | str] | None = Field(
        default=None,
        title="Disallowed Tools",
        examples=["Bash"],
    )
    """Tools this agent is not allowed to use."""

    critical_system_reminder_experimental: str | None = Field(
        default=None,
        title="Critical System Reminder",
        alias="criticalSystemReminder_EXPERIMENTAL",
    )
    """Critical system reminder message to display to the user."""

    skills: list[str] | None = Field(default=None, title="Skills", examples=["my-skill"])
    """Skills this agent has."""

    initial_prompt: str | None = Field(default=None, title="Initial Prompt")
    """Auto-submitted as the first user turn when this agent is the main thread agent.

    Slash commands are processed. Prepended to any user-provided prompt.
    """

    max_turns: int | None = Field(default=None, title="Max Turns")
    """Maximum number of agentic turns (API round-trips) before stopping."""

    background: bool | None = Field(default=None, title="Run in Background")
    """Whether this agent runs in the background."""

    hooks: AgentHooksConfig | None = Field(default=None, title="Agent Hooks")
    """Hook configurations for this agent."""

    effort: ReasoningEffort | int | None = Field(
        default=None,
        title="Reasoning effort",
        examples=["high"],
    )
    """Effort level for thinking depth."""

    permission_mode: PermissionMode | None = Field(
        default=None,
        title="Permission Mode",
        examples=["bypassPermissions"],
    )
    """Permission mode for this agent."""

    isolation: Literal["worktree"] | None = Field(
        default=None,
        title="Isolation Mode",
        examples=["worktree"],
    )
    """Isolation mode. ``"worktree"`` runs the agent in a separate git worktree."""

    auto_compact_window: int | None = Field(default=None, title="Auto-Compact Window")
    """Token count at which this agent compacts its own conversation as a subagent.

    Only lowers the inherited window. No effect on the main session agent."""

    omit_claude_md: bool | None = Field(default=None, title="Omit CLAUDE.md")
    """Run without user/project/local CLAUDE.md files when running as a subagent."""

    observer: str | None = Field(default=None, title="Observer Agent")
    """Agent type(s) (comma-separated, max 4) auto-spawned as background observers."""

    observer_message: str | None = Field(default=None, title="Observer Message")
    """Supplemental postamble appended to each activity digest sent to the observer."""

    def to_wire(self) -> dict[str, Any]:
        """Serialize to the wire-format dict for the CLI control protocol.

        Converts dict-style mcp_servers to the array format the CLI expects:
        ``{"git": config}`` -> ``[{"git": config}]``

        Returns a camelCase dict with None values excluded.
        """
        model = self.to_wire_model()
        return model.model_dump(by_alias=True, exclude_none=True)

    def to_wire_model(self) -> AgentWireDefinition:
        """Serialize to the wire-format dict for the CLI control protocol.

        Converts dict-style mcp_servers to the array format the CLI expects:
        ``{"git": config}`` -> ``[{"git": config}]``

        Returns a camelCase dict with None values excluded.
        """
        mcp = [
            name if config is None else {name: config}
            for name, config in (self.mcp_servers or {}).items()
        ]
        return AgentWireDefinition(
            description=self.description,
            prompt=self.prompt,
            tools=self.tools,
            model=self.model,
            memory=self.memory,
            mcp_servers=mcp or None,
            disallowed_tools=self.disallowed_tools,
            critical_system_reminder_experimental=self.critical_system_reminder_experimental,
            skills=self.skills,
            initial_prompt=self.initial_prompt,
            max_turns=self.max_turns,
            background=self.background,
            hooks=self.hooks,
            effort=self.effort,
            permission_mode=self.permission_mode,
            isolation=self.isolation,
            auto_compact_window=self.auto_compact_window,
            omit_claude_md=self.omit_claude_md,
            observer=self.observer,
            observer_message=self.observer_message,
        )

auto_compact_window class-attribute instance-attribute

auto_compact_window: int | None = Field(default=None, title='Auto-Compact Window')

Token count at which this agent compacts its own conversation as a subagent.

Only lowers the inherited window. No effect on the main session agent.

background class-attribute instance-attribute

background: bool | None = Field(default=None, title='Run in Background')

Whether this agent runs in the background.

critical_system_reminder_experimental class-attribute instance-attribute

critical_system_reminder_experimental: str | None = Field(
    default=None, title="Critical System Reminder", alias="criticalSystemReminder_EXPERIMENTAL"
)

Critical system reminder message to display to the user.

description class-attribute instance-attribute

description: str = Field(..., title='Agent Description', examples=['QA Assistant'])

A brief description of the agent's purpose.

disallowed_tools class-attribute instance-attribute

disallowed_tools: list[ToolName | str] | None = Field(
    default=None, title="Disallowed Tools", examples=["Bash"]
)

Tools this agent is not allowed to use.

effort class-attribute instance-attribute

effort: ReasoningEffort | int | None = Field(
    default=None, title="Reasoning effort", examples=["high"]
)

Effort level for thinking depth.

hooks class-attribute instance-attribute

hooks: AgentHooksConfig | None = Field(default=None, title='Agent Hooks')

Hook configurations for this agent.

initial_prompt class-attribute instance-attribute

initial_prompt: str | None = Field(default=None, title='Initial Prompt')

Auto-submitted as the first user turn when this agent is the main thread agent.

Slash commands are processed. Prepended to any user-provided prompt.

isolation class-attribute instance-attribute

isolation: Literal["worktree"] | None = Field(
    default=None, title="Isolation Mode", examples=["worktree"]
)

Isolation mode. "worktree" runs the agent in a separate git worktree.

max_turns class-attribute instance-attribute

max_turns: int | None = Field(default=None, title='Max Turns')

Maximum number of agentic turns (API round-trips) before stopping.

mcp_servers class-attribute instance-attribute

mcp_servers: Mapping[str, McpServerConfigForProcessTransport | None] | None = None

MCP servers for this agent.

Maps server names to configs. Use None as the value to reference a server already configured in settings::

memory class-attribute instance-attribute

memory: SettingSource | None = Field(
    default=None, title="Agent Memory", examples=["user", "project"]
)

Persistent cross-session memory scope for this agent.

model class-attribute instance-attribute

model: ModelName | Literal["inherit"] | str | None = Field(
    default=None, title="Agent Model", examples=["sonnet"]
)

The model to use for this agent.

observer class-attribute instance-attribute

observer: str | None = Field(default=None, title='Observer Agent')

Agent type(s) (comma-separated, max 4) auto-spawned as background observers.

observer_message class-attribute instance-attribute

observer_message: str | None = Field(default=None, title='Observer Message')

Supplemental postamble appended to each activity digest sent to the observer.

omit_claude_md class-attribute instance-attribute

omit_claude_md: bool | None = Field(default=None, title='Omit CLAUDE.md')

Run without user/project/local CLAUDE.md files when running as a subagent.

permission_mode class-attribute instance-attribute

permission_mode: PermissionMode | None = Field(
    default=None, title="Permission Mode", examples=["bypassPermissions"]
)

Permission mode for this agent.

prompt class-attribute instance-attribute

prompt: str = Field(..., title='Agent Prompt', examples=['Do XY'])

The prompt to use for this agent.

skills class-attribute instance-attribute

skills: list[str] | None = Field(default=None, title='Skills', examples=['my-skill'])

Skills this agent has.

tools class-attribute instance-attribute

tools: list[ToolName | str] | None = Field(default=None, title='Agent Tools', examples=['Bash'])

The tools this agent has access to.

to_wire

to_wire() -> dict[str, Any]

Serialize to the wire-format dict for the CLI control protocol.

Converts dict-style mcp_servers to the array format the CLI expects: {"git": config} -> [{"git": config}]

Returns a camelCase dict with None values excluded.

Source code in src/clawd_code_sdk/models/agents.py
def to_wire(self) -> dict[str, Any]:
    """Serialize to the wire-format dict for the CLI control protocol.

    Converts dict-style mcp_servers to the array format the CLI expects:
    ``{"git": config}`` -> ``[{"git": config}]``

    Returns a camelCase dict with None values excluded.
    """
    model = self.to_wire_model()
    return model.model_dump(by_alias=True, exclude_none=True)

to_wire_model

to_wire_model() -> AgentWireDefinition

Serialize to the wire-format dict for the CLI control protocol.

Converts dict-style mcp_servers to the array format the CLI expects: {"git": config} -> [{"git": config}]

Returns a camelCase dict with None values excluded.

Source code in src/clawd_code_sdk/models/agents.py
def to_wire_model(self) -> AgentWireDefinition:
    """Serialize to the wire-format dict for the CLI control protocol.

    Converts dict-style mcp_servers to the array format the CLI expects:
    ``{"git": config}`` -> ``[{"git": config}]``

    Returns a camelCase dict with None values excluded.
    """
    mcp = [
        name if config is None else {name: config}
        for name, config in (self.mcp_servers or {}).items()
    ]
    return AgentWireDefinition(
        description=self.description,
        prompt=self.prompt,
        tools=self.tools,
        model=self.model,
        memory=self.memory,
        mcp_servers=mcp or None,
        disallowed_tools=self.disallowed_tools,
        critical_system_reminder_experimental=self.critical_system_reminder_experimental,
        skills=self.skills,
        initial_prompt=self.initial_prompt,
        max_turns=self.max_turns,
        background=self.background,
        hooks=self.hooks,
        effort=self.effort,
        permission_mode=self.permission_mode,
        isolation=self.isolation,
        auto_compact_window=self.auto_compact_window,
        omit_claude_md=self.omit_claude_md,
        observer=self.observer,
        observer_message=self.observer_message,
    )

:fa-brands-github: Show source on GitHub