Microsoft AutoGen
Protect multi-agent conversations in Microsoft AutoGen with Nyraxis enforce mode.
Setup
Install the required packages:
pip install autogen nyraxisSet your environment variables:
export NYRAXIS_API_KEY="your-api-key"
export NYRAXIS_PROJECT_ID="your-project-id"Code Example
from autogen import ConversableAgent
from nyraxis import Nyraxis
nx = Nyraxis(mode="enforce")
assistant = ConversableAgent(
name="assistant",
system_message="You are a helpful AI assistant.",
llm_config={"config_list": [{"model": "gpt-4"}]},
)
user_proxy = ConversableAgent(
name="user_proxy",
human_input_mode="NEVER",
)
# Wrap agent reply function with Nyraxis enforcement
original_generate = assistant.generate_reply
def guarded_generate(messages, sender, **kwargs):
last_message = messages[-1]["content"]
result = nx.evaluate(last_message)
if result.blocked:
return "I cannot process this request due to policy restrictions."
reply = original_generate(messages, sender, **kwargs)
nx.evaluate(reply, direction="output")
return reply
assistant.generate_reply = guarded_generate
user_proxy.initiate_chat(assistant, message="Hello, help me with a task.")What Gets Protected
- All inbound messages between agents are evaluated before processing
- All outbound agent replies are checked against your configured policies
- Blocked content is intercepted before reaching any agent in the conversation
- Works across any number of agents in a group chat configuration