Trying to understand how to optimise on agent cost

Hi, We’ve built an agent with langchain, I’m spending around $0.9 per session - How do I optimse on this? any patterns that I can look for?

I’d start with one typical session trace before changing models. Split the cost into input tokens, output tokens, and number of model calls. Then look for repeated tool calls, retries, large tool responses, and old conversation history being sent on every turn. Those point to quite different fixes.

Try one change at a time on the same small set of tasks, and compare cost per successfully completed task. A cheaper call can still cost more overall if it needs extra attempts.

What does a session actually do, which model are you using, and roughly how many model calls does it make? A sanitized breakdown is enough—no prompts or customer data needed.

$0.90 per session usually means the context is growing every turn. A few things that helped me cut costs on a similar agent:

1. Trace one expensive session in LangSmith and sort the runs by tokens. Usually one or two steps (a big system prompt, a long tool output, or the full chat history) account for most of the cost.

2. Trim or summarize history instead of resending everything. trim_messages, or a small summary node that kicks in after N turns, keeps input tokens flat.

3. Shrink tool outputs before they go back to the model. Return only the fields the agent needs, not raw JSON or whole documents.

4. Route by difficulty: a cheap model for classification, extraction and simple tool calls, and the big model only for the final reasoning step.

5. Turn on prompt caching if your provider supports it, and keep the static part (system prompt plus tool schemas) at the start so it actually gets cached.

6. Cap recursion and tool-call loops so a confused agent can’t burn 20 steps.

Measuring per-step tokens first is the important bit, otherwise it’s easy to optimize the wrong node.

Worth checking how much of that $0.90 is tool output being re-sent as history on every turn. In sessions I’ve looked at, that’s often the biggest line, ahead of the model choice.