Skip to main content

Overview

This guide walks through building a chatbot that maintains conversation history across multiple messages. It uses:
  • CrewAI Flows to manage conversation state
  • Threads to persist state between runs
  • The Thread API (or Slack) for multi-turn interaction

Project Structure

Step 1: Define the Chat Agent

Create an agent that responds to user messages given conversation history:
src/my_chatbot/agents/chat_agent.py
Optionally, add a second agent that suggests follow-up questions:
src/my_chatbot/agents/suggest_agent.py

Step 2: Create the Chat Flow

The flow manages conversation state — it appends each user message and assistant response to a messages list that persists across runs via thread state:
src/my_chatbot/flows/chat_flow.py
How state works: When running inside a thread, Crewship passes the previous thread state (including messages) into the flow. The flow appends the new exchange and returns the updated state, which Crewship saves as a checkpoint.

Step 3: Configure crewship.toml

crewship.toml
  • input_key = "query" — maps incoming messages to the query field in ChatState
  • output_key = "messages" — tells integrations (like Slack) to extract the messages field from the output

Step 4: Deploy

Using the Chatbot

Via the Thread API

Create a thread and send messages to it:
Each run in the thread receives the accumulated messages from previous runs, so the agent has full conversation context.

Via the CLI

Via Slack

Once you’ve connected Slack and set this deployment as the default, users can simply mention the bot:
Replies in the same Slack thread automatically continue the conversation — Crewship maps each Slack thread to a Crewship thread behind the scenes.

Threads

Thread concepts and management

Slack Integration

Connect your chatbot to Slack

Streaming

Stream responses in real time

Thread API

Thread API reference