Skip to content

Commit 2854774

Browse files
fix(cli): escape Rich markup in BudgetExceededError and use stderr
Fixes critical issues in budget error handler: - Escape exception message to prevent Rich MarkupError when str(BudgetExceededError) contains [budget] tags - Print error to stderr to avoid corrupting JSON/JSONL structured output - Apply budget handling to missing _run_inline_workflow call site Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
1 parent 4222121 commit 2854774

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/praisonai/praisonai/cli/main.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4027,7 +4027,7 @@ def _run_inline_workflow(self, initial_prompt):
40274027
)
40284028

40294029
try:
4030-
output = agent.chat(full_prompt)
4030+
output = self._execute_agent_with_budget_handling(agent, "chat", full_prompt)
40314031
results.append({"step": step_name, "status": "success", "output": output})
40324032
context = output # Pass output to next step
40334033
print(f"[green] ✓ Completed: {step_name}[/green]")
@@ -4083,10 +4083,14 @@ def _execute_agent_with_budget_handling(self, agent, method_name, *args, **kwarg
40834083
return getattr(agent, method_name)(*args, **kwargs)
40844084
except BudgetExceededError as e:
40854085
from rich import print as rich_print
4086+
from rich.markup import escape
4087+
import sys
4088+
# Use stderr to avoid corrupting JSON/JSONL output in structured modes
40864089
rich_print(
4087-
f"[red]Budget limit exceeded: {e!s}. "
4090+
f"[red]Budget limit exceeded: {escape(str(e))}. "
40884091
"Hint: set budget via "
4089-
"execution=ExecutionConfig(max_budget=1.00) on your Agent.[/red]"
4092+
"execution=ExecutionConfig(max_budget=1.00) on your Agent.[/red]",
4093+
file=sys.stderr
40904094
)
40914095
sys.exit(1)
40924096

0 commit comments

Comments
 (0)