Skip to content

Invariant Agent Security and Debugging

A security and debugging layer for agentic AI systems.

Invariant offers a toolchain for building and securing agentic AI systems. It supports building secure agentic AI systems from scratch, and to secure existing or deployed AI agents in an organization.

For this, the Invariant Gateway intercepts and traces the LLM calls of your agent. This enables security guardrailing and insights during development and operation, without requiring any code changes.

Getting Started as Developer

To quickly integrate your agentic application with Invariant, it is enough to rely on our hosted gateway, to automatically trace your agent's LLM calls and to unlock the Invariant eco-system.

from swarm import Swarm, Agent
from openai import OpenAI
from httpx import Client

# === Invariant integration ===
client = Swarm(
    client=OpenAI(
        # redirect and authenticate with the Invariant Gateway
        http_client=Client(headers={"Invariant-Authorization": "Bearer <your-token>"}),
        base_url="https://explorer.invariantlabs.ai/api/v1/gateway/<your-dataset-id>/openai",
    )
)

# === Agent Implementation ===

# define a tool
def get_weather():
    return "It's sunny."

# define an agent
agent = Agent(
    name="Agent A",
    instructions="You are a helpful agent.",
    functions=[get_weather],
)

# run the agent
response = client.run(
    agent=agent,
    messages=[{"role": "user", "content": "What's the weather?"}],
)

print(response.messages[-1]["content"])
# Output: "It seems to be sunny."

With this code, your agent is automatically tracked and all execution traces will be logged in a designated dataset in Explorer (screenshot here).

Overall, this integration opens up your agent system to the full Invariant family of tools, allowing you to observe and debug, write unit tests, and analyze your agent's behavior for security vulnerabilities.

This documentation describes how to get started with Invariant eco-system and how to use the different tools, to build and secure your agentic AI systems.

Getting Started as a Security Admin

Looking to observe and secure AI agents in your organization? Read our no-code quickstart guides below, for configuring different agents directly with the Invariant Gateway.

This way, you can keep track of your organization's agents, without having to change their code.

If you are interested in deploying your own dedicated instance of the Invariant Gateway, see self-hosting.

Overview

With the gateway at the core, Invariant offers a family of tools for trace analysis and testing, allowing you to secure, debug and test your AI agents.

You can use each tool independently, or in combination with each other. The following interactive figure illustrates the Invariant eco-system and how the tools fit together. You can click on any of the boxes to learn more about the respective tool.

You can click any of the boxes to learn more about the respective tool.

Next Steps