Skip to content

Commit 4aa31ad

Browse files
Add error handling to agent cycle execution in run_agent_cycles function
1 parent e9b113b commit 4aa31ad

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

src/smolagents/bp_thinkers.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,18 +1029,21 @@ def run_agent_cycles(
10291029
# save the current folder for later restoration
10301030
original_folder = os.getcwd()
10311031
for i in range(cycles_cnt):
1032-
print("Running agent cycle:", i)
1033-
# restore the original folder
1034-
os.chdir(original_folder)
1035-
local_agent = get_default_thinker_agent(
1036-
model=model,
1037-
system_prompt=system_prompt,
1038-
tools=tools,
1039-
add_base_tools=add_base_tools,
1040-
max_steps=max_steps,
1041-
step_callbacks=step_callbacks,
1042-
executor_type=executor_type,
1043-
log_level=log_level,
1044-
planning_interval=planning_interval
1045-
)
1046-
local_agent.run(task_str, reset=True)
1032+
try:
1033+
print("Running agent cycle:", i)
1034+
# restore the original folder
1035+
os.chdir(original_folder)
1036+
local_agent = get_default_thinker_agent(
1037+
model=model,
1038+
system_prompt=system_prompt,
1039+
tools=tools,
1040+
add_base_tools=add_base_tools,
1041+
max_steps=max_steps,
1042+
step_callbacks=step_callbacks,
1043+
executor_type=executor_type,
1044+
log_level=log_level,
1045+
planning_interval=planning_interval
1046+
)
1047+
local_agent.run(task_str, reset=True)
1048+
except Exception as e:
1049+
print(f"Exception: {e}", "at cycle", i)

0 commit comments

Comments
 (0)