BUG: Premature validation of executor type in CodeAgent prevents subclassing. (original) (raw)

Problem
In CodeAgent.__init__, the executor type is validated before the executor is created.
This makes it impossible to subclass CodeAgent and override create_python_executor() to implement a custom executor, because the initialization raises a ValueError as soon as a non-standard executor_type is provided.

The validation logic should be inside create_python_executor() instead of the constructor.

Steps to reproduce

  1. Subclass CodeAgent to define a custom executor.
  2. Pass a custom executor_type (e.g., "my_executor") to the subclass.

from smolagents import CodeAgent

class CustomCodeAgent(CodeAgent): def create_python_executor(self): # Custom executor logic here return MyCustomExecutor()

agent = CustomCodeAgent( tools=[], model=my_model, executor_type="my_executor", # <- Raises error in init )

Actual behavior and error logs

ValueError: Unsupported executor type: my_executor

This happens even though the subclass overrides create_python_executor() and never relies on the base implementation.

Expected behavior
It should be possible to subclass CodeAgent and override create_python_executor() to support custom executors, without triggering a validation error in __init__.

Environment:

Additional context (optional)

For now, there is two workarounds:

from smolagents import CodeAgent

class CustomCodeAgent(CodeAgent): def init(self, *args, executor_type="my_executor", **kwargs): if executor_type == "my_executor": executor_type = "local" # Bypass validation super().init(*args, executor_type=executor_type, **kwargs) # To keep base init logic self.executor_type = "my_executor" # Restore custom type self.python_executor = self.create_python_executor()

def create_python_executorself):
    # Custom executor logic here
    return MyCustomExecutor()

Checklist