Dev48
Language
  • About
  • Services
  • Industries
  • Technologies
  • Articles
  • Contacts
Book a call
    Home/Articles/A semantic gate asks one question before an ai agent acts
Dev48
info@dev48.org+375 29 320-40-96WhatsApp@isky_by

© 2026 · All rights reserved.

A Semantic Gate Asks One Question Before an AI Agent Acts

Source: Signalwire•December 3, 2026 at 08:14 PM

A Semantic Gate Asks One Question Before an AI Agent Acts

A decision model checks what the caller meant before a SignalWire AI agent runs a function

Article

Dec 3, 2026

read

A decision model checks what the caller meant before a SignalWire AI agent runs a function

Anthony Minessale

CEO

Build it free.

Create a space and ship your first call flow in minutes.

Voice AI

AI Agents

Developer Tutorials

A caller on a phone carrier's support line says, "I'm thinking about cancelling. What would that cost me?" The model hears "cancel" and calls cancel_plan. On this SignalWire agent, that function carries a semantic gate. Before anything reaches the cancellation code, a separate decision model answers the developer's question: has the caller explicitly asked to cancel their plan? The answer falls well short of the threshold. The plan stays active, and the model is told to ask whether the caller wants to cancel or only wants to hear the cost.

A semantic gate is a yes or no question attached to a function, answered right before the platform runs it. The decision model reads the recent conversation, the application's own record of the call, and the exact call the model proposed. The function runs when the answer clears the developer's threshold. Otherwise nothing is dispatched, and the model receives the developer's on_fail output as an ordinary tool result.

Gates are written in SWML, or with SemanticGate in the Python and TypeScript server SDKs. The support line's code runs on the Python SDK, signalwire-sdk 3.18.0.

Where a gate fits in System-Directed AI

SignalWire agents run on System-Directed AI. At each step, the model knows only what that step tells it and sees only that step's tools. Handlers in the developer's code check the real account before anything changes. The model requests an action, and the platform decides what runs.

Those layers settle which functions exist at a given moment and what is true in the application's systems. A gate adds a question about meaning: did the caller ask, and did they agree to that amount? Steps decide which doors exist, gates ask a question at the door, and handlers check what is true behind it.

The model never sees the gate or its score. When a gate stops a function, the model gets a result written by the developer, the same way any function returns one.

What the decision model reads

Each check sends the decision model a snapshot of the call, taken when the check starts. A question refers to each part by its name:

Name

What it holds

conversation

The most recent part of the call, oldest first, 20 entries by default. It includes what the agent was told to say, such as say actions and, on standard agents, fillers. An agent reply the caller cut off is marked interrupted.

semantic_state

Whatever the application stored in global_data.semantic_state. Nothing else from global_data is sent.

proposed_function

The function's name and description, and the arguments exactly as they would be dispatched.

visual_input

On a video call, the caller's newest frames, for a gate that asks for them.

Each gate has a threshold above 0 and at most 1, and passes when the probability of yes is at or above it. A function runs only when every one of its gates passes.

Each check also has a time budget, 2.5 seconds by default. A check that cannot finish, because it ran out of time or the decision model failed, does not run the function either. The model is never told that the action happened.

Defining a gate in Python or SignalWire Markup Language (SWML)

In the Python SDK, a gate is a SemanticGate passed to define_tool(). This one guards the support line's cancellation:

The question names its input, conversation, in backticks, the way the decision model sees it. true_means and false_means spell out the near miss: a caller who asks about cancelling has not asked to cancel. The 0.95 threshold suits an action that is hard to undo.

on_fail becomes the function's result. tool_result states what happened, tool_prompt adds an instruction, and the model writes its own reply to the caller from both. gate_fillers is what the caller hears while the check runs.

The SDK checks every gate by the platform's rules when the tool is defined. A gate the platform would refuse raises ValueError in the developer's code instead of reaching a call. The platform drops any function with an invalid gate, so a gated function can never run without its gates.

The same gate in SWML sits on the function in SWAIG.functions:

A gate can check the arguments or the application's record

A gate's question can be about the call the model is making. On a refund, the model proposes an amount, and the gate asks whether the caller agreed to it:

When a caller has said "Twenty is fine" and the model calls refund_charge with 200, the decision model sees both. proposed_function holds 200 while conversation holds twenty, so the answer is no and no refund is issued.

A question can also be about what the application recorded. A caller can say "I already confirmed it," and the decision model has no way to check that claim. A gate that asks about semantic_state judges what the application itself established instead. The same holds for arithmetic and dates. The application works out the answer, stores it in semantic_state, and the gate asks about the stored result.

Confirming a change uses the SDK's Proposal pattern

The hardest gate to write is the one that waits for a yes. A caller's "yes" might answer an earlier question, arrive before the read-back finished, or be an "uh-huh" said while the agent was still talking. A decision model asked to find consent anywhere in a long call has far more to weigh than one asked about a single read-back.

The Python SDK's Proposal pattern narrows it. One function proposes the change: it records the change in semantic_state, reads it back word for word, and waits for the caller. The function that makes the change carries the gates from confirm_gates(), judged only on what was said since the proposal:

confirm_gates() returns three gates, asked together in one check:

  • answered: the caller's latest turn is an answer, and not a listening sound made over the read-back.

answered: the caller's latest turn is an answer, and not a listening sound made over the read-back.

  • agreed: that answer is a yes to this change.

agreed: that answer is a yes to this change.

  • read_back: what the caller answered was a read-back of this change.

read_back: what the caller answered was a read-back of this change.

The questions are the platform's own, replayed against logged confirmation checks.

