AI and Deep Learning Community Question

How do I optimize Agentic AI for cost-efficiency when using high-token LLMs?

Posted on 2024-08-15 • In AI and Deep Learning • By Kevin Lewis

We are running a fleet of agents using GPT-4, and the API bills are becoming insane. Every time an agent "thinks" or "reflects," it consumes thousands of tokens. Are there strategies to use smaller models like GPT-3.5 or Llama 3 for the reasoning steps and only "call in the big guns" (GPT-4) for the final execution or complex logic? How do you manage the routing?

3 Answers 9,298 Views

All answers to this question 3 Answers

Susan Walker Answered on 2024-08-17
Answered

This is a huge issue in production Agentic AI right now. The best strategy is "Semantic Routing." You use a very fast, cheap model (or even a simple vector search) to classify the complexity of the task. If it’s a simple data lookup, route it to a 7B parameter model. If it requires deep reasoning or multi-step planning, only then do you send it to GPT-4. Also, look into "Prompt Caching"—many providers are now offering discounts for reused context. Reducing the length of your system prompts and using more efficient "few-shot" examples can also save a ton of money.

William Scott Answered on 2024-08-19
Answered

Have you considered fine-tuning a smaller model on your specific agent's "thinking" patterns so it can eventually replace the expensive model for 80% of your tasks?

Kevin Lewis Commented on 2024-08-20
Commented

William, that’s exactly what we are experimenting with now. We are using GPT-4 to generate "Gold Standard" logs of how the agent should think, and then we plan to use those logs to fine-tune a smaller Llama model. It's a bit of an upfront investment in data collection, but the long-term ROI on API costs could be massive if we can get a 7B model to perform like a 70B one for our specific niche.

Margaret Hall Answered on 2024-08-21
Answered

Don't forget to implement "max iteration" limits. Sometimes agents get into a reasoning loop and can burn $10 worth of tokens in a few seconds if they aren't stopped.

Susan Walker Commented on 2024-08-22
Commented

Margaret is spot on. Without "Recursion Limits," your agents can become a bottomless pit for your budget. Always set a hard cap on how many turns an agent can take.

Write a Comment

Your email address will not be published. Required fields are marked (*)

Join the LearnersEra Community

Ask questions, share knowledge and learn from professionals across technology, project management and certification topics.

Change Country and Nearest City

Select your country and nearest city to see courses available in your region.