PtcRunner.SubAgent.Loop.Budget (PtcRunner v0.10.1)

Copy Markdown View Source

Budget checking, callback handling, and fallback recovery for SubAgent execution.

Handles:

  • Budget callback/token_limit checking
  • Budget exhaustion with fallback attempts
  • Last-expression fallback recovery
  • Budget introspection maps for Lisp and Elixir callbacks

Summary

Functions

Build budget map for (budget/remaining) Lisp introspection. Uses hyphenated keys (idiomatic PTC-Lisp/Clojure).

Check if budget is exceeded via callback or token_limit. Returns :continue or :stop.

Handle budget exceeded — try fallback or return error.

Handle unified budget exhaustion (work + retry turns consumed) with fallback attempt.

Functions

build_introspection_map(agent, state)

@spec build_introspection_map(PtcRunner.SubAgent.Definition.t(), map()) :: map()

Build budget map for (budget/remaining) Lisp introspection. Uses hyphenated keys (idiomatic PTC-Lisp/Clojure).

check_callback(state)

@spec check_callback(map()) :: :continue | :stop

Check if budget is exceeded via callback or token_limit. Returns :continue or :stop.

handle_exceeded(agent, state)

@spec handle_exceeded(PtcRunner.SubAgent.Definition.t(), map()) ::
  {:ok | :error, PtcRunner.Step.t()}

Handle budget exceeded — try fallback or return error.

handle_exhausted_termination(agent, state)

@spec handle_exhausted_termination(PtcRunner.SubAgent.Definition.t(), map()) ::
  {:ok | :error, PtcRunner.Step.t()}

Handle unified budget exhaustion (work + retry turns consumed) with fallback attempt.