Observed since 20 Oct, 23:20 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Production Infrastructure for AI Agents - Cost controls, observability, and framework-agnostic deployment
Production Infrastructure for AI Agents
Prevent runaway costs, gain observability, and deploy AI agents with confidence.
AI agents are transforming how we build software, but deploying them to production introduces critical operational challenges that traditional MLOps tools don't address:
AgentSentry is an open-source production infrastructure layer that provides:
┌─────────────────────────────────────────────────────────────┐
│ Your AI Agent │
│ (CrewAI, AutoGen, LangChain, etc.) │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ AgentSentry Layer │
│ ┌───────────────┐ ┌──────────────┐ ┌─────────────────┐ │
│ │ Token │ │ Observability│ │ Framework │ │
│ │ Guardrails │ │ & Tracing │ │ Adapters │ │
│ └───────────────┘ └──────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────┐
│ LLM APIs │
│ (OpenAI, Anthropic)│
└─────────────────────┘
| Feature | Description |
|---|---|
| Budget Guardrails | Circuit breaker pattern that kills execution when USD budget or loop thresholds are exceeded |
| Token Tracking | Automatic tracking of token usage, costs, and API calls with per-model pricing |
| Framework Adapters | Unified interface for CrewAI, AutoGen, LangChain, and custom frameworks |
| OpenTelemetry Integration | Distributed tracing and metrics for agent execution flows |
| Database Audit Logs | SQLAlchemy-based persistence for session logs, breaches, and metrics |
| CLI Tools | agentsentry stack deploy, agentsentry monitor sessions, and more |
# Install core package
pip install agentsentry
# Install with framework support
pip install agentsentry[crewai] # For CrewAI
pip install agentsentry[langchain] # For LangChain
pip install agentsentry[autogen] # For AutoGen
agentsentry init --framework crewai
This generates:
agentsentry.yaml - Configuration file.env.template - Environment variables templateexample_agent.py - Sample integration codeEdit agentsentry.yaml:
max_budget_usd: 5.0 # Kill agent if cost exceeds $5
max_loops: 20 # Kill agent after 20 iterations
enable_db_logging: true
database_url: "postgresql://localhost/agentsentry"
from agentsentry import AgentRunner, Config
from agentsentry.adapters.crewai import CrewAIAdapter
# Load configuration
config = Config.from_file('agentsentry.yaml')
# Initialize runner
runner = AgentRunner(config=config)
runner.register_adapter('crewai', CrewAIAdapter)
# Run your agent with cost controls
result = runner.run('crewai', {
'name': 'research-agent',
'task': 'Research AI trends',
'model': 'gpt-4'
})
print(f"Cost: ${result['metrics']['total_cost_usd']:.4f}")
print(f"Tokens: {result['metrics']['total_tokens']}")
That's it! Your agent now has:
AgentSentry follows a modular, adapter-based architecture designed for extensibility:
agentsentry/
├── core/ # Core orchestration engine
│ ├── runner.py # Main AgentRunner class
│ ├── config.py # Configuration management
│ └── base_adapter.py # Abstract adapter interface
├── adapters/ # Framework-specific adapters
│ ├── crewai.py # CrewAI integration
│ ├── autogen.py # AutoGen integration
│ └── langchain.py # LangChain integration
├── middleware/ # Interception & control layer
│ └── token_guardrail.py # Budget & loop enforcement
├── observability/ # Telemetry & tracking
│ ├── tracking.py # Execution tracker
│ └── telemetry.py # OpenTelemetry provider
├── persistence/ # Database layer
│ ├── database.py # SQLAlchemy logger
│ └── models.py # ORM models
└── cli/ # Command-line interface
└── commands/
├── stack.py # Stack deployment
├── monitor.py # Monitoring tools
└── init.py # Project initialization
Each framework adapter implements the BaseAdapter interface:
class BaseAdapter(ABC):
@abstractmethod
def initialize(self) -> None:
"""Initialize framework dependencies"""
@abstractmethod
def execute(self, agent_config: Dict) -> Dict:
"""Execute agent with AgentSentry controls"""
@abstractmethod
def shutdown(self) -> None:
"""Clean resource cleanup"""
This allows AgentSentry to support any agent framework through a plugin system.
The TokenGuardrail middleware implements the Circuit Breaker pattern for LLM API calls:
max_budget_usd and max_loopsBudgetExceededError when limits are exceededfrom agentsentry.middleware import TokenGuardrail, BudgetExceededError
guardrail = TokenGuardrail(config={
'max_budget_usd': 2.0,
'max_loops': 10
})
try:
with guardrail.track_execution(session_id='session-123'):
# Your agent code here
for i in range(100): # Will hit loop limit
response = llm.call(prompt)
# Track the call
guardrail.intercept_api_call(
session_id='session-123',
model='gpt-4',
prompt_tokens=100,
completion_tokens=50,
is_loop_iteration=True
)
except BudgetExceededError as e:
print(f"🚨 Circuit breaker triggered: {e.threshold_type}")
print(f"Total cost: ${e.total_cost}")
print(f"Loops executed: {e.loops_executed}")
Supported Pricing Models:
agentsentry.yaml)AgentSentry integrates with OpenTelemetry for distributed tracing and metrics:
# View active sessions
agentsentry monitor sessions
# Real-time cost analytics
agentsentry monitor costs --period 24h
# Follow a specific session
agentsentry monitor sessions --session-id abc123 --follow
| Metric | Description |
|---|---|
total_tokens | Cumulative token usage (prompt + completion) |
total_cost_usd | Total cost in USD |
loops_executed | Number of loop iterations |
api_calls | Total API calls made |
duration_seconds | Execution time |
AgentSentry uses SQLAlchemy with two core tables:
session_logs: Records for each agent execution
session_id, status, total_tokens, total_cost_usd, loops_executedthreshold_breaches: Audit trail for budget/loop violations
session_id, threshold_type, error_message, breached_atAgentSentry is in private beta but actively seeking core contributors for the open-source substrate. We're particularly interested in:
New Framework Adapters: Help us support more agent frameworks
Observability Enhancements: Expand telemetry capabilities
Cost Optimization: Advanced budget management
Production Hardening: Enterprise features
# Clone the repository
git clone https://github.com/nitindme/agentsentry.git
cd agentsentry
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest
The easiest way to contribute is by adding support for a new framework:
# agentsentry/adapters/your_framework.py
from agentsentry.core.base_adapter import BaseAdapter
from agentsentry.middleware.token_guardrail import TokenGuardrail
class YourFrameworkAdapter(BaseAdapter):
def __init__(self, config):
super().__init__(framework_name="your_framework", config=config)
self.guardrail = TokenGuardrail(config=self.config)
def initialize(self):
# Initialize your framework
pass
def execute(self, agent_config):
with self.guardrail.track_execution(agent_config['session_id']):
# Execute agent
# Track API calls using self.guardrail.intercept_api_call()
return {"status": "success"}
def shutdown(self):
# Cleanup
pass
# Add tests
tests/adapters/test_your_framework.py
# Add example
examples/your_framework_example.py
# Update docs
docs/adapters/your_framework.md
git checkout -b feature/your-adapter)git commit -am 'Add YourFramework adapter')git push origin feature/your-adapter)black for formatting and ruff for lintingSee the examples/ directory for complete working examples:
crewai_example.py: Integrating with CrewAI agentsguardrail_example.py: Using the guardrail middleware directlycustom_adapter_example.py: Building a custom adapterQ: Is AgentSentry a framework for building agents?
A: No. AgentSentry is infrastructure that wraps around your existing agent frameworks to add production features like cost controls and observability.
Q: Does it work with my existing agents?
A: Yes! AgentSentry is designed to integrate with minimal code changes. If we don't support your framework yet, you can build a custom adapter.
Q: How much overhead does it add?
A: Minimal. Token tracking adds <10ms per API call. The guardrail middleware is designed for production workloads.
Q: Can I use it without a database?
A: Yes. Set enable_db_logging: false in your config. Metrics will still be tracked in memory.
Q: Is it production-ready?
A: We're currently in private beta. The core infrastructure is stable, but we recommend thorough testing before production deployment.
AgentSentry is released under the MIT License. See LICENSE for details.
⭐ If AgentSentry solves a problem for you, please star the repo to help others discover it!
Made with ❤️ by the AgentSentry community
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.1.3 | 14 Feb 2026 | 14 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 23:20 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:5e06b6af0a2e276813e11bfe3d9c66e8c38a8d55c23b80d5d97673061eeeb97e