slack_search_media.py
Run the Example
1
Set up your virtual environment
2
Install dependencies
3
Export environment variables
4
Run the example
Save the code above as
slack_search_media.py, then run:Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Run SlackContextProvider with Gemini sub-agents, enabling search_messages and opt-in media tools for file download and upload.
"""
Slack Search & Media Tools
==========================
Demonstrates SlackContextProvider with:
- **search_messages** — Search using the legacy API (works with user
tokens `xoxp-`). Both bot and assisted read agents now have this
enabled alongside `search_workspace`.
- **enable_media_tools** — Opt-in file handling:
- `download_file` on read agents (fetch images/files for multimodal)
- `upload_file` on write agent (post generated content)
This example uses Gemini as the sub-agent model for Slack operations,
while the outer agent uses a different model. This pattern is useful
when you want faster/cheaper tool calls but stronger reasoning on top.
Requires:
GOOGLE_API_KEY
SLACK_BOT_TOKEN (xoxb-) — uses channel history, no search
Optional:
SLACK_USER_TOKEN (xoxp-) — enables search_messages API
With a bot token, search_messages returns `not_allowed_token_type` and
the agent falls back to get_channel_history. With a user token, both
search methods are available.
Usage:
python cookbook/12_context/06_slack_search_media.py
"""
from __future__ import annotations
import asyncio
from agno.agent import Agent
from agno.context.slack import SlackContextProvider
from agno.models.google import Gemini
slack = SlackContextProvider(
model=Gemini(id="gemini-3.5-flash"),
enable_media_tools=True,
)
agent = Agent(
model=Gemini(id="gemini-3.5-flash"),
tools=slack.get_tools(),
instructions=slack.instructions(),
markdown=True,
)
async def main() -> None:
print(f"slack.status() = {slack.status()}\n")
search_prompt = "Search Slack for recent discussions about 'deployment'. Summarize the top 3 results."
print(f"> {search_prompt}\n")
await agent.aprint_response(search_prompt)
if __name__ == "__main__":
asyncio.run(main())
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
Install dependencies
uv pip install -U "agno[slack]" google-genai
Export environment variables
export GOOGLE_API_KEY="your_google_api_key_here"
export SLACK_BOT_TOKEN="your_slack_bot_token_here"
$Env:GOOGLE_API_KEY="your_google_api_key_here"
$Env:SLACK_BOT_TOKEN="your_slack_bot_token_here"
Run the example
slack_search_media.py, then run:python slack_search_media.py
Was this page helpful?