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

# OpenAI Swarm

> The Obiguard x Swarm integration brings advanced AI gateway capabilities, full-stack observability, and reliability features to build production-ready AI agents.

Swarm is an experimental framework by OpenAI for building multi-agent systems. It showcases the handoff & routines pattern, making agent coordination and execution lightweight, highly controllable, and easily testable. Obiguard integration extends Swarm's capabilities with production-ready features like observability, reliability, and more.

## Getting Started

<Steps>
  <Step title="Install the Obiguard SDK">
    ```sh theme={null}
    pip install -U obiguard
    ```
  </Step>

  <Step title="Configure the LLM Client used in OpenAI Swarm">
    To build Swarm Agents with Obiguard, you'll need either one of these keys:

    * **Obiguard API Key**: Sign up on the [Obiguard app](https://app.Obiguard.ai) and copy your API key.

    * **Virtual Key**: Virtual Keys are a secure way to manage your LLM API KEYS in one place. Instead of handling
      multiple API keys in your code, you can store your LLM provider API Keys securely in Obiguard's vault

    Create a Virtual Key in the [Obiguard app](https://app.Obiguard.ai)

    ```py theme={null}
    from swarm import Swarm, Agent
    from obiguard import Obiguard

    obiguard_client = Obiguard(
      obiguard_api_key="vk-obg***", # Your Obiguard virtual key
    )

    client = Swarm(client=obiguard_client)
    ```
  </Step>

  <Step title="Create and Run an Agent">
    In this example we are building a simple Weather Agent using OpenAI Swarm with Obiguard.

    ```py theme={null}
    def get_weather(location) -> str:
      return "{'temp':67, 'unit':'F'}"

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

    messages = [{"role": "user", "content": "What's the weather in NYC?"}]

    response = client.run(agent=agent, messages=messages)
    print(response.messages[-1]["content"])
    ```
  </Step>
</Steps>

## E2E example with Function Calling in OpenAI Swarm

Here's a complete example showing function calling and agent interaction:

```py theme={null}
from swarm import Swarm, Agent
from obiguard import Obiguard

obiguard_client = Obiguard(
    obiguard_api_key="vk-obg***",  # Your Obiguard virtual key
)

client = Swarm(client=obiguard_client)

def get_weather(location) -> str:
    return "{'temp':67, 'unit':'F'}"

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

messages = [{"role": "user", "content": "What's the weather in NYC?"}]

response = client.run(agent=agent, messages=messages)
print(response.messages[-1]["content"])
```

> The current temperature in New York City is 67°F.

## Enabling Obiguard Features

By routing your OpenAI Swarm requests through Obiguard, you get access to the following production-grade features:

<CardGroup cols="3">
  <Card title="Interoperability" href="#1-interoperability-calling-different-llms">
    <p>Call various LLMs like Anthropic, Gemini, Mistral, Azure OpenAI, Google Vertex AI, and AWS Bedrock with minimal
    code changes.</p>
  </Card>

  <Card title="Observability" href="#2-observability-understand-your-agents">
    <p>Get comprehensive logs of agent interactions, including cost, tokens used, response time, and function calls.
    Send custom metadata for better analytics.</p>
  </Card>

  <Card title="Logs" href="#3-logs-and-traces">
    <p>Access detailed logs of agent executions, function calls, and interactions. Debug and optimize your agents
    effectively.</p>
  </Card>

  <Card title="Security & Compliance" href="#4-security-%26-compliance-enterprise-ready-controls">
    <p>Implement budget limits, role-based access control, and audit trails for your agent operations.</p>
  </Card>
</CardGroup>

### 1. Interoperability - Calling Different LLMs

When building with Swarm, you might want to experiment with different LLMs or use specific providers for different agent tasks.
Obiguard makes this seamless - you can switch between OpenAI, Anthropic, Gemini, Mistral, or cloud providers without changing your agent code.

Instead of managing multiple API keys and provider-specific configurations,
Obiguard's Virtual Keys give you a single point of control. Here's how you can use different LLMs with your Swarm agents:

<Tabs>
  <Tab title="Anthropic">
    ```python theme={null}
    obiguard_client = Obiguard(
      obiguard_api_key="vk-obg***", # Your Obiguard virtual key
    )

    client = Swarm(client=obiguard_client)
    ```
  </Tab>

  <Tab title="Azure OpenAI">
    ```python theme={null}
    client = Obiguard(
      obiguard_api_key="vk-obg***", # Your Obiguard virtual key
    )

    client = Swarm(client=obiguard_client)
    ```
  </Tab>
</Tabs>

### 2. [Observability - Understand Your Agents](/product/observability)

Building agents is the first step - but how do you know they're working effectively?
Obiguard provides comprehensive visibility into your agent operations through multiple lenses:

**Metrics Dashboard**: Track 40+ key performance indicators like:

* Cost per agent interaction
* Response times and latency
* Token usage and efficiency
* Success/failure rates
* Cache hit rates

### 3. [Logs and Traces](/product/observability/logs)

Logs are essential for understanding agent behavior, diagnosing issues, and improving performance.
They provide a detailed record of agent activities and tool use, which is crucial for debugging and optimizing processes.

Access a dedicated section to view records of agent executions, including parameters, outcomes, function calls, and errors.
Filter logs based on multiple parameters such as trace ID, model, tokens used, and metadata.

### 4. [Security & Compliance - Enterprise-Ready Controls](/product/enterprise-offering/security-Obiguard)

When deploying agents in production, security is crucial. Obiguard provides enterprise-grade security features:

<CardGroup cols="2">
  <Card title="Budget Controls" icon="money-bill">
    Set and monitor spending limits per Virtual Key. Get alerts before costs exceed thresholds.
  </Card>

  <Card title="Access Management" icon="lock">
    Control who can access what. Assign roles and permissions for your team members.
  </Card>

  <Card title="Audit Logging" icon="list-check">
    Track all changes and access. Know who modified agent settings and when.
  </Card>

  <Card title="Data Privacy" icon="shield-check">
    Configure data retention and processing policies to meet your compliance needs.
  </Card>
</CardGroup>

Configure these settings in the [Obiguard Dashboard](https://app.obiguard.ai).
