AgentGuard Quick Start ๐
July 31, 2025 ยท View on GitHub
Get protection in 30 seconds.
1. Install
# NPM (recommended)
npm install agent-guard
# Or download directly
curl -O https://raw.githubusercontent.com/dipampaul17/AgentGuard/main/agent-guard.js
2. Add to your agent
const agentGuard = require('agent-guard');
await agentGuard.init({ limit: 10 });
// Your existing agent code...
// AgentGuard now protects everything below
3. Verify it works
node verify-installation.js
Watch the cost counter: ๐ธ \$0.12... \$0.45... \$0.89...
4. Configure for your needs
const guard = await require('agent-guard').init({
limit: 50, // Kill at \$50
webhook: 'https://hooks.slack.com/...', // Slack alerts
silent: false // Show cost updates
});
// Check costs anytime
console.log(`Current: $${guard.getCost()}`);
5. For browser agents
<script src="agent-guard.js"></script>
<script>
AgentGuard.init({ limit: 25 });
// Your browser agent code...
</script>
Real Example: RAG Agent Protection
// Add at the top of your RAG agent
await require('agent-guard').init({ limit: 100 });
// Your existing code
async function processDocument(doc) {
const chunks = await chunkDocument(doc);
for (const chunk of chunks) {
// These API calls are now protected
const embedding = await openai.embeddings.create({...});
const response = await openai.chat.completions.create({...});
// AgentGuard tracks each call automatically
console.log('Processed chunk:', response);
}
}
Emergency Stop Examples
Runaway Loop Protection
๐ธ \$0.23... \$1.45... \$4.67... \$9.89
โ ๏ธ AGENTGUARD: Approaching limit (\$10)
๐ AGENTGUARD: KILLED PROCESS - Saved you \$90
What Gets Tracked
- โ OpenAI API calls (all models)
- โ Anthropic/Claude API calls
- โ Any API response logged to console
- โ Fetch/axios requests to AI APIs
- โ Real-time token & cost calculation
What Gets Protected
- ๐ก๏ธ Infinite loops calling AI APIs
- ๐ก๏ธ Expensive model calls (GPT-4, Claude Opus)
- ๐ก๏ธ Accidentally high token usage
- ๐ก๏ธ Recursive agent calls
- ๐ก๏ธ Development debugging sessions
Troubleshooting
"Not tracking my API calls"
- Make sure you
console.log()the API responses - Or use fetch/axios for automatic interception
"Kills too early"
- Adjust limit:
guard.setLimit(100) - Check pricing accuracy for your model
"Want to exclude certain calls"
- Initialize multiple guards for different components
- Use
silent: truemode for non-critical calls
Next Steps
- ๐ง GitHub Issues - Report bugs or request features
- ๐ฌ GitHub Discussions - Community support
- ๐ Full Documentation - Complete API reference
Stop losing money. Start shipping safely. ๐ก๏ธ