agent_loopingTier 1 · 70% confidence

ai-agents-agent-looping-agent-repeatedly-outputs-invalid-format-missing-ac-623c36a9

agent: ai_agents

When does this happen?

IF Agent repeatedly outputs 'Invalid Format: Missing Action:' after 'Thought:' when it should stop and provide a final answer.

How others solved it

THEN Include explicit 'AI: [final answer]' stopping instruction in the format instructions. Set `handle_parsing_errors=True` and `max_iterations` in the AgentExecutor to prevent infinite loops. Use an agent type (e.g., 'zero-shot-react-description') that supports the final answer token.

FORMAT_INSTRUCTIONS = """
When you need to use a tool:
Thought: Do I need to use a tool? Yes
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action

When you have the final answer:
Thought: Do I need to use a tool? No
AI: [your final answer here]
"""
agent = initialize_agent(tools, llm, agent='zero-shot-react-description', handle_parsing_errors=True, agent_kwargs={'format_instructions': FORMAT_INSTRUCTIONS, 'input_variables': ['input', 'agent_scratchpad', 'tool_names']})

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics