Skip to main content
MCPAgent provides flexible memory management options to control how conversation history is handled. You can choose between three different memory modes depending on your use case.

Memory Modes

1. Self-Managed Memory (memory_enabled=True)

When memory_enabled=True, the agent automatically manages conversation history internally. This is the simplest option for most use cases.

2. No Memory (memory_enabled=False)

When memory_enabled=False, the agent has no internal memory and treats each interaction independently.

3. External Memory Management

You can provide conversation history externally for full control over memory management. This allows you to implement custom memory strategies like limited history, persistence, or filtering.

Memory Strategies

Unlimited History

Keep all conversation history for maximum context:

Limited History

Limit conversation history to manage memory usage and context length:

Sliding Window

Implement a sliding window approach to maintain recent context while discarding older messages:

Best Practices

  1. For Simple Use Cases: Use memory_enabled=True for automatic memory management
  2. For Stateless Operations: Use memory_enabled=False when each interaction should be independent
  3. For Custom Control: Use external memory management when you need specific memory strategies
  4. Memory Limits: Consider implementing memory limits to prevent context overflow with large conversations
  5. Persistence: For long-running applications, consider persisting conversation history to external storage

Examples

See the following examples for practical implementations:

Configuration Options

The external_history parameter takes precedence over internal memory when provided, allowing you to override the agent’s internal memory with your own implementation.