u/Low_Edge7695

The 4-line function that fixed my agent's wrong answers (conditional edge in LangGraph)
▲ 11 r/LangChain+2 crossposts

The 4-line function that fixed my agent's wrong answers (conditional edge in LangGraph)

My ReAct agent gave wrong answers for a week. It would call a tool, get a result, and immediately answer without checking if the result made sense.

The fix was a conditional edge — 4 lines:

    def conditional_edge(state: MessageState):
        last_message = state["messages"][-1]
        if last_message.tool_calls:
            return "tool"
        return END

Without it: LLM → tool → answer (one shot, no self-correction)

With it: LLM → tool → check → loop back if needed → answer

Full repo (67 lines total): https://github.com/dunjeonmaster07/react-agent

What other simple patterns made a big difference in your agent's reliability?

u/Low_Edge7695 — 5 hours ago