Agent Operations: Build, Evaluate, and Monitor AI Agents
This skill covers the agent lifecycle beyond basic tracing: architecture patterns, evaluation, metrics, and production monitoring. All examples use Opik for observability — for SDK details (tracing, integrations, span types), load the opik skill.
The Agent Lifecycle
- Instrument — Add Opik tracing to make your agent's behavior visible (see
opik skill)
- Evaluate — Measure performance with datasets, metrics, and experiments
- Monitor — Track quality, cost, and reliability in production
- Optimize — Improve based on data from evaluation and production traces
Agent Architecture Patterns
Trace every component of your agent with appropriate span types:
import opik
@opik.track(name="research_agent")
def agent(query: str) -> str:
plan = plan_action(query) # general span
results = execute_tool(plan) # tool span
return generate_response(results) # llm span
@opik.track(type="tool")
def execute_tool(action: dict) -> str:
return search_web(action["query"])
@opik.track(type="llm")
def generate_response(context: str) -> str:
return llm_call(context)
What to Trace
| Component |
Span Type |
Key Data |
| Planning |
general |
Reasoning steps, decisions |
| Tool calls |
tool |
Tool name, parameters, results |
| LLM calls |
llm |
Prompt, response, tokens |
| Retrieval |
tool |
Query, documents |
| Validation |
guardrail |
Check results, pass/fail |
Evaluation
Evaluate agents at multiple levels — end-to-end and per-component:
from opik.evaluation import evaluate
from opik.evaluation.metrics import AnswerRelevance, Hallucination, AgentTaskCompletion
results = evaluate(
experiment_name="agent-v2",
dataset=dataset,
task=lambda item: {"output": agent(item["input"])},
scoring_metrics=[
AnswerRelevance(),
Hallucination(),
AgentTaskCompletion(),
]
)
Built-in Agent Metrics
| Metric |
What It Measures |
AgentTaskCompletion |
Did the agent fulfill its task? |
AgentToolCorrectness |
Were tools used correctly? |
TrajectoryAccuracy |
Did actions match expected sequence? |
AnswerRelevance |
Does the answer address the question? |
Hallucination |
Are there unsupported claims? |
41 Total Built-in Metrics
Heuristic (Equals, Contains, BLEU, ROUGE, BERTScore, IsJson, etc.), LLM-as-Judge (AnswerRelevance, Hallucination, Usefulness, GEval, etc.), RAG (ContextPrecision, ContextRecall, Faithfulness), and conversation metrics. See references/evaluation.md for the full list.
Production Monitoring
- Dashboards — Visualize quality, cost, latency, and error trends
- Online evaluation — Automatically score production traces with LLM-as-Judge
- Alerts — Get notified when metrics deviate (quality drops, cost spikes, error rates)
- Guardrails — PII detection, topic validation, custom safety checks
- Opik Assist — AI-powered root cause analysis for failed traces
Common Anti-Patterns
| Category |
Anti-Pattern |
| Reliability |
Unbounded loops, retry storms, silent failures |
| Security |
Prompt injection, privilege escalation, data leakage |
| Observability |
Late tracing (missing input), orphaned spans |
| Tools |
Tool loops, hallucinated tools, parameter errors |
Detailed References
| Topic |
Reference File |
| Agent architecture, reliability, security patterns |
references/agent-patterns.md |
| Evaluation datasets, experiments, all 41 metrics |
references/evaluation.md |
| Production dashboards, alerts, guardrails, cost tracking |
references/production.md |
1---2name: agent-ops3description: This skill should be used when the user asks about agent architecture, evaluation, metrics, production monitoring, debugging agents, or best practices for building reliable AI agents. Use for questions like "evaluate my agent", "set up production monitoring", "add guardrails", "detect hallucinations", "agent anti-patterns", "compare experiments", "create evaluation dataset".4---56# Agent Operations: Build, Evaluate, and Monitor AI Agents78This skill covers the agent lifecycle beyond basic tracing: architecture patterns, evaluation, metrics, and production monitoring. All examples use Opik for observability — for SDK details (tracing, integrations, span types), load the `opik` skill.910## The Agent Lifecycle11121. **Instrument** — Add Opik tracing to make your agent's behavior visible (see `opik` skill)132. **Evaluate** — Measure performance with datasets, metrics, and experiments143. **Monitor** — Track quality, cost, and reliability in production154. **Optimize** — Improve based on data from evaluation and production traces1617## Agent Architecture Patterns1819Trace every component of your agent with appropriate span types:2021```python22import opik2324@opik.track(name="research_agent")25def agent(query: str) -> str:26 plan = plan_action(query) # general span27 results = execute_tool(plan) # tool span28 return generate_response(results) # llm span2930@opik.track(type="tool")31def execute_tool(action: dict) -> str:32 return search_web(action["query"])3334@opik.track(type="llm")35def generate_response(context: str) -> str:36 return llm_call(context)37```3839### What to Trace4041| Component | Span Type | Key Data |42|-----------|-----------|----------|43| Planning | `general` | Reasoning steps, decisions |44| Tool calls | `tool` | Tool name, parameters, results |45| LLM calls | `llm` | Prompt, response, tokens |46| Retrieval | `tool` | Query, documents |47| Validation | `guardrail` | Check results, pass/fail |4849## Evaluation5051Evaluate agents at multiple levels — end-to-end and per-component:5253```python54from opik.evaluation import evaluate55from opik.evaluation.metrics import AnswerRelevance, Hallucination, AgentTaskCompletion5657results = evaluate(58 experiment_name="agent-v2",59 dataset=dataset,60 task=lambda item: {"output": agent(item["input"])},61 scoring_metrics=[62 AnswerRelevance(),63 Hallucination(),64 AgentTaskCompletion(),65 ]66)67```6869### Built-in Agent Metrics7071| Metric | What It Measures |72|--------|-----------------|73| `AgentTaskCompletion` | Did the agent fulfill its task? |74| `AgentToolCorrectness` | Were tools used correctly? |75| `TrajectoryAccuracy` | Did actions match expected sequence? |76| `AnswerRelevance` | Does the answer address the question? |77| `Hallucination` | Are there unsupported claims? |7879### 41 Total Built-in Metrics8081Heuristic (Equals, Contains, BLEU, ROUGE, BERTScore, IsJson, etc.), LLM-as-Judge (AnswerRelevance, Hallucination, Usefulness, GEval, etc.), RAG (ContextPrecision, ContextRecall, Faithfulness), and conversation metrics. See `references/evaluation.md` for the full list.8283## Production Monitoring8485- **Dashboards** — Visualize quality, cost, latency, and error trends86- **Online evaluation** — Automatically score production traces with LLM-as-Judge87- **Alerts** — Get notified when metrics deviate (quality drops, cost spikes, error rates)88- **Guardrails** — PII detection, topic validation, custom safety checks89- **Opik Assist** — AI-powered root cause analysis for failed traces9091## Common Anti-Patterns9293| Category | Anti-Pattern |94|----------|-------------|95| Reliability | Unbounded loops, retry storms, silent failures |96| Security | Prompt injection, privilege escalation, data leakage |97| Observability | Late tracing (missing input), orphaned spans |98| Tools | Tool loops, hallucinated tools, parameter errors |99100## Detailed References101102| Topic | Reference File |103|-------|----------------|104| Agent architecture, reliability, security patterns | `references/agent-patterns.md` |105| Evaluation datasets, experiments, all 41 metrics | `references/evaluation.md` |106| Production dashboards, alerts, guardrails, cost tracking | `references/production.md` |