# Build a Slack Agent with Pydantic AI

 | MLOps Community | 19:58

Source: https://www.youtube.com/watch?v=fYpCcJWR-GE
Channel: MLOps Community, now AAIF Live (https://www.youtube.com/@AAIFLive-x1r). Summarised by MLOps Talks.
Page: https://mlopstalks.com/talks/build-a-slack-agent-with-pydantic-ai
Published: 2025-04-11
Tags: agents, observability, structured-outputs

## TL;DR
- The tutorial builds a Slack digest agent that fetches messages, summarizes threads, and produces workspace-level reports with Pydantic AI.
- Pydantic models define the digest structure, while dependencies pass the current Slack channel or workspace into each agent at runtime.
- Pydantic AI is easy to learn and supports type safety, but its global configuration approach and limited access to built-in LLM tools can become problems in larger systems.

## Summary
This tutorial builds a Slack digest agent with Pydantic AI. The agent connects to Slack, fetches messages and replies, summarizes individual threads, and produces a broader workspace digest. The implementation uses separate Pydantic models for thread and workspace results, including fields such as titles, summaries, takeaways, tags, links, topics, moods, and trends. The code is split into modules for tasks, agents, models, services, clients, and CLI or GUI entry points. OpenAI provides the model, while secret values hold API credentials and Slack tokens. The tutorial also shows Logfire, which records agent runs and exposes prompts, models, processing times, filters, and queries for debugging. The speaker presents Pydantic AI as productive and readable, while noting limits around configuration and built-in LLM tools such as code execution or web search. Suggested extensions include Slack commands, user authentication, local models, and newsletter output.

## Key ideas
### The agent turns noisy Slack activity into structured digests
[00:00](https://www.youtube.com/watch?v=fYpCcJWR-GE&t=0s)
The tutorial starts from the problem of keeping up with large Slack communities and noisy workspaces. The agent finds important threads and summarizes them. A thread digest includes a title, summary, key takeaways, tags, links, and mentioned tools. A workspace digest works at a broader level, covering top threads, flops, overall mood, trending topics, and noteworthy sharing. The same idea can support a community Slack or a private work Slack.

### The architecture separates thread analysis from workspace analysis
[03:12](https://www.youtube.com/watch?v=fYpCcJWR-GE&t=192s)
The architecture passes a system prompt, an API key, a model name, and context about the Slack thread or workspace into the system. One agent focuses on individual conversations, while the other analyzes the workspace as a whole. The workflow has a digest setting, initialization, Slack content fetching, and content digestion. The Slack client retrieves channels, messages, and replies before the agents turn that material into structured summaries.

### The codebase divides the workflow into focused modules
[06:23](https://www.youtube.com/watch?v=fYpCcJWR-GE&t=383s)
The tutorial places the main workflow in task.py because the application runs as one sequence of steps. scripts.py provides the command-line entry point, while interfaces.py provides the graphical interface. agents.py contains the agent logic, models.py connects to large language models, services.py stores shared functions, and clients.py handles external APIs. This layout keeps the task workflow separate from the user interface, Slack connection, model configuration, and agent components.

### Pydantic models and dependencies give the agents structure and context
[10:57](https://www.youtube.com/watch?v=fYpCcJWR-GE&t=657s)
The implementation defines SlackThreadDepends and SlackWorkspaceDepends to carry the current channel or workspace name. SlackThreadDigest and SlackWorkspaceDigest define the expected output shape. The agent factory reads configuration, creates a dynamic system prompt, and adds the relevant dependency without changing the agent definition. The caller passes the model, prompt, and dependency to run_sync, which returns either a thread digest or a workspace digest.

### Secret handling keeps API credentials out of ordinary code paths
[09:27](https://www.youtube.com/watch?v=fYpCcJWR-GE&t=567s)
The project configuration includes the OpenAI API key and Slack bot token. The OpenAI settings provide the model name and API key needed to construct the model. The tutorial uses Pydantic's get_secret_value facility so the OpenAI key stays hidden until the code needs it. The Slack client uses the protected bot token to connect through Slack WebClient.

### Logfire exposes individual agent runs for debugging
[14:48](https://www.youtube.com/watch?v=fYpCcJWR-GE&t=888s)
Logfire shows agent activity as a series of colored bars, with each bar representing a digest run. Selecting a run reveals its prompt, model, and processing time. The speaker presents this as a way to locate bottlenecks and investigate problems. Filters and queries can also be used to inspect patterns and analyze how the digest agent behaves over time.

### Pydantic AI is approachable, but its trade-offs appear as systems grow
[16:26](https://www.youtube.com/watch?v=fYpCcJWR-GE&t=986s)
The speaker values Pydantic AI for its simple concepts, type safety, readable code, and ease of debugging. He also points out that the global namespace approach can make configuration difficult as a project grows, especially when many external settings become environment variables. The framework may limit teams that want built-in LLM tools such as code execution or web search. He presents it as a good fit for a quick, effective agent, with heavier systems potentially needing another approach.

### The example leaves room for Slack-native and broader digest features
[18:21](https://www.youtube.com/watch?v=fYpCcJWR-GE&t=1101s)
The proposed extensions include authentication through Arcade AI so the digest agent can enter private conversations as a user, plus a Slack command that summarizes a thread in place. The model could be replaced with a locally running system. The summaries could also feed a newsletter covering Slack, Discord, and Twitter sources, or a further LLM call could find potential topics for a LinkedIn post.

## Notable quotes
- "Our bot will find the best threads and summarize what's happening." (00:47)
- "The neat part is we can easily adapt the agent context without touching the agent definition." (13:14)
- "The type safety features are a lifesaver." (16:52)
- "But for those massive enterprise level projects, you might need something a bit more heavyduty." (18:06)

## Tools & references mentioned
- Pydantic AI
- Pydantic Logfire
- OpenAI
- Slack API
- Slack WebClient
- Arcade AI

## Who should watch
- You want a working example of a Slack summarization agent with a CLI and GUI entry point.
- You are deciding whether Pydantic AI fits a small or medium agent project and want to see its models, dependencies, and observability workflow.
- You need to understand where a simple Pydantic AI setup may become awkward because of configuration or limited built-in LLM tools.

## Related talks

- [Why Pydantic AI is the Future of AI Agents](https://mlopstalks.com/talks/why-pydantic-ai-is-the-future-of-ai-agents) (Samuel Colvin, Pydantic, 22:48)
- [Linear's Approach to Production AI Agents](https://mlopstalks.com/talks/linears-approach-to-production-ai-agents) (Kristin Boyer, LINEAR, 15:15)
- [How AI covered a human's paternity leave](https://mlopstalks.com/talks/how-ai-covered-a-humans-paternity-leave) (Quinten Rosseel, Wobby, 51:59)
- [DSPy: Transforming Language Model Calls into Smart Pipelines](https://mlopstalks.com/talks/dspy-transforming-language-model-calls-into-smart-pipelines) (Omar Khattab, Stanford, 1:05:40)
- [Building an AI agent with LangGraph, step by step tutorial](https://mlopstalks.com/talks/building-an-ai-agent-with-langgraph-step-by-step-tutorial) (, 10:39)
