Skip to content

Conversation

@isaacbmiller
Copy link
Collaborator

@isaacbmiller isaacbmiller commented Dec 5, 2025

📝 Changes Description

Refactors both dspy.History.

Goal
Multi turn chat has been a weaker part of the DSPy dx. It is not clear how you should maintain history, nor particularly easy to do so. These PRs should allow you to build multi turn, (optionally tool use) chatbots more easily.

This PR is the start of efforts to alleviate the concerns.

Overview
History

DSPy.History used to be set to only a single input type.

All inputs and outputs needed to match the current signature that is being used otherwise each step would be filtered to match those fields. This was done to guarantee that we could separate into proper user/assistant pairs. We relax that constraint and give the user more flexibility on how to collect and display messages.

History now has 4 possible modes that it can handle:

signature (the old default) - will filter strictly to the current signature
demos - has input/output fields labeled via a nested dict with: `{"input_fields": {"k":"v"}, "output_fields":{"k":"v"}}, but does not require them to match a signature. This still allows you to get user/assistant splitting.
flat - a dict of kv pairs - all messages go into the user side
raw - uses user/assistant messages

Next PRs:

  1. Change ReAct to use History as well
  2. Update documentation to reflect new usage for both History and ReAct
  3. Create a tutorial showing how to make a multi turn chatbot with history

@isaacbmiller isaacbmiller force-pushed the isaac/dspy-history-refactor2 branch from 55151bc to 6cb1249 Compare December 9, 2025 19:28
@isaacbmiller isaacbmiller changed the base branch from isaac/dspy-react-refactor to main December 9, 2025 19:28
- Improved docstring for the History class to clarify its purpose and usage.
- Added examples for different message modes (raw, demo, signature, flat) with explicit mode specification.
- Updated tests to ensure correct mode detection, including new cases for tool call IDs and names.
- Refactored tests to use parameterized cases for explicit mode settings.
- Allowed empty messages list in History, defaulting to flat mode.
- Removed deprecated factory methods in favor of direct message input in docs.
@isaacbmiller isaacbmiller marked this pull request as ready for review December 9, 2025 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants