Skip to main content
Learn how to effectively manage conversation context to create bots that remember past interactions, maintain coherent conversations, and provide contextually relevant responses. This guide covers context windows, history management, and advanced memory techniques.

What You’ll Learn

By the end of this guide, you’ll understand:
  • How conversation context works in Chatbot Platform
  • Configuring context window sizes
  • Managing conversation history effectively
  • When to clear or preserve context
  • Per-user vs per-channel context handling
  • Advanced memory management patterns
  • Context optimization for cost and performance

Prerequisites

Before starting, you should:
  • Have a working bot with at least one channel
  • Understand basic bot concepts from Support Bot Basics
  • Know how webhook integrations work
  • Have some experience with chatbot conversations

How Conversation Context Works

The Basics

Every time a user sends a message, your bot needs context to provide relevant responses:
Without conversation history, the bot wouldn’t understand what “it” refers to in the second question.

Context Window

The context window determines how many previous messages are included when sending requests to your AI integration:

Why Context Matters

Good Context:
  • Bot remembers what you’re talking about
  • No need to repeat information
  • Natural, flowing conversation
  • Better user experience
Poor Context:
  • Bot asks for information you already provided
  • Doesn’t understand references (“it”, “that”, “them”)
  • Repetitive or confused responses
  • Frustrating user experience

Step 1: Configure Context Window

1

Go to Bot Settings

Navigate to your bot and click the Settings or Behavior tab.
2

Set Context Window

Configure the number of messages to include:
  • Small (5-10 messages): Quick questions, minimal context needed
  • Medium (10-20 messages): Standard support conversations
  • Large (20-30 messages): Complex discussions, detailed troubleshooting
  • Very Large (30+ messages): Long-form consultations, extended sessions
Larger context windows cost more (more tokens sent to AI) but provide better context.
3

Consider Token Costs

Calculate approximate costs:
4

Test Different Sizes

Try different window sizes:
  1. Start with 15 messages
  2. Monitor conversation quality
  3. Check token usage
  4. Adjust up or down based on needs

Step 2: Understanding Per-User Context

Context is maintained per user and per channel:

Same User, Different Channels

Different Users, Same Channel

Platform-Specific Behavior

Telegram:
  • Per-user context in groups
  • Separate context for each private chat
  • Group messages don’t mix with private chats
Slack:
  • Thread-based context in channels
  • Per-user context in DMs
  • Different threads = different contexts
Discord:
  • Per-user context in servers
  • Thread-based in thread channels
  • DM context separate from server context

Step 3: Managing Conversation History

When to Clear Context

Clear conversation context when: User Explicitly Requests:
Topic Changes Dramatically:
Sensitive Information:
Error Recovery:

How to Clear Context

Via API:

When to Preserve Context

Keep conversation context when: Follow-up Questions:
Multi-Step Processes:
Troubleshooting:

Advanced Context Patterns

Pattern 1: Sliding Window with Summarization

For very long conversations, summarize older messages:

Pattern 2: Contextual Memory Injection

Inject relevant context from external sources:

Pattern 3: Topic-Based Context Segmentation

Maintain separate contexts for different topics:

Pattern 4: Selective Context Filtering

Remove irrelevant messages from context:

Context Optimization

Reducing Token Usage

Strategy 1: Compress System Prompts
Strategy 2: Remove Redundant Messages
Strategy 3: Dynamic Window Sizing

Improving Response Quality

Strategy 1: Include Structured Context
Strategy 2: Reference Previous Solutions

API Examples

For complete API documentation, see the OpenAPI specification.

Best Practices

Right-Size Windows

Use appropriate context window for your use case

Monitor Costs

Track token usage and optimize for cost

Clear When Needed

Don’t let stale context confuse the bot

Enrich Context

Add relevant external data to improve responses

Context Window Guidelines

System Prompt Best Practices

Include context handling instructions in your system prompt:

Troubleshooting

Bot doesn’t remember earlier messages

Possible causes:
  • Context window too small
  • Conversation history cleared accidentally
  • Integration not receiving full message array
Solutions:
  • Increase context window size
  • Check conversation history via API
  • Verify webhook payload includes messages array
  • Review integration logs

Bot confused by old context

Possible causes:
  • Topic changed but old context still included
  • Context window too large
  • Multiple unrelated topics in same conversation
Solutions:
  • Implement topic detection and context clearing
  • Reduce context window size
  • Add context filtering logic
  • Provide clear conversation restart mechanism

High token costs

Possible causes:
  • Context window too large
  • Verbose system prompts
  • Not filtering irrelevant messages
Solutions:
  • Reduce context window
  • Compress system prompts
  • Implement message filtering
  • Use cheaper models for simple queries
  • Add summarization for long conversations

Different context per channel

Expected behavior: Each channel maintains separate context If you need shared context:
  • Use external database to store cross-channel history
  • Implement custom context loading in integration
  • Reference Conversation Archives MCP server
  • Link user IDs across platforms

Next Steps

Build Grounded Bot

Add external data sources to context

Personal Assistant

Advanced context with multiple tools

Conversation API

Programmatic history management

Message History

View and analyze conversations