jd-opensource/joyagent-jdgenie · error · AgentExecutionError
{error_msg}
Error message
{error_msg} What it means
smolagents-style CodeAgent raises AgentExecutionError in _step_stream when executing the generated code in the sandbox fails (runtime exception in the model-written Python, tool error, or forbidden import). The sandbox error message is passed through verbatim.
Solutions
- Read the wrapped error_msg to see the actual sandbox exception and fix the model prompt or the code
- Pass additional_authorized_imports=[...] to CodeAgent when the model legitimately needs imports like requests or numpy
- Add the failing packages to the execution environment the sandbox uses
- Increase max_iterations / improve the system prompt so the agent can self-correct on execution failures
Example fix
# before agent = CodeAgent(tools=[python_interpreter]) # model code 'import requests' -> AgentExecutionError: Import of requests is not allowed # after agent = CodeAgent(tools=[python_interpreter], additional_authorized_imports=["requests"])
Defensive patterns
Strategy: try-catch
Validate before calling
authorized = {"os", "math"} | set(additional_authorized_imports)
imports = set(re.findall(r'^\s*(?:import|from)\s+(\w+)', generated_code, re.M))
missing = imports - authorized # pass missing into additional_authorized_imports first Try / catch
from smolagents import AgentExecutionError
try:
result = agent.run(task)
except AgentExecutionError as e:
if 'is not allowed' in str(e):
agent.authorized_imports += [extracted_module]
logger.warning('execution failed: %s', e) Prevention
- List all needed modules in additional_authorized_imports at init
- Ensure sandbox image has required packages installed
- Review execution_logs after each run to catch recurring failures
- Improve prompts so generated code handles exceptions itself
When it happens
Trigger: Any exception raised while running the model-generated code via the python interpreter (sandboxed_executor/execute_python_code), including unauthorized imports detected by the sandbox ("Import of X is not allowed").
Common situations: Model writes code calling libraries not in additional_authorized_imports; generated code hits NameError/ZeroDivisionError; sandbox lacks packages the model assumed (requests, pandas); model calls undefined functions.
Related errors
- Empty or invalid response from LLM
- Invalid tool_choice: " + toolChoice
- Invalid or empty response from LLM
- Error in generating model output
- Error in code parsing
AI-assisted analysis of jd-opensource/joyagent-jdgenie@2417e0b8b6 (2026-09-08).
Data as JSON: /api/errors/0a28eba470b63bfa.
Report an issue: GitHub.
Appendix: source
Thrown at genie-tool/genie_tool/tool/ci_agent.py:197
):
execution_logs = str(self.python_executor.state["_print_outputs"])
if len(execution_logs) > 0:
execution_outputs_console = [
Text("Execution logs:", style="bold"),
Text(execution_logs),
]
memory_step.observations = "Execution logs:\n" + execution_logs
self.logger.log(
Group(*execution_outputs_console), level=LogLevel.INFO
)
error_msg = str(e)
if "Import of " in error_msg and " is not allowed" in error_msg:
self.logger.log(
"[bold red]Warning to user: Code execution failed due to an unauthorized import - Consider passing said import under `additional_authorized_imports` when initializing your CodeAgent.",
level=LogLevel.INFO,
)
raise AgentExecutionError(error_msg, self.logger)
memory_step.observations = observation
finalObj = FinalAnswerCheck(
input_messages=self.input_messages,
execution_logs=execution_logs,
model=self.model,
task=self.task,
prompt_temps=self.prompt_templates,
memory_step=memory_step,
grammar=self.grammar,
request_id=f"{model_request_id}-final",
)
finalFlag, exeLog = finalObj.check_is_final_answer()
self.logger.log(Group(*execution_outputs_console), level=LogLevel.INFO)
# self.logger.log(f"check finalanswer 已完成 {finalFlag} {str(exeLog)}")
memory_step.action_output = exeLog
View on GitHub (pinned to 2417e0b8b6)