Controlling Cost and Latency in Agentic AI Systems
Asked in an AI Engineer Interview
Interviewer: A simple customer request causes an agent to make 12 LLM calls and 8 tool calls, increasing cost and latency significantly.
Question: How would you redesign the agent orchestration and AI Gateway to control token usage, tool calls, model selection, and execution budgets?
Explanation:
Set execution budgets: Define maximum LLM calls, tool calls, tokens, and execution time per request.
Use model routing: Send simple tasks to smaller, cheaper models and complex reasoning to larger models.
Reduce LLM calls: Combine related reasoning steps instead of calling the LLM repeatedly.
Control tool usage: Allow tools only when necessary and prevent repeated calls with the same inputs.
Cache results: Cache repeated LLM responses, embeddings, and tool results.
AI Gateway: Centralize model routing, rate limits, token limits, cost tracking, retries, and policies.
Early stopping: Stop the agent once the required answer is obtained instead of continuing unnecessary reasoning.
Monitor: Track tokens/request, LLM calls, tool calls, latency, cost, and success rate.
Preparing for an ML or AI interview or Looking for Transition in AI? Check out the resource below, it covers key concepts with 1000 interview question Answers, Roadmap, Projects and practical topics to help you prepare with confidence.
AI Interview Bundle: https://lnkd.in/dez6Ji7E AI Structured Course: https://aptai.in/learn-ai