Agent Response Schema#
Overview#
The Agent API exposes roster agents and invite-options through two distinct response paths that differ in base class, serialization method, and icon handling. Understanding these differences is critical when consuming or extending agent endpoints.
Response Model Hierarchy#
There are two parallel response shapes for roster agents:
1. Pydantic ResponseModel-based β used by the dedicated /agent/roster and /agent/invite-options endpoints (registered at GET /agent/roster and GET /agent/invite-options in roster.py).
AgentRosterResponseinapi/fields/agent_fields.pyholds the core agent fields:icon_type,icon,icon_background, and metadata. It extendsResponseModelfromapi/fields/base.py, which setsfrom_attributes=True,extra="ignore", andserialize_by_alias=True.AgentInviteOptionResponseextendsAgentRosterResponsewith three extra fields:is_in_current_workflow,in_current_workflow_count, andexisting_node_ids.- Neither model defines an
icon_urlcomputed field. Consumers receive rawiconandicon_typevalues β no URL conversion is performed.
2. AppDetailWithSite/AppPartial-based β used by the generic /agent (Agent App) endpoints that remap an App ORM object to a roster-shaped response.
AppPartialandAppDetailWithSiteinapi/controllers/console/app/app.pyboth carry a@computed_fieldpropertyicon_urlthat callsbuild_icon_url(icon_type, icon).AppDetailSiteResponse, embedded inAppDetailWithSiteas thesitefield, also computesicon_urlfor the WebApp site surface .
icon_url Availability by Endpoint#
| Endpoint | Response Class | Has icon_url? | Icon value |
|---|---|---|---|
GET /agent (Agent App list) | AgentAppPagination β AgentAppPartial | β Yes (computed) | Signed URL for image type |
GET /agent/<id> (Agent App detail) | AgentAppDetailWithSite | β Yes (computed) | Signed URL for image type |
GET /agent/roster | AgentRosterListResponse | β No | Raw icon string from DB |
GET /agent/invite-options | AgentInviteOptionsResponse | β No | Raw icon string from DB |
build_icon_url returns None for non-image icon types (e.g., emoji), and a signed file URL for image type .
Serialization Path Differences#
Roster / Invite-options endpoints use AgentRosterService.serialize_agent(), a static method that manually builds a plain dict . This dict is then validated and serialized via dump_response(AgentRosterListResponse, ...) or dump_response(AgentInviteOptionsResponse, ...). The service populates icon directly from the Agent ORM field without conversion .
Agent App endpoints use Pydantic's model_validate(..., from_attributes=True) against AppDetailWithSite or AgentAppPagination, which triggers the icon_url computed field during serialization .
The roster and invite-options responses are built from the Agent model directly, while Agent App responses are built from the App model re-shaped by _serialize_agent_app_detail / _serialize_agent_app_pagination .
AgentComposerAgentResponse β Composer surface#
The Composer surface uses AgentComposerAgentResponse (also a ResponseModel), which mirrors the roster shape with icon_type, icon, icon_background but no icon_url. It also uses str | None for icon_type instead of the typed AgentIconType enum.
Key Source Files#
| File | Purpose |
|---|---|
api/fields/agent_fields.py | All agent-specific Pydantic response models |
api/controllers/console/agent/roster.py | Roster, invite-options, and Agent App API controllers |
api/controllers/console/app/app.py | AppPartial, AppDetailWithSite, icon_url computed field |
api/services/agent/roster_service.py | serialize_agent() β manual dict serializer used by roster/invite-options |
api/libs/helper.py | build_icon_url() β signs image URLs, returns None for emoji |
api/fields/base.py | ResponseModel base class configuration |