Skip to content

Commit 78f0a71

Browse files
Revert "fix: resolve BudgetExceededError CLI traceback issues (fixes #1627) (…" (#1642)
This reverts commit 2e05f2c.
1 parent e01f63d commit 78f0a71

2 files changed

Lines changed: 29 additions & 101 deletions

File tree

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

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

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,6 @@ def __init__(
544544
verification_hooks: Optional[List[Any]] = None, # Deprecated: use autonomy=AutonomyConfig(verification_hooks=[...])
545545
output: Optional[Union[bool, str, Dict[str, Any], 'OutputConfig']] = None,
546546
execution: Optional[Union[bool, str, Dict[str, Any], 'ExecutionConfig']] = None,
547-
max_budget: Optional[float] = None, # Budget limit in USD - convenience alias for ExecutionConfig(max_budget=...)
548547
templates: Optional[Union[Dict[str, Any], 'TemplateConfig']] = None,
549548
caching: Optional[Union[bool, str, Dict[str, Any], 'CachingConfig']] = None,
550549
hooks: Optional[Union[List[Any], Dict[str, Any], 'HooksConfig']] = None,
@@ -623,9 +622,6 @@ def __init__(
623622
- Dict[str, Any]: Config overrides (e.g. {"max_iter": 10, "max_rpm": 60})
624623
- ExecutionConfig: Custom configuration
625624
Controls: max_iter, max_rpm, max_execution_time, max_retry_limit
626-
max_budget: Budget limit in USD (convenience alias). Creates ExecutionConfig(max_budget=value).
627-
If both execution.max_budget and max_budget are provided, max_budget takes precedence.
628-
Use execution=ExecutionConfig(...) for full execution control.
629625
templates: Template configuration. Accepts:
630626
- Dict[str, Any]: Template fields (e.g. {"system": "...", "prompt": "..."})
631627
- TemplateConfig: Custom configuration
@@ -737,42 +733,6 @@ def __init__(
737733
web = apply_config_defaults("web", web, WebConfig)
738734
if output is None:
739735
output = apply_config_defaults("output", output, OutputConfig)
740-
741-
# Handle max_budget convenience parameter
742-
if max_budget is not None:
743-
from ..config.feature_configs import ExecutionConfig, resolve_execution
744-
if execution is None:
745-
execution = ExecutionConfig(max_budget=max_budget)
746-
else:
747-
# If execution config is already provided, merge max_budget into it
748-
resolved_exec = resolve_execution(execution)
749-
if resolved_exec is None:
750-
execution = ExecutionConfig(max_budget=max_budget)
751-
else:
752-
# Update existing config with max_budget
753-
if hasattr(resolved_exec, 'max_budget'):
754-
if (
755-
resolved_exec.max_budget is not None
756-
and resolved_exec.max_budget != max_budget
757-
):
758-
import warnings
759-
warnings.warn(
760-
(
761-
f"Both execution.max_budget={resolved_exec.max_budget} and "
762-
f"max_budget={max_budget} were provided; "
763-
"using max_budget."
764-
),
765-
UserWarning,
766-
stacklevel=3,
767-
)
768-
# Use dataclasses.replace to avoid mutating shared state
769-
import dataclasses
770-
execution = dataclasses.replace(resolved_exec, max_budget=max_budget)
771-
elif not hasattr(resolved_exec, 'max_budget'):
772-
# Fallback for older config objects
773-
import dataclasses
774-
execution = dataclasses.replace(resolved_exec, max_budget=max_budget)
775-
776736
if execution is None:
777737
execution = apply_config_defaults("execution", execution, ExecutionConfig)
778738
if caching is None:

src/praisonai/praisonai/cli/main.py

Lines changed: 29 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4065,38 +4065,6 @@ def _run_inline_workflow(self, initial_prompt):
40654065

40664066
return results[-1].get("output", "") if results else ""
40674067

4068-
def _execute_agent_with_budget_handling(self, agent, method_name, *args, **kwargs):
4069-
"""
4070-
Execute an agent method with graceful BudgetExceededError handling.
4071-
4072-
Args:
4073-
agent: The agent instance
4074-
method_name: Name of the method to call ('start' or 'chat')
4075-
*args, **kwargs: Arguments to pass to the method
4076-
4077-
Returns:
4078-
The result of the agent method call
4079-
4080-
Raises:
4081-
SystemExit: On BudgetExceededError with clean error message
4082-
Exception: Re-raises any other exceptions
4083-
"""
4084-
try:
4085-
method = getattr(agent, method_name)
4086-
return method(*args, **kwargs)
4087-
except Exception as e:
4088-
# Handle BudgetExceededError gracefully
4089-
from praisonaiagents.errors import BudgetExceededError
4090-
4091-
if isinstance(e, BudgetExceededError):
4092-
from rich import print as rich_print
4093-
# Single-line error message with actionable guidance
4094-
rich_print(f"[red]Budget limit exceeded: {e!s} - Set max_budget parameter (e.g., Agent(max_budget=1.00))[/red]")
4095-
sys.exit(1)
4096-
else:
4097-
# Re-raise other exceptions
4098-
raise
4099-
41004068
def _extract_cli_config_for_yaml(self):
41014069
"""
41024070
Extract CLI configuration that should be passed to YAML processing.
@@ -4643,26 +4611,26 @@ def level_based_approve(function_name, arguments, risk_level):
46434611
from rich.panel import Panel
46444612

46454613
with Live(Panel(Spinner("dots", text="Generating..."), border_style="cyan"), refresh_per_second=10, transient=True):
4646-
result = self._execute_agent_with_budget_handling(auto_rag, 'chat', prompt)
4614+
result = auto_rag.chat(prompt)
46474615
else:
4648-
result = self._execute_agent_with_budget_handling(auto_rag, 'chat', prompt)
4616+
result = auto_rag.chat(prompt)
46494617
else:
46504618
# Resolve display mode from CLI flags
46514619
display_mode = self._resolve_display_mode()
46524620

46534621
if display_mode == 'silent':
46544622
# -qq: No output at all, exit code only
46554623
if hasattr(agent, 'start'):
4656-
result = self._execute_agent_with_budget_handling(agent, 'start', prompt)
4624+
result = agent.start(prompt)
46574625
else:
4658-
result = self._execute_agent_with_budget_handling(agent, 'chat', prompt)
4626+
result = agent.chat(prompt)
46594627

46604628
elif display_mode == 'quiet':
46614629
# -q: Result only, no spinners or status
46624630
if hasattr(agent, 'start'):
4663-
result = self._execute_agent_with_budget_handling(agent, 'start', prompt)
4631+
result = agent.start(prompt)
46644632
else:
4665-
result = self._execute_agent_with_budget_handling(agent, 'chat', prompt)
4633+
result = agent.chat(prompt)
46664634
if result is not None:
46674635
output = getattr(result, 'output', None) or (str(result) if result else None)
46684636
if output:
@@ -4674,31 +4642,31 @@ def level_based_approve(function_name, arguments, risk_level):
46744642
from praisonaiagents.output.status import enable_status_output, disable_status_output
46754643
enable_status_output(show_timestamps=True, show_metrics=True)
46764644
if hasattr(agent, 'start'):
4677-
result = self._execute_agent_with_budget_handling(agent, 'start', prompt)
4645+
result = agent.start(prompt)
46784646
else:
4679-
result = self._execute_agent_with_budget_handling(agent, 'chat', prompt)
4647+
result = agent.chat(prompt)
46804648
disable_status_output()
46814649
except ImportError:
46824650
if hasattr(agent, 'start'):
4683-
result = self._execute_agent_with_budget_handling(agent, 'start', prompt)
4651+
result = agent.start(prompt)
46844652
else:
4685-
result = self._execute_agent_with_budget_handling(agent, 'chat', prompt)
4653+
result = agent.chat(prompt)
46864654

46874655
elif display_mode == 'debug':
46884656
# -vv: SDK TraceOutput with markdown rendering
46894657
try:
46904658
from praisonaiagents.output.trace import enable_trace_output, disable_trace_output
46914659
enable_trace_output(use_markdown=True)
46924660
if hasattr(agent, 'start'):
4693-
result = self._execute_agent_with_budget_handling(agent, 'start', prompt)
4661+
result = agent.start(prompt)
46944662
else:
4695-
result = self._execute_agent_with_budget_handling(agent, 'chat', prompt)
4663+
result = agent.chat(prompt)
46964664
disable_trace_output()
46974665
except ImportError:
46984666
if hasattr(agent, 'start'):
4699-
result = self._execute_agent_with_budget_handling(agent, 'start', prompt)
4667+
result = agent.start(prompt)
47004668
else:
4701-
result = self._execute_agent_with_budget_handling(agent, 'chat', prompt)
4669+
result = agent.chat(prompt)
47024670

47034671
elif display_mode == 'jsonl':
47044672
# --output jsonl: JSONL structured output for CI/CD
@@ -4720,9 +4688,9 @@ def level_based_approve(function_name, arguments, risk_level):
47204688

47214689
start_time = time.time()
47224690
if hasattr(agent, 'start'):
4723-
result = self._execute_agent_with_budget_handling(agent, 'start', prompt)
4691+
result = agent.start(prompt)
47244692
else:
4725-
result = self._execute_agent_with_budget_handling(agent, 'chat', prompt)
4693+
result = agent.chat(prompt)
47264694

47274695
# Emit final result
47284696
reason = getattr(result, 'completion_reason', None) if hasattr(result, 'completion_reason') else 'complete'
@@ -4741,9 +4709,9 @@ def level_based_approve(function_name, arguments, risk_level):
47414709
import json as json_mod
47424710
start_time = time.time()
47434711
if hasattr(agent, 'start'):
4744-
result = self._execute_agent_with_budget_handling(agent, 'start', prompt)
4712+
result = agent.start(prompt)
47454713
else:
4746-
result = self._execute_agent_with_budget_handling(agent, 'chat', prompt)
4714+
result = agent.chat(prompt)
47474715

47484716
output = result.output if hasattr(result, 'output') else str(result)
47494717
envelope = {
@@ -4764,15 +4732,15 @@ def level_based_approve(function_name, arguments, risk_level):
47644732
flow = track_workflow()
47654733
flow.start()
47664734
if hasattr(agent, 'start'):
4767-
result = self._execute_agent_with_budget_handling(agent, 'start', prompt)
4735+
result = agent.start(prompt)
47684736
else:
4769-
result = self._execute_agent_with_budget_handling(agent, 'chat', prompt)
4737+
result = agent.chat(prompt)
47704738
flow.stop()
47714739
except ImportError:
47724740
if hasattr(agent, 'start'):
4773-
result = self._execute_agent_with_budget_handling(agent, 'start', prompt)
4741+
result = agent.start(prompt)
47744742
else:
4775-
result = self._execute_agent_with_budget_handling(agent, 'chat', prompt)
4743+
result = agent.chat(prompt)
47764744

47774745
elif display_mode == 'editor':
47784746
# --output editor: User-friendly step-by-step format
@@ -4782,9 +4750,9 @@ def level_based_approve(function_name, arguments, risk_level):
47824750

47834751
# Run agent
47844752
if hasattr(agent, 'start'):
4785-
result = self._execute_agent_with_budget_handling(agent, 'start', prompt)
4753+
result = agent.start(prompt)
47864754
else:
4787-
result = self._execute_agent_with_budget_handling(agent, 'chat', prompt)
4755+
result = agent.chat(prompt)
47884756

47894757
# SDK callbacks (interaction, llm_content) handle display —
47904758
# no explicit editor.output() needed here.
@@ -4806,15 +4774,15 @@ def level_based_approve(function_name, arguments, risk_level):
48064774
from praisonaiagents.output.status import enable_status_output, disable_status_output
48074775
enable_status_output(show_timestamps=False, show_metrics=False)
48084776
if hasattr(agent, 'start'):
4809-
result = self._execute_agent_with_budget_handling(agent, 'start', prompt)
4777+
result = agent.start(prompt)
48104778
else:
4811-
result = self._execute_agent_with_budget_handling(agent, 'chat', prompt)
4779+
result = agent.chat(prompt)
48124780
disable_status_output()
48134781
except ImportError:
48144782
if hasattr(agent, 'start'):
4815-
result = self._execute_agent_with_budget_handling(agent, 'start', prompt)
4783+
result = agent.start(prompt)
48164784
else:
4817-
result = self._execute_agent_with_budget_handling(agent, 'chat', prompt)
4785+
result = agent.chat(prompt)
48184786

48194787
# ===== POST-PROCESSING WITH NEW FEATURES =====
48204788

@@ -4892,7 +4860,7 @@ def level_based_approve(function_name, arguments, risk_level):
48924860
Now, {final_instruction.lower()}:"""
48934861

48944862
final_agent = PraisonAgent(**final_agent_config)
4895-
result = self._execute_agent_with_budget_handling(final_agent, 'start', final_prompt)
4863+
result = final_agent.start(final_prompt)
48964864
print(f"\n[bold green]✅ Final agent processing complete[/bold green]\n")
48974865

48984866
# Save output if --save is enabled

0 commit comments

Comments
 (0)