Tutorial: lock down a refund pipeline
Build your first agent gave an agent tools, and Restrict a pipeline with a security policy restricted which executors a pipeline may use. This tutorial is about the next question: once an agent is running, what is it allowed to do with its tools, and when?
You’ll build a small refund pipeline and tighten it three times. Each control answers a different question:
| Control | Question it answers | Who owns it |
|---|---|---|
tool_policy with an input condition |
“Is this particular call acceptable, whatever the agent or step?” (no refund over £200) | The operator, in the Gateway’s config |
allowed_tools on a step |
“Which tools does this step need?” | The pipeline author, per step |
load_skills on a step |
“Which instructions must this step always follow?” | The pipeline author, per step |
The reason for all three is that a prompt is a request, not a guarantee. A model can be argued with, confused, or fed text by a customer that reads like an instruction. These controls are enforced by the Gateway, outside the model, so they hold even when the prompt doesn’t.
What you’ll build
Section titled “What you’ll build”A refund-desk agent with two tools from a stand-in billing system
(lookup_order and issue_refund), run by a three-step pipeline:
investigatelooks the order up. It can read, and nothing else.decideapplies the refund policy and says approve or deny. It has no tools at all.actissues the refund if (and only if) the decision was to approve. It can callissue_refund, and nothing else.
On top of that, a Gateway-wide rule says no refund over £200 is ever issued by an agent, whatever the pipeline decides.
Prerequisites
Section titled “Prerequisites”- Build your first agent completed.
You have the Gateway and VectorStep running under
~/.vectorstep, and a provider configured. - Optional but useful: Give your agent a skill, which introduces skills. Step 5 here builds on it.
1. Add a stand-in billing system
Section titled “1. Add a stand-in billing system”You don’t need a real payments system to learn this. The agent talks to a
billing system through an MCP server, so for the tutorial you’ll use a tiny one
that only pretends to refund. Each issue_refund call it receives is appended
to a file, which is how you’ll check what got through.
The Gateway container already has python3, and the script uses only the
standard library. Put it next to the agent:
mkdir -p ~/.vectorstep/agents/refund-deskcat > ~/.vectorstep/agents/refund-desk/billing_mcp.py <<'EOF'"""A stand-in billing MCP server for the tutorial. It issues no real refunds:it records each issue_refund call in /tmp/refunds.log so you can see what got through."""import json, sys
ORDERS = {"1001": 50.00, "1002": 480.00} # order id -> amount paid (GBP)TOOLS = [ {"name": "lookup_order", "description": "Look up an order by id. Returns the amount paid.", "inputSchema": {"type": "object", "properties": {"order_id": {"type": "string"}}, "required": ["order_id"]}}, {"name": "issue_refund", "description": "Issue a refund. Arguments: order_id, amount (number) and currency (GBP, USD or EUR).", "inputSchema": {"type": "object", "properties": {"order_id": {"type": "string"}, "amount": {"type": "number"}, "currency": {"type": "string"}}, "required": ["order_id", "amount", "currency"]}},]
def send(obj): sys.stdout.write(json.dumps(obj) + "\n") sys.stdout.flush()
for line in sys.stdin: line = line.strip() if not line: continue msg = json.loads(line) method, rid = msg.get("method"), msg.get("id") if method == "initialize": send({"jsonrpc": "2.0", "id": rid, "result": { "protocolVersion": "2024-11-05", "capabilities": {"tools": {}}, "serverInfo": {"name": "billing", "version": "0"}}}) elif method == "tools/list": send({"jsonrpc": "2.0", "id": rid, "result": {"tools": TOOLS}}) elif method == "tools/call": name, args = msg["params"]["name"], msg["params"]["arguments"] if name == "lookup_order": paid = ORDERS.get(str(args.get("order_id"))) text = (f"Order {args.get('order_id')}: paid GBP {paid:.2f}" if paid is not None else "Order not found") else: with open("/tmp/refunds.log", "a") as f: f.write(json.dumps(args) + "\n") text = f"REFUNDED {args}" send({"jsonrpc": "2.0", "id": rid, "result": { "content": [{"type": "text", "text": text}], "isError": False}}) elif rid is not None: send({"jsonrpc": "2.0", "id": rid, "result": {}})EOFRegister it as an MCP server named billing in
~/.vectorstep/config/gateway.yaml, alongside any mcp_servers you already
have:
mcp_servers: billing: command: python3 args: ["/data/agents/refund-desk/billing_mcp.py"](/data/agents/... is where the container sees ~/.vectorstep/agents/, as in
the first tutorial.)
2. Write the agent and the first, unprotected pipeline
Section titled “2. Write the agent and the first, unprotected pipeline”~/.vectorstep/agents/refund-desk/agent.yaml:
name: refund-deskmodel: anthropic/claude-sonnet-4-6max_tokens: 4096tools: - billingUse whichever provider and model you set up earlier; nothing here depends on that line.
~/.vectorstep/agents/refund-desk/soul.md:
# Refund Desk
You help with customer refund requests using the billing tools you are given.Be brief and factual. Only report an action as done if a tool call succeeded.
## Confidence
Confidence measures how sure you are that you completed your task correctly,from 0.0 to 1.0. If you did what was asked and the tools confirmed it, scorehigh. If a tool failed or was refused, or you could not do the task, say so andscore low. Never leave it at the 0.0 in the template.
## Output format
Respond with ONLY the JSON object your prompt asks for. No preamble, nomarkdown fences, no commentary outside the JSON.Now a pipeline with a single step and no controls at all, so you can see the
problem first. ~/.vectorstep/pipelines/refund-desk.yaml:
name: refund-deskdescription: Handle a customer refund requestversion: 1stage: testing
trigger: match: { event: refund-request }
context_template: include: - summary # makes {{summary}} resolve in the prompts below
steps: - name: handle executor: gateway executor_config: agent: refund-desk confidence_threshold: 0.75 prompt_template: | A customer sent this request: {{summary}} Look up the order and, if the customer is asking for a refund, issue it for the amount paid in GBP. Respond with ONLY this JSON: {"confidence": 0.0, "summary": "what you did", "next_step_context": ""}context_template.include is what makes {{summary}} resolve in the prompt. Leave it out
and the field renders as an empty string, so the model would see no request at all.
Restart the Gateway (a new mcp_servers entry needs a restart, not a reload),
then reload VectorStep:
cd ~/.vectorstepdocker compose restart gatewaycurl -X POST http://localhost:8000/reload \ -H "Authorization: Bearer $(grep VECTORSTEP_ADMIN_TOKEN ~/.vectorstep/.env | cut -d= -f2)"3. See the problem
Section titled “3. See the problem”Ask for a refund on order 1002, which cost £480:
curl -X POST "http://localhost:8000/webhook?source=generic&allow_testing=true" \ -H "Authorization: Bearer $(grep VECTORSTEP_WEBHOOK_TOKEN ~/.vectorstep/.env | cut -d= -f2)" \ -H "Content-Type: application/json" \ -d '{"pipeline": "refund-desk", "event": "refund-request", "summary": "Please refund order 1002, it arrived damaged."}'Now check what reached the billing system:
docker compose exec gateway cat /tmp/refunds.log{"order_id": "1002", "amount": 480.0, "currency": "GBP"}The agent refunded £480 without anyone looking at it. Nothing went wrong here. The agent did what it was asked. But in a real deployment the request text comes from a customer, and the amount a model will refund is a function of what it was told. You want a limit that doesn’t depend on the model behaving.
Clear the log before moving on:
docker compose exec gateway rm -f /tmp/refunds.log4. Control one: cap the amount with tool_policy
Section titled “4. Control one: cap the amount with tool_policy”tool_policy is an operator-owned rule set in the Gateway’s config. Every tool
call from every agent passes through it, and an agent author can’t loosen it
through the API. Add this to ~/.vectorstep/config/gateway.yaml:
tool_policy: default: allow rules: - deny: server: billing tool: issue_refund input: - { path: amount, op: gt, value: 200 } reason: "Refunds over 200 need a human"The input list is the new part: it looks at the call’s arguments, not just
the tool’s name. Read the rule as “deny issue_refund on the billing server
when amount is greater than 200.” See Conditions on
arguments for the
other operators and for paths into nested arguments.
tool_policy is read at startup, so restart the Gateway and send the same
request again:
docker compose restart gatewaycurl -X POST "http://localhost:8000/webhook?source=generic&allow_testing=true" \ -H "Authorization: Bearer $(grep VECTORSTEP_WEBHOOK_TOKEN ~/.vectorstep/.env | cut -d= -f2)" \ -H "Content-Type: application/json" \ -d '{"pipeline": "refund-desk", "event": "refund-request", "summary": "Please refund order 1002, it arrived damaged."}'
docker compose exec gateway cat /tmp/refunds.logWhat you should see
Section titled “What you should see”The log is empty (or cat reports no such file, since nothing was ever
written). The refund never reached the billing system. Open the run in
http://localhost:8000/ui/, expand the handle step and its Agent trace: you’ll see
the agent’s issue_refund call followed by a red Tool denied entry that names the layer
(tool_policy, rule #0) and shows the reason you wrote. The trace header also counts
it (“1 denied”). The model receives that reason
as an error result and typically tells you it couldn’t complete the refund. Because
soul.md tells the agent to score low when a tool is refused, the run usually ends
escalated rather than completed, which is the right outcome for “needs a human”.
Now check the rule isn’t simply blocking everything. Send a request for order 1001, which cost £50:
curl -X POST "http://localhost:8000/webhook?source=generic&allow_testing=true" \ -H "Authorization: Bearer $(grep VECTORSTEP_WEBHOOK_TOKEN ~/.vectorstep/.env | cut -d= -f2)" \ -H "Content-Type: application/json" \ -d '{"pipeline": "refund-desk", "event": "refund-request", "summary": "Please refund order 1001, it never arrived."}'
docker compose exec gateway cat /tmp/refunds.log{"order_id": "1001", "amount": 50.0, "currency": "GBP"}Small refunds go through and large ones don’t. Clear the log again:
docker compose exec gateway rm -f /tmp/refunds.log5. Control two: give each step only the tools it needs
Section titled “5. Control two: give each step only the tools it needs”The policy limits how much. It says nothing about which step may refund. Right now one step does the investigating, the thinking and the refunding, so anything that goes wrong in the thinking can reach the refund tool.
Split the work into three steps and scope each one with allowed_tools.
Replace ~/.vectorstep/pipelines/refund-desk.yaml:
name: refund-deskdescription: Investigate, decide, then act, each step with only the tools it needsversion: 2stage: testing
trigger: match: { event: refund-request }
context_template: include: - summary
steps: - name: investigate executor: gateway executor_config: agent: refund-desk allowed_tools: - { server: billing, tool: "lookup_*" } # read only confidence_threshold: 0.75 prompt_template: | A customer sent this request: {{summary}} Look up the order they mention and report the amount paid. Respond with ONLY this JSON. In next_step_context put the real order id and amount, for example "order 1001, GBP 50.00": {"confidence": 0.0, "summary": "the order and amount paid", "next_step_context": ""}
- name: decide executor: gateway executor_config: agent: refund-desk allowed_tools: [] # no tools at all confidence_threshold: 0.85 prompt_template: | Customer request: {{summary}} Findings: {{steps.investigate.next_step_context}} Decide whether to approve a refund. Approve when the customer reports a problem with the order and the amount is GBP 200 or less. Otherwise deny. Respond with ONLY this JSON: {"confidence": 0.0, "summary": "approve or deny, and why", "next_step_context": "APPROVE <order id> <amount> GBP, or DENY: <reason>"}
- name: act executor: gateway executor_config: agent: refund-desk allowed_tools: - { server: billing, tool: issue_refund } # the one tool this step needs confidence_threshold: 0.85 prompt_template: | Decision: {{steps.decide.next_step_context}} If the decision starts with APPROVE, call issue_refund with that order id, amount and currency. If it starts with DENY, do not call any tool. Respond with ONLY this JSON: {"confidence": 0.0, "summary": "what you did", "next_step_context": ""}Three things to know about allowed_tools:
- It only narrows. A call has to pass the agent’s
tools:list, the operator’stool_policy(evaluated first) and the step’s list. The step can’t grant anything the other two don’t. - Absent and empty differ. No
allowed_toolsmeans no change.allowed_tools: []means no tools, which is whatdecidewants: it only reasons about whatinvestigatefound. toolis a glob on the tool’s own name, solookup_*coverslookup_orderand any lookup tool added to the server later.
Reload VectorStep (no Gateway restart needed, since this is pipeline config) and try both orders again:
curl -X POST http://localhost:8000/reload \ -H "Authorization: Bearer $(grep VECTORSTEP_ADMIN_TOKEN ~/.vectorstep/.env | cut -d= -f2)"for req in "refund order 1001, it never arrived" "refund order 1002, it arrived damaged"; do curl -X POST "http://localhost:8000/webhook?source=generic&allow_testing=true" \ -H "Authorization: Bearer $(grep VECTORSTEP_WEBHOOK_TOKEN ~/.vectorstep/.env | cut -d= -f2)" \ -H "Content-Type: application/json" \ -d "{\"pipeline\": \"refund-desk\", \"event\": \"refund-request\", \"summary\": \"Please $req.\"}" sleep 60donedocker compose exec gateway cat /tmp/refunds.logWhat you should see
Section titled “What you should see”Only the £50 refund is in the log. For order 1002, decide should say DENY
because of the £200 limit in its prompt, and act then has nothing to do.
Open a run in the UI and compare the three steps’ traces. investigate only
ever has lookup_order to call. decide has no tool calls, and the model isn’t
shown any tools. act can see only issue_refund.
Now the important part: the two layers are independent. decide is only a
prompt, so a model could still get it wrong and say APPROVE for the £480 order.
If it does, act calls issue_refund with 480, and the tool policy from step 4
refuses it. You don’t need to arrange that to trust it. The rule from step 4 is
still in force and doesn’t care how the pipeline got there.
If a step does try a tool outside its scope, the trace shows a Tool denied entry
labelled step scope (allowed_tools) (and no rule number, since no policy rule was
involved) instead of tool_policy, rule #…. That’s how you tell which layer
stopped a call. The underlying event is tool_denied with source: step_scope.
6. Control three: make decide always follow the refund policy
Section titled “6. Control three: make decide always follow the refund policy”decide currently carries the refund rules in its prompt. In a real system the
rules are longer, they change, and several pipelines share them, which is
exactly what a skill is for. Put them in one:
~/.vectorstep/skills/refund-policy/SKILL.md:
---name: refund-policydescription: > Use when deciding whether to approve a customer refund. Covers the approval limit, which reasons qualify and how to word the decision.---
# Refund policy
1. Approve only when the customer reports a real problem with the order: damaged, not delivered, or not as described.2. Never approve a refund over GBP 200. Deny it and say it needs a human.3. Never approve a refund for an order you could not find.4. State the decision in one line, starting with APPROVE or DENY.Grant it to the agent, in ~/.vectorstep/agents/refund-desk/agent.yaml:
name: refund-deskmodel: anthropic/claude-sonnet-4-6max_tokens: 4096tools: - billingskills: - refund-policySkills reload without a restart (using the admin-token reload from Give your agent a skill).
Normally the model sees only the skill’s one-line description and has to choose
to call load_skill. For decide that choice is a risk: the step must always
apply the policy. Preload it, and drop the rules from the prompt. In
refund-desk.yaml, change decide:
- name: decide executor: gateway executor_config: agent: refund-desk allowed_tools: [] load_skills: [refund-policy] # in the prompt from turn one confidence_threshold: 0.85 prompt_template: | Customer request: {{summary}} Findings: {{steps.investigate.next_step_context}} Decide whether to approve a refund. Respond with ONLY this JSON: {"confidence": 0.0, "summary": "approve or deny, and why", "next_step_context": "APPROVE <order id> <amount> GBP, or DENY: <reason>"}Reload VectorStep and trigger the £480 request again.
What you should see
Section titled “What you should see”In decide’s agent trace you’ll see a Skill preloaded entry for refund-policy and
no load_skill call. The policy was in the system prompt before the model
said anything. The model’s reply should DENY, citing the £200 limit, and again
nothing reaches /tmp/refunds.log.
Two details worth noticing:
- The step has no tools, and the skill still works. Preloading isn’t a tool
call, so
allowed_tools: []andtool_policydon’t apply to it. The step gets the policy and still has nothing it can do. load_skillscan’t grant anything. The skill must already be in the agent’sskills:list. Removerefund-policyfromagent.yaml, reload, and run again: thedecidestep fails before any model call with an error saying the skill isn’t granted to the agent. Put it back afterwards.
What changed in the stats
Section titled “What changed in the stats”allowed_tools and load_skills are both part of a step’s calibration
bucket, the key under which VectorStep groups a step’s history to measure how
often it’s right. Changing either starts a fresh bucket for that step (n=0),
the same as editing its prompt, and going back to the old setting rejoins the
old history. Steps that don’t use them are unaffected. See
Confidence for what a bucket is.
On the skill’s page in the UI (Skills, then refund-policy), preloaded
steps are counted separately, as “(+N preloaded)”, so a skill that’s always
preloaded doesn’t look like one that’s granted but never used.
| You did | Control | It guarantees |
|---|---|---|
Denied issue_refund when amount > 200 |
tool_policy input condition |
No agent, in any pipeline, issues an oversized refund, even if everything else is wrong |
Gave investigate read tools, decide none, act one |
allowed_tools |
A step can’t call a tool it doesn’t need, so it can’t be talked into it |
Preloaded refund-policy into decide |
load_skills |
The step always has the policy, with no chance the model skips loading it |
Each is useful alone. Together they give you independent layers: the policy holds if a step’s scope is too wide, the scope holds if the prompt is ignored, and the preloaded skill makes the prompt less likely to be ignored in the first place.
Where next
Section titled “Where next”- Tool policy for every operator and the rest of the rule schema.
- Skills and Writing good skills for when to preload and when to leave a skill on demand.
- Securing a deployment for how these fit alongside tokens, security policies and network controls.
- Restrict a pipeline with a security policy for the executor-level counterpart.