標準の slack_send_message ツールはブロックを受け付けてないので全てテキストモードで投稿される。
まあでも小さいコードなので、以下のようなパッチをいれてしまえば自然な動作になる。ブロック構文のバリデータとかは作りたくはなさそう。
diff --git a/src/strands_tools/slack.py b/src/strands_tools/slack.py index e23a5cc..deeb88e 100644 --- a/src/strands_tools/slack.py +++ b/src/strands_tools/slack.py @@ -673,7 +673,7 @@ def slack(action: str, parameters: Dict[str, Any] = None, agent=None) -> str: @tool -def slack_send_message(channel: str, text: str, thread_ts: str = None) -> str: +def slack_send_message(channel: str, text: str, thread_ts: str = None, blocks: list = None) -> str: """Send a message to a Slack channel. This is a simplified interface for the most common Slack operation: sending messages. @@ -735,6 +735,8 @@ def slack_send_message(channel: str, text: str, thread_ts: str = None) -> str: params = {"channel": channel, "text": text} if thread_ts: params["thread_ts"] = thread_ts + if blocks: + params["blocks"] = blocks response = client.chat_postMessage(**params) if response and response.get("ts"):
実はシステムプロンプトに Create rich messages with blocks using chat_postMessage action って書いてあるので、もしかするとブロック構文は使えませんって誘導されるかもしれない。その場合はシステムプロンプトのそこら辺を消し飛ばしてしまうとよい。自分はシステムプロンプトに以下のようなサンプルを入れたらいい感じに使うようになった。
- Create rich messages with blocks using chat_postMessage action
- slack_send_message(
channel=...,
text="Hello from Strands!",
blocks=[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Hello from Strands!"
}
}
])