One of the most important practices when running Agentic AI systems in production is setting up **real-time cost alerts**. Without proper monitoring, a single runaway agent workflow can generate hundreds or even thousands of dollars in unexpected LLM costs within hours.
This practical guide shows you how to implement effective LangSmith cost alerts for your CrewAI and LangGraph agents as of March 24, 2026.
Why LangSmith Cost Alerts Are Essential
Agentic AI systems have highly variable costs. A complex multi-agent workflow can easily consume $5–$50+ per run. Without alerts, you may only discover excessive spending after reviewing your monthly bill.
Step-by-Step: Setting Up LangSmith Cost Alerts
1. Enable LangSmith Tracing
import os
os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_API_KEY"] = "lsv2_your_key_here"
os.environ["LANGCHAIN_PROJECT"] = "agentic-ai-production"
2. Create a Custom Cost Monitoring Callback
from langsmith import Client
from langchain_core.callbacks import BaseCallbackHandler
class CostAlertHandler(BaseCallbackHandler):
def __init__(self, alert_threshold: float = 2.0):
self.client = Client()
self.alert_threshold = alert_threshold # Alert if run cost exceeds this amount
def on_llm_end(self, response, **kwargs):
# This is called after every LLM call
run_id = kwargs.get("run_id")
if run_id:
run = self.client.read_run(run_id)
if run.total_cost and run.total_cost > self.alert_threshold:
self.send_cost_alert(run)
def send_cost_alert(self, run):
print(f"🚨 COST ALERT: Run {run.id} exceeded threshold!")
print(f"Cost: ${run.total_cost:.4f}")
print(f"Workflow: {run.name}")
# Add your notification logic here (Slack, email, SMS, etc.)
# Example: Send to Slack webhook
# requests.post(SLACK_WEBHOOK_URL, json={"text": f"Cost alert: ${run.total_cost}"})
3. Integrate the Handler into Your Agent
from langgraph.graph import StateGraph
# Add the cost alert handler
cost_handler = CostAlertHandler(alert_threshold=1.5) # Alert at $1.50 per run
# Build your LangGraph
workflow = StateGraph(AgentState)
# ... add your nodes and edges
app = workflow.compile()
# Run with cost monitoring
result = app.invoke(
{"messages": [HumanMessage(content="Research latest Agentic AI trends")]},
config={"callbacks": [cost_handler]}
)
Advanced Cost Alert Strategies
- Daily Budget Alerts: Alert when daily spend exceeds a threshold
- Per-User Cost Alerts: Monitor cost per customer or department
- Anomaly Detection: Alert when cost suddenly spikes compared to historical average
- Workflow-Specific Alerts: Different thresholds for different agent workflows
Recommended Alert Channels in 2026
- Slack / Microsoft Teams notifications
- Email alerts with run traces
- PagerDuty / Opsgenie for critical thresholds
- Custom dashboard with visual cost trends
Last updated: March 24, 2026 – Implementing LangSmith cost alerts is one of the highest-ROI practices for anyone running production Agentic AI systems. Early detection of cost anomalies can save thousands of dollars per month.
Pro Tip: Start with conservative thresholds (e.g., $1.50 per run) and gradually adjust them as you better understand your typical workflow costs.