You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(gepa): rewrite Section 8 with accurate custom proposer behavior for ReAct
- Clarify custom proposer receives ALL components (regular + ReAct)
- Add realistic signature with ReAct failure patterns and component types
- Use exact naming from implementation: examples_with_feedback, component_reflective_data, propose_instruction
- Show _format_examples() helper matching real markdown formatting
- Remove regular component handling to keep example focused on ReAct
- Test code example validates successfully
- Fix contradiction: optimize_react_components must be True (not irrelevant)
docs(gepa): clarify custom proposer behavior in routing section
Change 'overrides the default routing' to 'receives all components and handles the optimization logic' to avoid confusion with optimize_react_components which still controls discovery/serialization
docs(gepa): remove discouraging recommendation from custom proposer section
Users reading this section want to learn how to implement custom proposers for ReAct - don't discourage them from doing so
@@ -550,7 +550,7 @@ When `optimize_react_components=True`, GEPA:
550
550
1.**Discovers ReAct modules** - Finds all `dspy.ReAct` instances in your program (including nested modules)
551
551
2.**Extracts components** - Collects react instructions, extract instructions, and tool schemas from each ReAct module
552
552
3.**Routes to proposers** - Separates components by type and routes them appropriately:
553
-
-**With custom `instruction_proposer`**: Your custom proposer overrides the default routing and receives all components (both regular instructions and ReAct components)
553
+
-**With custom `instruction_proposer`**: Your custom proposer receives all components (both regular instructions and ReAct components) and handles the optimization logic
554
554
-**With default proposer**: Regular instructions use default instruction proposer, ReAct components use specialized `ReActModuleProposer`
555
555
4.**Optimizes jointly** - ReAct proposer improves all four components together based on execution feedback
556
556
5.**Applies updates** - Updates your ReAct modules with improved instructions and tool descriptions
@@ -686,30 +686,166 @@ for tool_name, tool in optimized_agent.tools.items():
686
686
print(f" Argument descriptions:", tool.arg_desc)
687
687
```
688
688
689
-
### Compatibility with Custom Instruction Proposers
689
+
### Custom Instruction Proposers and ReAct Optimization
690
+
691
+
**Important:** When you provide a custom `instruction_proposer`, it receives ALL components (regular predictors AND ReAct modules). You must set `optimize_react_components=True` to enable ReAct module discovery and serialization, then handle the optimization logic yourself.
692
+
693
+
**How it works internally:**
694
+
695
+
1.**Component Discovery** - GEPA discovers components in your program:
696
+
- Regular predictors → keys like `"predict"`, `"chain_of_thought"`
697
+
- ReAct modules → keys like `"react_module"` or `"react_module:agent_name"`
698
+
699
+
2.**ReAct Serialization** - When `optimize_react_components=True`, GEPA serializes ReAct modules as JSON:
700
+
```json
701
+
{
702
+
"react": "instruction for reasoning and tool selection",
703
+
"extract": "instruction for answer extraction",
704
+
"tools": {
705
+
"tool_name": {
706
+
"desc": "what the tool does",
707
+
"args": {"param": {"type": "string"}},
708
+
"arg_desc": {"param": "description of param"}
709
+
}
710
+
}
711
+
}
712
+
```
713
+
714
+
3.**Custom Proposer Receives**:
715
+
-`candidate: dict[str, str]` - **All values are strings**
- Contains execution traces: inputs, outputs (including full ReAct trajectory), and your metric's feedback
720
+
- For ReAct: `Generated_Outputs` includes the entire trajectory with all tool calls and reasoning
721
+
- Use this to understand what went wrong and guide your improvements
722
+
-`components_to_update: list[str]` - Component keys to optimize this round
723
+
724
+
4.**Your Responsibility**:
725
+
- For ReAct components: Use `json.loads()` to parse, improve all 4 parts, use `json.dumps()` to return
726
+
- For regular components: Improve the instruction string directly
727
+
- Return `dict[str, str]` with same keys
728
+
729
+
**What this means:**
730
+
- Your custom proposer receives ALL components: regular signatures AND ReAct modules
731
+
- GEPA still does discovery and JSON serialization, but YOU handle the optimization logic
732
+
- ReAct components are passed with keys like `"react_module"` or `"react_module:agent_name"`
733
+
734
+
#### Implementing a Custom Proposer for ReAct
735
+
736
+
If you need custom logic, you must handle ReAct components yourself. ReAct components are stored as JSON strings containing all 4 parts:
690
737
691
-
ReAct component optimization works seamlessly with custom instruction proposers. When you provide a custom instruction proposer AND enable `optimize_react_components=True`:
692
-
693
-
**Component routing:**
694
-
-**Signature instructions** → Your custom instruction proposer
695
-
-**Tool descriptions** → Built-in `ToolProposer` with specialized tool reflection prompt
738
+
```python
739
+
import json
696
740
697
-
**Key points:**
698
-
- Both operate independently during the same GEPA run
0 commit comments