Skip to content

Commit 61fd5cc

Browse files
Merge pull request #992 from xyloid/fix/react_instr_from_sig
fix(react): `ReAct` doesn't use `instructions` from the given `Signature`
2 parents bcf47c8 + 7acf4c8 commit 61fd5cc

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

dspy/predict/react.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ def __init__(self, signature, max_iters=5, num_results=3, tools=None):
2828
inputs_ = ", ".join([f"`{k}`" for k in self.input_fields.keys()])
2929
outputs_ = ", ".join([f"`{k}`" for k in self.output_fields.keys()])
3030

31-
instr = [
31+
instr = []
32+
33+
if self.signature.instructions is not None:
34+
instr.append(f"{self.signature.instructions}\n")
35+
36+
instr.extend([
3237
f"You will be given {inputs_} and you will respond with {outputs_}.\n",
3338
"To do this, you will interleave Thought, Action, and Observation steps.\n",
3439
"Thought can reason about the current situation, and Action can be the following types:\n",
35-
]
40+
])
3641

3742
self.tools["Finish"] = dspy.Example(
3843
name="Finish",

tests/predict/test_react.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,16 @@ def test_custom_tools():
154154
"Thought 3: Even more thoughts\n\n"
155155
"Action 3: Finish[baz]"
156156
)
157+
158+
159+
def test_signature_instructions():
160+
class ExampleSignature(dspy.Signature):
161+
"""You are going to generate output based on input."""
162+
163+
input = dspy.InputField()
164+
output = dspy.OutputField()
165+
166+
react = dspy.ReAct(ExampleSignature)
167+
168+
assert react.react[0].signature.instructions is not None
169+
assert react.react[0].signature.instructions.startswith("You are going to generate output based on input.")

0 commit comments

Comments
 (0)