All Agent Engineering

Finding tool errors and redundant calls in smolagents loops

From a multi-step log, write a diagnosis of tool inputs, error messages and deterministic work allocation.

AINavWritten / Updated
On this page

At a glance

When an agent keeps failing in its loop or repeats the same call, the cause may be an unclear tool description, missing information, a process that could be hard-coded, or simply a reasoning mistake by the model. The smolagents tutorial "Building good agents" offers clues for telling these cases apart. This entry turns it into a diagnosis sheet. The input is a multi-step run record, the failing tools and the current information flow; the deliverable is a list of changes to tool input descriptions, error messages and deterministic work allocation, with notes on which changes you still need to verify yourself.

Runtime and applicability

Article type
Engineering practice
Verified
Applies to
  • smolagents Finding tool errors and redundant calls in smolagents loops

Execution locations and responsibilities

  • smolagents Python runtime Use the workflow below to distinguish responsibilities of the caller, runtime, and external actions.
Engineering workflow order
Engineering workflow order1. Organize the run record → 2. Attribute each anomaly → 3. Revise the failing tool's inputs and error messages → 4. Find calls to merge or make deterministic → 5. Complete the information flow → 6. Only then consider a stronger model, planning or templates, and re-run to compare. Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.1. Organize the run record2. Attribute each anomaly3. Revise the failing tool's inputs and error messages4. Find calls to merge or make deterministic5. Complete the information flow6. Only then consider a stronger model, planning ortemplates, and re-run to compare

Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.

When to use

  • First decide what kind of problem each failure is. The tutorial notes that in agentic workflows some errors are real errors and others are the LLM not reasoning properly. Its example: the user receives a file path instead of an image because the model did not save the generated image to a variable and could only return the path it had logged, which is not a system defect. Attribute each anomaly before choosing between fixing a tool, adding information or changing the model.

When not to use

  • The tutorial supports switching to a stronger model with a single image-generation example and names Qwen2/5-72B-Instruct as an alternative that would not have made that mistake; this is specific to that example and gives no general guarantee, so whether it helps your task is yours to evaluate.
  • instructions is only appended to the system prompt; the tutorial does not describe how it interacts with a customized prompt_templates, so this entry does not cover that combination.
  • The tool code printed in the tutorial is illustrative, and its strptime call shows no format argument, so it cannot be copied as is.
  • Deterministic functions fit only steps that need no judgment; the material gives no general rule for deciding whether a given flow can be made deterministic, so that call depends on your own workload.

Prerequisites and input

  • A saved record of one multi-step run, including for each step the tool called, its arguments, and the result or error.
  • Permission to edit the relevant tool definitions; the ability to set instructions when the agent is created, and to pass the task text and additional_args when calling agent.run.
  • Knowledge of which parts of the workflow are actually fixed and do not need the model to decide each time.

Engineering checks

Evidence and attribution — First decide what kind of problem each failure is. The tutorial notes that in agentic workflows some errors are real errors and others are the LLM not reasoning properly. Its example: the user receives a file path instead of an image because the model did not save the generated image to a variable and could only return the path it had logged, which is not a system defect. Attribute each anomaly before choosing between fixing a tool, adding information or changing the model.

Tool contract and error messages — For a failing tool, check whether the argument formats are stated, whether the output is readable and whether failures are explained. In the tutorial's poor example, date_time has no format description, location has no description of how to write it, nothing is logged on failure and the output is hard to interpret. The improved version adds formats and an example, raises a ValueError with the expected format and the full exception text when conversion fails, and returns a readable weather sentence. The tutorial also recommends that tools use print to emit anything useful to the LLM, particularly details on execution errors.

Work allocation and information flow — Then check which calls can be removed. The tutorial's main guideline is to reduce the number of LLM calls: merge two tools into one where possible, and base logic on deterministic functions instead of agentic decisions. Separately, the model only knows what is explicitly put in its prompt, so the task, standing instructions, tool descriptions and extra objects each have their own place.

1. Organize the run record

Where: terminal output or logs you saved from the smolagents Python runtime. Input: the multi-step run record. Action: list each step with the tool, arguments, and result or error, plus the time and token fields if your output shows them, as the tutorial's sample trace does. Completion check: one row per step, with repeated and failed calls visible. Stop: if the log lacks arguments or error detail, add print output inside the tool as in step 3 and obtain a new record rather than guessing a cause.

2. Attribute each anomaly

