r/LangChain • • 6d ago

Discussion Past ~40 tools, my AI coding agent started picking the wrong one. It didn't fail, it just looked right. Here's what fixed it

I kept adding tools and MCP servers to my coding setup and hit a problem I didn't expect. Context wasn't the issue. The agent started choosing the wrong tool.

There was no error. It would call a similar "search" tool, get a plausible answer and move on. That's what makes it easy to miss.

I asked around, and here's what worked for people using Cursor, Claude Code, Codex and custom agents:

  1. The limit is about choosing, not context size

Problems showed up around 40-50 tools, long before the context window was full. When two tools sound alike, the pick is close to a coin flip.

  1. Say when to use each tool

Not two tools that both say "search", but "search code in this repo" vs "search the public docs".

  1. Flag tools that write

If the model thinks a tool is read-only, it calls it freely. Never let a short description hide a write.

  1. Load details only when needed

Keep a short summary in context and load the full schema only when a task needs it.

  1. Use a search_tools + call_tool pair

One tool finds the right tools, another runs them. Someone said this keeps idle context under ~1k tokens whether there are 30 tools or 300.

  1. Run the same task twice

If it picks different tools each time, your descriptions overlap.

My question:

When you have similar tools, do you merge them into one tool with a parameter, or keep them separate with very specific descriptions? Merging seems cleaner, but I wonder if it just moves the confusion into the arguments.

And how many tools do you keep enabled day to day? Is anyone running 100+ without issues?

2 Upvotes

14 comments sorted by

3

u/SpareIntroduction721 6d ago

This has been resolved like long time ago

1

u/Elmanouzi_Fogosa 4d ago

by who though, are you talking about a standard router pattern or the search_tools setup OP mentioned

0

u/sandeepK1125 6d ago

Fair. Tool search mostly handles it now. Still curious which setup you use, though.

1

u/ank100 6d ago

i only merge when the tools do the same thing on different inputs. if they have different side effects (read vs write) i keep them separate with very specific descriptions, otherwise the argument just ends up carrying the confusion like you guessed. day to day i keep maybe 10-15 enabled per task and put the rest behind a search tool, past that the wrong picks creep in for me. the run-it-twice check is a good one btw.

0

u/sandeepK1125 6d ago

Good point about read vs write. That’s a cleaner rule than mine. 10–15 per task matches what I’ve seen too.

2

u/fiddler48 6d ago

Merging just relocates the ambiguity into argument dispatch, which is harder to debug than a wrong tool call.

1

u/ChemicalExcellent463 6d ago

the worrying bit is the wrong search returning something plausible and the agent just moving on. when you run the same task twice, how do you check which tools it picked?

1

u/Senior-Assumption864 6d ago

do you version the tool descriptions, or just rewrite them whenever it picks wrong?

2

u/Michael_Jeffords 6d ago

i keep them in git next to a small file of like 20 tasks with the tool it should pick for each, and every time i touch a description i rerun that set a couple times and diff the tool names it actually called, because rewriting one description to fix a wrong pick has a habit of quietly stealing calls from the neighboring tool and you won't see that unless you rerun the whole set

1

u/Senior-Assumption864 5d ago

thats a clean setup, a fixed set of tasks to diff after each description change makes a lot of sense

1

u/NEXAI-JinZhedong 3d ago

I’d separate tools when their consequences differ, especially reading an inspection result versus changing a machine setting. Merge only when the same permissions and validation apply; then test confusing requests and log both the chosen tool and its arguments. Two runs are a useful smoke test, but a small repeatable set of ambiguous requests would tell you more about whether a description change helped.