Build an AI SDLC Software Factory with Claude Code starts 12 December. Enrolment closes in 9 days
Courses / Cut AI Agent Costs with Token EconomicsProLesson 4 of 84:01

Load AI agent tools and data on demand

Why does connecting many MCPs make your AI agent cost more? Param Harrison explains that tool schemas are part of the input. If you add many MCPs, the model reads all of their schemas. Load tools on demand instead. When you have many MCPs, give the agent a CLI it can call. Anthropic does this in Claude: it searches the code with grep instead of building an index again and again. The same goes for data. Do not give the model a whole CSV or PDF. Let a tool read it and send only what is needed. After this lesson you can cut the tools and data your agent reads on every call. The example is a medical agent that pulls only the right facts.

What this covers: tool schemas in the prompt, MCPs, and loading tools on demand. It also covers CLIs, code search with grep, tools that read files, and agentic RAG.

Full session: Cut AI Agent Costs with Token Economics

#aiagents #llm #aicost

Chapters

  1. Tools are part of the input
  2. Load tools on demand with a CLI
  3. Let tools read the files
  4. A medical agent that reads less

Transcript

Tools are part of the input

Okay, now oftentimes what these input costs constitute of these input costs are not just your system prompt or prompt or your agentic loop, but also the calls to your tools. For example, if you are dumping all your tools in your prompt itself, okay, these are my tools, then most probably or these are my MCP, like you you you you add hundreds of MCP and connect everything. Now you feel everything is connected, and Claude will take care of you know, calling the MCP and so on, but at what cost? You are basically ingesting all the MCP schema into it. Now Claude have only two options. it will still share the shape of your MCP and then it will call like what is that? Still, it is better than sharing entire tools schema, but again, like you need to cut that.

Load tools on demand with a CLI

How you can cut that, you can you know load the tools on demand, like CLI, for example. Instead of loading everything directly, you can load it on demand. Yeah, instead of if you are going for more than five or six MCP, in my opinion, wherever you can cut the cost, you can go for CLIs, where you can provide access to the CLI and you can say, like, okay, you can utilize this CLI and you can do the same technique. What Anthropic is using in their Claude, like instead of you know going and building and reindexing the code again and again, that will be more costlier. Rather, you go and grep the code base and more more smarter search code search can be much more cheaper compared to compared to sharing the entire index of the code base.

Let tools read the files

Okay, now this is one of the things which you need to be very careful on. whenever there is you might have experienced this, like when you are actually inputting entire data directly, then probably the output quality will be lower as well as the cost will be higher. But when you are actually sharing, this is the path, and you can read it more more as code and then read it. For example, CSV or PDF, instead of directly giving access for the model to read it, you can allow tools to read that, and then you will be able to deterministically control what is the answer and what you can easily reduce the tokens. This applies not just for coding agent, this applies for any AI agents as

A medical agent that reads less

well. For example, when you are building an AI agent, which is a which is a medical medical system where it is answering for any of the medical query for doctors. Now the doctor is asking for a query, and instead of instead they they provide a query and you can call a CLI and that CLI is calling your your brain that is the actual source of information and it is able to pick and choose what data to get, and you will be only sending those data for you know further answering. Now you are you are basically reducing the amount of data which is being fed. Instead of feeding everything to the LLM, you are feeding only the fraction of content. It's a very simple example of rag, but you can build capabilities, agentic RAG, you can build capabilities very similar to that inside any agentic loop as well.

This lesson comes with Pro, $149 a year: Get Pro. This lesson is cut from the free Lightning session Cut AI Agent Costs with Token Economics. The Live Labs build the same system with you, free, on Thursdays: see the Live Labs.