
Capability-authorisation and transaction-ledger defence layer for tool-using LLM agents, with policy compilation, parameter provenance checks, and auditable tool execution.
Anonymous source repository for paper: ''ToolFence: Fine-Grained Authorization for Secure Tool-Using LLM Agents`` reorganised and modified from the original implementation. This project implements a capability-authorisation and transaction-ledger defence layer for tool-using agents, including a policy compiler, parameter provenance checking, dynamic capability granting, persistent transaction accounting, and targeted test suites.
This repository contains no non-public data, credentials, or model weights.
Figure: ToolFence runtime and authorisation boundary overview
ToolFence enforces bounded, auditable tool execution for LLM agents. It separates policy compilation, runtime monitoring, and capability approval from the agent itself, using:
AgentDojo is only used as an external benchmark framework; the core ledger and authorisation logic do not depend on it.
The source tree is under ToolFence_anonymous 3/; paths in the table below are relative to that directory.
| Location | Corresponding Mechanism |
|---|---|
src/toolfence/guarded_net.py, transaction_net.py | Workflow stages, capability & evidence transaction ledger; atomic reservation, trusted receipts, dynamic authorisation proposals, intra-task authorisation |
src/toolfence/semantic/ | Isolated policy compiler, typed tool catalogues & capabilities, concrete parameter and provenance validation |
src/toolfence/hybrid/ | Deterministic fast path, dynamic capability authorisation, cross-session capability shape cache |
src/toolfence/runtime.py, colored_runtime.py, agentdojo_defense.py | Agent runtime and final guarded ledger execution boundary |
src/toolfence/judge/, core/, foundation/ | Isolated reviewer, shared monitoring logic and foundational authorisation structures |
experiments/ | Host sandbox examples that do not depend on models |
tests/unit/ | Regression tests for transactions, parameter provenance, dynamic authorisation and paper-mode behaviour |
Requires Python 3.10 or newer.
cd "ToolFence_anonymous 3"
# editable install with test dependencies
python -m pip install -e '.[test]'
# run unit test suite
python -m pytest -q tests/unit
Import:
import toolfence
Full tests require AgentDojo for benchmark boundary integration. Either install AgentDojo into your environment or provide it via PYTHONPATH. Core functionality works without AgentDojo.
These examples do not invoke LLMs or real external tools. They validate mechanism behaviour only and do not measure prompt injection success rates.
cd "ToolFence_anonymous 3"
python experiments/run_guarded_net_cases.py --output output/guarded-example
python experiments/run_refinement_cases.py --output output/refinement-example
The three real benchmarks are AgentDojo, ASB (memory poisoning), and MCPTox. The runners and reviewed JSON manifests are under ToolFence_anonymous 3/experiments/real_benchmarks/.
Full prerequisites, model-server commands, external data paths, smoke tests, and per-benchmark options are documented in the benchmark README.
Quick start:
cd "ToolFence_anonymous 3"
python -m pip install -e '.[test,llm]'
python -m pip install agentdojo
export PYTHONPATH=src:.
export OUT=results_real/benchmarks_100
python -m experiments.real_benchmarks.run_agentdojo_100 \
--subset-size 100 --model-profile qwen --judges qwen --output-dir "$OUT"
python -m experiments.real_benchmarks.run_asb_100 \
--subset-size 100 --model-profile qwen --judges qwen --output-dir "$OUT"
python -m experiments.real_benchmarks.run_mcptox_100 \
--subset-size 100 --model-profile qwen --judges qwen --output-dir "$OUT"
Before running the full suite:
TOOLFENCE_AGENTDOJO_SPLIT and TOOLFENCE_AGENTDOJO_SRC.TOOLFENCE_BLUEPRINTING to the Blueprinting source root and place the original ASB data under data/asb_orig/.response_all.json to data/mcptox/response_all.json (command in the benchmark README).qwen profile expects an OpenAI-compatible endpoint on port 8000; llama70b expects port 8002. Select with --model-profile qwen|llama70b|both.For a quick smoke test, replace --subset-size 100 with --smoke and use a separate output directory, e.g. OUT=results_real/benchmarks_smoke. To aggregate results:
python -m experiments.real_benchmarks.summarize_results \
results_real/benchmarks_100 \
--old-dir results_real/final_100_qwen
This writes summary.csv and REPORT.md under the result directory.
The strict_capabilities=True mode changes behaviour for high-assurance defence:
SemanticPolicyCompiler uses a pinned ToolManifest and validates exact name/parameter matches against the trusted catalogue. Model-generated effect labels are overridden by the controller manifest.DERIVED bindings must point to a single named output field from a single upstream tool. Ambiguous or unstructured provenance cannot authorise sensitive parameters.external_disclosure=False and mutates_state=False. All parameters must be justified by the original user request.To attach ToolFence to your agent host:
ToolManifest. Mark each tool’s operation, side effects, and privilege-affecting parameters.SemanticPolicyCompiler with your pinned manifest. The compiler must only see authenticated user requests and the trusted catalogue.RuntimeJudge for runtime capability adjudication.TaskContract, configures TransitionRule, EvidenceStep, and HostToolBinding inside GuardedTransactionNet.ToolFenceAuthorizationBoundary referencing the trusted catalogue, transaction net, host bindings, actor, reviewer, and policy revision.If a complete TaskContract is missing, GuardedBoundary(refine_missing=True) creates a pending RefinementProposal rather than granting access. The host must call review_refinement; after approval, the agent resubits the call. Operations with uncertain outcomes stay reserved until reconciliation.
Important: Controller APIs (
issue,configure,ingest,activate,review_refinement,reconcile) are administrative interfaces and must never be exposed as agent tools. Model outputs or tool returns alone are not trusted evidence.
The published package and source tree contain: