> ## Documentation Index
> Fetch the complete documentation index at: https://phidatainc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Channel Summarizer

> An agent that reads channel history and produces structured summaries.

An agent that reads channel history and produces structured summaries. Supports follow-up questions in the same thread via session history.

```python channel_summarizer.py theme={null}
"""
Channel Summarizer
==================

An agent that reads channel history and produces structured summaries.
Supports follow-up questions in the same thread via session history.

Key concepts:
  - ``SlackTools`` with ``enable_get_thread`` and ``enable_search_messages``
    lets the agent read Slack data as tool calls.
  - ``add_history_to_context=True`` + ``db`` enables follow-up questions
    within the same Slack thread — the agent remembers previous exchanges.
  - ``num_history_runs=5`` includes the last 5 exchanges for context.

Slack scopes: app_mentions:read, assistant:write, chat:write, im:history,
             channels:history, channels:read, search:read, users:read

Environment variables:
    SLACK_TOKEN         Bot token (xoxb-) for standard Slack APIs
    SLACK_USER_TOKEN    User token (xoxp-) required for search_messages
"""

from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIChat
from agno.os.app import AgentOS
from agno.os.interfaces.slack import Slack
from agno.tools.slack import SlackTools

# ---------------------------------------------------------------------------
# Create Example
# ---------------------------------------------------------------------------

agent_db = SqliteDb(session_table="agent_sessions", db_file="tmp/summarizer.db")

summarizer = Agent(
    name="Channel Summarizer",
    model=OpenAIChat(id="gpt-4o"),
    db=agent_db,
    tools=[
        SlackTools(
            enable_get_thread=True,
            enable_search_messages=True,
            enable_list_users=True,
        )
    ],
    instructions=[
        "You summarize Slack channel activity.",
        "Your context includes the Slack channel_id and thread_ts you are responding in.",
        "When asked to summarize 'this channel', use the channel_id from your context.",
        "When asked about a channel:",
        "1. Use get_channel_history with the channel_id to fetch recent messages",
        "2. Look for messages with thread_ts and reply_count > 0 — these have threaded replies",
        "3. Use get_thread with the channel_id and thread_ts to expand important threads",
        "4. Group messages by topic/theme",
        "5. Highlight decisions, action items, and blockers",
        "Format summaries with clear sections:",
        "- Key Discussions (include expanded thread context)",
        "- Decisions Made",
        "- Action Items",
        "- Questions/Blockers",
        "Use bullet points and keep summaries concise.",
    ],
    # Session history — enables follow-up questions in the same Slack thread
    add_history_to_context=True,
    num_history_runs=5,
    add_datetime_to_context=True,
    markdown=True,
)

agent_os = AgentOS(
    agents=[summarizer],
    interfaces=[
        Slack(
            agent=summarizer,
            reply_to_mentions_only=True,
        )
    ],
)
app = agent_os.get_app()

# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    agent_os.serve(app="channel_summarizer:app", reload=True)
```

## Run the Example

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U "agno[os,slack]" openai
    ```
  </Step>

  <Step title="Export environment variables">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export OPENAI_API_KEY="your_openai_api_key_here"
      export SLACK_SIGNING_SECRET="your_slack_signing_secret_here"
      export SLACK_TOKEN="your_slack_token_here"
      export SLACK_USER_TOKEN="your_slack_user_token_here"
      ```

      ```bash Windows theme={null}
      $Env:OPENAI_API_KEY="your_openai_api_key_here"
      $Env:SLACK_SIGNING_SECRET="your_slack_signing_secret_here"
      $Env:SLACK_TOKEN="your_slack_token_here"
      $Env:SLACK_USER_TOKEN="your_slack_user_token_here"
      ```
    </CodeGroup>
  </Step>

  <Step title="Configure Slack">
    Complete [Slack setup](/agent-os/interfaces/slack/setup): create and install the app, expose the server through public HTTPS, and add the scopes listed in the example. The default event request URL is `<public-url>/slack/events`; HITL examples also use `<public-url>/slack/interactions` for interactivity. Use any custom prefix shown in the example instead of `/slack`.
  </Step>

  <Step title="Run the example">
    Save the code above as `channel_summarizer.py`, then run:

    ```bash theme={null}
    python channel_summarizer.py
    ```
  </Step>
</Steps>

Full source: [cookbook/05\_agent\_os/interfaces/slack/channel\_summarizer.py](https://github.com/agno-agi/agno/blob/main/cookbook/05_agent_os/interfaces/slack/channel_summarizer.py)
