Skip to content

Document and extend the WP_Agent_Channel chat ability contract for bridge metadata #100

@chubes4

Description

@chubes4

Context

PR #99 added AgentsAPI\AI\Channels\WP_Agent_Channel, which gives direct webhook-style transports a reusable way to run a chat ability and deliver a response:

That PR already establishes the minimum chat ability call shape used by WP_Agent_Channel::run_agent():

$ability->execute(
    array(
        'agent'      => $this->agent_slug,
        'message'    => $message_text,
        'session_id' => '' === (string) $this->session_id ? null : $this->session_id,
    )
);

and WP_Agent_Channel::deliver_result() already understands these output shapes:

array(
    'reply'      => 'assistant text',
    'session_id' => 'optional-new-session-id',
)

or:

array(
    'messages' => array(
        array( 'role' => 'assistant', 'content' => 'assistant text' ),
    ),
)

The first consumer is Miguel's openclaWP wacli transport:

Data Machine has a parallel bridge entry point through datamachine/send-message in data-machine-chat-bridge:

These systems overlap around the same primitive: send one user message to one WP agent, optionally continue a session, and return assistant output.

Problem

The minimum contract exists, but it is not yet documented as a durable Agents API contract, and it does not yet describe the richer metadata that real channels and remote bridges need:

  • attachments
  • source/client context
  • external provider/channel identity
  • external conversation/thread ID
  • external message ID for idempotency
  • room kind (dm, group, channel)
  • optional runtime metadata/tool/turn information

Without documenting the base contract and defining its bridge-ready extension points, each runtime will keep growing incompatible variants (openclawp/chat, datamachine/send-message, future Intelligence chat ability, etc.).

Current shapes

openclawp/chat aligns with the minimum WP_Agent_Channel contract:

{
  "agent": "agent-slug",
  "message": "text",
  "session_id": "optional"
}

and returns:

{
  "session_id": "uuid",
  "reply": "assistant text",
  "completed": true
}

datamachine/send-message accepts a richer shape:

{
  "message": "text",
  "agent_id": 123,
  "session_id": "optional",
  "attachments": [],
  "client_context": {}
}

and returns Data Machine's chat response shape (session_id, response, completed, metadata/tool data, etc.).

Proposal

Document the existing minimum WP_Agent_Channel chat ability contract, then extend it in a backward-compatible way for bridge/channel metadata.

Base input, already used by WP_Agent_Channel:

{
  "agent": "agent-slug",
  "message": "text",
  "session_id": "optional"
}

Bridge-ready input extension:

{
  "agent": "agent-slug-or-id",
  "message": "text",
  "session_id": "optional",
  "attachments": [],
  "client_context": {
    "source": "channel|bridge|rest|block",
    "client_name": "wacli",
    "external_provider": "whatsapp",
    "external_conversation_id": "opaque-room-id",
    "external_message_id": "opaque-message-id",
    "room_kind": "dm|group|channel"
  }
}

Base output, already understood by WP_Agent_Channel:

{
  "session_id": "uuid",
  "reply": "assistant text",
  "completed": true
}

Optional richer output:

{
  "session_id": "uuid",
  "reply": "assistant text",
  "messages": [],
  "completed": true,
  "metadata": {}
}

Acceptance criteria

  • Document the existing WP_Agent_Channel chat ability input/output contract as the minimum portable contract.
  • Document optional bridge/channel fields (attachments, client_context) without breaking existing ability implementations.
  • Decide whether WP_Agent_Channel::run_agent() should pass normalized client_context once issue Add normalized channel message and session mapping primitives #102 lands.
  • Decide whether extract_replies() should also understand response as a common alias for reply, since Data Machine uses that field today.
  • Leave runtimes free to register adapters behind the contract (openclawp/chat, Data Machine, Intelligence, etc.).

Why this belongs in agents-api

The overlap is now visible in at least two implementations. A documented contract makes WP_Agent_Channel and future remote bridge APIs portable without forcing every channel or bridge to hard-code runtime-specific ability shapes.

Related issues:

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