AutoGen
Evaluate input before AutoGen runs and buffer output for a second decision.
Recipe: targets the AgentChat package family, not legacy pyautogen APIs. The synchronous wrapper runs in a CLI without an existing event loop. For async servers use an async evaluation boundary; do not call asyncio.run inside an active loop.
Prepare the boundary
Complete the quickstart, set NYRAXIS_API_KEY and NYRAXIS_BASE_URL, and configure an applicable policy for the docs-integration agent. Keep all credentials server-side.
python -m pip install nyraxis-sdk==1.3.2 autogen-agentchat autogen-ext[openai]Save nyraxis_gate.py beside your application. It evaluates input before calling your generator, requires a complete non-empty policy evaluation, then checks buffered output before returning it. Permission errors, incomplete checks and transport failures interrupt the operation.
Connect AutoGen
Set the provider environment variables referenced below. Save this as example.py beside nyraxis_gate.py, then run python example.py.
import asyncio
import os
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient
from nyraxis_gate import guarded_text_call
async def run_agent(prompt):
model = OpenAIChatCompletionClient(model=os.environ["OPENAI_MODEL"])
try:
agent = AssistantAgent("support", model_client=model)
result = await agent.run(task=prompt)
text = result.messages[-1].content
if not isinstance(text, str):
raise TypeError("Expected a final text message")
return text
finally:
await model.close()
def generate(prompt):
return asyncio.run(run_agent(prompt))
print(guarded_text_call("Explain how to contact support.", generate))The provider API follows its upstream documentation. Pin that provider/framework version in your application lockfile. Recipe status is distinct from a live account test; review the support matrix.
Verify this integration
Run one safe prompt, one synthetic Secrets detection input, and one case where the generated output contains the synthetic password marker. Count provider calls: input blocking should stop the generator; output blocking should prevent the buffered answer from reaching the user. Repeat with an unreachable Nyraxis API and verify that the request does not proceed.
This boundary checks complete text. It does not automatically authorize tools, inspect every internal step, or block tokens after they have been emitted. Add application permissions before side effects and separate gates for intermediate untrusted data.