Hi Everyone,
I am hitting the following error while building my first space using the first_agent_template from the AI course. anyone faced similar situation, could you please advice how did you overcome this error?
runtime error
Exit code: 1. Reason: Traceback (most recent call last):
File “/home/user/app/app.py”, line 1, in
from smolagents import CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, InferenceClientModel, load_tool, tool
ImportError: cannot import name ‘InferenceClientModel’ from ‘smolagents’ (/usr/local/lib/python3.10/site-packages/smolagents/init.py)
Container logs:
===== Application Startup at 2025-07-14 21:51:54 =====
Traceback (most recent call last):
File “/home/user/app/app.py”, line 1, in
from smolagents import CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, InferenceClientModel, load_tool, tool
ImportError: cannot import name ‘InferenceClientModel’ from ‘smolagents’ (/usr/local/lib/python3.10/site-packages/smolagents/init.py)
Traceback (most recent call last):
File “/home/user/app/app.py”, line 1, in
from smolagents import CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, InferenceClientModel, load_tool, tool
ImportError: cannot import name ‘InferenceClientModel’ from ‘smolagents’ (/usr/local/lib/python3.10/site-packages/smolagents/init.py)
1 Like
It is probably because the version of the smolegents
library is not compatible. InferenceClientModel
was formerly known as HfApiModel
.
Therefore, I recommend updating the version of the smolegents
library or using HfApiModel
.
Updating smolagents
pip install -U smolagents
Use HfApiModel with older smolagents
pip install smolagents==1.13.0
Appreciate your update, John.
could you please direct me to upgrade the smolagents here? i mean from where i need to run
pip install -U smolagents
1 Like
I tried with
pip install smolagents==1.14.0 in requirement.txt
hitting the following error
===== Application Startup at 2025-07-15 02:29:28 =====
tool.py: 0%| | 0.00/635 [00:00<?, ?B/s]
tool.py: 100%|██████████| 635/635 [00:00<00:00, 5.56MB/s]
Traceback (most recent call last):
File “/home/user/app/app.py”, line 57, in
agent = CodeAgent(
File “/usr/local/lib/python3.10/site-packages/smolagents/agents.py”, line 1248, in init
super().init(
File “/usr/local/lib/python3.10/site-packages/smolagents/agents.py”, line 214, in init
assert not missing_keys, (
AssertionError: Some prompt templates are missing from your custom prompt_templates
: {‘final_answer’}
tool.py: 0%| | 0.00/635 [00:00<?, ?B/s]
tool.py: 100%|██████████| 635/635 [00:00<00:00, 4.18MB/s]
Traceback (most recent call last):
File “/home/user/app/app.py”, line 57, in
agent = CodeAgent(
File “/usr/local/lib/python3.10/site-packages/smolagents/agents.py”, line 1248, in init
super().init(
File “/usr/local/lib/python3.10/site-packages/smolagents/agents.py”, line 214, in init
assert not missing_keys, (
AssertionError: Some prompt templates are missing from your custom prompt_templates
: {‘final_answer’}
1 Like
AssertionError: Some prompt templates are missing from your custom prompt_templates
: {‘final_answer’}
smolagents==1.14.0
Yeah. That’s why smolagents==1.13.0
in official template. Might be solved in 1.20.0
(latest).
Thanks. I went with HFAPI instead of inferenceClientmodel. I modified the template script to use the tool to get time stamp. now , it is running but whatever prompt i give, it is throwing “error” message. any thoughts
1 Like
To find the cause, click here to view the log. If only “Error” is displayed, it is impossible to determine the specific issue.
Thanks for your continuous support
error from log
response = await route_utils.call_process_api( File “/usr/local/lib/python3.10/site-packages/gradio/route_utils.py”, line 322, in call_process_api output = await app.get_blocks().process_api( File “/usr/local/lib/python3.10/site-packages/gradio/blocks.py”, line 2137, in process_api result = await self.call_function( File “/usr/local/lib/python3.10/site-packages/gradio/blocks.py”, line 1675, in call_function prediction = await utils.async_iteration(iterator) File “/usr/local/lib/python3.10/site-packages/gradio/utils.py”, line 735, in async_iteration return await anext(iterator) File “/usr/local/lib/python3.10/site-packages/gradio/utils.py”, line 729, in anext return await anyio.to_thread.run_sync( File “/usr/local/lib/python3.10/site-packages/anyio/to_thread.py”, line 56, in run_sync return await get_async_backend().run_sync_in_worker_thread( File “/usr/local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py”, line 2470, in run_sync_in_worker_thread return await future File “/usr/local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py”, line 967, in run result = context.run(func, *args) File “/usr/local/lib/python3.10/site-packages/gradio/utils.py”, line 712, in run_sync_iterator_async return next(iterator) File “/usr/local/lib/python3.10/site-packages/gradio/utils.py”, line 873, in gen_wrapper response = next(iterator) File “/home/user/app/Gradio_UI.py”, line 197, in interact_with_agent for msg in stream_to_gradio(self.agent, task=prompt, reset_agent_memory=False): File “/home/user/app/Gradio_UI.py”, line 145, in stream_to_gradio total_input_tokens += agent.model.last_input_token_count TypeError: unsupported operand type(s) for +=: ‘int’ and ‘NoneType’
1 Like
TypeError: unsupported operand type(s) for +=: ‘int’ and ‘NoneType’
This error can probably be avoided by adding pydantic==2.10.6
to requirements.txt
. Probably.