Allow and deny API demo
Compare an allowed tool call with a denied call using a simulated refund.
On this page
Complete example
If this demo’s tools are not yet registered, use the publish command for setup. Configure the policy in the console, then run with your test amount.
| Input | Active rule and expected result |
|---|---|
amount = 5 · currency = USD | Allow positive USD amounts through 10; one simulated receipt. |
amount = 15 · currency = USD | Deny USD amounts above 10; no receipt. |
Classify the actual catalog entry for refund_create as Write, select amount and currency, and activate a policy that allows positive USD amounts through 10 inclusive and denies everything else. Deep Agents catalog names can differ from native names. These are demonstration limits you configure. Amounts use major units: 5 with USD means USD 5.00. EUR requests are denied by this demonstration policy. Review policy activation →
pip install openeightConfigure your model
Choose your model provider to see its installation command.
pip install langchain-openaiSet AGENT_MODEL to provider:model using a tool-calling model available to your account. Set AGENT_MODEL_API_KEY to that provider’s credential; it is separate from your OPENEIGHT_API_KEY.
export AGENT_MODEL="openai:<your-tool-calling-model>"
export AGENT_MODEL_API_KEY="<your-model-provider-key>"export OPENEIGHT_ENDPOINT='https://app.openeight.ai'
export OPENEIGHT_AGENT_NAME="your-agent-slug"
export OPENEIGHT_API_KEY="<your-agent-api-key>"Save as refund_langchain_sync.py. This file includes all imports and helpers. Effects are simulated; managed examples use the model provider configured above.
python refund_langchain_sync.py publish
# Configure policies in the console.
python refund_langchain_sync.py run 5 USD
python refund_langchain_sync.py run 15 USD"""Minimal API demo: refund_create accepts amount in major units and an explicit currency.
For the complete order-based refund scenario, see the Examples guide.
Uses an explicitly configured model provider and simulated receipts.
First-time setup only: python refund_langchain_sync.py publish
Then configure tools/policies in the console.
Run: python refund_langchain_sync.py run 5 USD
"""
import argparse
import os
from decimal import Decimal
from typing import Literal
from langchain.chat_models import init_chat_model
from openeight import OpenEightConfig
from openeight.langchain import create_agent
def build_model():
provider, separator, model = os.environ["AGENT_MODEL"].partition(":")
if not separator or not provider.strip() or not model.strip():
raise ValueError("Set AGENT_MODEL to provider:model")
api_key = os.environ["AGENT_MODEL_API_KEY"]
if not api_key.strip():
raise ValueError("Set AGENT_MODEL_API_KEY explicitly")
return init_chat_model(model, model_provider=provider, api_key=api_key)
receipts = []
def refund_create(amount: float, currency: Literal["USD", "EUR"]) -> str:
"""Record a simulated refund in major units (5 means 5 dollars for USD); never contact a payment provider."""
if type(amount) not in (int, float):
raise ValueError("Expected a numeric amount in major units")
value = Decimal(str(amount))
if not value.is_finite() or value <= 0 or value != value.quantize(Decimal("0.01")):
raise ValueError("Expected a positive amount with at most two decimal places")
if currency not in ("USD", "EUR"):
raise ValueError("Expected USD or EUR")
receipts.append({"amount": amount, "currency": currency, "simulated": True})
return "Simulated refund recorded"
def main(command, amount, currency):
model = build_model() # Explicit application-owned model/provider configuration.
openeight_config = OpenEightConfig(
agent_name=os.environ["OPENEIGHT_AGENT_NAME"],
endpoint=os.environ["OPENEIGHT_ENDPOINT"],
credential=os.environ["OPENEIGHT_API_KEY"],
)
agent = create_agent(model=model, tools=[refund_create], openeight=openeight_config)
if command == "publish":
agent.publish()
else:
agent.invoke({"messages": [("user", f"Simulate a refund of {amount} {currency} in major units using refund_create. Preserve the requested amount and currency; never change them to bypass policy.")]})
print("Simulated receipts:", receipts)
print(agent.delivery_status())
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("command", choices=["publish", "run"])
parser.add_argument("amount", type=float, nargs="?", default=5)
parser.add_argument("currency", choices=["USD", "EUR"], nargs="?", default="USD")
args = parser.parse_args()
main(args.command, args.amount, args.currency)