Skip to content

AgentSpec

Base classes

Name Children Inherits
BaseModel
pydantic.main
!!! abstract "Usage Documentation"

⋔ Inheritance diagram

graph TD
  107846716674912["config.AgentSpec"]
  107846697802608["main.BaseModel"]
  137699722799616["builtins.object"]
  107846697802608 --> 107846716674912
  137699722799616 --> 107846697802608

🛈 DocStrings

Bases: BaseModel

How to reach an agent: a command to launch (stdio) or a URL (HTTP / WebSocket).

Source code in src/acptui/config.py
class AgentSpec(BaseModel):
    """How to reach an agent: a command to launch (stdio) or a URL (HTTP / WebSocket)."""

    model_config = ConfigDict(frozen=True, extra="forbid")

    id: str
    """Short identifier, used on the command line (``acptui run <id>``)."""

    name: str
    """Display name."""

    command: tuple[str, ...] = ()
    """Program and arguments of a local (stdio) agent."""

    url: str | None = None
    """URL of a remote agent (``http(s)://`` or ``ws(s)://``)."""

    env: Mapping[str, str] = Field(default_factory=dict)
    """Extra environment variables for a local agent (``${VAR}`` is expanded)."""

    headers: Mapping[str, str] = Field(default_factory=dict)
    """HTTP headers for a remote agent (``${VAR}`` is expanded)."""

    description: str = ""
    """One line about the agent."""

    homepage: str = ""
    """Where to get it."""

    install: str = ""
    """Command that installs the agent."""

    builtin: bool = False
    """Whether the agent comes from the built-in registry."""

    options: Mapping[str, str | bool] = Field(default_factory=dict)
    """Initial session config options (``config_id`` -> value), e.g. ``{"model": "opus"}``."""

    @model_validator(mode="after")
    def _check_target(self) -> AgentSpec:
        if bool(self.command) == bool(self.url):
            msg = f"agent {self.id!r} needs exactly one of `command` and `url`"
            raise ValueError(msg)
        return self

    @property
    def is_remote(self) -> bool:
        """Whether the agent is reached over the network."""
        return self.url is not None

    @property
    def available(self) -> bool:
        """Whether the agent can be started: its program is on ``PATH`` (or it is remote)."""
        if self.url is not None:
            return True
        program = self.command[0]
        return Path(program).is_file() or shutil.which(program) is not None

    @property
    def target(self) -> str:
        """The command line or URL, for display."""
        return self.url if self.url is not None else " ".join(self.command)

    def resolved_env(self) -> dict[str, str]:
        """The extra environment, with ``${VAR}`` references expanded."""
        return {key: expand_env(value) for key, value in self.env.items()}

    def resolved_headers(self) -> dict[str, str]:
        """The headers, with ``${VAR}`` references expanded."""
        return {key: expand_env(value) for key, value in self.headers.items()}

available property

available: bool

Whether the agent can be started: its program is on PATH (or it is remote).

builtin class-attribute instance-attribute

builtin: bool = False

Whether the agent comes from the built-in registry.

command class-attribute instance-attribute

command: tuple[str, ...] = ()

Program and arguments of a local (stdio) agent.

description class-attribute instance-attribute

description: str = ''

One line about the agent.

env class-attribute instance-attribute

env: Mapping[str, str] = Field(default_factory=dict)

Extra environment variables for a local agent (${VAR} is expanded).

headers class-attribute instance-attribute

headers: Mapping[str, str] = Field(default_factory=dict)

HTTP headers for a remote agent (${VAR} is expanded).

homepage class-attribute instance-attribute

homepage: str = ''

Where to get it.

id instance-attribute

id: str

Short identifier, used on the command line (acptui run <id>).

install class-attribute instance-attribute

install: str = ''

Command that installs the agent.

is_remote property

is_remote: bool

Whether the agent is reached over the network.

name instance-attribute

name: str

Display name.

options class-attribute instance-attribute

options: Mapping[str, str | bool] = Field(default_factory=dict)

Initial session config options (config_id -> value), e.g. {"model": "opus"}.

target property

target: str

The command line or URL, for display.

url class-attribute instance-attribute

url: str | None = None

URL of a remote agent (http(s):// or ws(s)://).

resolved_env

resolved_env() -> dict[str, str]

The extra environment, with ${VAR} references expanded.

Source code in src/acptui/config.py
def resolved_env(self) -> dict[str, str]:
    """The extra environment, with ``${VAR}`` references expanded."""
    return {key: expand_env(value) for key, value in self.env.items()}

resolved_headers

resolved_headers() -> dict[str, str]

The headers, with ${VAR} references expanded.

Source code in src/acptui/config.py
def resolved_headers(self) -> dict[str, str]:
    """The headers, with ``${VAR}`` references expanded."""
    return {key: expand_env(value) for key, value in self.headers.items()}

:fa-brands-github: Show source on GitHub