agent_loop_malformed_promptTier 1 · 70% confidence

ai-agents-agent-loop-malformed-agent-runs-indefinitely-with-invalid-format-missin-58b82c43

agent: ai_agents

When does this happen?

IF Agent runs indefinitely with 'Invalid Format: Missing Action:' after 'Thought:' when using custom format instructions in LangChain's zero-shot-react-description agent.

How others solved it

THEN Adjust the custom format instructions to include the standard tokens: 'Action:' for tool calls and 'Final Answer:' for the final response. For the zero-shot-react-description agent, the required format is: 'Thought: ... \nAction: <tool_name>\nAction Input: <input>' followed by 'Observation:' and then 'Thought: I now know the final answer\nFinal Answer: <answer>'. Avoid using non‑standard action names like 'Action: return AgentFinish.' as they are not recognized by the parser.

Use the default format_instructions from the agent class or replicate the standard template:

```
Answer the following questions as best you can. You have access to the following tools:

{tools}

Use the following format:

Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
```

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics