OpenAI Cookbook:用 Agents API 做一個會查資料、開 PR 的 Slack 機器人
Build a Slack bot with the Agents API
摘要分析
OpenAI Cookbook 2026 年 9 月新增的 Agents API 應用範例。同事在 Slack 標記機器人就能搜尋對話、調查專案、分析資料或準備 GitHub PR;每條 thread 對應一個 Agents API session 與獨立沙箱,追問會延續同一調查。步驟:複製 .env 範例 → docker build 沙箱映像 → 填 API key 與受限的 executor key → 用 manifest 建 Slack app 取得 token → uv run main.py 以 Socket Mode 啟動,不需公開 webhook。可選接 Notion、Google Drive、GitHub。
- 需 Python 3.14+、uv、Docker;cp .env.example .env
- docker build -t agent-api-sandbox:latest examples/agents_api/sandboxes/docker/application_managed
- 填 OPENAI_API_KEY 與 OPENAI_EXECUTOR_API_KEY(只有後者進沙箱)
- 用 manifest 建 Slack app,設 SLACK_BOT_TOKEN、SLACK_APP_TOKEN
- uv run examples/agents_api/apps/slack_bot/main.py,thread 內 @機器人即可用
One of the Agents API application recipes OpenAI added in September 2026 (alongside an SRE incident-response agent and a data analyst). Teammates tag the bot in Slack to search conversations, investigate projects, analyze data or prepare a GitHub pull request; each Slack thread maps to its own Agents API session and isolated sandbox workspace, so follow-ups continue the same investigation. Slack supplies the trigger and interface, the Agents API keeps conversation state, runs the agent and streams progress, and your application controls Slack access, credentials and sandbox lifecycle. Steps: copy the .env example, build the Docker sandbox image, set OPENAI_API_KEY plus a restricted executor key with api.agents.environments.connect permission, create the Slack app from the provided manifest and collect the bot and app-level tokens, then start with uv run main.py in Socket Mode (no public webhook needed). Optional shared tools include Notion, Google Drive and GitHub.
- Python 3.14+, uv, Docker; copy .env.example
- Build the sandbox Docker image
- Set OPENAI_API_KEY and a restricted executor key
- Create the Slack app from the manifest
- uv run main.py and mention the bot in a thread
關鍵字:OpenAI Agents APISlack bot沙箱自動化Socket Mode
來源原文:https://developers.openai.com/cookbook/examples/agents_api/apps/slack_bot/readme.md
本頁為報導內容的摘要與分析,版權屬原媒體所有;請以原文為準。
