Skip to content

[Bug] dspy.ReAct doesn't format/use dspy.History OutputFields #8195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nickthegroot opened this issue May 8, 2025 · 1 comment
Open

[Bug] dspy.ReAct doesn't format/use dspy.History OutputFields #8195

nickthegroot opened this issue May 8, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@nickthegroot
Copy link

nickthegroot commented May 8, 2025

What happened?

When using dspy.ReAct and passing dspy.History as a InputField, none of the included OutputFields are used in the LLM chain.

Steps to reproduce

from dspy import ReAct, History, Signature, InputField, OutputField

class GenerateAnswer(Signature):
    question: str = InputField(desc="The question to answer")
    history: History = InputField(desc="The conversation history")

    answer: str = OutputField(desc="The answer to the question")

react = ReAct(GenerateAnswer, tools=[])
history = History(messages=[{"question": "What's the capital of Germany?", "answer": "The capital of Germany is Berlin"}])

react.forward(question="What is the capital of France?", history=history)

Checking the LLM call chain reveals that the user portion is correctly passed, but the assistant portion is not.

lm.history

[
    {'role': 'system', 'content': '...'}, # omitted for brevity
    {'role': 'user', 'content': "[[ ## question ## ]]\nWhat's the capital of Germany?"}, # InputField correctly passed
    {'role': 'assistant', 'content': '[[ ## next_thought ## ]]\nNone\n\n[[ ## next_tool_name ## ]]\nNone\n\n[[ ## next_tool_args ## ]]\nNone'}, # OutputField not passed
    {'role': 'user', 'content': """[[ ## question ## ]]\nWhat is the capital of France?\n\n[[ ## trajectory ## ]]\n\n\nRespond with the correspondi
ng output fields, starting with the field `[[ ## next_thought ## ]]`, then `[[ ## next_tool_name ## ]]` (must be formatted as a 
valid Python Literal['finish']), then `[[ ## next_tool_args ## ]]` (must be formatted as a valid Python dict[str, Any]), and the
n ending with the marker for `[[ ## completed ## ]]`."""}
]
@nickthegroot nickthegroot added the bug Something isn't working label May 8, 2025
@chenmoneygithub chenmoneygithub self-assigned this May 8, 2025
@chenmoneygithub
Copy link
Collaborator

@nickthegroot Thanks for reporting the issue, I will take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants