Skip to content

feat(assistant): instruct agent to fence tables and fixed-width content for Discord#9

Merged
0xmrpeter merged 1 commit into
Open-ACP:mainfrom
kevin-david:assistant-format-discord
May 9, 2026
Merged

feat(assistant): instruct agent to fence tables and fixed-width content for Discord#9
0xmrpeter merged 1 commit into
Open-ACP:mainfrom
kevin-david:assistant-format-discord

Conversation

@kevin-david

Copy link
Copy Markdown
Contributor

Why

Discord's markdown renderer doesn't handle native tables — unwrapped tabular output (| col1 | col2 | rows) displays as raw text instead of an aligned grid. Same problem for ASCII art, tree output, and any aligned-column content.

What changes

One-line addition to the assistant's system prompt (src/assistant.ts) instructing the model to wrap tables / ASCII art / tree output / aligned-column text in triple-backtick fences.

Why an LLM instruction (not adapter-side detection)

Tables and fixed-width content are intent-laden — the model knows when it's making one. A targeted instruction in the system prompt is reliable and free; adapter-side regex detection works for markdown tables but breaks on tree output, aligned text, and is fragile mid-stream when text arrives as deltas.

Scope

Only the assistant session (the bot's concierge thread). Per-session prompts to coding agents in their own session threads aren't covered — a separate, slightly different injection point would be needed for those (the agent's system prompt is owned by Claude Code, not us).

Test plan

  • Ask the assistant something that warrants tabular output (e.g., "show me a table of installed agents") and confirm the response uses ``` fences

🤖 Generated with Claude Code

…nt for Discord

Discord's markdown renderer doesn't handle native tables — unwrapped tabular
output (`| col1 | col2 |` rows) displays as raw text instead of an aligned
grid. Same problem for ASCII art, tree output, and any aligned-column content.

Add a one-line guideline to the assistant's system prompt telling the model
to wrap such content in triple-backtick fences. Cheap, reliable, and applies
to every assistant response without per-message overhead.

Note: this only covers the `Assistant` (the bot's concierge thread). Per-
session prompts to coding agents in their own session threads still need
the same instruction — out of scope here, can ship as a separate change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@0xmrpeter 0xmrpeter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, well-scoped fix for a real Discord rendering issue. The LLM-instruction approach is the right call — the model knows when it's producing tabular content better than any regex heuristic could, and it handles tree output / aligned text naturally. The inline rationale in the prompt is good prompt engineering.

One thing to track separately: per-session agent prompts (owned by Claude Code) aren't covered here. Worth opening an issue to revisit once the assistant-side fix is validated.

LGTM — merge after manual smoke test.

@0xmrpeter 0xmrpeter merged commit bd80432 into Open-ACP:main May 9, 2026
3 checks passed
kevin-david added a commit to kevin-david/discord-adapter that referenced this pull request May 9, 2026
The agent (Claude Code, etc.) running in a per-session thread doesn't see the
assistant's system prompt, so a separate injection point is needed to give it
the same Discord-rendering guidance: wrap tables, ASCII art, tree output, and
aligned/fixed-column text in triple-backtick fences (Discord's markdown
renderer doesn't handle native tables).

Prepend a one-time '[Discord rendering note: ...]' to the user's first message
of any new Discord session (gated by promptCount === 0 so lazy-resumed sessions
don't re-prepend mid-conversation).

Counterpart to Open-ACP#9, which covered the assistant session.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@kevin-david kevin-david deleted the assistant-format-discord branch May 9, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants