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: true mode for non-critical calls

Next Steps

Stop losing money. Start shipping safely. ๐Ÿ›ก๏ธ