Skip to content

feat: let adapters provide platform-specific context notes for the system prompt #13309

@bigshezhang

Description

@bigshezhang

Problem

Platform-specific behavioral notes (e.g. "you do NOT have access to Slack APIs") are currently hardcoded in gateway/session.py build_session_context_prompt() as an if/elif chain (lines 265-283). Only Slack and Discord have notes — all other platforms (Feishu, Mattermost, DingTalk, Matrix, WeCom, etc.) get nothing.

This approach does not scale: every new platform requires editing session.py, and third-party adapter authors cannot inject platform context without modifying core gateway code.

Proposed Solution

  1. Add a platform_notes: Optional[str] = None field to SessionSource (dataclass in gateway/session.py)

  2. Replace the hardcoded if/elif block in build_session_context_prompt() with a generic check:

# Replace lines 265-283 with:
if context.source.platform_notes:
    lines.append("")
    lines.append(f"**Platform notes:** {context.source.platform_notes}")
  1. Each adapter sets platform_notes when constructing SessionSource:
# In gateway/platforms/slack.py
SessionSource(
    platform=Platform.SLACK,
    chat_id=...,
    platform_notes=(
        "You are running inside Slack. "
        "You do NOT have access to Slack-specific APIs — you cannot search "
        "channel history, pin/unpin messages, manage channels, or list users. "
        "Do not promise to perform these actions."
    ),
)

This way adapters fully own their platform context — no core changes needed when adding a new platform.

Benefits

  • Adapter authors can customize what the agent knows about their platform (capabilities, limitations, formatting rules, message length limits, etc.)
  • Existing Slack/Discord notes are migrated to their respective adapters — zero behavior change
  • New platforms (Feishu, Mattermost, DingTalk, etc.) can add context like:
    • "Messages support Feishu rich text cards — use markdown for formatting"
    • "Mattermost supports reactions and threads — prefer thread replies for long outputs"
  • Minimal diff — one field addition, one block replacement, N adapter-side additions

Files to Change

File Change
gateway/session.pySessionSource Add platform_notes: Optional[str] = None field + serialize/deserialize
gateway/session.pybuild_session_context_prompt() Replace hardcoded Slack/Discord block with generic platform_notes check
gateway/platforms/slack.py Set platform_notes=... on SessionSource construction
gateway/platforms/discord.py Set platform_notes=... on SessionSource construction
Other adapters (optional) Can now add their own platform notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havecomp/gatewayGateway runner, session dispatch, deliverytype/featureNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions