Skip to content

Add __str__() methods to response types for human-readable protocol messages #91

@bokelley

Description

@bokelley

Summary

Add __str__() methods to AdCP response types to generate consistent, human-readable messages for protocol layers (MCP, A2A, REST).

Motivation

When building AdCP implementations, response types need human-readable messages for:

  • MCP tool results (displayed to users)
  • A2A task messages (agent communication)
  • REST API responses (optional message field)

Currently, each implementation must define these messages independently, leading to inconsistent messaging across the ecosystem.

Proposed Changes

Add __str__() methods to these response types:

Response Type Message Pattern
GetProductsResponse "Found N products that match your requirements."
ListCreativeFormatsResponse "Found N creative formats."
ListAuthorizedPropertiesResponse "Found N authorized publisher domains."
CreateMediaBuyResponse "Media buy {media_buy_id} created successfully."
UpdateMediaBuyResponse "Media buy {media_buy_id} updated successfully."
SyncCreativesResponse "Creative sync completed: N created, N updated, N deleted."
GetMediaBuyDeliveryResponse "Delivery data for N media buys."
GetSignalsResponse "Found N signals matching your criteria."
ActivateSignalResponse Status-based: "Signal activated successfully" / "Signal activation in progress" / etc.
ListCreativesResponse "Found N creatives." or "Found N creatives, showing M."

Example Implementation

class GetProductsResponse(AdCPBaseModel):
    products: list[Product]
    # ... other fields

    def __str__(self) -> str:
        count = len(self.products)
        if count == 0:
            return "No products matched your requirements."
        elif count == 1:
            return "Found 1 product that matches your requirements."
        else:
            return f"Found {count} products that match your requirements."

Benefits

  1. Consistency - All AdCP implementations return the same messages
  2. No schema changes - __str__() doesn't add fields to the JSON schema
  3. Protocol-agnostic - Works for MCP, A2A, and REST
  4. Agent-friendly - Clear, conversational messages for AI agents

Reference Implementation

These patterns are currently implemented in the adcp-sales-agent in src/core/schema_adapters.py.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions