Skip to content

API Reference parrot.handlers.avatar

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

parrot.handlers.avatar

View source

Avatar session endpoint — start/stop/viewers for an avatar session (FEAT-242, FEAT-249).

Additional endpoint for Mode C (multi-viewer LITE):

POST /api/v1/avatar/{agent_id}/viewers
    For an active LITE session, mint up to ``count`` additional subscribe-only
    viewer tokens and return them as a list. No secrets are ever returned.

Provides authenticated REST endpoints for the LiveAvatar LITE avatar session:

POST /api/v1/agents/avatar/{agent_id}/start
    Start an avatar session for the named agent.  Returns viewer credentials
    ONLY (``livekit_url``, ``client_token``, ``session_id``).  The
    ``agent_token``, ``ws_url`` and ``session_token`` are NEVER returned to
    the client.  The live :class:`LiveAvatarClient` (with its keep-alive
    loop) is kept alive and stored in ``app['avatar_sessions']`` so the
    matching ``/stop`` can tear it down.

POST /api/v1/agents/avatar/{agent_id}/stop
    Stop an active avatar session by ``session_id``: stops the LiveAvatar
    session, cancels the keep-alive loop, and closes the HTTP client.

Both endpoints are served through :class:AvatarSessionView, a navigator.views.BaseView decorated with @is_authenticated() and @user_session() (mirrors :class:AgentTalk) — so an unauthenticated caller can neither start nor stop a session.

Integration with AgentVoiceTalk: The avatar mode is exposed as a request flag (avatar=true) on the voice endpoint. A separate POST to /api/v1/agents/avatar/{agent_id}/start pre-starts the avatar session and returns viewer credentials that the browser uses to join the LiveKit room; the browser still calls the voice endpoint as normal for the actual dialogue.

Attribute AVATAR_SESSIONS_KEY

Class AvatarSessionView

Authenticated entrypoint for the avatar start/stop actions.

Routed at /api/v1/agents/avatar/{agent_id}/{action} where action is start or stop. Authentication/session decorators match :class:AgentTalk, so unauthenticated callers are rejected before any avatar session is created or destroyed.

Method AvatarSessionView.post

post() -> web.Response

Returns: web.Response

Method AvatarSessionView.get

get() -> web.Response

Returns: web.Response

Class AvatarViewersView

Authenticated endpoint to mint extra subscribe-only viewer tokens (Mode C).

Routed at POST /api/v1/avatar/{agent_id}/viewers. Authentication mirrors :class:AvatarSessionView — only authenticated callers may mint viewer tokens.

Method AvatarViewersView.post

post() -> web.Response

Returns: web.Response

Function avatar_upstream_error_response

Translate a LiveAvatar upstream error into a clean JSON response.

Without this, the upstream ClientResponseError propagates and aiohttp returns a bare 500 whose body does NOT carry the reason — the frontend cannot tell "no credits" from a real server bug. Map the two cases the frontend acts on:

  • "No credits" (LiveAvatar code 4033 / 403) -> 402 so the UI can show an actionable "avatar has no credits" message.
  • Any other upstream failure -> 502 (provider error).

avatar_upstream_error_response(exc: ClientResponseError) -> web.Response

Parameter Type Default Description
exc ClientResponseError

Returns: web.Response

Function close_all_avatar_sessions

Best-effort teardown of any lingering avatar sessions on shutdown.

Registered as an on_cleanup callback by the bot manager. Iterates the session store, stops each LiveAvatar session or direct-audio publisher (FEAT-256 avatar-OFF path) and closes its client.

close_all_avatar_sessions(app: web.Application) -> None

Parameter Type Default Description
app web.Application

Function register_avatar_routes

Register avatar session endpoints on the provided aiohttp router.

Follows the same defensive-import pattern used by _register_voice_routes in manager.py. Routes are served through the authenticated :class:AvatarSessionView.

register_avatar_routes(router: Any) -> bool

Parameter Type Default Description
router Any The aiohttp UrlDispatcher to register routes on.

Returns: bool — True if routes were registered, False if the stack is missing.

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