> ## Documentation Index
> Fetch the complete documentation index at: https://docs-omnicoreagent.omnirexfloralabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Production Cookbook

> Production-oriented OmniCoreAgent examples for metrics, telemetry, guardrails, and operational configuration

# Production

> Deploy OmniCoreAgent with confidence. Runtime usage metrics and guardrails.

## Examples

| File                                                    | What You'll Learn                                                     |
| ------------------------------------------------------- | --------------------------------------------------------------------- |
| [metrics\_observability.py](./metrics_observability.py) | Track tokens, requests, response times, and usage for cost estimation |
| [guardrails.py](./guardrails.py)                        | Protect agents from prompt injection attacks                          |

***

## 📊 Metrics & Observability

Track everything your agent does:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from omnicoreagent import OmniCoreAgent

agent = OmniCoreAgent(
    name="monitored_agent",
    system_instruction="You are a helpful assistant.",
    model_config={"provider": "openai", "model": "gpt-4o"},
    agent_config={
        "request_limit": 100,
        "total_tokens_limit": 50000,
    },
)

# After running queries...
metrics = await agent.get_metrics()
print(f"Total requests: {metrics['total_requests']}")
print(f"Total tokens: {metrics['total_tokens']}")
print(f"Request tokens: {metrics['total_request_tokens']}")
print(f"Response tokens: {metrics['total_response_tokens']}")
```

**Available Metrics**:

* `total_requests` — Number of `agent.run()` calls
* `total_tokens` — Total tokens used (input + output)
* `total_request_tokens` — Tokens sent to LLM
* `total_response_tokens` — Tokens received from LLM

***

## 🛡️ Guardrails

Protect against prompt injection attacks:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
agent = OmniCoreAgent(
    name="protected_agent",
    system_instruction="You are a customer service agent.",
    model_config={"provider": "openai", "model": "gpt-4o"},
    agent_config={
        "guardrail_config": {
            "strict_mode": True,  # Block suspicious inputs
        },
    },
)
```

**Guardrails Detect**:

* Prompt injection attempts
* Jailbreak attempts
* System prompt extraction attempts
* Role manipulation attacks

***

## 🔧 Usage Limits

Set limits to prevent runaway request or token usage:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
agent_config={
    "request_limit": 100,        # Max requests per session
    "total_tokens_limit": 50000, # Max tokens before stopping
    "max_steps": 10,             # Max reasoning loops
}
```

***

**Previous**: [Background Agents](../background_agents) — Scheduled autonomous tasks
