NORNR
Mandates, approvals and evidence for autonomous agents.
Guide / LlamaIndex
10 minutesHow to set a cost limit on a LlamaIndex agent
Add a governed budget, approval threshold and audit trail to a LlamaIndex agent workflow using NORNR in under 10 minutes.
1. Why LlamaIndex agents need cost limits
LlamaIndex is built for retrieval-augmented generation and agent reasoning over large document sets. When those agents call paid LLMs, embedding APIs or external data services, there is no built-in layer that asks whether the cost is within a mandate before the query executes.
NORNR adds that layer. Place the policy check before any paid tool call and the agent gets a clear approved, queued or rejected outcome. Rejected or queued decisions never reach the paid API.
2. Install the SDK
bash
pip install agentpay llama-index-core llama-index-llms-openai
3. Create the governed wallet
python
from agentpay import Wallet
wallet = Wallet.create(
owner="llamaindex-rag-agent",
daily_limit=60,
require_approval_above=20,
base_url="https://nornr.com",
)
4. Gate the query engine or tool call
python
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.llms.openai import OpenAI
decision = wallet.pay(
amount=10.00,
to="openai",
purpose="rag query over internal docs",
)
if decision.get("status") == "approved":
documents = SimpleDirectoryReader("./data").load_data()
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine(llm=OpenAI(model="gpt-4o-mini"))
response = query_engine.query("What are the key risk factors?")
print(response)
elif decision.get("status") == "queued":
print("Query queued for operator review.", decision)
else:
print("Query blocked by policy.", decision)
The pattern works the same for agent tool calls — wrap the NORNR check around any step that would result in a paid API interaction.
5. Decision output
output
{"status": "approved", "requiresApproval": false}
{"status": "queued", "requiresApproval": true}
{"status": "rejected", "reasons": ["counterparty_not_allowed"]}
6. Common mistakes
- Calling the query engine before the NORNR check — the cost already incurred at that point.
- Setting the approval threshold higher than the daily limit.
- Not logging the decision object alongside the query result for audit purposes.