Skip to content

registry

Class info

Re-exported classes

Class Module Description
BaseDistribution aclientp.registry.model Base class for agent distribution methods.
BinaryDistribution aclientp.registry.model Distribution via a pre-built binary archive.
DistributionUnion aclientp.registry.model Container that holds the possible distribution variants for an agent.
NpxDistribution aclientp.registry.model Distribution via npx / bunx.
Registry aclientp.registry.model Top-level ACP registry response.
RegistryAgent aclientp.registry.model A single agent entry in the ACP registry.
UvxDistribution aclientp.registry.model Distribution via uvx.

🛈 DocStrings

ACP Registry - fetch and query agent entries from the ACP registry.

BaseDistribution

Bases: BaseModel, ABC

Base class for agent distribution methods.

Source code in src/aclientp/registry/model.py
class BaseDistribution(BaseModel, ABC):
    """Base class for agent distribution methods."""

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

    @abstractmethod
    def format_cmd(self) -> str: ...

    @abstractmethod
    def format_args(self) -> tuple[str, ...]: ...

BinaryDistribution

Bases: BaseDistribution

Distribution via a pre-built binary archive.

Source code in src/aclientp/registry/model.py
class BinaryDistribution(BaseDistribution):
    """Distribution via a pre-built binary archive."""

    archive: str
    cmd: str

    def format_cmd(self) -> str:
        return Path(self.cmd).name

    def format_args(self) -> tuple[str, ...]:
        return (*self.args,)

DistributionUnion

Bases: BaseModel

Container that holds the possible distribution variants for an agent.

Source code in src/aclientp/registry/model.py
class DistributionUnion(BaseModel):
    """Container that holds the possible distribution variants for an agent."""

    npx: NpxDistribution | None = None
    uvx: UvxDistribution | None = None
    binary: dict[str, BinaryDistribution] | None = None

NpxDistribution

Bases: BaseDistribution

Distribution via npx / bunx.

Source code in src/aclientp/registry/model.py
class NpxDistribution(BaseDistribution):
    """Distribution via npx / bunx."""

    package: str

    def format_cmd(self) -> str:
        return "bunx"

    def format_args(self) -> tuple[str, ...]:
        return (self.package, *self.args)

Registry

Bases: BaseModel

Top-level ACP registry response.

Source code in src/aclientp/registry/model.py
class Registry(BaseModel):
    """Top-level ACP registry response."""

    version: str
    agents: list[RegistryAgent]
    extensions: list[Any] = Field(default_factory=list)

RegistryAgent

Bases: BaseModel

A single agent entry in the ACP registry.

Source code in src/aclientp/registry/model.py
class RegistryAgent(BaseModel):
    """A single agent entry in the ACP registry."""

    id: str
    name: str
    version: str
    description: str
    repository: str | None = None
    authors: list[str] = Field(default_factory=list)
    license: str
    icon: str | None = None
    distribution: DistributionUnion

    def __str__(self) -> str:
        return f"{self.name} ({self.id})"

    @cached_property
    def dist(self) -> Distribution:
        """Resolve the best distribution for the current platform."""
        match self.distribution:
            case DistributionUnion(npx=NpxDistribution() as npx):
                return npx
            case DistributionUnion(uvx=UvxDistribution() as uvx):
                return uvx
            case DistributionUnion(binary=dict() as binaries):
                platform_key = get_platform_key()
                binary_distro: BinaryDistribution | None = binaries.get(platform_key)
                if binary_distro is not None:
                    return binary_distro
                raise ValueError(f"No binary distribution found for platform {platform_key!r}")
            case _:
                raise ValueError("Unsupported distribution type.")

    async def prepare(
        self,
        extra_args: list[str] | None = None,
        *,
        bin_dir: Path = DEFAULT_BIN_DIR,
    ) -> list[str]:
        """Resolve this agent to a runnable command list."""
        args = extra_args or []
        match self.dist:
            case NpxDistribution() as dist:
                return prepare_npx(dist, args)
            case UvxDistribution() as dist:
                return prepare_uvx(dist, args)
            case BinaryDistribution() as dist:
                return await prepare_binary(dist, args, bin_dir)
            case _:
                raise ValueError("Unsupported distribution type.")

dist cached property

dist: Distribution

Resolve the best distribution for the current platform.

prepare async

prepare(extra_args: list[str] | None = None, *, bin_dir: Path = DEFAULT_BIN_DIR) -> list[str]

Resolve this agent to a runnable command list.

Source code in src/aclientp/registry/model.py
async def prepare(
    self,
    extra_args: list[str] | None = None,
    *,
    bin_dir: Path = DEFAULT_BIN_DIR,
) -> list[str]:
    """Resolve this agent to a runnable command list."""
    args = extra_args or []
    match self.dist:
        case NpxDistribution() as dist:
            return prepare_npx(dist, args)
        case UvxDistribution() as dist:
            return prepare_uvx(dist, args)
        case BinaryDistribution() as dist:
            return await prepare_binary(dist, args, bin_dir)
        case _:
            raise ValueError("Unsupported distribution type.")

UvxDistribution

Bases: BaseDistribution

Distribution via uvx.

Source code in src/aclientp/registry/model.py
class UvxDistribution(BaseDistribution):
    """Distribution via uvx."""

    package: str

    def format_cmd(self) -> str:
        return "uvx"

    def format_args(self) -> tuple[str, ...]:
        return ("--python", "3.13", self.package, *self.args)

fetch_agent async

fetch_agent(agent_id: str) -> RegistryAgent | None

Fetch a single agent by ID from the registry or built-in agents.

Source code in src/aclientp/registry/fetch.py
async def fetch_agent(agent_id: str) -> RegistryAgent | None:
    """Fetch a single agent by ID from the registry or built-in agents."""
    if agent := _builtin_agent(agent_id):
        return agent
    agents = await list_agents()
    return next((a for a in agents if a.id == agent_id), None)

fetch_registry async

fetch_registry() -> Registry

Fetch the ACP registry data.

Source code in src/aclientp/registry/fetch.py
async def fetch_registry() -> Registry:
    """Fetch the ACP registry data."""
    return await anyenv.get_json(
        REGISTRY_URL,
        headers={"User-Agent": "Mozilla/5.0"},
        return_type=Registry,
        cache=True,
    )

list_agents async

list_agents() -> list[RegistryAgent]

List all agents from the ACP registry, including built-in agents.

Source code in src/aclientp/registry/fetch.py
async def list_agents() -> list[RegistryAgent]:
    """List all agents from the ACP registry, including built-in agents."""
    registry = await fetch_registry()
    return _merge_builtin_agents(registry.agents)