Critical: fix bug in new subagent tool call budget to not be session-level but tool call loop level
This commit is contained in:
parent
b84f9e410c
commit
e64d646bad
1 changed files with 9 additions and 2 deletions
11
run_agent.py
11
run_agent.py
|
|
@ -2879,13 +2879,15 @@ class AIAgent:
|
||||||
# Generate unique task_id if not provided to isolate VMs between concurrent tasks
|
# Generate unique task_id if not provided to isolate VMs between concurrent tasks
|
||||||
effective_task_id = task_id or str(uuid.uuid4())
|
effective_task_id = task_id or str(uuid.uuid4())
|
||||||
|
|
||||||
# Reset retry counters at the start of each conversation to prevent state leakage
|
# Reset retry counters and iteration budget at the start of each turn
|
||||||
|
# so subagent usage from a previous turn doesn't eat into the next one.
|
||||||
self._invalid_tool_retries = 0
|
self._invalid_tool_retries = 0
|
||||||
self._invalid_json_retries = 0
|
self._invalid_json_retries = 0
|
||||||
self._empty_content_retries = 0
|
self._empty_content_retries = 0
|
||||||
self._last_content_with_tools = None
|
self._last_content_with_tools = None
|
||||||
self._turns_since_memory = 0
|
self._turns_since_memory = 0
|
||||||
self._iters_since_skill = 0
|
self._iters_since_skill = 0
|
||||||
|
self.iteration_budget = IterationBudget(self.max_iterations)
|
||||||
|
|
||||||
# Initialize conversation (copy to avoid mutating the caller's list)
|
# Initialize conversation (copy to avoid mutating the caller's list)
|
||||||
messages = list(conversation_history) if conversation_history else []
|
messages = list(conversation_history) if conversation_history else []
|
||||||
|
|
@ -4044,7 +4046,12 @@ class AIAgent:
|
||||||
final_response = f"I apologize, but I encountered repeated errors: {error_msg}"
|
final_response = f"I apologize, but I encountered repeated errors: {error_msg}"
|
||||||
break
|
break
|
||||||
|
|
||||||
if api_call_count >= self.max_iterations and final_response is None:
|
if final_response is None and (
|
||||||
|
api_call_count >= self.max_iterations
|
||||||
|
or self.iteration_budget.remaining <= 0
|
||||||
|
):
|
||||||
|
if self.iteration_budget.remaining <= 0 and not self.quiet_mode:
|
||||||
|
print(f"\n⚠️ Session iteration budget exhausted ({self.iteration_budget.used}/{self.iteration_budget.max_total} used, including subagents)")
|
||||||
final_response = self._handle_max_iterations(messages, api_call_count)
|
final_response = self._handle_max_iterations(messages, api_call_count)
|
||||||
|
|
||||||
# Determine if conversation completed successfully
|
# Determine if conversation completed successfully
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue