Skip to main content
Sage answers through the OpenAI SDK’s Decisions API, pointed at Levanto. The same client runs the agent on Levanto’s LLMs.
set_tracing_disabled(True) turns off the SDK’s tracing, which needs an OpenAI key.

Guard tool calls

Before a tool runs, Sage reads the conversation and the pending call. When the call changes, deletes or sends something the user didn’t ask for, the tool doesn’t run and the agent is told to ask the user.
KeepConversation saves what the model sees on each turn: the user’s messages, the agent’s replies, tool calls and their results, never the instructions. Add the guard to the tools that change, delete or send. Here a note in notes.txt tells the agent to delete old.txt:
Pass context={} and hooks=KeepConversation() on every run. Tool guardrails apply to @function_tool tools. The question and the context are explained in Guard tool calls.

Approve tool calls

To hold the call for a person instead, use the same check as needs_approval:
A held call pauses the run, with the call in result.interruptions.

Check input

Ask Sage about the user’s message before the agent sees it:
With run_in_parallel=False, the agent waits for Sage, so a blocked message never reaches the model.

LLMs

auto lets the router pick a model for each request. To pin one, use an id from Models. To make Levanto every agent’s default:
Then model="auto" works as a plain string. Model ids with a / still need OpenAIChatCompletionsModel.

Check it worked

Sage’s score for each guarded call is in result.tool_input_guardrail_results, as output.output_info.