We flip an LLM into an agent by giving it instruments.
Instruments let the agent look issues up, name APIs, and take motion. You already know the drill: the agent causes; the instruments execute.
Often, we design every device to deal with a small operation.
When going through a bigger activity, the agent often must work issues out in a loop: it first calls one device, primarily based on the outcome, the agent decides what to do subsequent, perhaps name one other device.
However right here is the factor: lots of these intermediate selections aren’t that onerous. Oftentimes, the agent is simply choosing the apparent subsequent step primarily based on what the final device returned. It nonetheless has to make that decision itself, although, and every of these spherical journeys is one other LLM name, including time and price to the duty.
So what if we might hand over an entire piece of labor by means of a single device name?
With a choice mannequin, sure, that is potential! And right here is how.
Primarily, we let the choice mannequin drive the circulation: contained in the device, it picks an motion and appears at what comes again. Primarily based on the outcomes, it determines the subsequent transfer. This loop goes on till it has sufficient proof handy again to the agent.
As a result of choice fashions are skilled to make quick selections cheaply, the routine steps can now be dealt with with a fraction of the time and price. The agent actually solely makes one device name, and it may well focus its reasoning on the place it issues.
Right here’s the brand new drill: the agent delegates the work; the device manages the steps.
Because the choice mannequin is embedded in a device the agent calls, we name it the decision-model-as-a-tool sample.
On this put up, we’ll make this sample concrete. We’ll take into account a case research of constructing a customer-support agent that investigates a delayed order and finds a technique to meet the client’s supply deadline. We’ll give the agent an order-specialist device with a choice mannequin inside.
Is shifting these selections into the device value it? Let’s discover out.
If you wish to study extra about patterns for LLM-decision-model collaboration, be at liberty to test my earlier put up: Choice Fashions in Motion: Construct a Hybrid LLM Workflow
···
1. The Agent We Need to Construct
Say a buyer sends our agent this request:
My order ORD-1042 nonetheless hasn’t shipped, and I want it by Friday, October 23. Might you discover out what’s occurring and whether or not there’s a technique to get it right here in time?
There are two issues to determine: why the order is delayed, and if one other achievement possibility might meet the deadline. The agent ought to examine and suggest subsequent steps.
1.1 What can the agent search for?
For our case research, we’ll use six Python features that signify operations the assist agent might need entry to:
-
get_order_details(): It gives order standing, merchandise, vacation spot, warehouse, and monitoring identifiers; -
get_tracking_events(): accommodates service occasions and any supply estimate; -
get_fulfillment_notes(): warehouse notes that will clarify the delay; -
get_alternative_inventory(): inventory availability for a similar merchandise at different warehouses; -
get_shipping_options(): supply estimates, extra costs, and dispatch cutoffs; -
get_fulfillment_policy(): guidelines for rerouting an order and waiving delivery surcharges.
These features solely retrieve info from a small, artificial dataset I curated.
Now, if we have been constructing a traditional agent, what would we do?
We’d expose all six features as instruments, proper? That may definitely work.
However does the agent have to handle each step of the investigation?
1.2 What if we gave the agent one device as a substitute?
Let’s first have a look at what a typical investigation entails.
For a delayed order, the agent would possibly go like this: test the order → learn the warehouse notes → search for inventory elsewhere → evaluate delivery choices → test the rerouting coverage. One other order might take a distinct path.
However look carefully at what occurs between the lookups. Every time, the agent solutions the identical kind of query:
Given the query and the proof to date, which lookup ought to come subsequent, or is that sufficient?
So the investigation is known as a sequence of selections. Each picks an possibility from the out there ones primarily based on what has been realized to date.
That’s precisely what a choice mannequin is constructed for: it takes some context, then picks one of many choices.
And if a choice mannequin could make these decisions, the agent doesn’t have to make them one after the other. The agent passes within the order ID and a query. Provided that enter, the device decides which lookups to run.
This manner, the agent actually solely sees one easy interface and does the work that wants an LLM: understanding the request and writing the reply. The choice mannequin handles the steps in between.
1.3 How the items match collectively
Contained in the specialist device, at every choice level, Python prepares the out there features with their arguments as distinct choices, and the proof collected to date to function the context. Then, the mannequin chooses which perform to run by returning an motion identifier. Python calls the corresponding perform and provides its outcome to the proof pool. After that, Python requests the subsequent choice.
We additionally embrace carried out and blocked as choices, so the mannequin can end when it has sufficient proof or cease when the out there operations can not resolve the query.
This whole loop runs inside an unusual device name managed by the OpenAI Brokers SDK. We title this device as order_specialist(), and register it because the agent’s device.
One factor to remember: the agent would not have direct entry to these backend operation features, and it can not name these features. It solely sees one device, i.e.,order_specialist(), and may name it with an order ID and a query. As soon as the device returns, the agent makes use of the collected proof to reply the client.
Right here’s what the complete interplay seems to be like:

···
2. Construct the Specialist Device
For our present case research, we’ll use Choice-1 on Azure as the choice mannequin, and use OpenAI Brokers SDK for configuring LLM agent. We’ll additionally briefly present how one can name different choice fashions from OpenRouter.
You will discover the entire implementation right here.
2.1 Begin with the investigation loop
When the agent calls order_specialist(), we run the next loop:
Within the code snippet above, we first put together the out there actions, then ask the choice mannequin to pick out one primarily based on the query and the proof collected to date. Every motion identifier maps to a Python perform and its arguments, so actions[choice] provides us every part wanted to carry out the chosen lookup.
After executing it, we add the outcome to proof. Then, we repeat. The subsequent choice due to this fact has entry to what we simply realized.
When it has sufficient proof, the mannequin also can choose carried out. Or, when the out there operations can not resolve the query, the mannequin can choose blocked. Both method, the loop ends and returns the collected data to the agent.
So what goes into actions?
Our available_actions() helper prepares lookups utilizing the knowledge presently out there. Initially, we all know the order ID, so we will provide order particulars, warehouse notes, and the coverage lookup. As soon as the order particulars reveal the merchandise identifier, a list lookup turns into out there. Transport lookups observe when we have now the warehouse identifiers and vacation spot.
We additionally take away equivalent lookups already accomplished. Because the proof grows, the alternatives change with it.
2.2 Let the choice mannequin select
With the ready potential actions, we will now put them in entrance of the choice mannequin and ask it to choose. Right here, we’ll use Choice-1 by means of Azure.
First, we flip every motion into an outline:
The keys are the motion identifiers. The motion’s description accommodates the perform title, its arguments, and its docstring. For instance, a delivery lookup would seem as:
As talked about above, we additionally add the 2 stopping choices:
Now we will assemble the request:
Right here, state holds the context for the choice. We embrace AS_OF, the present time in our instance, as a result of the query entails a supply deadline.
Underneath questions, we outline one selection query named motion. Its standards accommodates the choices we simply ready. The instruction half explains the mannequin the duty goal.
We ship this payload to the Azure endpoint:
The response provides us the chosen motion identifier. Afterward, Python both executes the corresponding perform or returns the proof if the mannequin chosen a stopping possibility.
We now have an clever device that performs an inner choice loop.
2.3 Bonus: Strive one other choice mannequin
Azure isn’t the one possibility. We will additionally entry choice fashions by means of OpenRouter, together with GPT-6 Luna Selections:
To strive Jev, merely change the mannequin identifier to typesafe/jev-1.14.
2.4 Give the device to the agent
Within the subsequent step, we make the device out there to an LLM agent.
We expose order_specialist() with the OpenAI Brokers SDK’s @function_tool decorator. Its interface seems to be like this:
The agent provides order_id and query. The docstring tells the agent what the device does and what these arguments imply.
So how can we hold the proof and file the mannequin’s selections through the investigation? That is the aim of context.
In contrast to the opposite two arguments, context is provided by the SDK, relatively than the LLM. It carries a Python dictionary the place we retailer these data. RunContextWrapper[dict] is the SDK’s wrapper round that dictionary, which we entry by means of context.context.
For the LLM that powers the agent, we’ll use GPT-6-Luna on Azure with medium reasoning effort:
Subsequent, we give the agent the next directions:
We will now configure the agent with our decision-model device:
Word that the agent has entry to only one device. The choice mannequin contained in the device manages the investigation.
Now we’re able to run the agent.
···
3. Run the Agent
To run the agent:
Bear in mind the context parameter in our device? We initialize its dictionary right here, then move it into the agent run. The device shops its retrieved data in proof and its inner alternatives and measurements in selections.
On this run, I can see that the agent accomplished the investigation: it defined why the order was delayed and recognized the identical potential supply possibility.
Throughout this course of, Luna known as order_specialist as soon as, asking it to research the delay and discover choices for assembly the Friday deadline. Contained in the device, Choice-1 chosen 5 backend operations earlier than selecting carried out:
The entire run took 8.9 seconds.
Now you could be questioning: how a lot did we really achieve by shifting these selections into the device? Let’s discover out.
Right here, I configured one other agent with direct entry to our 6 backend features. All the things else, just like the Luna mannequin, directions, and settings, keep the identical:
Parallel device calls stay disabled, so this agent selects one backend operation per flip. We then give it the identical request:
This agent additionally accomplished the investigation, reaching the identical core advice, however made six Luna calls and took 25.4 seconds. Subsequently, our decision-model-as-a-tool setup was 2.85 instances quicker, with 24.7% decrease mannequin price.
···
4. Closing Ideas
Most agent instruments wrap a single operation, and oftentimes that’s the fitting name.
However when the agent retains chaining the identical few operations collectively, it is a good time to ask whether or not it must be in that loop in any respect.
In our case, shifting these routine decisions into the device made the run nearly 3 times quicker and a couple of quarter cheaper, and the agent nonetheless reached the identical advice.
The take-away: your agent doesn’t need to make each choice. A few of them can dwell in its instruments.
















