Building the shop agent
The shop agent is the running example for the whole course: a deterministic stand-in that turns a support message into one tool call, so every lesson can govern it with no model key.
Last updated: 14 Oct, 2026 · Agent Governance Toolkit 4.1.0
The previous lesson showed why an agent needs a gate. This lesson packages that agent into one small module the rest of the course reuses, and is honest about the one piece that is faked: the model.
Standing in for the model
A production agent sends the message to a model and reads back the tool it chose. That needs a key and gives a different answer each run, which would make a course impossible to check. The stand-in keeps the same shape, the message in and a tool name plus arguments out, but decides with rules.
def decide(message):
m = message.lower()
if "refund" in m: return "refund", {"order_id": "A-2291", "amount": 40}
if "status" in m or "where" in m: return "order_status", {"order_id": "A-2291"}
if "close" in m or "delete" in m: return "delete_account", {"customer_id": "C-5"}
return "reply", {"text": "How can I help?"}The line that swaps in a real model
In production decide would call a model instead. The shape of the return is the same, so nothing downstream changes. This block is shown, not run, because it needs a key the course does not use.
# production version: ask a model, read back the chosen tool (needs a key, not run here)
from litellm import completion
def decide(message):
reply = completion(model="groq/openai/gpt-oss-120b",
messages=[{"role": "user", "content": message}],
tools=TOOL_SCHEMAS)
call = reply.choices[0].message.tool_calls[0]
return call.function.name, json.loads(call.function.arguments)Running the four message types
The tools and the run loop are the same as before. Running one message of each kind shows the router covering refunds, status checks, the dangerous close, and a fallback reply.
for msg in ["I want a refund", "where is my order?",
"please close the account", "hello"]:
name, args = decide(msg)
print(f"{msg:28} -> {name:15} {TOOLS[name](**args)}")I want a refund -> refund refunded 40 on A-2291 where is my order? -> order_status A-2291: out for delivery please close the account -> delete_account DELETED account C-5 hello -> reply How can I help?
What the router produced
- Each message mapped to one tool, the way a model's tool call would, so later lessons can gate by the tool name.
- The close still ran, because there is still no gate. That is the job of the govern() lesson next.
- The output is the same every run, which is what lets the course check it. A real model would vary.
A stand-in vs a real model
| The stand-in | A real model | |
|---|---|---|
| Decides with | Rules in Python | A prompt and tool schemas |
| Needs a key | No | Yes |
| Same answer each run | Yes | No |
| Good for | Learning and tests | Production |
Where the stand-in agent fits
- A test suite for a governed agent, where you want the tool choice fixed so the policy is what is under test.
- A local demo with no key, to show the gate working before wiring a model in.
- A replay of a captured session, feeding recorded tool choices back through the gate.
Related
- Previous: Why an agent needs governance
- Next: govern(): the smallest real gate
- Add a
track_packagetool and a rule indecidethat routes track to it. - Make
decidereturn a different order id when the message contains one. - Print the tool name and arguments only, without calling the tool, to see the model's decision on its own.
Slow is fine. Stopping is the only problem.