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
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 amessages list that persists across runs via thread state:
src/my_chatbot/flows/chat_flow.py
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 thequeryfield inChatStateoutput_key = "messages"— tells integrations (like Slack) to extract themessagesfield from the output
Step 4: Deploy
Using the Chatbot
Via the Thread API
Create a thread and send messages to it: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:Related
Threads
Thread concepts and management
Slack Integration
Connect your chatbot to Slack
Streaming
Stream responses in real time
Thread API
Thread API reference