Skip to content

Commit d755392

Browse files
author
praisonai-bot
committed
fix(agent): critical UnboundLocalError on Agent() without max_budget
PR #1635 introduced a local 'from ... import ExecutionConfig' inside __init__ (line 743 inside 'if max_budget is not None:' branch). Per Python scoping rules, a name assigned anywhere in a function is treated as local throughout the entire function. When max_budget is None (the common case), the local branch never executes but line 777 still hits 'ExecutionConfig' and raises UnboundLocalError, breaking every Agent() instantiation without max_budget. ExecutionConfig is already imported at module level (line 162-166). Only resolve_execution needs the local lazy import. Test: tests/unit/agent/test_scientific_writer_agent.py surfaced this; now passes along with 311 other agent unit tests.
1 parent a410bc8 commit d755392

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

  • src/praisonai-agents/praisonaiagents/agent

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,12 @@ def __init__(
740740

741741
# Handle max_budget convenience parameter
742742
if max_budget is not None:
743-
from ..config.feature_configs import ExecutionConfig, resolve_execution
743+
# NOTE: ExecutionConfig is imported at module level (see top of file).
744+
# Do NOT re-import it locally here — a local import statement would
745+
# make Python treat ExecutionConfig as a local name throughout this
746+
# entire __init__ function and break the branch below that uses it
747+
# when max_budget is None (UnboundLocalError).
748+
from ..config.feature_configs import resolve_execution
744749
if execution is None:
745750
execution = ExecutionConfig(max_budget=max_budget)
746751
else:

0 commit comments

Comments
 (0)