Description
Updated planning prompts do not receive a usable remaining-step budget.
All three built-in prompt templates contain the single-braced text {remaining_steps}. populate_template() uses Jinja with StrictUndefined, so that text is not interpolated and reaches the model verbatim.
There is a second issue on the same data path: _generate_planning_step() derives the value from self.max_steps. When run(..., max_steps=N) overrides the configured default, the execution loop uses N, but planning still uses the constructor value.
Reproduction
from smolagents import CodeAgent
from smolagents.models import ChatMessage, MessageRole, Model
class RecordingModel(Model):
def __init__(self):
super().__init__(model_id="recording")
self.calls = []
def generate(self, messages, **kwargs):
self.calls.append(messages)
return ChatMessage(
role=MessageRole.ASSISTANT,
content="<code>\nprint(\"continue\")\n</code>",
)
model = RecordingModel()
agent = CodeAgent(
tools=[],
model=model,
max_steps=20,
planning_interval=1,
)
agent.run("demo", max_steps=3)
for messages in model.calls:
text = str(messages)
if "steps remaining" in text:
print(text)
The update-planning requests contain:
Beware that you have {remaining_steps} steps remaining.
After correcting the Jinja syntax alone, step 2 would still be calculated from 20 - 2 rather than the effective per-run budget 3 - 2.
Expected behavior
- The built-in CodeAgent, structured CodeAgent, and ToolCallingAgent planning templates render a numeric remaining-step value.
- The value comes from the effective budget of the current run, including a
run(max_steps=...) override.
- Regression tests cover every built-in planning template and the per-run override path.
Environment
- smolagents:
1.27.0.dev0 at e3a5b8994b301983b91c0325546e9dc82eab8cf0
- Python: 3.12.13
- OS: macOS
Description
Updated planning prompts do not receive a usable remaining-step budget.
All three built-in prompt templates contain the single-braced text
{remaining_steps}.populate_template()uses Jinja withStrictUndefined, so that text is not interpolated and reaches the model verbatim.There is a second issue on the same data path:
_generate_planning_step()derives the value fromself.max_steps. Whenrun(..., max_steps=N)overrides the configured default, the execution loop usesN, but planning still uses the constructor value.Reproduction
The update-planning requests contain:
After correcting the Jinja syntax alone, step 2 would still be calculated from
20 - 2rather than the effective per-run budget3 - 2.Expected behavior
run(max_steps=...)override.Environment
1.27.0.dev0ate3a5b8994b301983b91c0325546e9dc82eab8cf0