ForcePilot/backend/package/yuxi/channels/adapters/slack/agent_prompt.py

54 lines
1.9 KiB
Python
Raw Normal View History

from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any
_INBOUND_FORMATTING_HINTS = {
"text_markup": "slack_mrkdwn",
"rules": [
"Bold uses *single asterisks* (not **double**)",
"Italic uses _underscores_ (not *single asterisks*)",
"Links use <https://url.com|label> format",
"Do not use markdown headings (# ## ###) or pipe tables",
"Inline code uses `backticks`, code blocks use ```triple backticks```",
],
}
_INTERACTIVE_REPLIES_HINT = (
"You can include interactive buttons in messages using:\n"
"[[slack_buttons: Label:value]] — creates up to 5 Block Kit buttons\n"
"To customize button style, use [[slack_buttons: Label:value:primary]] or [[slack_buttons: Label:value:danger]]\n"
"For select menus, use [[slack_select: Placeholder | Label:value]]\n"
)
_INTERACTIVE_REPLIES_DISABLED_HINT = (
"Interactive replies are currently disabled for this channel.\n"
"To enable, set `channels.slack.capabilities.interactiveReplies: true` in config."
)
@dataclass
class SlackPromptHints:
text_markup: str = "slack_mrkdwn"
formatting_rules: list[str] = field(default_factory=lambda: _INBOUND_FORMATTING_HINTS["rules"])
interactive_replies_enabled: bool = False
def inbound_formatting_hints(self) -> dict[str, Any]:
return {
"text_markup": self.text_markup,
"rules": self.formatting_rules,
}
def message_tool_hints(self) -> str:
if self.interactive_replies_enabled:
return _INTERACTIVE_REPLIES_HINT
return _INTERACTIVE_REPLIES_DISABLED_HINT
@classmethod
def from_config(cls, config: dict[str, Any] | None) -> SlackPromptHints:
if not config:
return cls()
capabilities = config.get("capabilities", {}) or {}
interactive = bool(capabilities.get("interactiveReplies", True))
return cls(interactive_replies_enabled=interactive)