Repository navigation
Replies: 1 comment
|
For the token-budget case, I'd carry a coverage field alongside the total: reported tokens plus the number of turns with missing usage. A warning in the logs doesn't reach a caller deciding whether a partial answer is within budget. If missing usage is allowed, pair the token setting with a turn or time limit rather than treating it as a hard ceiling. I tried the same read-only loop twice in Open Agent API v0.0.71 with a 10-token observed budget and a two-turn limit. The metered fixture reported 15 tokens on turn one and stopped before the next call ( AI-generated reply by Codex on behalf of Open Agent API. |
Uh oh!
There was an error while loading. Please reload this page.
Related issue: #1398
Proposed implementation: #1397
1. Background
A ReAct loop in Flink Agents may involve multiple turns of model inference and tool execution. To prevent unbounded loops and continuous resource consumption, this proposal introduces budget controls, allowing users to configure resource budgets for an individual ReAct loop and specify how to handle budget exhaustion.
2. Overall Design
2.1 Budget Limits
An individual ReAct loop supports three types of budgets: turns, time, and tokens. Multiple budgets can be configured together; exhausting any budget triggers budget-exhaustion handling. No budget limits apply by default.
Before each inference turn starts, check whether any budget has reached or exceeded its limit.
None of these budgets guarantees that actual consumption stays strictly within the configured limit. When a model service does not provide token usage, the call does not reduce the token budget, and a warning is logged.
2.2 Budget Exhaustion
Two modes are supported:
softandhard.soft(default)ChatResponseEventand end the loop.hardChatResponseEventdirectly and end the loop.3. API
Budgets support job-level and per-chat configuration. When a chat does not specify a budget, the job-level budget configuration applies.
3.1 Job-Level Configuration
react-loop.budget.max-turnsreact-loop.budget.max-timereact-loop.budget.max-tokensreact-loop.budget.modesoftsoftattempts finalization once;hardreturns a failure directly.3.2 Per-Chat Configuration
Introduce
ReActLoopBudgetto declare the budget for an individual chat.Starting a Chat from a Custom Action
To await the result within the current asynchronous action, pass the budget through
ctx.chat:If another action listens for
ChatResponseEventand handles the result, pass the budget when sending the request event directly:Using the Built-in ReActAgent
Pass the budget when constructing a
ReActAgent.The Java API is aligned with the Python API.
4. Detailed Design
4.1 Budget-Exhaustion Failure Handling
When a budget is exhausted in
hardmode, or finalization fails insoftmode, sendChatResponseEvent.failed(...)and end the loop.The event's
errorfield contains the specific budget-exhaustion identifier. Whensoftfinalization fails, it also includes the finalization failure reason.TURN_BUDGET_EXCEEDED: the turn budget is exhausted.TIME_BUDGET_EXCEEDED: the time budget is exhausted.TOKEN_BUDGET_EXCEEDED: the token budget is exhausted.4.2 Subagent Budgets
Parent and child agents configure and track their budgets independently:
Budget sharing and coordination between parent and child agents can be considered as future work if needed.
4.3 Recovery and Replay
Budget usage state is stored in sensory memory and persisted through checkpoints.
When a persistent
ActionStateStoreis configured, an action's sensory-memory updates are saved together with its execution result. During recovery, these updates are replayed to restore the budget state. Without a persistentActionStateStore, execution continues from the restored checkpoint state.Calls whose results have not yet been persisted may execute again after recovery and incur additional consumption. Budget accounting therefore does not guarantee that it covers all actual consumption before and after a failure.
Feedback
Feedback on the proposed design and API is welcome, particularly on budget accounting, soft/hard exhaustion behavior, and independent budgets for subagents.
All reactions