Building a Production AI Slack Bot with Pydantic AI and Logfire

tiger_data · Tech · 2025 · source Agentic: yes · promotional bias: med · source-backed · extracted with prompt 0.5.4 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Production AI Slack assistant for remote-company knowledge work

Tiger Data needed a production Slack bot that could help employees recover context from company conversations and tools without drowning in Slack history, while remaining reliable, debuggable, scalable, and flexible across LLM providers.

Constraints:

Architecture

Tiger Data built Tiger Agent for Work as a Slack bot backed by a PostgreSQL work queue, Pydantic AI for LLM/provider/tool orchestration, eight MCP servers for company data, and Pydantic Logfire for distributed tracing. Pydantic AI loads MCP servers from configuration, translates tools across providers, retries tool calls, and supports model switching by environment variable. Logfire instruments database, LLM, MCP, and HTTP calls so each Agent Run is visible as structured trace data queryable with SQL.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  slack-interface[Slack interface] --> postgresql-work-queue[PostgreSQL work queue]
  postgresql-work-queue --> tiger-agent[Tiger Agent]
  tiger-agent --> pydantic-ai-agent[Pydantic AI agent]
  pydantic-ai-agent --> mcp-servers[MCP servers]
  pydantic-ai-agent --> llm-provider[LLM provider]
  tiger-agent --> logfire-tracing[Logfire tracing]
  pydantic-ai-agent --> logfire-tracing
  mcp-servers --> logfire-tracing
  postgresql-work-queue --> logfire-tracing
  logfire-tracing --> logfire-mcp-server[Logfire MCP server]
  logfire-mcp-server --> claude-code[Claude Code]
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Slack interface User-facing Slack mention surface where employees ask the agent for context. PostgreSQL work queue, Tiger Agent
PostgreSQL work queue Atomic event-claiming queue that supports horizontal scaling for Slack events. Slack interface, Tiger Agent, Logfire tracing
Tiger Agent Production Slack bot with memory, context, MCP access, and production reliability behavior. PostgreSQL work queue, Pydantic AI agent, Logfire tracing
Pydantic AI agent LLM orchestration layer that loads toolsets, calls model providers, handles tool invocations, and retries failures. Tiger Agent, MCP servers, LLM provider, Logfire tracing
MCP servers Eight tool servers for Slack search, docs, Salesforce, GitHub, Linear, meeting transcripts, user memory, and progress reports. Pydantic AI agent, Logfire tracing
LLM provider Configurable provider/model such as Claude or GPT-4o selected through environment configuration. Pydantic AI agent
Logfire tracing Distributed tracing and AI observability for database, framework, MCP, HTTP, prompts, tools, responses, and latency. Tiger Agent, Pydantic AI agent, MCP servers, PostgreSQL work queue, Logfire MCP server
Logfire MCP server MCP interface that lets Claude Code query tracing data with SQL and help fix errors. Logfire tracing, Claude Code
Claude Code Developer assistant connected to Logfire traces for AI-assisted debugging. Logfire MCP server

Data flow

A Slack mention enters Tiger Agent's PostgreSQL-backed work queue. The agent loads MCP server definitions from configuration, creates a Pydantic AI agent with those servers as toolsets, calls the selected LLM provider, invokes MCP tools as needed, retries failures automatically, and returns a Slack response. Logfire captures the database work, LLM prompts, tool invocations, arguments, responses, latency, and HTTP/MCP spans into structured trace data.

4 supporting quotes
“Tiger Agent runs on a PostgreSQL-backed work queue with atomic event claiming and horizontal scaling. Pydantic AI plugs into this architecture cleanly because it doesn't force us into a different event model.”article, stated
“After this, we load Pydantic AI config, connect to servers, fetch tool definitions, and translate them for whatever LLM provider we're using.”article, stated
“When a Slack mention event comes in, the agent loads MCP servers from configuration, creates a Pydantic AI agent with those servers as toolsets”article, stated
“a Slack mention event comes in, the agent loads MCP servers from configuration, creates a Pydantic AI agent with those servers as toolsets, runs the agent with a user prompt, and returns a response. Pydantic AI calls the LLM, handles tool invocations, retries failures. Logfire captures every step.”article, stated

Why this architecture

Tiger Data chose Pydantic AI because it abstracted MCP, retries, and provider APIs without forcing a different event model, and chose Logfire because agent debugging required seeing the entire tool/LLM workflow as structured traces. Keeping a PostgreSQL work queue preserved the team's scaling architecture, while environment-based model switching let them handle different model behavior, cost, uptime, and outages.

4 supporting quotes
“Pydantic AI handles the tedious parts while staying out of our way. ### MCP servers that just work Adding a server to Tiger Agent means dropping a few lines into mcp_config.json:”article, stated
“Pydantic AI plugs into this architecture cleanly because it doesn't force us into a different event model. It’s more a library for the LLM/agent bits as opposed to an opinionated framework for our entire project.”article, stated
“We knew distributed tracing would really help us here and landed on OpenTelemetry.”article, stated
“Each LLM has its own behavior, uptime, reliability, context window, cost, and proficiency in agentic tasks. It is actually not an easy problem to “decide” on what model to use until you’ve tested them extensively both in development and production.”article, stated

Models used: Claude · GPT-4o · Claude 4.5 Sonnet · LLMs via Pydantic AI

Scale

Alternatives considered (roads not taken)

Build the LLM library and agent plumbing from scratch

Rejected because: That would require thousands of lines of scaffolding for integrations, retries, provider switching, debugging, and logging before solving the Slack problem.

“After assessing quite a few options (including building our own LLM library), we picked Pydantic AI”article, stated
“Do this from scratch and you'll write thousands of lines of scaffolding just to get started. We integrated eight MCP servers (as of now) into Tiger Agent: Slack search, customer docs, Salesforce cases, GitHub repos, Linear tickets, meeting transcripts, user memory, and progress reports.”article, stated

Write protocol handlers and retry logic for every MCP server

Rejected because: Pydantic AI loads MCP servers and handles tool translation/retries automatically.

“Without a framework, you're writing protocol handlers, format converters, and retry logic for every server. That's a lot of plumbing code that has nothing to do with your Slack agent.”article, stated
“MCP servers fail. Networks hiccup. Rate limits hit. Pydantic AI retries tool calls by default. We don't need to manually write retry logic. It works out of the box.”article, stated

Keep using Jaeger for traces

Rejected because: Jaeger technically worked but had poor developer experience compared with Logfire's Pydantic AI integration.

“We did try Jaeger first, and it technically worked, but the developer experience was poor. We then tried Pydantic Logfire because it integrated really well with Pydantic AI.”article, stated
“We then tried Pydantic Logfire because it integrated really well with Pydantic AI. Since the interface was instantly better, we decided this was what we were going to stick with.”article, stated

Commit to one LLM provider implementation

Rejected because: Provider behavior, reliability, context, cost, and agentic performance vary, and model outages happen.

“It is actually not an easy problem to “decide” on what model to use until you’ve tested them extensively both in development and production.”article, stated
“Pydantic AI translates between provider APIs automatically. This is a really big deal because it saves our engineering team the time of re-implementing how each model company calls their models.”article, stated

Patterns

tool-use-orchestration (mcp-integration)

Tiger Agent loads eight MCP servers as toolsets so the Slack bot can search company systems, docs, tickets, repositories, transcripts, memory, and reports.

“Each server provides tools the agent calls to answer questions about Tiger Data's products and customer issues.”article, stated
“The agent now has access to all our eight MCP servers.”article, stated

model-routing (provider-abstraction)

The system can switch between Claude, GPT-4o, and Claude Sonnet by environment variable while Pydantic AI translates provider APIs.

“We started with a Claude model, switched to OpenAI’s GPT-4o, then back to Claude 4.5 Sonnet.”article, stated
“Each time, we only had to change one environment variable”article, stated

observability-tracing (debugging)

Logfire captures LLM calls, prompts, tool interactions, responses, latency, MCP spans, database calls, and HTTP requests as structured traces.

“When Tiger Agent responds to a Slack mention, Pydantic Logfire captures each tool call, its arguments, response, and latency.”article, stated
“For LLM calls, it shows the system prompt, user prompt, all tool interactions, and the final response”article, stated

durable-execution (production-runtime)

Tiger Agent uses a PostgreSQL-backed work queue with atomic event claiming and Pydantic AI retries for failed tool calls.

“Tiger Agent runs on a PostgreSQL-backed work queue with atomic event claiming and horizontal scaling.”article, stated
“MCP servers fail. Networks hiccup. Rate limits hit. Pydantic AI retries tool calls by default.”article, stated

agent-memory (context)

The Slack bot includes user memory and progress reports as MCP-backed context sources for ongoing company knowledge work.

“Slack search, customer docs, Salesforce cases, GitHub repos, Linear tickets, meeting transcripts, user memory, and progress reports.”article, stated
“with its own memory, context, and production-grade reliability.”article, stated

Tradeoffs

Use Pydantic AI as a library rather than building everything in-house

Chose Pydantic AI for LLM/MCP/provider mechanics over A custom LLM library and MCP plumbing.

Rationale: Pydantic AI avoided low-value scaffolding while still fitting Tiger Agent's PostgreSQL work queue architecture.

“After assessing quite a few options (including building our own LLM library), we picked Pydantic AI”article, stated
“It’s more a library for the LLM/agent bits as opposed to an opinionated framework for our entire project.”article, stated

Prefer SQL-queryable traces

Chose Logfire spans stored as rows with JSONB attributes over Tracing tools with custom query languages.

Rationale: SQL made debugging accessible to engineers and supported direct queries over agent runs and tool calls.

“Other tracing tools have custom query languages. Logfire uses SQL. Engineers already know SQL.”article, stated
“The spans are stored as rows with JSONB attributes.”article, stated

Use a framework for agent mechanics but keep event architecture

Chose Pydantic AI plugged into a PostgreSQL-backed work queue over A framework that imposes a new event model.

Rationale: The team wanted LLM/agent abstractions without rewriting the production event-processing architecture.

“Pydantic AI plugs into this architecture cleanly because it doesn't force us into a different event model.”article, stated
“Tiger Agent runs on a PostgreSQL-backed work queue with atomic event claiming and horizontal scaling.”article, stated

Gotchas (what bit them)

The LLM call is only a small piece of a production agent.

Root cause: Tool integration, retries, provider switching, debugging, and logging dominate the operational scaffolding.

Resolution: Use Pydantic AI for the agent/LLM/MCP mechanics and keep custom code focused on the Slack product.

“the actual LLM call itself is only one very small piece of the overall system.”article, stated
“You need tool integrations, retry logic, provider switching, production debugging, and comprehensive logging.”article, stated

Debugging agents without tracing is like debugging blind.

Root cause: The final output hides intermediate model decisions, tool calls, tool arguments, tool failures, and cross-service timing.

Resolution: Instrument the AI framework, MCP, database, and HTTP layers with Logfire.

“From the user’s perspective, without tracing, you only see the final output.”article, stated
“Many things can go wrong, and without tracing, you are essentially trying to find a bug without a debugger or console logs.”article, stated

Manual log correlation does not scale across services.

Root cause: A request may produce logs from many services that need chronological correlation.

Resolution: Store spans as structured rows and query traces with SQL.

3 supporting quotes
“We have at least nine services that may all produce logs for any given request”article, stated
“Doing this manually is a herculean task.”article, stated
“Logfire uses SQL. Engineers already know SQL.”article, stated

Model choice cannot be settled once in advance.

Root cause: Providers differ in behavior, uptime, reliability, context window, cost, and agentic capability.

Resolution: Keep provider switching cheap through Pydantic AI's abstraction and environment-variable model selection.

“Each LLM has its own behavior, uptime, reliability, context window, cost, and proficiency in agentic tasks.”article, stated
“Each time, we only had to change one environment variable”article, stated

Evaluation

The article emphasizes production observability over a formal offline eval harness: Tiger Data observes Agent Runs, tool calls, args, responses, latency, error spans, service-level failures, and provider behavior through Logfire and SQL queries.

Metrics: tool call arguments, responses, and latency · LLM system prompt, user prompt, tool interactions, and final response · error counts by service · provider uptime/reliability/cost/context behavior · daily adoption by more than half the company within six weeks

3 supporting quotes
“Pydantic Logfire captures each tool call, its arguments, response, and latency.”article, stated
“For LLM calls, it shows the system prompt, user prompt, all tool interactions, and the final response”article, stated
“Give me a count of errors by service in the aws-dev environment.”article, stated

Outcomes

The system handled thousands of concurrent conversations, integrated eight MCP servers, had at least nine services producing logs per request, and instrumented core layers in under one hour.

3 supporting quotes
“Reduced debugging time with Pydantic AI's "Agent Run" visualization”article, stated
“This was quite a magical experience for us because it made the entire LLM and tool workflow super easy to read and understand”article, stated
“Tiger Agent for Work is open sourced on Github.”article, stated