Cost Tracking for LangGraph Agents #205
bmdhodl
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Cost Tracking for LangGraph Agents
Category: Show and tell
Labels: langgraph, cost-control, budget
LangGraph agents can run for a long time — branching, backtracking, calling tools across multiple nodes. Without cost tracking, you have no idea what a graph execution costs until the OpenAI invoice arrives.
Here's how to add per-node budget enforcement to a LangGraph agent.
The
guarded_nodedecoratorAgentGuard provides a LangGraph-specific decorator that wraps any node with budget and loop guards:
Every node execution is:
BudgetExceededis raisedWhat happens when the budget is exceeded
BudgetExceededpropagates up through the graph execution. You can catch it at the top level:The budget is shared across all nodes — so a $5 limit applies to the entire graph execution, not per-node.
Adding the
guard_nodeto your graphFor more control, you can add a standalone guard node that checks the budget between steps:
This checks the budget explicitly between the research and synthesis steps.
Install
Zero runtime dependencies in the core SDK. The LangGraph integration is an optional extra.
Repo: github.com/bmdhodl/agent47
Anyone running LangGraph in production? Curious how you're handling cost tracking today.
Beta Was this translation helpful? Give feedback.
All reactions