Unable to run CodeAgent withlocal trasformers

I’m trying to run this piece of code that i have found in the docs Agents - Guided tour

from smolagents import CodeAgent, TransformersModel

model_id = “meta-llama/Llama-3.2-3B-Instruct”

model = TransformersModel(model_id=model_id)
agent = CodeAgent(tools=, model=model, add_base_tools=True)

agent.run(
“Could you give me the 118th number in the Fibonacci sequence?”,
)

At step 1, it gives me this output:

*Executing parsed code: ────────────────────────────────────────────────────────────────────────────────────────

Generate the Fibonacci sequence up to the 120th number (since indexing starts at 0)

fibonacci_sequence = fibonacci(n=120)

Find the index of the 118th number in the sequence

index = index(fibonacci_sequence, 118)

Use the index to get the 118th number

answer = fibonacci_sequence[index]

print(f"The 118th number in the Fibonacci sequence is {answer}")
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Code execution failed at line ‘fibonacci_sequence = fibonacci(n=120)’ due to: InterpreterError: Forbidden function
evaluation: ‘fibonacci’ is not among the explicitly allowed tools or defined/imported in the preceding code*

I’m really stucked into this problem sice i would like to continue the agent course without using HfAPI
Is anyone able to tell me which is the problem?

1 Like

There are quite a few changes to the library, so I’m not sure what the exact cause is. It would be easy to work around it with code like this, but I’m not sure if it will work.

#agent = CodeAgent(tools=[], model=model, add_base_tools=True)
agent = CodeAgent(tools=, model=model, add_base_tools=True, additional_authorized_imports=["*"])

I have modified the code line for the agent as suggested but i still get the problem. I attach a screenshot so that the output is clearer.

1 Like

This is probably a library bug…:sweat_smile:

The ideal solution in this case is to fix the library. Alternatively, you can wait for it to be fixed or try to find a workaround yourself. However, in some cases, it may be quicker to try downgrading the library first.

pip install smalagents==1.13.0
pip install smalagents==1.12.0
pip install git+https://github.com/huggingface/smolagents
1 Like