Core Features

Circuit Breaker

Automatically stop runaway agents and prevent cascading failures with intelligent circuit breakers.

How It Works

The circuit breaker monitors agent behavior and automatically trips when anomalies are detected, preventing runaway costs, infinite loops, or cascading failures.

CLOSED

Normal operation, requests flow through

OPEN

Tripped, all requests blocked

HALF-OPEN

Testing recovery, limited requests

Configuration

Circuit breakers are a cloud feature: state is tracked server-side by Tork so that a trip applies across every process sharing the policy. Reach it with @torknetwork/sdk (npm install @torknetwork/sdk, entry class TorkClient) or, from any other language, the REST API directly. This is a different package from the on-device tork-governance family, which decides locally, exports Tork instead, and has no circuit-breaker state to share.

Python note: there is no Python cloud SDK. The Python examples below call the REST API with requests and a Bearer token.

Circuit breakers are keyed by policy name. Inspect current state with a GET:

python
# There is no Python cloud SDK — call the REST API with a Bearer token.
import os, requests

TORK_API = "https://tork.network/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['TORK_API_KEY']}"}

# All circuit breakers for your account
r = requests.get(f"{TORK_API}/circuit-breaker", headers=HEADERS)
for cb in r.json()["circuitBreakers"]:
    print(cb["policyName"], cb["state"], cb["stats"]["errorRate"])

# A single policy's breaker
r = requests.get(
    f"{TORK_API}/circuit-breaker",
    headers=HEADERS,
    params={"policy": "pii-strict"},
)
cb = r.json()["circuitBreaker"]
print(cb["state"])          # closed, open, or half_open
print(cb["errorCount"], cb["successCount"])

Trip Triggers

Circuit breakers can trip based on multiple conditions:

Error Rate

Too many consecutive failures or high failure percentage

Latency

Response times consistently exceeding thresholds

Cost Anomaly

Spending rate significantly above baseline

Token Usage

Token consumption exceeding limits

Loop Detection

Repetitive patterns indicating infinite loops

Manual Controls

Force a breaker open, closed, or back to a clean slate with a POST. Opening accepts an optional timeout in seconds:

python
# Trip a breaker open for 5 minutes
requests.post(f"{TORK_API}/circuit-breaker", headers=HEADERS, json={
    "action": "open",
    "policyName": "pii-strict",
    "timeout": 300,
})

# Close it again, or reset the counters entirely
requests.post(f"{TORK_API}/circuit-breaker", headers=HEADERS, json={
    "action": "close", "policyName": "pii-strict",
})
requests.post(f"{TORK_API}/circuit-breaker", headers=HEADERS, json={
    "action": "reset", "policyName": "pii-strict",
})

Webhook Notifications

Receive notifications when circuit breakers change state:

json
{
  "event": "circuit_breaker.opened",
  "agent_id": "agent-123",
  "timestamp": "2024-01-15T10:30:00Z",
  "data": {
    "previous_state": "CLOSED",
    "new_state": "OPEN",
    "trigger": "failure_rate",
    "failure_rate": 0.65,
    "failure_count": 13,
    "window_duration": "60s"
  }
}

Important: When a circuit breaker trips, all requests to that agent are immediately blocked until manual reset or automatic recovery.

Documentation

Learn to integrate TORK

Upgrade Plan

Current: free

Support

Get help from our team