Skip to content

Commit b1e4f3d

Browse files
committed
refactor(gepa): refine reflection prompts for tool optimization
Improve instructions for the reflection LM to focus on reinforcing successful patterns and providing progressively optimized updates for predictor instructions and tool descriptions.
1 parent a133545 commit b1e4f3d

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

dspy/teleprompt/gepa/instruction_proposal.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,15 @@ def __call__(
316316
return updated_components
317317

318318
class GenerateImprovedToolModuleDescriptionsFromFeedback(dspy.Signature):
319-
"""Improve a tool-using module based on execution examples and feedback.
319+
"""I provided an assistant with predictor instructions and tool descriptions,
320+
but its performance needs improvement based on the examples_with_feedback below.
320321
321-
These components are progressively optimized - refine what needs improvement.
322-
Analyze the examples_with_feedback to identify successful patterns and failure causes.
323-
Generate improved texts to help the module succeed on similar tasks.
324-
Place improved texts at their appropriate level of abstraction and/or specificity.
322+
Your task is to propose better predictor instructions, tool descriptions, and tool argument descriptions that address the issues shown in these examples.
323+
Focus on reinforcing patterns that clearly improve the assistant's performance on similar tasks, rather than rewriting everything from scratch unless necessary.
324+
These components are progressively optimized - refine only what needs to change.
325+
326+
Analyze the examples_with_feedback to identify success and failure patterns, and write improved instructions and descriptions at their appropriate level of abstraction and/or specificity,
327+
so that each layer plays a clear, complementary role without unnecessary repetition or verbosity unless redundancy clearly helps the assistant's performance.
325328
"""
326329

327330
current_predictor_instruction = dspy.InputField(
@@ -379,9 +382,8 @@ def __call__(
379382

380383
for module_key in components_to_update:
381384
if module_key not in candidate or module_key not in reflective_dataset:
382-
logger.warning(f"Skipping {module_key}: not in candidate={module_key not in candidate}, not in reflective_dataset={module_key not in reflective_dataset}")
385+
logger.debug(f"Skipping {module_key}: not in candidate={module_key not in candidate}, not in reflective_dataset={module_key not in reflective_dataset}")
383386
continue
384-
385387
current_module_config = json.loads(candidate[module_key])
386388

387389
# Predictor keys: 1 for tool modules, 2 for ReAct modules (extra extract predictor)
@@ -411,7 +413,7 @@ def __call__(
411413
signature = signature.append(
412414
f"improved_tool_{tool_name}_desc",
413415
dspy.OutputField(
414-
desc=f"Concise description of tool '{tool_name}'",
416+
desc=f"Improved description of tool '{tool_name}'",
415417
default=None
416418
)
417419
)
@@ -420,7 +422,7 @@ def __call__(
420422
signature = signature.append(
421423
f"improved_tool_{tool_name}_arg_{arg_name}_desc",
422424
dspy.OutputField(
423-
desc=f"Concise description of tool '{tool_name}' parameter '{arg_name}'",
425+
desc=f"Improved description of the argument '{arg_name}' of tool '{tool_name}'",
424426
default=None
425427
)
426428
)
@@ -443,7 +445,6 @@ def __call__(
443445
kwargs["current_extract_instruction"] = current_module_config[extract_predictor_key]
444446

445447
propose_descriptions = dspy.Predict(signature)
446-
447448
result = propose_descriptions(**kwargs)
448449

449450
# Build improved config (reflection LM returns None to keep original, or new text)

0 commit comments

Comments
 (0)