Skip to content

AgentPicker

Base classes

Name Children Inherits
Screen
textual.screen
The base class for screens.

β‹” Inheritance diagram

graph TD
  107846719869680["picker.AgentPicker"]
  107846717858048["screen.Screen"]
  107846685555472["typing.Generic"]
  137699722799616["builtins.object"]
  107846718477920["widget.Widget"]
  107846718489888["dom.DOMNode"]
  107846718374032["message_pump.MessagePump"]
  107846717858048 --> 107846719869680
  107846685555472 --> 107846717858048
  137699722799616 --> 107846685555472
  107846718477920 --> 107846717858048
  107846718489888 --> 107846718477920
  107846718374032 --> 107846718489888
  137699722799616 --> 107846718374032

πŸ›ˆ DocStrings

Bases: Screen[None]

Choose an agent from the registry, or type a command / URL.

Source code in src/acptui/ui/screens/picker.py
class AgentPicker(Screen[None]):
    """Choose an agent from the registry, or type a command / URL."""

    DEFAULT_CSS = """
    AgentPicker {
        align: center top;
        #picker {
            width: 100%;
            max-width: 110;
            height: 1fr;
            padding: 1 2 0 2;
        }
        #heading { text-style: bold; color: $accent; margin: 0 0 1 0; }
        #agents { height: 1fr; border: round $primary 50%; }
        #agents:focus { border: round $primary; }
        #custom { margin: 1 0 0 0; }
        #hint { color: $text-muted; margin: 1 0 0 0; }
    }
    """

    BINDINGS: ClassVar = [
        Binding("c", "custom", "Command / URL"),
        Binding("escape", "focus_list", "Back", show=False),
        Binding("q", "app.quit", "Quit"),
    ]

    class Picked(Message):
        """An agent was chosen."""

        def __init__(self, spec: AgentSpec) -> None:
            super().__init__()
            self.spec = spec

    def __init__(self, agents: list[AgentSpec], cwd: str) -> None:
        super().__init__()
        self.agents = agents
        self.cwd = cwd

    def compose(self) -> ComposeResult:
        with Vertical(id="picker"):
            home = str(Path.home())
            cwd = "~" + self.cwd[len(home) :] if self.cwd.startswith(home) else self.cwd
            heading = Content.assemble("acptui Β· pick an agent for ", (cwd, "italic"))
            yield Static(heading, id="heading")
            yield OptionList(*(agent_option(spec) for spec in self.agents), id="agents")
            yield Input(
                placeholder="…or an agent command (e.g. my-agent --acp) or URL, then enter",
                id="custom",
            )
            yield Static(
                "acptui speaks ACP v2 only: agents that negotiate another version get an error.",
                id="hint",
            )
        yield Footer()

    def on_mount(self) -> None:
        options = self.query_one("#agents", OptionList)
        options.focus()
        first_available = next((i for i, spec in enumerate(self.agents) if spec.available), 0)
        options.highlighted = first_available

    def on_option_list_option_selected(self, event: OptionList.OptionSelected) -> None:
        spec = next((s for s in self.agents if s.id == event.option_id), None)
        if spec is not None:
            self.post_message(self.Picked(spec))

    def on_input_submitted(self, event: Input.Submitted) -> None:
        value = event.value.strip()
        if not value:
            return
        spec = url_spec(value) if "://" in value else command_spec(value.split())
        self.post_message(self.Picked(spec))

    def action_custom(self) -> None:
        """Focus the command input."""
        self.query_one("#custom", Input).focus()

    def action_focus_list(self) -> None:
        """Focus the agent list."""
        self.query_one("#agents", OptionList).focus()

Picked

Bases: Message

An agent was chosen.

Source code in src/acptui/ui/screens/picker.py
class Picked(Message):
    """An agent was chosen."""

    def __init__(self, spec: AgentSpec) -> None:
        super().__init__()
        self.spec = spec

action_custom

action_custom() -> None

Focus the command input.

Source code in src/acptui/ui/screens/picker.py
def action_custom(self) -> None:
    """Focus the command input."""
    self.query_one("#custom", Input).focus()

action_focus_list

action_focus_list() -> None

Focus the agent list.

Source code in src/acptui/ui/screens/picker.py
def action_focus_list(self) -> None:
    """Focus the agent list."""
    self.query_one("#agents", OptionList).focus()

:fa-brands-github: Show source on GitHub