AxioRank Docs
Integrations

AutoGen / AG2

Guard an AutoGen or AG2 tool function with AxioRank before registering it.

AutoGen (and the AG2 fork) turn plain Python callables into agent tools with register_function(...), deriving the tool schema from the function signature and docstring. guard_function wraps the callable first, so every execution is scored by AxioRank; the wrapper preserves the name, docstring, and signature, so AutoGen's schema generation sees the original tool.

Install

The adapter is framework-free (it never imports autogen), so the base SDK is enough and it works with both autogen and ag2 without pinning either:

pip install axiorank

Guard, then register

from autogen import register_function
from axiorank import AxioRank
from axiorank.integrations.autogen import guard_function

axio = AxioRank(api_key="axr_live_...")

def transfer_funds(account: str, amount: float) -> str:
    """Move money between accounts."""
    ...

register_function(
    guard_function(transfer_funds, axio, on_deny="return"),
    caller=assistant,
    executor=user_proxy,
    name="transfer_funds",
    description="Move money between accounts",
)

Async functions work the same way; pass async_client=AsyncAxioRank(...) instead of client.

Recover or fail

on_deny="return" returns a short, model-readable refusal that AutoGen hands back to the model as the tool result, so the conversation can adapt. The default, on_deny="raise", raises AxioRankDeniedError instead.

Next steps

On this page