Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A5c ai Babysitter stack resolution cost enforcement

From Leeroopedia
Knowledge Sources
Domains Kubernetes, Cost_Management, Stack_Resolution
Last Updated 2026-10-23 00:00 GMT

Overview

Concrete tool for resolving agent stack execution configuration and enforcing budget limits during agent dispatch.

Description

Three functions in the agent dispatch controller handle stack resolution and cost enforcement:

  • resolveStack(stack, options) — Translates an AgentStack CRD into an ExecutionConfig with adapter, provider, model, prompt, MCP servers, skills, approval mode, env, and memory config.
  • estimateCost(event) — Computes the cost of a model usage event using per-model rate tables (Claude, GPT-4o, Gemini) with input/output token pricing. Falls back to a default rate for unknown models.
  • checkBudget(run, event) — Checks whether a usage event exceeds the run's budget limits (maxTokens or maxCostUsd). Returns { exceeded, reason, current, limit, totalTokens, totalCost }.

Usage

  • Agent dispatch Step 4: Resolve the stack and enforce budget before creating a K8s Job.

Code Reference

Source Location

  • Repository: Babysitter
  • File: packages/kradle/core/src/agent-dispatch-controller.js:L26-33 (estimateCost), L93-135 (resolveStack), L144-161 (checkBudget)

Signature

function resolveStack(stack, { organizationRef, identity }): ExecutionConfig;
// ExecutionConfig: { adapter, provider, model, prompt, mcpServers, skills, approvalMode, env, memoryConfig }

function estimateCost(event): number;
// event: { usage: { inputTokens, outputTokens }, model }

function checkBudget(run, event): {
  exceeded: boolean, reason?: string,
  current?: number, limit?: number,
  totalTokens?: number, totalCost?: number
};

Import

// Accessible via createAgentDispatchController
import { createAgentDispatchController } from "@a5c-ai/kradle";
const controller = createAgentDispatchController();

I/O Contract

Inputs

Name Type Required Description
stack AgentStack CRD Yes Stack with provider, model, adapter, budget
run.spec.budget.maxTokens number No Token budget limit
run.spec.budget.maxCostUsd number No Cost budget limit
event.usage object Yes (cost) { inputTokens, outputTokens }

Outputs

Name Type Description
ExecutionConfig object Adapter, provider, model, prompt, MCP servers, skills
cost number Estimated cost in USD
budgetCheck object exceeded flag, reason, totals

Usage Examples

Resolve Stack and Check Budget

const controller = createAgentDispatchController();

// Resolve the stack to execution config
const execConfig = controller.resolveStack(agentStack, {
  organizationRef: "my-org",
  identity: "user@example.com",
});
console.log("Provider:", execConfig.provider, "Model:", execConfig.model);

// Check budget after a usage event
const budgetCheck = controller.checkBudget(run, {
  usage: { inputTokens: 5000, outputTokens: 2000 },
  model: "claude-sonnet-4-20250514",
});

if (budgetCheck.exceeded) {
  console.error("Budget exceeded:", budgetCheck.reason);
}

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment