Skip to content

Latest commit

 

History

History
87 lines (65 loc) · 2.63 KB

File metadata and controls

87 lines (65 loc) · 2.63 KB

Critical Fix: Agent Iteration Limit

Problem Identified

The agent was executing successfully but hitting the iteration limit before completing all tool calls and returning the Final Answer.

Error in logs:

"Invalid or incomplete response"
"No JSON object found in output: Agent stopped due to iteration limit or time limit."

Root Cause

The ReAct agent format counts each Thought-Action-Observation cycle as one iteration:

  1. Thought: I need to parse the resume
  2. Action: resume_parser (iteration 1)
  3. Observation: Resume data
  4. Thought: Now extract skills
  5. Action: skill_extractor (iteration 2)
  6. Observation: Skills data ... and so on

With 6 tools to call + final answer, the agent needs at least 12-15 iterations, but was limited to 10 iterations.

Solution Applied

File: backend/app/services/agents/resume_agent_service.py Method: _execute_agent_analysis()

Changes:

# BEFORE:
agent = ResumeIntelligenceAgent(
    max_iterations=10,  # Too low!
    max_execution_time=20.0,  # Too short!
    verbose=True
)

# AFTER:
agent = ResumeIntelligenceAgent(
    max_iterations=30,  # Increased to allow all tools
    max_execution_time=60.0,  # Increased to 60 seconds
    verbose=True
)

Why These Numbers?

  • max_iterations=30: Allows for 6 tool calls × 2 iterations each + buffer for final answer
  • max_execution_time=60.0: Gives LLM enough time to process each tool call (HuggingFace API can be slow)

Expected Behavior After Fix

  1. Agent executes all 6 tools without hitting iteration limit
  2. Agent calls analysis_formatter as final step
  3. Agent returns valid JSON in Final Answer
  4. JSON validation succeeds
  5. Analysis stored with status = success
  6. Frontend displays AI-generated analysis

Testing

  1. Restart backend
  2. Upload resume
  3. Check backend logs for:
    • "Agent initialized with 6 tools, max_iterations=30, max_execution_time=60.0s"
    • All 6 tools executing successfully
    • "Agent output successfully validated and parsed"
  4. Check database: status should be success
  5. Frontend should display AI analysis (not loading spinner)

Frontend Loading Issue

The frontend shows "Analysis in progress" for 2+ minutes because:

  1. Agent execution takes ~26 seconds (as seen in logs)
  2. Frontend polls for results every few seconds
  3. Until analysis is complete and stored, it returns 404
  4. Once analysis is stored, frontend displays it

This is normal behavior. The fix ensures the analysis completes successfully.

Files Modified

  • backend/app/services/agents/resume_agent_service.py
    • _execute_agent_analysis() - Increased max_iterations and max_execution_time