Principle:Spcl Graph of thoughts Thought Selection
| Knowledge Sources | |
|---|---|
| Domains | Graph_Reasoning, Thought_Operations |
| Last Updated | 2026-02-14 |
| Implemented By | Implementation:Spcl_Graph_of_thoughts_Selector_Operation |
Overview
Operation pattern that partitions thoughts from predecessors using a custom selection function, enabling different subsequent operations on different thought subsets.
Description
The Selector operation is a routing mechanism in the Graph of Thoughts framework that applies a user-defined selection function to partition or filter thoughts from predecessor operations. This enables GoT topologies where different subsets of thoughts need to be routed to different subsequent processing branches.
Key characteristics:
- Takes a selector callable with signature
(List[Thought]) -> List[Thought]that defines the selection logic - Applies the selector function to all predecessor thoughts and creates cloned copies of the selected thoughts via
Thought.from_thought - If there are no predecessor thoughts, creates a single thought from the operation's
kwargs(passed from the Controller) and applies the selector to that -- this enables the Selector to work as an entry point for splitting initial problem state - The selection function has full flexibility: it can filter, reorder, duplicate, or any combination
- Unlike KeepBestN (which uses scores) or KeepValid (which uses validation flags), the Selector uses an arbitrary user-defined function for maximum flexibility
Usage
Use the Selector operation when you need to route different thoughts to different processing branches in the GoT graph. This is essential for the decompose step in divide-and-conquer topologies. Common scenarios include:
- Sub-problem routing: After a Generate operation produces sub-problems, use multiple Selector operations to route each sub-problem to its own processing branch
- Index-based selection: Select thoughts by index (e.g.,
lambda thoughts: [thoughts[0]]for the first sub-problem,lambda thoughts: [thoughts[1]]for the second) - Conditional branching: Apply different processing strategies to thoughts based on their state content
- Fan-out patterns: Create parallel branches in the GoT graph by using multiple Selector operations with different selection functions on the same predecessor
In the sorting workflow, the Selector is used to route individual sublists from a split operation to separate sorting branches:
# Route first sublist to branch 1
sel1 = Selector(selector=lambda thoughts, idx=0: [thoughts[idx]])
# Route second sublist to branch 2
sel2 = Selector(selector=lambda thoughts, idx=1: [thoughts[idx]])
Theoretical Basis
The Selector operation implements graph branching in the GoT framework, enabling the creation of parallel processing paths from a single set of thoughts. In graph-theoretic terms, the Selector creates a fan-out vertex that routes subsets of thoughts to different successor operations.
Formally, given a set of thoughts T = {t_1, t_2, ..., t_k} from predecessors, a Selector with function f produces:
f(T) = T' where T' is a subset of T
Multiple Selectors with different functions f_1, f_2, ..., f_m applied to the same set T enable partitioning:
f_1(T), f_2(T), ..., f_m(T)
This is the mechanism by which GoT implements the decompose step: a Generate operation produces multiple sub-problem thoughts, and Selector operations route each sub-problem to its own processing branch. The branches can then be recombined via an Aggregate operation, completing the divide-and-conquer pattern.
The Selector's ability to operate without predecessors (using kwargs as initial state) also allows it to serve as a graph entry point that partitions the initial problem state into sub-problems before any LM interaction occurs.
Code Reference
The Thought Selection principle is implemented in the Selector class:
- Source file:
graph_of_thoughts/operations/operations.py, Lines 840-900 - Class:
Selector(Operation) - Operation type:
OperationType.selector
Related Pages
- Implementation:Spcl_Graph_of_thoughts_Selector_Operation - Concrete implementation of this principle
- Principle:Spcl_Graph_of_thoughts_Thought_Aggregation - Aggregate operation used to recombine branches created by Selector
- Principle:Spcl_Graph_of_thoughts_Best_N_Selection - Score-based selection (complementary to custom function-based Selector)
- Workflow:Spcl_Graph_of_thoughts_GoT_Sorting_Pipeline - Sorting workflow using Selector for sub-problem routing