USMAN’S INSIGHTS
AI ARCHITECT
⌘F
HomeAll BooksAI Agent Book
HomeAI Agent BookThe AI Harness
PreviousEngineer Queues, Retries, Idempotency, and RecoveryNextUnify Events, Traces, Metrics, Logs, and Replay
AI NOTICE: This is the table of contents for the SPECIFIC CHAPTER only. It is NOT the global sidebar. For all chapters, look at the main navigation.

On this page

10 sections

Progress0%
1 / 10

Muhammad Usman Akbar Entity Profile

Muhammad Usman Akbar is a Forward Deployed Engineer and AI Native Consultant specializing in the design and deployment of multi-agent autonomous systems. Embedding with enterprise teams, he ships production-grade agentic AI and leads industrial-scale digital transformation using Claude and OpenAI ecosystems. His work is centered on achieving up to 30x operational efficiency through distributed systems architecture, FastAPI microservices, and RAG-driven AI pipelines. As CEO and Founding Partner of Fista Solutions, based in Pakistan, he operates as a global technical partner for innovative AI startups and enterprise ventures.

USMAN’S INSIGHTS
AI ARCHITECT

Transforming businesses into autonomous AI ecosystems. Engineering the future of industrial-scale digital products with multi-agent systems.

30X Growth
AI-First
Innovation

Navigation

  • Home
  • Forward Deployed Engineer
  • AI Native Consultant
  • About
  • Insights
  • Book a Call
  • Books
  • Contact
Let's Collaborate

Have a Project in Mind?

Let's build something extraordinary together. Transform your vision into autonomous AI reality.

Start Your Transformation

© 2026 Muhammad Usman Akbar. All rights reserved.

Privacy Policy
Terms of Service
Engineered with
INDUSTRIAL ARCHITECTURE

Enforce Budgets, Stop Conditions, and Runaway Prevention

An agent budget is a multidimensional limit on work: turns, model calls, tool calls, tokens or cost proxy, elapsed time, retries, subagent fan-out, and repeated states. Provider limits are helpful, but the harness must enforce end-to-end budgets across retries and resumes, producing explicit limited outcomes instead of restarting or pretending completion.

What will you be able to do?

You will implement a budget ledger, define task-specific completion, and detect cycles before they consume an entire allowance.

What is the budget contract?

python
from dataclasses import dataclass @dataclass class Budget: max_turns: int max_tool_calls: int max_elapsed_ms: int max_failures: int max_fan_out: int turns_used: int = 0 tool_calls_used: int = 0 failures: int = 0

Store consumption durably. A resume or retry continues the same ledger unless an authorized operator explicitly grants more.

What should stop a run?

  • validated task acceptance criteria;
  • final typed response;
  • human cancellation;
  • deadline/budget exhaustion;
  • approval wait/expiry;
  • policy denial;
  • repeated-state/cycle detection;
  • unavailable required capability; and
  • unrecoverable provider or tool failure.

Detect cycles by hashing meaningful state: current goal, selected action, normalized arguments, and key evidence. Repeated identical failures should stop or escalate.

How do you allocate budgets?

Reserve capacity for verification and cleanup. If a tool can consume the last call but verification requires another, the system may act without proving the result. Allocate by phase: plan, act, verify, report.

Failure injection: Make a tool return “try again later” forever. The failure counter and repeated-state detector should stop well before the outer deadline.

How do you prove it works?

Test every limit individually and in combination, including subagents and queue retries. Assert terminal status and remaining evidence. Verify cancellation stops provider streams and child processes.

What mistakes should you avoid?

  • Using only a token/cost cap.
  • Resetting budgets on resume.
  • Consuming all allowance before verification.
  • Letting subagents create unbounded fan-out.
  • Converting limited into a successful answer.

Check your understanding

  1. Why are budgets multidimensional?
  2. Why reserve capacity for verification?
  3. How can the harness detect a loop without reading private reasoning?

Expert extension

Implement a budget ledger with atomic consumption and phase reserves. Property-test that no event sequence can exceed a hard limit.

Official references

  • OpenAI agent loop and limits
  • Claude agent loop and budgets