opencode icon indicating copy to clipboard operation
opencode copied to clipboard

[FEATURE]: `message` tool for subagent-to-user direct output

Open jcyamacho opened this issue 3 days ago • 0 comments

Feature hasn't been suggested before.

  • [x] I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Feature Request: message tool for subagent-to-user direct output

Problem

When a subagent (via subtask: true command or Task tool) generates carefully formatted output, the main agent receives it and often reformulates, summarizes, or adds commentary before presenting to the user. There's no way to guarantee verbatim output delivery.

Example scenario:

A subagent generates a SQL migration script that must be exact:

ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
CREATE INDEX idx_users_last_login ON users(last_login);
UPDATE users SET last_login = created_at WHERE last_login IS NULL;

The subagent produces exactly what the user needs. But the main agent receives this and responds with:

"I've generated a migration script for you. It adds a last_login column and creates an index. Here's what it does..."

The user wanted the raw SQL to copy-paste, not an explanation of it.

Proposed Solution

Add a message tool that subagents can invoke to push content directly to the user, bypassing the main agent's interpretation layer.

API Design

message({
  content: string,       // Content to display to user
  format?: "text" | "markdown" | "code",  // Display hint (default: "text")
  language?: string,     // For format: "code", e.g., "sql", "yaml"
  label?: string,        // Optional header, e.g., "Migration Script"
})

Usage Example

---
description: Generate database migration
agent: db-expert
subtask: true
---

Analyze the schema changes needed and generate a migration script.

After generating, use the `message` tool to send it directly to the user:

message({
  content: "<the migration SQL>",
  format: "code",
  language: "sql",
  label: "Migration Script"
})

Behavior

  1. Subagent calls message tool with content
  2. OpenCode captures and displays content directly in TUI (verbatim)
  3. Main agent still receives subagent's return value for context awareness
  4. Message content is marked as "already displayed" so main agent knows not to repeat it

Symmetry with question tool

This mirrors the existing question tool pattern:

  • question: Subagent -> User (input) -> Subagent
  • message: Subagent -> User (output)

Both enable direct subagent-user communication without main agent mediation.

Use Cases

  1. Migration scripts - SQL/schema changes that must be copy-paste ready
  2. Config file generation - YAML/JSON/TOML that shouldn't be narrated
  3. Code generation - Output code blocks without explanation
  4. CLI commands - Exact commands the user should run
  5. Reports/analysis - Structured output the user will export or share

Implementation Notes

  • Permission: Follow question pattern - denied by default, enable with permission.message: allow
  • TUI: Display in a distinct block (similar to tool output) with optional label
  • Main agent prompt: Inject note like "The following content was already displayed to the user via message tool: [truncated preview]"

jcyamacho avatar Jan 13 '26 13:01 jcyamacho