change_plan takes no arguments. It reads the new plan from semantic_state, the record of what was read back, so the model cannot swap in a different plan. After the change, complete() records what was done, and a later proposal is judged on its own read-back.

When a gate stops change_plan, the model is told why and answers the caller in words before it calls another tool. Two of the gates quote the proposal from semantic_state in what the model is told. The SDK's guide gives the confirmation its own step. That step's only tools are the confirm tool, the decline tool and a tool that notes other requests. "Yes, and can you add a line for my daughter?" then becomes two calls.

Proposal(..., unclear=True, threshold=0.6) lets the gates answer unclear as well as yes or no. An unclear answer asks the caller again, up to twice in a row for the same proposal, and a third counts as a no.

On a video call, a gate can look at the camera

A gate with visual_input also sees the caller's newest video frames. On the support line, a caller verifies on camera:

The gate checks that an ID is on camera, and checking the ID against the account stays in the handler. Passing visual_input=1 to define_tool() for verify_identity sends the handler the frame the gate judged, never a newer one. When the call has no video frame to show, the gate fails without being asked. Frames are taken at most one per second, none older than eight seconds, and go to the decision model as part of the check.

What the caller hears while a gate is checked

A gated function's wait_file plays only after its gates pass. By default, the function's own fillers start as soon as the model calls it, while the check runs. A filler that announces the action, such as "OK, cancelling your plan now," is then heard even when the gate says no. On standard agents it also lands in the conversation the gate reads.

Two settings prevent that. A neutral gate_fillers phrase such as "Let me check that." covers the check, and fillers_at_gates=False holds a function's own fillers until after a pass.

Every check lands in the call record

Each checked function call carries a semantic_gates entry in its record, delivered with the post-prompt data and the calling.ai.swaig event. For the cancellation question at the top, a fail looks like this:

outcome is pass, fail or unclear, or names an error such as timeout, and dispatched says whether the function ran. Each gate's confidence sits beside its threshold, so thresholds can be tuned on real calls. The post-prompt data also carries a tally of every check in the call.

As starting points, the platform guide recommends 0.9 or above for actions that are hard to undo. The confirm gates use 0.8, or about 0.6 when they can answer unclear.

Questions a decision model can answer well

The decision model reads each question literally and answers only it, so the wording does most of the work:

  • A good question asks one thing. "Did the caller confirm the order and the address?" works better as two gates.

A good question asks one thing. "Did the caller confirm the order and the address?" works better as two gates.

  • A question names its input in backticks: conversation, semantic_state, proposed_function or visual_input.

A question names its input in backticks: conversation, semantic_state, proposed_function or visual_input.

  • criteria say what counts as yes and as no, which matters most for near misses.

criteria say what counts as yes and as no, which matters most for near misses.

  • Calculations and date comparisons happen in the application, which stores the result in semantic_state.

Calculations and date comparisons happen in the application, which stores the result in semantic_state.

  • A question about the application's record holds up when a caller insists something is already done.

A question about the application's record holds up when a caller insists something is already done.

Documentation and the SDK

Semantic gates need signalwire-sdk 3.6.0 or later, gates on video 3.7.1, and the confirm pattern 3.8.0. The current release is 3.18.0.

  • Semantic gates guide: gating a function end to end, in SWML and both server SDKs.

Semantic gates guide: gating a function end to end, in SWML and both server SDKs.

  • SemanticGatereference for Python: every argument and its SWML key.

SemanticGatereference for Python: every argument and its SWML key.

  • Gates in the SWML reference: the keys a gated function accepts.

Gates in the SWML reference: the keys a gated function accepts.

  • Conversation patterns: the confirm pattern, read-backs callers can interrupt, and testing a call flow without a live call.

Conversation patterns: the confirm pattern, read-backs callers can interrupt, and testing a call flow without a live call.

← All articles

What this article says

More in Telecom & Networks

All →
SES Board Nominates Dick Schoof for Election at 2027 Annual General Meeting
SES

SES Board Nominates Dick Schoof for Election at 2027 Annual General Meeting

Rakuten Site Manager: AI-powered site management for “first-time right” infrastructure deployment
Rakuten Symphony

Rakuten Site Manager: AI-powered site management for “first-time right” infrastructure deployment

AI is changing the speed of cybersecurity. The fundamentals matter more than ever
Ericsson

AI is changing the speed of cybersecurity. The fundamentals matter more than ever

How wireless connectivity creates seamless mobile experiences
Infinera

How wireless connectivity creates seamless mobile experiences

Nokia AI-RAN boosts Elisa's uplink by 13% in live 5G network
Infinera

Nokia AI-RAN boosts Elisa's uplink by 13% in live 5G network

Why AI in financial services needs advanced optical and IP connectivity
Infinera

Why AI in financial services needs advanced optical and IP connectivity

More from Signalwire

Introducing PGI Realtime, the Voice Model That Comes Connected
Signalwire

Introducing PGI Realtime, the Voice Model That Comes Connected

Introducing the SignalWire MCP Server
Signalwire

Introducing the SignalWire MCP Server

Write Server-Side Tools for a SignalWire AI Agent
Signalwire

Write Server-Side Tools for a SignalWire AI Agent

Give a Voice AI Agent a Personality and Modes
Signalwire

Give a Voice AI Agent a Personality and Modes

Prompt Injection on the Phone: How to Secure Voice AI Agents
Signalwire

Prompt Injection on the Phone: How to Secure Voice AI Agents

Build a Talking Jack-o'-Lantern with a SignalWire AI Agent
Signalwire

Build a Talking Jack-o'-Lantern with a SignalWire AI Agent