Skip to content

Commit 1b10b65

Browse files
committed
docs(gepa): make custom proposer section more approachable and clear
Improve the custom proposer documentation to be more user-friendly while maintaining technical accuracy. Changes: - Warmer, more inviting opening ("best way to start") - Concrete example with 'search' tool instead of generic placeholders - Plain English explanations for each component ("How the agent reasons...") - Clear separation: "What you can improve" vs "What to preserve" - Simpler code example with inline comments explaining ReAct vs regular - Concise "reference shows how to" bullets (3 key points) - More approachable tone without sacrificing precision This makes the advanced feature more accessible to users who need custom optimization logic beyond the defaults. Follows up on the previous commit addressing PR comment about custom proposer example.
1 parent ef5563e commit 1b10b65

File tree

1 file changed

+42
-18
lines changed

1 file changed

+42
-18
lines changed

docs/docs/api/optimizers/GEPA/GEPA_Advanced.md

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -754,35 +754,59 @@ for tool_name, tool in optimized_agent.tools.items():
754754

755755
#### Implementing a Custom Proposer for ReAct
756756

757-
If you need custom logic, you can start with the existing implementation at [`ReActModuleProposer`](https://github.com/stanfordnlp/dspy/blob/main/dspy/teleprompt/gepa/instruction_proposal.py). This reference implementation shows how to:
757+
If you need custom optimization logic beyond the default, you can build your own proposer. The best way to start is by looking at the reference implementation: [`ReActModuleProposer`](https://github.com/stanfordnlp/dspy/blob/main/dspy/teleprompt/gepa/instruction_proposal.py).
758758

759-
- Parse ReAct JSON configurations with `json.loads()`
760-
- Build dynamic signatures for tools and parameters
761-
- Call the reflection LM to optimize all components jointly
762-
- Handle optional improvements (reflection LM returns `None` to keep originals)
763-
- Serialize improved components back to JSON with `json.dumps()`
759+
**Understanding ReAct component structure**
764760

765-
**Key concepts for custom proposers:**
761+
When GEPA optimizes ReAct modules, it serializes them as JSON strings containing all the pieces you can improve:
766762

767-
ReAct components are JSON strings containing 4 parts:
768763
```json
769764
{
770765
"react": "instruction for reasoning and tool selection",
771766
"extract": "instruction for answer extraction",
772767
"tools": {
773-
"tool_name": {
774-
"desc": "what the tool does",
775-
"args": {"param": {"type": "string"}},
776-
"arg_desc": {"param": "description of param"}
768+
"search": {
769+
"desc": "Search the web for information",
770+
"args": {"query": {"type": "string"}},
771+
"arg_desc": {"query": "The search query to execute"}
777772
}
778773
}
779774
}
780775
```
781776

782-
Your proposer receives:
783-
- `candidate: dict[str, str]` - Component names to instructions (ReAct values are JSON strings)
784-
- `reflective_dataset: dict[str, list[ReflectiveExample]]` - Execution traces with feedback
785-
- `components_to_update: list[str]` - Which components to optimize this round
777+
**What you can improve:**
778+
- **`react`** - How the agent reasons and decides which tools to use
779+
- **`extract`** - How the agent extracts the final answer from execution results
780+
- **`tools[*].desc`** - What each tool does and when to use it
781+
- **`tools[*].arg_desc`** - What each parameter means and how to use it
786782

787-
Your proposer returns:
788-
- `dict[str, str]` - Same keys with improved instructions (ReAct as JSON strings)
783+
**What to preserve:**
784+
- **`tools[*].args`** - The tool's parameter schema (types, required fields, etc.)
785+
786+
**Your proposer's interface**
787+
788+
Your custom proposer is a callable that receives component instructions and execution feedback, then returns improved versions:
789+
790+
```python
791+
def your_custom_proposer(
792+
candidate: dict[str, str], # Current instructions for all components
793+
reflective_dataset: dict[str, list], # Execution examples with feedback
794+
components_to_update: list[str], # Which components to optimize this round
795+
) -> dict[str, str]: # Return improved instructions
796+
"""
797+
For ReAct components:
798+
- Use json.loads() to parse the JSON string
799+
- Improve what needs fixing based on the feedback
800+
- Use json.dumps() to serialize back
801+
802+
For regular components:
803+
- Just return the improved instruction string
804+
"""
805+
# Your optimization logic here
806+
pass
807+
```
808+
809+
**The reference shows how to:**
810+
- Parse and rebuild the JSON structure
811+
- Generate dynamic fields for tools/parameters
812+
- Use execution feedback to guide improvements

0 commit comments

Comments
 (0)