Skip to content

elicitation

Class info

Classes

Name Children Inherits
FormElicitationScreen
acptui.ui.screens.elicitation
A form for the requested schema, built and validated by promptantic.
    UrlElicitationScreen
    acptui.ui.screens.elicitation
    Asks the user to visit a URL (e.g. to sign in); closes when the agent reports completion.

      🛈 DocStrings

      Elicitation: structured input the agent asks for, as a form (promptantic) or a URL to visit.

      FormElicitationScreen

      Bases: ModalScreen['CreateElicitationResponse']

      A form for the requested schema, built and validated by promptantic.

      Source code in src/acptui/ui/screens/elicitation.py
      class FormElicitationScreen(ModalScreen["CreateElicitationResponse"]):
          """A form for the requested schema, built and validated by promptantic."""
      
          DEFAULT_CSS = "FormElicitationScreen {" + DIALOG_CSS + "}"
          BINDINGS: ClassVar = [
              Binding("escape", "cancel", "Cancel"),
              Binding("ctrl+s", "submit", "Submit", priority=True),
          ]
      
          def __init__(self, request: FormElicitationRequest) -> None:
              super().__init__()
              self.request = request
              self.schema: dict[str, Any] = request.requested_schema.model_dump(
                  mode="json", by_alias=True, exclude_none=True
              )
              self.form = FormView(target_for(self.schema))
      
          def compose(self) -> ComposeResult:
              with Vertical(id="dialog"):
                  yield Static(Content(self.schema.get("title") or "The agent needs input"), id="message")
                  yield Static(Content(self.request.message))
                  if description := self.schema.get("description"):
                      yield Static(Content(description), classes="help")
                  yield self.form
                  with Horizontal(id="buttons"):
                      yield Button("Submit", variant="success", id="submit", compact=True)
                      yield Button("Decline", variant="error", id="decline", compact=True)
                      yield Button("Cancel", id="cancel", compact=True)
      
          def action_submit(self) -> None:
              self.form.submit()
      
          def on_form_view_submitted(self, event: FormView.Submitted) -> None:
              event.stop()
              self.dismiss(AcceptElicitationResponse(content=event.result))
      
          def action_cancel(self) -> None:
              """Close without an answer."""
              self.dismiss(CancelElicitationResponse())
      
          def on_button_pressed(self, event: Button.Pressed) -> None:
              event.stop()
              match event.button.id:
                  case "submit":
                      self.action_submit()
                  case "decline":
                      self.dismiss(DeclineElicitationResponse())
                  case _:
                      self.action_cancel()
      
          def cancel(self) -> None:
              """Close because the agent cancelled the request."""
              if self.is_attached:
                  self.dismiss(CancelElicitationResponse())
      

      action_cancel

      action_cancel() -> None
      

      Close without an answer.

      Source code in src/acptui/ui/screens/elicitation.py
      def action_cancel(self) -> None:
          """Close without an answer."""
          self.dismiss(CancelElicitationResponse())
      

      cancel

      cancel() -> None
      

      Close because the agent cancelled the request.

      Source code in src/acptui/ui/screens/elicitation.py
      def cancel(self) -> None:
          """Close because the agent cancelled the request."""
          if self.is_attached:
              self.dismiss(CancelElicitationResponse())
      

      UrlElicitationScreen

      Bases: ModalScreen['CreateElicitationResponse']

      Asks the user to visit a URL (e.g. to sign in); closes when the agent reports completion.

      Source code in src/acptui/ui/screens/elicitation.py
      class UrlElicitationScreen(ModalScreen["CreateElicitationResponse"]):
          """Asks the user to visit a URL (e.g. to sign in); closes when the agent reports completion."""
      
          DEFAULT_CSS = "UrlElicitationScreen {" + DIALOG_CSS + " #url { color: $text-accent; } }"
          BINDINGS: ClassVar = [Binding("escape", "cancel", "Cancel"), Binding("o", "open", "Open URL")]
      
          def __init__(self, request: UrlElicitationRequest) -> None:
              super().__init__()
              self.request = request
              self.elicitation_id = request.elicitation_id
      
          def compose(self) -> ComposeResult:
              with Vertical(id="dialog"):
                  yield Static("The agent asks you to open a URL", id="message")
                  yield Static(Content(self.request.message))
                  yield Static(Content(self.request.url), id="url")
                  yield Static("Waiting for the agent to confirm… (o: open in browser)", classes="help")
                  with Horizontal(id="buttons"):
                      yield Button("Open", variant="primary", id="open", compact=True)
                      yield Button("Done", variant="success", id="done", compact=True)
                      yield Button("Decline", variant="error", id="decline", compact=True)
                      yield Button("Cancel", id="cancel", compact=True)
      
          async def action_open(self) -> None:
              """Open the URL in a browser (in a thread: it may block)."""
              await asyncio.to_thread(webbrowser.open, self.request.url)
      
          def action_cancel(self) -> None:
              """Cancel the elicitation."""
              self.dismiss(CancelElicitationResponse())
      
          async def on_button_pressed(self, event: Button.Pressed) -> None:
              match event.button.id:
                  case "open":
                      await self.action_open()
                  case "done":
                      self.dismiss(AcceptElicitationResponse())
                  case "decline":
                      self.dismiss(DeclineElicitationResponse())
                  case _:
                      self.action_cancel()
      
          def complete(self) -> None:
              """The agent reported the elicitation complete."""
              if self.is_attached:
                  self.dismiss(AcceptElicitationResponse())
      
          def cancel(self) -> None:
              """Close because the agent cancelled the request."""
              if self.is_attached:
                  self.dismiss(CancelElicitationResponse())
      

      action_cancel

      action_cancel() -> None
      

      Cancel the elicitation.

      Source code in src/acptui/ui/screens/elicitation.py
      def action_cancel(self) -> None:
          """Cancel the elicitation."""
          self.dismiss(CancelElicitationResponse())
      

      action_open async

      action_open() -> None
      

      Open the URL in a browser (in a thread: it may block).

      Source code in src/acptui/ui/screens/elicitation.py
      async def action_open(self) -> None:
          """Open the URL in a browser (in a thread: it may block)."""
          await asyncio.to_thread(webbrowser.open, self.request.url)
      

      cancel

      cancel() -> None
      

      Close because the agent cancelled the request.

      Source code in src/acptui/ui/screens/elicitation.py
      def cancel(self) -> None:
          """Close because the agent cancelled the request."""
          if self.is_attached:
              self.dismiss(CancelElicitationResponse())
      

      complete

      complete() -> None
      

      The agent reported the elicitation complete.

      Source code in src/acptui/ui/screens/elicitation.py
      def complete(self) -> None:
          """The agent reported the elicitation complete."""
          if self.is_attached:
              self.dismiss(AcceptElicitationResponse())
      

      cancelled_elicitation

      cancelled_elicitation() -> CreateElicitationResponse
      

      The response when the user (or the agent) cancelled.

      Source code in src/acptui/ui/screens/elicitation.py
      def cancelled_elicitation() -> CreateElicitationResponse:
          """The response when the user (or the agent) cancelled."""
          return CancelElicitationResponse()