Skip to content

API Reference parrot.handlers.agents.abstract

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.handlers.agents.abstract

View source

Alias AGENTS_DIR

Re-exported from parrot.conf.AGENTS_DIR.

Alias AIMessage

Re-exported from parrot.models.responses.AIMessage.

Alias AbstractTool

Re-exported from parrot.tools.abstract.AbstractTool.

Class AgentHandler

Abstract class for chatbot/agent handlers.

Provide a complete abstraction for exposing AI Agents as a REST API.

Parameter Type Default Description
request web.Request None
*args ()
app web.Application None
**kwargs {}

Attributes:

Attribute Type Description
agent_name str
agent_id str
on_startup Optional[Callable]
on_shutdown Optional[Callable]
on_cleanup Optional[Callable]
base_route str
additional_routes List[Dict[str, Any]]
app web.Application

Method AgentHandler.set_program

Set the program slug for the agent.

set_program(program_slug: str) -> None

Parameter Type Default Description
program_slug str

Method AgentHandler.setup

Setup the handler with the application and route.

setup(app: Union[WebApp, web.Application], route: List[Dict[Any, str]] = None) -> None

Parameter Type Default Description
app Union[WebApp, web.Application] The web application instance.
route List[Dict[Any, str]] None The route configuration.

Method AgentHandler.create_agent

create_agent(app: web.Application)

Parameter Type Default Description
app web.Application

Method AgentHandler.define_tools

Define additional tools for the agent.

define_tools()

Method AgentHandler.db_connection

Return a database connection.

db_connection(driver: str = 'pg', dsn: str = None, credentials: dict = None) -> AsyncDB

Parameter Type Default Description
driver str 'pg'
dsn str None
credentials dict None

Returns: AsyncDB

Method AgentHandler.register_background_task

Register a background task with the BackgroundService. Add an optional task wrapper to handle the task execution. Args: task (Callable[..., Awaitable]): The task to be executed. request (web.Request, optional): The request object. Defaults to None. done_callback (Optional[Callable[..., Awaitable]], optional): A callback to be called when the task is done. Defaults to None. *args: Positional arguments to pass to the task. **kwargs: Keyword arguments to pass to the task. Returns: JobRecord: The job record containing the task ID and other details. Raises: RuntimeError: If the request is not available.

register_background_task(task: Callable[..., Awaitable], request: web.Request = None, done_callback: Optional[Callable[..., Awaitable]] = None, *args, **kwargs) -> JobRecord

Parameter Type Default Description
task Callable[..., Awaitable]
request web.Request None
done_callback Optional[Callable[..., Awaitable]] None
*args ()
**kwargs {}

Returns: JobRecord

Method AgentHandler.find_jobs

Return Jobs by User.

find_jobs(request: web.Request) -> web.Response

Parameter Type Default Description
request web.Request

Returns: web.Response

Method AgentHandler.get_task_status

Get the status of a background task by its ID.

get_task_status(task_id: str, request: web.Request = None) -> JSONResponse

Parameter Type Default Description
task_id str
request web.Request None

Returns: JSONResponse

Method AgentHandler.add_route

Instance method to add custom routes.

add_route(method: str, path: str, handler: str)

Parameter Type Default Description
method str
path str
handler str

Method AgentHandler.create_temp_directory

Create the temporary directory for saving Agent Documents.

create_temp_directory(name: str = 'documents')

Parameter Type Default Description
name str 'documents'

Method AgentHandler.get_user_session

Return the user session from the request.

get_user_session()

Method AgentHandler.get_userid

Return the user ID from the session.

get_userid(session: Optional[Dict[str, Any]] = None, idx: str = 'user_id') -> Optional[str]

Parameter Type Default Description
session Optional[Dict[str, Any]] None
idx str 'user_id'

Returns: Optional[str]

Method AgentHandler.service_auth

Decorator to ensure the service is authenticated.

service_auth(fn: Union[Any, Any]) -> Any

Parameter Type Default Description
fn Union[Any, Any]

Returns: Any

Method AgentHandler.get_agent

Return the agent instance.

get_agent() -> Any

Returns: Any

Method AgentHandler.send_notification

Return the notification provider instance.

send_notification(content: str, provider: str = 'telegram', recipients: Union[List[dict], dict] = None, **kwargs) -> Any

Parameter Type Default Description
content str
provider str 'telegram'
recipients Union[List[dict], dict] None
**kwargs {}

Returns: Any

Method AgentHandler.open_prompt

Opens a prompt file and returns its content.

open_prompt(prompt_file: str = None) -> str

Parameter Type Default Description
prompt_file str None

Returns: str

Method AgentHandler.ask_agent

Asks the agent a question and returns the response.

ask_agent(query: str = None, prompt_file: str = None, *args, **kwargs) -> Tuple[AgentResponse, AIMessage]

Parameter Type Default Description
query str None
prompt_file str None
*args ()
**kwargs {}

Returns: Tuple[AgentResponse, AIMessage]

Alias AgentResponse

Re-exported from parrot.models.responses.AgentResponse.

Alias BasicAgent

Re-exported from parrot.bots.agent.BasicAgent.

Class JobWSManager

Extends the generic WebSocketManager with one helper that sends a direct message to the user owning a finished job.

Method JobWSManager.notify_job_done

Push a JSON message to every open WS belonging to user_id.

notify_job_done(*, user_id: int | str, job_id: str, status: str, result: Optional[Any] = None, error: Optional[str] = None) -> None

Parameter Type Default Description
user_id int | str
job_id str
status str
result Optional[Any] None
error Optional[str] None

Class RedisWriter

RedisWriter class.

Attributes:

Attribute Type Description
redis Get Redis Connection.

Function auth_by_attribute

Ensure the request is authenticated and the user belongs to at least one of allowed Job Codes.

auth_by_attribute(allowed: Sequence[str], attribute: str = 'job_code') -> Callable[[Callable[..., Awaitable]], Callable[..., Awaitable]]

Parameter Type Default Description
allowed Sequence[str]
attribute str 'job_code'

Returns: Callable[[Callable[..., Awaitable]], Callable[..., Awaitable]]

Function auth_groups

Ensure the request is authenticated and the user belongs to at least one of allowed groups.

auth_groups(allowed: Sequence[str]) -> Callable[[Callable[..., Awaitable]], Callable[..., Awaitable]]

Parameter Type Default Description
allowed Sequence[str]

Returns: Callable[[Callable[..., Awaitable]], Callable[..., Awaitable]]

Alias resolve_component_api_key

Re-exported from parrot.llm_defaults.resolve_component_api_key.

Alias resolve_component_llm

Re-exported from parrot.llm_defaults.resolve_component_llm.

Alias resolve_request_tenant

Re-exported from parrot.handlers.scope.resolve_request_tenant.

Alias usage_component

Re-exported from parrot.observability.context.usage_component.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally