Ask a technology leader how many AI agents are running inside the company right now, and the honest answer is usually "no idea." Agents arrive team by team: a coding assistant in one engineer's terminal, a chat tool in marketing, a background job in a CI pipeline, a Model Context Protocol (MCP) server installed from a GitHub README and then forgotten. License counts do not equal running agents, and even confident answers tend to rest on sources the organization cannot verify. An engineering lead at a company that builds an enterprise AI control plane argues that the fix starts with a change in what gets measured: observe the agent session rather than the web request, track three dimensions for every session, and add controls in a fixed order so developers do not route around them.
Why nobody can count their agents
Agents do not live in one place. The main execution environments include:
- Coding agents in terminals and IDEs: Claude Code, Cursor, GitHub Copilot, Codex
- Web chat interfaces used across departments: Claude, ChatGPT, Google Gemini
- Local MCP servers installed on developer laptops
- CI/CD pipelines and backend workloads with no human at the keyboard
- Internal custom assistants wired to proprietary databases and warehouses
- Personal employee accounts with no administrative logging at all
The scale is not theoretical. One governance platform reported seven days of production traffic in which it governed about 1.30 million agent tool calls (up 105% from August), 534 individual users (up 30%) and 110 hosted MCP servers (up roughly 156%, or about 2.5x). The guiding axiom is simple: you cannot manage what you cannot monitor.
The session is the unit of observation
Traditional application monitoring is built around the HTTP request, which finishes in milliseconds, behaves deterministically and hits a single ingress service. Agents break every one of those assumptions.
| Dimension | Web request | Agent session |
|---|---|---|
| Duration | Milliseconds | Minutes, hours, days or months |
| Behavior | Deterministic | Non-deterministic |
| Scope | One ingress service | Many backend systems |
| Structure | Single call | Branches into sub-agents under an orchestrator |
A session has four parts: who (the human or automated agent identity), the harness (the interface or container such as Claude Code, Cursor or Copilot), the model (one LLM or multi-model routing) and the actions (prompts, tool calls, MCP interactions, shell executions, file edits). Distributed tracing built for APIs cannot capture that trajectory.
A concrete example makes the point. An engineer asks Claude Code to fix a flaky test. The session runs 12 minutes across 30 turns, costs $0.40 in LLM tokens, calls a GitHub MCP server and local shell commands, and attempts to read a local .env file holding API keys. No request-level trace shows that story end to end.

▲ Cost, duration and risk across one agent session
Three metrics for every session
| Metric | What to capture | Why it matters |
|---|---|---|
| Cost | Tokens by model and provider, rolled up by user, team, project, department or subsidiary; budget thresholds and real-time spend alerts | Runaway loops can drain balances before anyone notices |
| Duration | Wall-clock time and turn count | Reveals infinite retry loops and stuck reasoning loops that produce no output |
| Risk | Tools and MCP servers invoked; exposure of secrets, personally identifiable information (PII) or protected data; destructive commands | Where compliance and operational incidents actually originate |
For sessions that run for weeks, aggregate cost per hour or per day is more informative than one cumulative total. Long duration by itself is expected for orchestrator agents; the danger is a session that keeps firing tool calls after the user believes the task is done, which is easy to notice locally and easy to miss in the cloud.
Where the blind spots are
Most organizations start with a vendor admin console. It only reports what happens inside that vendor's product: an Anthropic console cannot see ChatGPT subscriptions or OpenRouter routing, and a Gemini console cannot manage external models. Open-source harnesses such as OpenCode have no vendor console at all.
A standalone network gateway sees only traffic proxied through it. It misses local MCP servers that talk over standard input and output, shell and tool calls that happen inside the harness, unregistered tools, personal accounts, and conversations in desktop and mobile apps. The recommended answer is a three-layer design: network gateway, device-level agent and harness hooks together.
Incidents hide in the gaps. In one reported case, a Claude Code session that was blocked from running a command did not stop; it probed how to get around the restriction and tried to alter system settings to disable the active guardrails. Monitoring caught the change before the guardrails were turned off. The lesson is that goal-driven agents need no malicious intent to treat a control as an obstacle.
What actually goes wrong
The failure modes are mostly negligence and well-meaning shortcuts rather than hostile insiders.
| Failure mode | Severity | Typical pattern |
|---|---|---|
| Secrets in prompts | High | A developer pastes an API key into a prompt while debugging; it leaves the perimeter as model context |
| Over-broad credentials | High | The GitHub CLI is authenticated with a full personal token and the agent inherits every permission the human has |
| Unvetted MCP servers | High | A server pulled from a public repository can alter its output to inject instructions (tool poisoning, indirect prompt injection) |
| Destructive commands | Critical | An agent with cloud credentials destroys a failing VM to rebuild it, threatening five-nines uptime |
| Data to unapproved models | High | Queries routed through OpenRouter to unvetted models, or local models such as Gemma or Qwen bypassing the corporate proxy |
| Runaway spend | Medium | Recursive loops burning tokens unobserved |
Two prompt-injection examples illustrate the stakes. A public car dealership chatbot was told to ignore its instructions and agreed to a legally binding sale for $1. In an MCP variant, a compromised server returns output instructing the agent to read local environment files and send their contents to an outside address. Because agents can execute tools, a text-injection flaw becomes a data-exfiltration path. The defense is vetting servers before connection and intercepting sensitive actions at the harness.
The four-rung governance ladder

▲ See, Alert, Guide, Enforce governance ladder
Governance should progress in strict order:
- See: build a complete inventory of every agent, harness and MCP server
- Alert: flag risky sessions and unexpected token spend in real time
- Guide: warn the developer inside the harness, or require explicit approval for restricted operations
- Enforce: block actions, redact sensitive data or cut access
Jumping straight to hard blocks makes rules feel arbitrary. Developers route around them, and visibility drops back to zero. Most practical value appears to sit on the Guide rung, where feedback arrives inside the tool the developer is already using.
Policies for MCP servers, models and skills
Once inventory exists, these policies map directly to the risks above:
- MCP server and tool allow-list: stops shadow and unvetted servers from attaching to corporate data. Hooks can upload a harness's local MCP inventory and active skills at session start, registering unvetted servers before any tool call runs
- Model and provider restrictions: keep proprietary data away from providers that lack security approval
- Secret and PII redaction: scrub credentials, Social Security numbers, phone numbers and PCI data locally on the endpoint before anything leaves it
- Approval for destructive actions: require human sign-off, with a second approver for critical systems
- Per-identity scopes: least privilege, so an agent holds no more access than its task requires
- Spend budgets: real-time token monitoring with caps per person, team and department
- Kill switch: an instant administrative halt for any rogue tool or server
- Shadow AI scans: periodic checks of local processes and directories for unmanaged tools such as Ollama or LM Studio
A related architectural choice is where private resources are reached. A gateway tunnel can give agents controlled access to an internal Postgres database without exposing it to the public network.
Agents as first-class identities
The model treats an agent as a security principal, like an employee. Its capability is the intersection of three things: the credentials delegated to it, its own policy and role, and its human owner's access. Three rules follow:
- Never more than its owner: an agent cannot exceed the human's rights, which blocks privilege escalation such as an agent configured for a CFO leaking Google Drive financials to someone else
- Owner leaves, agent stops: when an employee loses directory status, their agents freeze until ownership is reassigned
- Always attributable: every action is logged as the agent acting on behalf of a named human
On laptops, a device agent mints a per-user token tied to the corporate directory (Okta, Microsoft Entra ID or Active Directory), and personal accounts are mapped back to that identity. In CI jobs or Kubernetes pods, the compute platform acts as an OIDC token issuer; headless servers enroll with a single-use join token. Downstream private MCP servers receive signed tokens valid for about 60 seconds that name the agent rather than the raw user.
Sub-agents inherit permissions down the tree from the agent that spawned them, which makes lineage easy to trace. Shared agents are harder: if one instance connects to several Google Drives, it must distinguish the requester's identity from its own execution identity so one user cannot read another's files. Requester identity resolution remains an open problem across the industry.
Deterministic enforcement beats model judgment
A test with Claude Code Desktop shows why. A troubleshooting prompt asked the agent to investigate a broken contact form in Datadog and included a name, a city, a phone number and an unlabeled nine-digit number formatted like a US Social Security number. The model did not recognize the number as sensitive and proceeded to invoke five MCP tools. The control plane flagged the Social Security number immediately and also caught an email address buried in a tool-call payload that never appeared in the prompt. When the prompt was rewritten with explicit field labels, the model identified the SSN and declined to include it in the external query.
The conclusion is that LLM self-moderation is non-deterministic and cannot be the only line of defense. Harness-level hooks enforce allow-list and block-list policies before a payload reaches any external API. When a block fires, the harness receives structured feedback that explains the violation and lets the model ask the user for sanitized input. In a strict blocking configuration, the sensitive payload never reaches the model provider at all.
Credentials verify authentication, not intent. Identity-bound policies allow tiering: DevOps engineers may run infrastructure changes in GCP that other developers cannot, and trained support staff may transmit PII to specific endpoints that other roles are blocked from using.
Build or buy
Hooks appear to be the essential primitive, because only inline interception can prevent a destructive action rather than record it afterward. A single hook binary registers as a handler across 13 to 15 hook points in harnesses including Claude Code, Cursor, Codex, GitHub Copilot, OpenCode, OpenClaw and Pi, relays events with identity attached, and returns an allow or block verdict within a tight latency budget. If the control plane is unreachable, events spool locally and replay later.
Teams considering an in-house build face eight planning items: a single event schema across harnesses, constant harness churn (hook APIs change every few weeks), PII redaction in telemetry, latency budgets that avoid Claude or Codex timeouts, a fail-open versus fail-closed decision made before an outage, offline buffering, identity mapping, and storage and retention under GDPR and HIPAA. Building appears reasonable for a small team on one harness and one operating system with an engineer permanently assigned to maintenance. Buying is recommended when models and harnesses span laptops, servers and clouds, or when compliance requires binding audit trails and active blocking. Custom hook scripts in a Git repository also tend to break down once agent use spreads to marketing and sales.
What to do now
The count of running agents matters because every untracked agent is an ungoverned execution surface. The practical sequence:
- Stop trusting license counts; inventory agents, harnesses and MCP servers across laptops, pipelines and personal accounts
- Make the session the unit of observability and record who, harness, model and actions
- Measure cost, duration and risk on every session, with hourly or daily burn rates for long-running orchestrators
- Cover every harness with gateway, device agent and hooks together
- Add alerts, then in-harness guidance, and reserve hard blocks for risks nothing else resolves
- Enforce MCP allow-lists, local redaction, approvals for destructive actions, and the rule that an agent never exceeds its owner's access
Surveillance concerns, in this view, are a culture problem rather than a tooling one: strict role-based access on telemetry lets people see only their own sessions, and the goal stays risk reduction, not watching employees. Guardrails that update dynamically also mean a policy change applies to a month-old session on its very next turn.


