Skip to main content

Cost control for AI agents — loop detection, budget caps, audit trail

Project description

Orka

Your AI agent burns money in a loop. Orka cuts it before the bill lands — and proves how much it saved.

pip install orkaia

PyPI version Python 3.10+ License: MIT


What just happened

An OpenAI Operator agent bought a dozen eggs for $31 — its own safety protocol failed to trigger. Replit's coding agent deleted a production database in 9 seconds, during a freeze meant to prevent exactly that. A research agent burned $200 in a retry loop at 3am before anyone noticed.

There's no checkpoint between your agent's decision and the irreversible action. No cost cap. No loop detection. No audit trail.

Orka sits in front of every action and decides: let it pass, flag it, or cut it.


Try it now — no API key, no signup

import orka

orka.init(mode="local")  # no key, no network, runs offline

@orka.guard(agent_id="my-agent", task_type="web_search")
def search(query: str) -> str:
    return your_llm.call(query)

# Run your agent as usual...
for i in range(10):
    search(query="python tutorial")  # same query = loop detected

# See what Orka caught
orka.summary()

Output:

==================================================
  Orka Run Summary
==================================================
  Run:            a1b2c3d4...
  Actions:        10
  Interventions:  8
  Cost:           ~$0.0065
  Saved:          ~$0.0052
    [loop] web_search repeated 3+ times
==================================================

Your agent ran. Orka watched. You see exactly what it would have cut, and how much it would have saved. Zero config, zero signup, zero network.

Want it to actually cut? Add enforce=True:

orka.init(mode="local", enforce=True)
# Now loops and budget overruns raise OrkaPolicyBlocked

What Orka does

Feature What it does How
Loop guard Detects when your agent repeats the same action Fingerprints tool+args, breaks at N repetitions
Budget cap Stops a run before it blows past your cost limit Configurable per-run USD ceiling
Cost meter Tracks estimated spend per action Token count × model price table
Audit trail Records every action with cost, status, timestamps Local SQLite or cloud ledger
Savings report Shows exactly how much Orka prevented orka.summary() or dashboard
Human approval Pauses high-risk actions for human review Cloud mode — approval flow in dashboard
Policy engine Blocks actions by rule (task type, domain, quota) Configurable policies per agent

Two modes

Local (free, offline, no signup)

orka.init(mode="local")                    # audit: observe only
orka.init(mode="local", enforce=True)      # enforce: actually cut
orka.init(mode="local", per_run_usd=2.0)   # budget cap at $2
orka.init(mode="local", loop_threshold=5)   # break after 5 repeats

Data stays in ~/.orka/local.db. No network. No account.

Cloud (team features, dashboard)

orka.init(api_key="orka_...")  # get key at orka.ia.br

Adds: centralized ledger, team approval flows, cross-agent dashboard, org-level enforcement, real-time alerts.


Works with any framework

LangChain

from orka.integrations.langchain import OrkaCallbackHandler

cb = OrkaCallbackHandler(agent_id="my-agent")
llm = ChatOpenAI(model="gpt-4o", callbacks=[cb])

CrewAI / AutoGen / custom

@orka.guard(agent_id="researcher", task_type="web_search")
def search_web(query: str) -> str:
    return firecrawl.scrape(query)

Works with def and async def — detected automatically.


Handle blocks

from orka import OrkaPolicyBlocked

@orka.guard(agent_id="agent", task_type="send_email", risk="HIGH")
def send_email(to: str, body: str) -> bool:
    return email_client.send(to, body)

try:
    send_email("user@example.com", "Report ready")
except OrkaPolicyBlocked as e:
    print(f"Blocked: {e.reason}")
    # In cloud mode: queued for human approval in dashboard

Install

pip install orkaia                  # core
pip install "orkaia[langchain]"     # + LangChain callback
pip install "orkaia[openai]"        # + OpenAI adapter

Python 3.10+.


Examples

Demo What it shows
local_audit_demo/ Agent in loop → Orka detects → shows savings (no key)
economy_loop_demo/ Loop cut + dollar savings report
quickstart.py Cloud mode in 30 lines

Links

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

orkaia-0.3.0.tar.gz (27.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

orkaia-0.3.0-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file orkaia-0.3.0.tar.gz.

File metadata

  • Download URL: orkaia-0.3.0.tar.gz
  • Upload date:
  • Size: 27.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for orkaia-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0c374c2c4a68cdb291560b65d89ada29d06d9fc455b7d441c95c413d761837e6
MD5 69e489c8e5d64fc646392bd36e9cb265
BLAKE2b-256 a63ddd1b464f2dec2eb28871cea2869207983b1f17ce7062001e712e536bbc11

See more details on using hashes here.

File details

Details for the file orkaia-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: orkaia-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for orkaia-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4fe28bbb5ce37f2988c9aa92f1dd48fc23f5fe341886d3b85a11b82ee426d036
MD5 58fd09866e9b905cab6ec77b02096e13
BLAKE2b-256 15d541615f9c342d06971ec63beb906b497ecbe3ad6dc5417d3fc018515f9683

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page