smolagents is Hugging Face’s small Python library for agents. Its OpenAIModel class “connects to an OpenAI-compatible API server”, with api_base for the URL. BroadNet Inference serves chat completions at https://inference.broadnet.ai/v1, so it works directly. BroadRouter is BroadNet’s own site; this follows the smolagents 1.26.0 docs.
Install
pip install smolagents
export BROADNET_API_KEY='your-broadnet-key'
CodeAgent
import os
from smolagents import OpenAIModel, CodeAgent
model = OpenAIModel(
model_id="broadnet/deepseek-v4.1-flash",
api_base="https://inference.broadnet.ai/v1",
api_key=os.environ["BROADNET_API_KEY"],
max_tokens=4000,
)
agent = CodeAgent(tools=[], model=model)
print(agent.run("What is 6 * 7? Use Python to check."))
CodeAgent asks the model to write Python between <code> tags and runs it locally. The request is a plain chat completion with stop sequences such as </code>, and no tools field. That means it doesn’t depend on native tool calling, so it can run on broadnet/deepseek-v4.1-flash, the model on BroadNet’s unlimited plans. Code quality still varies by model, so test your own tasks.
CodeAgent runs code the model writes. Read smolagents’ guidance on secure code execution before you give it tools that touch files, networks or credentials.
ToolCallingAgent
from smolagents import ToolCallingAgent, tool
@tool
def get_weather(city: str) -> str:
"""Get the weather for a city.
Args:
city: The city name.
"""
return f"21C in {city}"
model = OpenAIModel(
model_id="broadnet/glm-5.3",
api_base="https://inference.broadnet.ai/v1",
api_key=os.environ["BROADNET_API_KEY"],
max_tokens=4000,
)
agent = ToolCallingAgent(tools=[get_weather], model=model)
print(agent.run("What's the weather in Riyadh?"))
ToolCallingAgent sends your tools, plus its own final_answer tool, as function schemas with tool_choice: "required". Use broadnet/glm-5.3 or broadnet/qwen3.8-27b; BroadNet’s docs list tools for these two models only.
Which model to pick
| Agent | Model |
|---|---|
CodeAgent, long runs on a flat-price plan |
broadnet/deepseek-v4.1-flash |
ToolCallingAgent |
broadnet/glm-5.3 |
| Either agent with image input | broadnet/qwen3.8-27b |
A plan session runs one request at a time, and an agent sends its steps one after another, so one session fits one agent. Prices for every model.
How we tested this
On 2026-11-15 we installed smolagents 1.26.0 in a clean virtual environment and ran both agents against a local mock server that speaks BroadNet’s chat-completions shape. The CodeAgent on the DeepSeek ID received a code reply, ran it and returned 42. Its requests had max_tokens: 4000, stop sequences and no tools. For the ToolCallingAgent, we checked the request shape: the model ID was sent unchanged, with both tool schemas and tool_choice: "required". smolagents sends tool results back as user messages. Our mock didn’t follow that format, so we didn’t run that agent to a final answer. We had no BroadNet key, so we did not test real model output.
Troubleshooting
- 401. The key is wrong, expired or out of allowance.
- 404.
api_basemust end in/v1. Check the model ID. Paid models need a top-up; the $5 credit covers onlybroadnet/gemma-4-26b-a4band the two Transcribe models. - “Make sure to provide correct code blobs”. The model’s reply had no code block. Raise
max_tokens, because reasoning counts toward it, or try another model. Why answers come back empty. - ToolCallingAgent never finishes. Switch to
broadnet/glm-5.3orbroadnet/qwen3.8-27b. - 429. A pay-as-you-go key allows 30 requests a minute. smolagents can throttle itself with
requests_per_minute. See errors and retries.