Where: the collected logs and record table. Input: failed/repeated steps and actual errors. As a local diagnostic method distinguish tool implementation faults, runtime problems, external-service failures, unclear tool descriptions/errors, missing model information, reasoning mistakes and unknowns with insufficient evidence; these are work categories, not a documented fixed classification API. Record concrete evidence and an owner. The tutorial’s image-path example can suggest a missing stored variable but cannot explain every tool failure. Route confirmed implementation/runtime/service errors to the responsible owner for repair or escalation, and collect more logs when evidence is missing. Completion: each item has a category, evidence, owner and disposition. Stop unsupported attribution or externally consequential reruns while evidence is incomplete instead of forcing faults into a reasoning category.

3. Revise the failing tool's inputs and error messages

Where: the definition of the failing tool. Input: records attributed to the tool. Action: state the format of parameters such as date_time and the expected form of location; when conversion fails, raise a ValueError carrying the expected format and the full exception text; have the tool print information useful to the model, which the tutorial places in the forward method; and make the output easy to read. Completion check: apply the tutorial's test, asking whether a newcomer using the tool for the first time could fix their own mistake from the description and the error. Stop: if the format to document depends on the real behavior of an external service and the material does not give it, record it as to be confirmed instead of inventing it. Note that the printed tutorial code shows no format argument for strptime, so treat it as an illustration of message design, not verified code.

4. Find calls to merge or make deterministic

Where: repeated calls in the record table and the tool list. Input: calls that always appear together and flows with a fixed order. Action: as in the tutorial, merge two tools that are always used together, like its single tool that calls both a distance API and a weather API, and turn logic that needs no judgment into a deterministic function. Completion check: each merge or fixed flow states which LLM calls it should remove; this is an estimate, not a measured figure. Stop: if the order of calls depends on the model's judgment about content, do not make it deterministic.

5. Complete the information flow

Where: three different call sites. The instructions argument when the agent is created; the task text and additional_args in the agent.run call; and each tool's description. Input: records attributed to missing information. Action: put task specifics into the task text passed to run; put rules that should always apply in instructions at agent creation, which the tutorial says are appended to the system prompt and do not replace it; put tool-specific usage into that tool's description; pass audio, images or other objects through additional_args in the run call. Completion check: each missing piece of information has a stated home, marked as creation-time or run-time. Stop: do not touch prompt_templates in this step, since the tutorial does not advise it as a first move.

6. Only then consider a stronger model, planning or templates, and re-run to compare

Where: the agent creation code, then the record from the new run. Input: anomalies that remain after the earlier steps. Action: per the tutorial, you may try a more powerful LLM, or set planning_interval so the agent runs a planning step between action steps; changing prompt_templates is generally not advised. Re-run and compare with the old record step by step. Completion check: the earlier failing steps are gone or explained. Stop: if the same error repeats, go back to step 2 and attribute it again instead of stacking more changes; changes you cannot re-run in your environment are marked unverified on the sheet.

Task example

This is a synthetic manual walkthrough and was not executed. Suppose a weather lookup tool fails on three consecutive steps with the arguments "tomorrow afternoon", "2026/11/13 3pm" and "11/13/26 15:00:00", and the error shows only a raw parsing exception. Attribution: the tool lacks a format description and a clear error, so it is a tool problem. Revision: state the single accepted time format and the place-name form in the parameter descriptions, and raise a ValueError with a format hint when parsing fails. The log also shows that every place triggers a distance call and then a weather call, so the two are merged into one tool. Hypothetical expected observations: on re-run, fewer failing steps and fewer calls. These have not been verified; the reader should compare against their own run records.

Completion checks

  • Each failed or repeated step has a category, concrete log evidence, owner and repair/escalation/evidence-gathering branch; retain unknown causes instead of forcing a model attribution.
  • The failing tool states the argument formats, how place or identifier values should be written, the error message and the output form.
  • Each merge or deterministic decision names the calls it replaces and does not hard-code a flow that depends on the model's judgment.
  • Each piece of missing information is placed in the task text, instructions, a tool description or additional_args, distinguishing creation time from run time.
  • The re-run record was compared step by step with the old one, and changes that could not be re-run are marked unverified.

Verification scope

This entry is based only on the supplied smolagents "Building good agents" tutorial. The documentation was read, but installation, login, API execution and output were not tested; the observations in the walkthrough are hypothetical, not verified results.

Sources

All links are official pages; verification dates are listed per source, and links point to the version checked.

  1. smolagents · smolagents documentation: hf-multi

Found an error? Tell us →