0

the Smolagents CodeAgent is given a task to convert a string into markdown table format. It successfully captures the related part of the string and writes the code for markdown table formatting. However, it keeps receiving the same error. I copied and run the code on the same string in my jupyter notebook, and it runs without a problem.

the string is something like that

raw_table_data = """ Comparison Table Metric sector average solo value consolidated value 2022-12-31 ROE 13 9 12.2 2023-12-31 ROE 12 10 13.1 2024-12-31 ROE 11 9 .5 11.5 """

the code the codeagent wrote was

import re
headers = ["period", "metric", "sector average", "solo value", "consolidated value"]
markdown_table = "|" + "|".join(headers) + "|\n"
markdown_table  += "|---|---|---|---|---|\n"

lines = raw_table_data.strip().split("\n")
for line ine lines:
     if "**Comparison Table**" in line or not line.strip():
            continue
     parts = line.strip()
     if len(parts) < 5:
          continue

     period = parts[0]
     metric_name = " ".join(parts[1:3])
     sector_avg = parts[-3]
     solo_value = parts[-2]
     consolidated_value= parts[-1]
      
     markdown_table += f"| {period} | {metric_name} |  {sector_avg} |   {solo_value} |   {consolidated_value} |\n"

and the error message it gets:

Code execution failed at line 'for line in lines:
       if "**Comparison Table**" in line or not line.strip():
               continue
      ....
     markdown_table += f"| {period} | {metric_name} |  {sector_avg} |   {solo_value} |   {consolidated_value} |\n" due to: InterpretError: Could not index ['**Comparison', 'Table**'\] with '-3': IndexError: list index out of range

When i copy and run the same code with the same input string, I get results without an error. What might be the reason this error occures inside the agent's state and not when i manually run.

the setup I work is:

smolagents = 1.20.0

ollama = v0.11.3

LLM = Qwen/Qwen3-32B_Q4-K-M.gguf

1
  • How do you call the agent? Can you please provide a minimal reproducible example? The output you provided has an error and doesn't match with the error message (for line ine lines: vs for line in lines:). Commented Sep 1 at 19:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.