Skip to content
Beta. VectorStep is in beta.Let us know if something breaks.

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.

A refund-desk agent with two tools from a stand-in billing system (lookup_order and issue_refund), run by a three-step pipeline:

  1. investigate looks the order up. It can read, and nothing else.
  2. decide applies the refund policy and says approve or deny. It has no tools at all.
  3. act issues the refund if (and only if) the decision was to approve. It can call issue_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.

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:

Terminal window
mkdir -p ~/.vectorstep/agents/refund-desk
cat > ~/.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": {}})
EOF

Register 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-desk
model: anthropic/claude-sonnet-4-6
max_tokens: 4096
tools:
- billing

Use 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, score
high. If a tool failed or was refused, or you could not do the task, say so and
score 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, no
markdown 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-desk
description: Handle a customer refund request
version: 1
stage: 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:

Terminal window
cd ~/.vectorstep
docker compose restart gateway
curl -X POST http://localhost:8000/reload \
-H "Authorization: Bearer $(grep VECTORSTEP_ADMIN_TOKEN ~/.vectorstep/.env | cut -d= -f2)"

Ask for a refund on order 1002, which cost £480:

Terminal window
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:

Terminal window
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:

Terminal window
docker compose exec gateway rm -f /tmp/refunds.log

4. 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:

Terminal window
docker compose restart gateway
Terminal window
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."}'
docker compose exec gateway cat /tmp/refunds.log

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:

Terminal window
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:

Terminal window
docker compose exec gateway rm -f /tmp/refunds.log

5. 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-desk
description: Investigate, decide, then act, each step with only the tools it needs
version: 2
stage: 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’s tool_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_tools means no change. allowed_tools: [] means no tools, which is what decide wants: it only reasons about what investigate found.
  • tool is a glob on the tool’s own name, so lookup_* covers lookup_order and any lookup tool added to the server later.

Reload VectorStep (no Gateway restart needed, since this is pipeline config) and try both orders again:

Terminal window
curl -X POST http://localhost:8000/reload \
-H "Authorization: Bearer $(grep VECTORSTEP_ADMIN_TOKEN ~/.vectorstep/.env | cut -d= -f2)"
Terminal window
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 60
done
docker compose exec gateway cat /tmp/refunds.log

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-policy
description: >
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-desk
model: anthropic/claude-sonnet-4-6
max_tokens: 4096
tools:
- billing
skills:
- refund-policy

Skills 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.

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: [] and tool_policy don’t apply to it. The step gets the policy and still has nothing it can do.
  • load_skills can’t grant anything. The skill must already be in the agent’s skills: list. Remove refund-policy from agent.yaml, reload, and run again: the decide step fails before any model call with an error saying the skill isn’t granted to the agent. Put it back afterwards.

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.