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

# AutoGen Integration

> Protect multi-agent AutoGen conversations with RAXE

<Info>New to RAXE? Start with the [Quickstart](/quickstart) and learn [how detection works](/concepts/detection-engine).</Info>

## Overview

RAXE provides `RaxeConversationGuard` for automatic security scanning of AutoGen multi-agent conversations. The integration uses AutoGen's hook system to intercept messages without modifying your agent code.

## Installation

```bash theme={null}
pip install raxe[autogen]
```

## Quick Start

```python theme={null}
from autogen import AssistantAgent, UserProxyAgent
from raxe import Raxe
from raxe import RaxeConversationGuard

# Create RAXE client
raxe = Raxe()

# Create conversation guard (default: log-only mode)
guard = RaxeConversationGuard(raxe)

# Create AutoGen agents
llm_config = {"model": "gpt-4", "api_key": "..."}
assistant = AssistantAgent("assistant", llm_config=llm_config)
user = UserProxyAgent("user", code_execution_config={"use_docker": False})

# Register agents with guard
guard.register(assistant)
guard.register(user)

# Start conversation - all messages are automatically scanned
user.initiate_chat(assistant, message="Hello! How are you?")
```

## Configuration

```python theme={null}
from raxe import AgentScannerConfig

# Block on HIGH or CRITICAL threats
config = AgentScannerConfig(
    on_threat="block",  # "log" (default) or "block"
    block_severity_threshold="HIGH",  # "LOW", "MEDIUM", "HIGH", "CRITICAL"
    scan_prompts=True,
    scan_tool_calls=True,
    scan_tool_results=False,  # Disable tool result scanning for performance
)

guard = RaxeConversationGuard(raxe, config=config)
```

## Multi-Agent Scenarios

### Register Multiple Agents

```python theme={null}
# Create agents
researcher = AssistantAgent("researcher", llm_config=llm_config)
writer = AssistantAgent("writer", llm_config=llm_config)
critic = AssistantAgent("critic", llm_config=llm_config)
user = UserProxyAgent("user")

# Register all at once
guard.register_all(researcher, writer, critic, user)
```

### GroupChat

```python theme={null}
from autogen import GroupChat, GroupChatManager

# Create and register agents
agents = [researcher, writer, critic]
for agent in agents:
    guard.register(agent)

# Create group chat
groupchat = GroupChat(agents=agents, messages=[], max_round=10)
manager = GroupChatManager(groupchat=groupchat, llm_config=llm_config)

# Register manager too
guard.register(manager)

# Start protected chat
user.initiate_chat(manager, message="Research AI safety")
```

## Error Handling

```python theme={null}
from raxe import RaxeBlockedError

try:
    user.initiate_chat(assistant, message=user_input)
except RaxeBlockedError as e:
    print("Message blocked for security reasons")
```

## Callbacks

```python theme={null}
def on_threat_detected(result):
    print(f"Threat detected: {result.severity}")

config = AgentScannerConfig(
    on_threat="block",
    on_threat_callback=on_threat_detected,
)
```

## Best Practices

<AccordionGroup>
  <Accordion title="Start with log-only mode">
    Monitor threats before enabling blocking:

    ```python theme={null}
    # Default: log-only
    guard = RaxeConversationGuard(raxe)
    ```
  </Accordion>

  <Accordion title="Register all conversation participants">
    Ensure all agents are protected:

    ```python theme={null}
    guard.register_all(assistant, user, manager)
    ```
  </Accordion>

  <Accordion title="Handle blocking gracefully">
    Catch exceptions for user-friendly responses:

    ```python theme={null}
    from raxe import RaxeBlockedError

    try:
        user.initiate_chat(assistant, message=user_input)
    except RaxeBlockedError:
        print("Request blocked for security reasons")
    ```
  </Accordion>
</AccordionGroup>

## AutoGen v0.4+ (Wrapper-based)

For AutoGen v0.4+ which uses the async message-based API, use `wrap_agent()`:

```python theme={null}
from autogen_agentchat.agents import AssistantAgent
from raxe import Raxe
from raxe import RaxeConversationGuard

# Create RAXE guard
raxe = Raxe()
guard = RaxeConversationGuard(raxe)

# Create agent and wrap with RAXE
assistant = AssistantAgent("assistant", model_client=client)
protected = guard.wrap_agent(assistant)

# Use protected agent - messages will be scanned
```

## Supported Versions

| AutoGen Version           | API Style                      | Status     |
| ------------------------- | ------------------------------ | ---------- |
| pyautogen 0.2.x           | Hook-based (`register()`)      | Supported  |
| autogen-agentchat \~= 0.2 | Hook-based (`register()`)      | Supported  |
| autogen-agentchat 0.4.x+  | Wrapper-based (`wrap_agent()`) | Supported  |
| AG2 (fork)                | Hook-based                     | Compatible |

## What's Next

<CardGroup cols={2}>
  <Card title="Production Checklist" icon="list-check" href="/guides/production-checklist">
    Deploy RAXE safely to production
  </Card>

  <Card title="Custom Rules" icon="pencil" href="/rules/custom-rules">
    Create detection rules for your specific use case
  </Card>
</CardGroup>
