When the budget is overrun and the protection mode is set to throw
When it does, AgentGuard throws an error with detailed information. Developers can catch the error with a try-catch and access the error.agentGuardData
Get the data at the time of the overrun. Example:
try { const response = await openai.chat.completions.create({...}); } catch (error) { if (error.message.includes('AGENTGUARD_LIMIT_EXCEEDED')) { console.log('预算超支:', error.agentGuardData); } }
Error messages include current total spend, budget cap, percentage overspend, etc., making it easy for developers to adjust tasks or switch to low-cost models.
This answer comes from the articleAgentGuard: A Tool for Monitoring AI Agent Costs in Real Time and Preventing OverspendingThe