Skip to content

FastAgency

fastagency.FastAgency #

FastAgency(
    wf: Workflows,
    ui: UI,
    *,
    title: Optional[str] = None,
    description: Optional[str] = None
)

Initialize the FastAgency object.

PARAMETER DESCRIPTION
wf

The workflows object to use

TYPE: Workflows

ui

The UI object to use

TYPE: UI

title

The title of the FastAgency. If None, the default string will be used. Defaults to None.

TYPE: Optional[str] DEFAULT: None

description

The description of the FastAgency. If None, the default string will be used. Defaults to None.

TYPE: Optional[str] DEFAULT: None

Source code in fastagency/app.py
def __init__(
    self,
    wf: Workflows,
    ui: UI,
    *,
    title: Optional[str] = None,
    description: Optional[str] = None,
) -> None:
    """Initialize the FastAgency object.

    Args:
        wf (Workflows): The workflows object to use
        ui (UI): The UI object to use
        title (Optional[str], optional): The title of the FastAgency. If None, the default string will be used. Defaults to None.
        description (Optional[str], optional): The description of the FastAgency. If None, the default string will be used. Defaults to None.
    """
    self._title = title or "FastAgency application"
    default_description = "FastAgency application"

    if len(wf.names) == 0:
        logger.warning(f"No workflows found in {wf}")
        default_description += " - No workflows found"
    else:
        default_description += " - Workflows:"
        for name in wf.names:
            default_description += f" - {name}: {wf.get_description(name)}"
    self._description = description or default_description

    logger.info(f"Initializing FastAgency {self} with workflows: {wf} and UI: {ui}")
    self._wf = wf
    self._ui = ui
    logger.info(f"Initialized FastAgency: {self}")

description property #

description: str

Return the description of the FastAgency.

title property #

title: str

Return the title of the FastAgency.

ui property #

ui: UI

Return the UI object.

wf property #

Return the workflows object.

create #

create(import_string: str) -> Generator[None, None, None]

Create the FastAgency.

Source code in fastagency/app.py
@contextmanager
def create(self, import_string: str) -> Generator[None, None, None]:
    """Create the FastAgency."""
    with self._ui.create(app=self, import_string=import_string):
        yield

handle_asgi async #

handle_asgi(
    scope: dict[str, Any],
    receive: Callable[[dict[str, Any]], Awaitable[None]],
    send: Callable[[dict[str, Any]], Awaitable[None]],
) -> None
Source code in fastagency/app.py
async def handle_asgi(
    self,
    scope: dict[str, Any],
    receive: Callable[[dict[str, Any]], Awaitable[None]],
    send: Callable[[dict[str, Any]], Awaitable[None]],
) -> None:
    if isinstance(self.ui, ASGI):
        return await self.ui.handle_asgi(self, scope, receive, send)
    else:
        raise FastAgencyASGINotImplementedError(
            "ASGI interface not supported for UI: {self.ui}"
        )

handle_wsgi #

handle_wsgi(
    environ: dict[str, Any],
    start_response: Callable[..., Any],
) -> list[bytes]
Source code in fastagency/app.py
def handle_wsgi(
    self, environ: dict[str, Any], start_response: Callable[..., Any]
) -> list[bytes]:
    if isinstance(self.ui, WSGI):
        return self.ui.handle_wsgi(self, environ, start_response)
    else:
        raise FastAgencyWSGINotImplementedError(
            "WSGI interface not supported for UI: {self.ui}"
        )

start #

start(
    import_string: str,
    name: Optional[str] = None,
    initial_message: Optional[str] = None,
    single_run: bool = False,
) -> None

Start the FastAgency.

Source code in fastagency/app.py
def start(
    self,
    import_string: str,
    name: Optional[str] = None,
    initial_message: Optional[str] = None,
    single_run: bool = False,
) -> None:
    """Start the FastAgency."""
    self.ui.start(
        app=self,
        import_string=import_string,
        name=name,
        initial_message=initial_message,
        single_run=single_run,
    )