Skip to content

Commit 93ab728

Browse files
fix: restore backward compatibility and error handling (fixes critical regressions)
- Add back max_budget parameter to Agent constructor with deprecation warning - Restore BudgetExceededError handling in CLI with clean error messages - Implement compatibility for both max_budget param and ExecutionConfig.max_budget - Update all agent execution calls to use budget error handling wrapper Addresses reviewer feedback from CodeRabbit, Greptile, and Gemini regarding: - Breaking API change from removing max_budget parameter - BudgetExceededError regression causing raw tracebacks (issue #1627) Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
1 parent b2611e5 commit 93ab728

2 files changed

Lines changed: 176 additions & 34 deletions

File tree

  • src
    • praisonai-agents/praisonaiagents/agent
    • praisonai/praisonai/cli

src/praisonai-agents/praisonaiagents/agent/agent.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ def __init__(
555555
backend: Optional[Any] = None, # External managed agent backend (e.g., ManagedAgentIntegration)
556556
cli_backend: Optional[Union[str, Any]] = None, # CLI backend for delegating turns (e.g., "claude-code")
557557
interrupt_controller: Optional['InterruptController'] = None, # G2: Cooperative cancellation
558+
max_budget: Optional[float] = None, # Deprecated: use execution=ExecutionConfig(max_budget=...)
558559
):
559560
"""Initialize an Agent instance.
560561
@@ -576,6 +577,8 @@ def __init__(
576577
handoffs: List of Agent or Handoff objects for agent-to-agent collaboration.
577578
auto_save: **Deprecated** — use ``memory=MemoryConfig(auto_save="name")``.
578579
rate_limiter: **Deprecated** — use ``execution=ExecutionConfig(rate_limiter=obj)``.
580+
max_budget: **Deprecated** — use ``execution=ExecutionConfig(max_budget=...)``.
581+
Convenient alias for setting budget limits directly.
579582
memory: Memory system configuration. Accepts:
580583
- bool: True enables defaults, False disables
581584
- MemoryConfig: Custom configuration
@@ -787,6 +790,14 @@ def __init__(
787790
alternative="use 'execution=ExecutionConfig(rate_limiter=obj)' instead",
788791
stacklevel=3
789792
)
793+
if max_budget is not None:
794+
warn_deprecated_param(
795+
"max_budget",
796+
since="1.0.0",
797+
removal="2.0.0",
798+
alternative="use 'execution=ExecutionConfig(max_budget=...)' instead",
799+
stacklevel=3
800+
)
790801
# Note: parallel_tool_calls is NOT deprecated - it's a new Gap 2 feature
791802
# Both direct parameter and ExecutionConfig.parallel_tool_calls are supported
792803
if verification_hooks is not None:
@@ -969,10 +980,27 @@ def __init__(
969980
# Budget guard extraction
970981
_max_budget = getattr(_exec_config, 'max_budget', None)
971982
_on_budget_exceeded = getattr(_exec_config, 'on_budget_exceeded', 'stop') or 'stop'
983+
984+
# Override with deprecated max_budget parameter if provided (backward compatibility)
985+
if max_budget is not None:
986+
if _max_budget is not None:
987+
import warnings
988+
warnings.warn(
989+
f"Both 'max_budget' parameter and 'execution.max_budget' are set. "
990+
f"Using max_budget parameter (${max_budget}) over execution.max_budget (${_max_budget}). "
991+
f"Consider using only 'execution=ExecutionConfig(max_budget={max_budget})' instead.",
992+
DeprecationWarning,
993+
stacklevel=3
994+
)
995+
_max_budget = max_budget
972996
else:
973997
max_iter, max_rpm, max_execution_time, max_retry_limit = 20, None, None, 2
974998
_max_budget = None
975999
_on_budget_exceeded = 'stop'
1000+
1001+
# Apply deprecated max_budget parameter if provided (backward compatibility)
1002+
if max_budget is not None:
1003+
_max_budget = max_budget
9761004
# Keep parallel_tool_calls parameter value when no ExecutionConfig provided
9771005
# (already set from parameter, no need to override)
9781006

0 commit comments

Comments
 (0)