Skip to content

API Reference parrot.handlers.agent

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

parrot.handlers.agent

View source

AgentTalk - HTTP Handler for Agent Conversations

Provides a flexible HTTP interface for talking with agents/bots using the ask() method with support for multiple output modes and MCP server integration.

Alias AIMessage

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

Alias AbstractBot

Re-exported from parrot.bots.abstract.AbstractBot.

Alias AgentResponse

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

Class AgentTalk

AgentTalk Handler - Universal agent conversation interface.

Features:

  • POST to /api/v1/agents/chat/{agent_id} to interact with agents
  • PATCH to /api/v1/agents/chat/{agent_id} to configure tools/MCP servers
  • Uses BotManager to retrieve the agent
  • Supports multiple output formats (JSON, HTML, Markdown, Terminal)
  • Session-scoped ToolManager: PATCH persists tools under '{agent_id}_tool_manager'
  • POST temporarily swaps user's ToolManager onto the agent and restores it after
  • Leverages OutputMode for consistent formatting
  • Session-based conversation management

Attributes:

Attribute Type Description
user_objects_handler UserObjectsHandler Lazy-initialized UserObjectsHandler for session-scoped managers.

Method AgentTalk.post_init

post_init(*args, **kwargs)

Parameter Type Default Description
*args ()
**kwargs {}

Method AgentTalk.post

POST handler for agent interaction. PBAC-guarded via requires_permission.

Endpoint: POST /api/v1/agents/chat/{agent_id}

Access is checked against PBAC policies for agent:chat action. If PBAC is not configured, access is allowed (backward compatible).

Request body::

{
    "agent_name": "my_agent",
    "query": "What is the weather like?",
    "session_id": "optional-session-id",
    "user_id": "optional-user-id",
    "stream": false,
    "output_mode": "json|html|markdown|terminal|default",
    "search_type": "similarity",
    "use_vector_context": true,
    "format_kwargs": {
        "show_metadata": true,
        "show_sources": true
    }
}

If the user's session contains a ToolManager (configured via PATCH), it will temporarily replace the agent's built-in ToolManager for the duration of this request and be restored afterwards.

.. deprecated:: Passing tools, mcp_servers, or tool_config inline in POST is deprecated. Use PATCH /api/v1/agents/chat/{agent_id} to configure tools and MCP servers instead.

Returns:

  • JSON response if output_mode is 'json' or Accept header is application/json
  • HTML page if output_mode is 'html' or Accept header is text/html
  • Markdown/plain text otherwise
  • When stream=true: HTTP chunked text/plain response. Text chunks arrive progressively; the final chunk (after a \n\x00 separator) is a JSON object with the AIMessage metadata envelope.

post()

Method AgentTalk.patch

PATCH /api/v1/agents/chat/{agent_id} — PBAC-guarded via agent:configure.

Configures the agent's tool manager and/or refreshes agent data. Access is checked against PBAC policies for the agent:configure action. If PBAC is not configured, access is allowed (backward compatible).

Tool configuration request body::

{
    "tools": [...],
    "mcp_servers": [
        {
            "name": "weather_api",
            "url": "https://api.example.com/mcp",
            "auth_type": "api_key",
            "auth_config": {"api_key": "xxx"},
            "headers": {"User-Agent": "AI-Parrot/1.0"}
        }
    ]
}

The resulting ToolManager is stored in the user's session under the key {agent_id}_tool_manager and will be used by subsequent POST requests for this agent.

If no tool/MCP configuration keys are present, falls through to the existing refresh_data logic.

patch()

Method AgentTalk.put

PUT /api/v1/agents/chat/{agent_id}

Uploads data (Excel) or adds queries (slug) to the agent.

put()

Method AgentTalk.get

GET /api/v1/agents/chat/

Returns information about the AgentTalk endpoint.

get()

Method AgentTalk.debug_agent

debug_agent(agent)

Parameter Type Default Description
agent

Alias AuthRequiredEnvelope

Re-exported from parrot.auth.oauth2.models.AuthRequiredEnvelope.

Alias AuthRequiredPayload

Re-exported from parrot.auth.credentials.AuthRequiredPayload.

Alias AuthorizationRequired

Re-exported from parrot.auth.exceptions.AuthorizationRequired.

Alias BotManager

Re-exported from parrot.manager.BotManager.

Alias CredentialRequired

Re-exported from parrot.auth.credentials.CredentialRequired.

Alias HumanInteractionInterrupt

Re-exported from parrot.core.exceptions.HumanInteractionInterrupt.

Alias HydrationUnavailableError

Re-exported from parrot.memory.hydration.HydrationUnavailableError.

Alias MCPServerConfig

Re-exported from parrot.mcp.integration.MCPServerConfig.

Alias OutputFormatter

Re-exported from parrot.outputs.OutputFormatter.

Alias OutputMode

Re-exported from parrot.outputs.OutputMode.

Class PausedEnvelope

HTTP-200 structured reply returned by AgentTalk when a SUSPEND tool raises HumanInteractionInterrupt.

Modelled on AuthRequiredEnvelope — the frontend detects status == "paused" and renders the appropriate HITL widget for the interaction type.

Fields:

Field Type Default Description
status str 'paused' Discriminator literal — always "paused".
turn_id str Correlation ID wrapping interaction_id (shared with resume path).
interaction_id str UUID of the pending HumanInteraction in Redis.
interaction_type str Interaction type string (e.g. "single_choice").
question str The question posed to the human.
context Optional[str] None Optional short background shown above the question.
options Optional[list] None For choice-type interactions — list of option dicts.
form_schema Optional[Dict[str, Any]] None For form-type interactions — JSON Schema dict.
default_response Any None Default value if the human does not respond in time.
deadline Optional[str] None ISO-8601 absolute expiry derived from the interaction TTL.
source_agent Optional[str] None Name of the agent that raised the interrupt.

Alias SafeUploadMixin

Re-exported from parrot.handlers.uploads.SafeUploadMixin.

Alias SessionDeletedError

Re-exported from parrot.memory.hydration.SessionDeletedError.

Alias ToolManager

Re-exported from parrot.tools.manager.ToolManager.

Alias ToolkitConfigService

Re-exported from parrot.handlers.toolkit_persistence.ToolkitConfigService.

Alias UserObjectsHandler

Re-exported from parrot.handlers.user_objects.UserObjectsHandler.

Alias WebSearchAgent

Re-exported from parrot.bots.search.WebSearchAgent.

Alias agent_tooling_ref

Re-exported from parrot.tools.spec.agent_tooling_ref.

Alias brain_admin_grant

Re-exported from parrot.memory.dream.models.brain_admin_grant.

Alias collect_auth_requirements

Re-exported from parrot.auth.pending.collect_auth_requirements.

Alias current_turn_tracker

Re-exported from parrot.auth.retry_safety.current_turn_tracker.

Alias get_toolkit_owner

Re-exported from parrot.tools.manager.get_toolkit_owner.

Alias hydrate_params

Re-exported from parrot.tools.spec.hydrate_params.

Alias reset_current_web_session

Re-exported from parrot.handlers.web_hitl.reset_current_web_session.

Alias resolve_request_tenant

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

Alias resolve_user_id

Re-exported from parrot.auth.session_identity.resolve_user_id.

Alias retrieve_vault_credential

Re-exported from parrot.security.vault_utils.retrieve_vault_credential.

Alias set_current_web_session

Re-exported from parrot.handlers.web_hitl.set_current_web_session.

Alias track_turn

Re-exported from parrot.auth.retry_safety.track_turn.

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