Managing History
Manage conversation history and threads
ControlFlow provides powerful mechanisms for managing conversation history and creating private threads within your AI workflows. This guide will help you understand how to leverage these features to create more sophisticated and context-aware applications.
Understanding Flow History
In ControlFlow, each Flow
maintains its own conversation history. This history includes all the interactions, decisions, and outputs generated during the execution of tasks within that flow. By default, this history is used to provide context for subsequent tasks, allowing for coherent and context-aware conversations.
Creating and Managing Threads
Creating a New Thread
When you create a new Flow
, it automatically generates a new thread with a unique ID. This thread isolates the conversation history for that particular flow.
Specifying a Thread ID
You can also create a flow with a specific thread ID, which is useful for resuming conversations or creating deterministic threads:
Resuming a Conversation
To resume a previous conversation, you can create a new flow with the same thread ID:
Creating Private Sub-Threads
Sometimes you may want to create a private conversation that doesn’t affect the main thread. You can do this by creating a new flow within your current flow. The events in the private flow won’t be visible to the parent flow.
One reason to create private threads is to perform activities that would otherwise pollute the context for all agents, like loading and summarizing data in a file. By creating a private thread, you can have an agent load a file into its context and produce a summary, then use only the summary in the parent flow. None of the other agents will have to endure the token or time cost of loading the file.
Managing History Across Flows
Inheriting Parent Flow History
By default, when you create a new flow within another flow, it inherits the history of its parent:
If you want to completely isolate a sub-flow’s history from its parent, you can set load_parent_events=False
: