Skip to main content

Code

research_assistant.py
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
from agno.tools.websearch import WebSearchTools

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

research_assistant = Agent(
    name="Research Assistant",
    model=OpenAIChat(id="gpt-4o"),
    db=agent_db,
    tools=[
        SlackTools(
            enable_search_messages=True,
            enable_get_thread=True,
            enable_list_users=True,
            enable_get_user_info=True,
        ),
        WebSearchTools(),
    ],
    instructions=[
        "You are a research assistant that helps find information.",
        "You can search Slack messages using: from:@user, in:#channel, has:link, before:/after:date",
        "You can also search the web for current information.",
        "When asked to research something:",
        "1. Search Slack for internal discussions",
        "2. Search the web for external context",
        "3. Synthesize findings into a clear summary",
        "Identify relevant experts by looking at who contributed to discussions.",
    ],
    add_history_to_context=True,
    num_history_runs=3,
    add_datetime_to_context=True,
    markdown=True,
)

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

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

Usage

1

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate
2

Set Environment Variables

export SLACK_TOKEN=xoxb-your-bot-user-token
export SLACK_SIGNING_SECRET=your-signing-secret
export OPENAI_API_KEY=your-openai-api-key
3

Install Dependencies

uv pip install -U "agno[slack]" openai
4

Run Example

python research_assistant.py

Key Features

  • Slack Message Search: Searches workspace history using Slack query syntax (from:@user, in:#channel, has:link, before:/after:date)
  • Web Search Integration: Combines internal Slack findings with external web results for comprehensive answers
  • User Lookup: Identifies relevant experts by resolving user IDs and checking who contributed to discussions
  • Session Persistence: SQLite database stores conversation history across restarts