> ## 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.

# CrewAI

> Use Obiguard with CrewAI to take your AI Agents to production

## Introduction

CrewAI is a framework for orchestrating role-playing, autonomous AI agents designed to solve complex, open-ended tasks through collaboration. It provides a robust structure for agents to work together, leverage tools, and exchange insights to accomplish sophisticated objectives.

Obiguard enhances CrewAI with production-readiness features, turning your experimental agent crews into robust systems by providing:

* **Complete observability** of every agent step, tool use, and interaction
* **Built-in reliability** with fallbacks, retries, and load balancing
* **Cost tracking and optimization** to manage your AI spend
* **Access to 200+ LLMs** through a single integration
* **Guardrails** to keep agent behavior safe and compliant
* **Version-controlled prompts** for consistent agent performance

<Card title="CrewAI Official Documentation" icon="arrow-up-right-from-square" href="https://docs.crewai.com/">
  Learn more about CrewAI's core concepts and features
</Card>

### Installation & Setup

<Steps>
  <Step title="Install the required packages">
    ```bash theme={null}
    pip install -U crewai obiguard
    ```
  </Step>

  <Step title="Generate API Key" icon="lock">
    Create a Obiguard API key with optional budget/rate limits from the [Obiguard dashboard](https://app.obiguard.ai/).
    You can also attach configurations for reliability, caching, and more to this key. More on this later.
  </Step>

  <Step title="Configure CrewAI with Obiguard">
    The integration is simple - you just need to update the LLM configuration in your CrewAI setup:

    ```python theme={null}
    from crewai import LLM
    from obiguard import OBIGUARD_GATEWAY_URL, createHeaders

    # Create an LLM instance with Obiguard integration
    gpt_llm = LLM(
      model="gpt-4o",
      base_url=OBIGUARD_GATEWAY_URL,
      api_key="dummy", # We are using a Virtual key, so this is a placeholder
      extra_headers=obiguard.copy_headers()
    )

    #Use them in your Crew Agents like this:

    @agent
    def lead_market_analyst(self) -> Agent:
      return Agent(
        config=self.agents_config['lead_market_analyst'],
        verbose=True,
        memory=False,
        llm=gpt_llm
      )

    ```

    <Info>
      **What are Virtual Keys?** Virtual keys in Obiguard securely store your LLM provider API keys (OpenAI, Anthropic,
      etc.) in an encrypted vault.
      They allow for easier key rotation and budget management. [Learn more about virtual keys here](/virtual-keys).
    </Info>
  </Step>
</Steps>

## Production Features

### 1. Enhanced Observability

Obiguard provides comprehensive observability for your CrewAI agents, helping you understand exactly what's happening during each execution.

<Tabs>
  <Tab title="Traces">
    Traces provide a hierarchical view of your crew's execution, showing the sequence of LLM calls, tool invocations,
    and state transitions.
  </Tab>

  <Tab title="Logs">
    Obiguard logs every interaction with LLMs, including:

    * Complete request and response payloads
    * Latency and token usage metrics
    * Cost calculations
    * Tool calls and function executions

    All logs can be filtered by metadata, trace IDs, models, and more, making it easy to debug specific crew runs.
  </Tab>

  <Tab title="Metrics & Dashboards">
    Obiguard provides built-in dashboards that help you:

    * Track cost and token usage across all crew runs
    * Analyze performance metrics like latency and success rates
    * Identify bottlenecks in your agent workflows
    * Compare different crew configurations and LLMs
  </Tab>
</Tabs>

### 2. Model Interoperability

CrewAI supports multiple LLM providers, and Obiguard extends this capability by providing access to over 200 LLMs through a unified interface.
You can easily switch between different models without changing your core agent logic:

```python theme={null}
from crewai import Agent, LLM
from obiguard import OBIGUARD_GATEWAY_URL, createHeaders

# Set up LLMs with different providers
openai_llm = LLM(
    model="gpt-4o",
    base_url=OBIGUARD_GATEWAY_URL,
    api_key="dummy",
    extra_headers=createHeaders(
        obiguard_api_key="vk-obg***",  # Your Obiguard virtual key
    )
)

anthropic_llm = LLM(
    model="claude-3-5-sonnet-latest",
    max_tokens=1000,
    base_url=OBIGUARD_GATEWAY_URL,
    api_key="dummy",
    extra_headers=createHeaders(
        obiguard_api_key="vk-obg***",  # Your Obiguard virtual key
    )
)

# Choose which LLM to use for each agent based on your needs
researcher = Agent(
    role="Senior Research Scientist",
    goal="Discover groundbreaking insights about the assigned topic",
    backstory="You are an expert researcher with deep domain knowledge.",
    verbose=True,
    llm=openai_llm  # Use anthropic_llm for Anthropic
)
```

Obiguard provides access to LLMs from providers including:

* OpenAI (GPT-4o, GPT-4 Turbo, etc.)
* Anthropic (Claude 3.5 Sonnet, Claude 3 Opus, etc.)
* Mistral AI (Mistral Large, Mistral Medium, etc.)
* Google Vertex AI (Gemini 1.5 Pro, etc.)
* Cohere (Command, Command-R, etc.)
* AWS Bedrock (Claude, Titan, etc.)
* Local/Private Models

<Card title="Supported Providers" icon="server" href="/integrations/llms">
  See the full list of LLM providers supported by Obiguard.
</Card>

## Set Up Enterprise Governance for CrewAI

**Why Enterprise Governance?**

If you are using CrewAI inside your organization, you need to consider several governance aspects:

* **Cost Management**: Controlling and tracking AI spending across teams
* **Access Control**: Managing which teams can use specific models
* **Usage Analytics**: Understanding how AI is being used across the organization
* **Security & Compliance**: Maintaining enterprise security standards
* **Reliability**: Ensuring consistent service across all users

Obiguard adds a comprehensive governance layer to address these enterprise needs. Let's implement these controls step by step.

<Steps>
  <Step title="Create guardrail policy">
    You can choose to create a guardrail policy to protect your data and ensure compliance with organizational policies.
    Add guardrail validators on your LLM inputs and output to govern your LLM usage.
  </Step>

  <Step title="Create Virtual Key">
    Virtual Keys are Obiguard's secure way to manage your LLM provider API keys.
    Think of them like disposable credit cards for your LLM API keys.

    To create a virtual key:
    Go to [Virtual Keys](/virtual-keys) in the Obiguard dashboard. Select the guardrail policy and your LLM provider.
    Save and copy the virtual key ID

    <Note>
      Save your virtual key ID - you'll need it for the next step.
    </Note>
  </Step>

  <Step title="Connect to CrewAI">
    After setting up your Obiguard API key with the attached config, connect it to your CrewAI agents:

    ```python theme={null}
    from crewai import Agent, LLM
    from obiguard import OBIGUARD_GATEWAY_URL, createHeaders

    # Configure LLM with your API key
    obiguard_llm = LLM(
      model="gpt-4o",
      base_url=OBIGUARD_GATEWAY_URL,
      api_key="YOUR_Obiguard_API_KEY"
    )

    # Create agent with Obiguard-enabled LLM
    researcher = Agent(
      role="Senior Research Scientist",
      goal="Discover groundbreaking insights about the assigned topic",
      backstory="You are an expert researcher with deep domain knowledge.",
      verbose=True,
      llm=obiguard_llm
    )
    ```
  </Step>
</Steps>

<Note>
  ### Enterprise Features Now Available

  **Your CrewAI integration now has:**

  * Departmental budget controls
  * Model access governance
  * Usage tracking & attribution
  * Security guardrails
  * Reliability features
</Note>

## Frequently Asked Questions

<AccordionGroup>
  <Accordion title="How does Obiguard enhance CrewAI?">
    Obiguard adds production-readiness to CrewAI through comprehensive observability (traces, logs, metrics),
    reliability features (fallbacks, retries, caching), and access to 200+ LLMs through a unified interface. This makes
    it easier to debug, optimize, and scale your agent applications.
  </Accordion>

  <Accordion title="Can I use Obiguard with existing CrewAI applications?">
    Yes! Obiguard integrates seamlessly with existing CrewAI applications. You just need to update your LLM
    configuration code with the Obiguard-enabled version. The rest of your agent and crew code remains unchanged.
  </Accordion>

  <Accordion title="Does Obiguard work with all CrewAI features?">
    Obiguard supports all CrewAI features, including agents, tools, human-in-the-loop workflows, and all task process
    types (sequential, hierarchical, etc.). It adds observability and reliability without limiting any of the
    framework's functionality.
  </Accordion>

  <Accordion title="Can I use my own API keys with Obiguard?">
    Yes! Obiguard uses your own API keys for the various LLM providers.
    It securely stores them as virtual keys, allowing you to easily manage and rotate keys without changing your code.
  </Accordion>
</AccordionGroup>

## Resources

<CardGroup cols="3">
  <Card title="CrewAI Docs" icon="book" href="https://docs.crewai.com/">
    <p>Official CrewAI documentation</p>
  </Card>
</CardGroup>
