AI agent keeps looping and won't stop calling tools

Posted 2 weeks ago

Worldwide

Summary

I run a small B2B lead-gen agency, and to save my team time I built an AI agent that handles inbound leads from our website form. The idea is simple: when a lead comes in, the agent looks them up (it has a few tools — an enrichment API to pull company size, a tool to check our CRM for duplicates, and one to draft a personalized first email), decides if they're a fit, and either drafts the outreach or marks them as not qualified. It's built with LangGraph and OpenAI function calling. It worked fine in testing but now that real leads are flowing in, it's misbehaving. The main problem is the agent gets stuck in a loop — it calls the enrichment tool, gets the result, then calls it again with the exact same arguments, over and over, until it hits the recursion limit and crashes. Sometimes it also ignores the tool output completely and hallucinates a company size instead of using what the tool returned. So it's clearly something in how the agent loop and tool results are being handled, not the tools themselves (I tested those separately and they return correct data). A few guesses, though I could be wrong: - the tool result isn't being appended back to the state/messages correctly, so the agent never "sees" that it already called it - my conditional edge in LangGraph is routing back to the agent node when it should go to end - the function-calling response isn't being parsed right, so it re-triggers the same call The stack is plain Python 3.11, LangGraph, and OpenAI. I just need someone to find why it loops and ignores tool output, fix it so the agent uses tool results and stops when it's done, and add a sane recursion guard. A couple sentences on what was actually broken would be great, since I want to understand it and not reintroduce it. I'll give you the repo, a couple of sample lead payloads, and an env example so you can reproduce it in minutes. Timeline should be a day or two. When you apply, tell me in one line the most common reason a LangGraph agent loops forever on the same tool call — copy-paste proposals are easy to spot. And mention one agent or LangGraph bug you've actually fixed before.

  • Less than 30 hrs/week
    Hourly
  • < 1 month
    Duration
  • Expert
    Experience Level
  • $30.00

    -

    $60.00

    Hourly
  • Remote Job
  • One-time project
    Project Type
Skills and Expertise
Mandatory skills
Large Language Model
LangChain
Activity on this job
  • Proposals:50+
  • Last viewed by client:2 weeks ago
  • Hires:
    1
  • Interviewing:
    2
  • Invites sent:
    0
  • Unanswered invites:
    0
About the client
Member since Mar 31, 2026
  • United States
    Henderson3:34 PM
  • $2.4K total spent
    9 hires, 0 active
  • 81 hours
  • Finance & Accounting
    Large company (100-1,000 people)

Explore similar jobs on Upwork

Co-Pilot TrainingHourly‐ Posted 2 months ago
Claude
AI Model Training
Artificial Intelligence
Training & Development
Training Session
AI DeveloperHourly‐ Posted 1 month ago
AI Chatbot
JavaScript
Large Language Model
Multimodal Large Language Model
Chatbot Development
Artificial Intelligence
NLP Tokenization
Natural Language Processing
Python

How it works

  • Post a job icon
    Create your free profile
    Highlight your skills and experience, show your portfolio, and set your ideal pay rate.
  • Talent comes to you icon
    Work the way you want
    Apply for jobs, create easy-to-by projects, or access exclusive opportunities that come to you.
  • Payment simplified icon
    Get paid securely
    From contract to payment, we help you work safely and get paid securely.
Want to get started? Create a profile

About Upwork

  • Rating is 4.9 out of 5.
    4.9/5
    (Average rating of clients by professionals)
  • G2 2021
    #1 freelance platform
  • 49,000+
    Signed contract every week
  • $2.3B
    Freelancers earned on Upwork in 2020

Find the best freelance jobs

Growing your career is as easy as creating a free profile and finding work like this that fits your skills.

Trusted by

  • Microsoft Logo
  • Airbnb Logo
  • Bissell Logo
  • GoDaddy Logo