Prerequisites
Before you begin, ensure you have:- A SambaCloud account with an active API key.
- Python 3.10 or later. Run
python --versionto confirm. AutoGen 0.4 and later requires Python 3.10, and on Python 3.9pipinstalls the incompatible 0.2 release instead.
Installation
This guide uses the AutoGen 0.4 and later packages:autogen-agentchat for agents and teams, and the model clients in autogen-ext.
-
Create and activate a virtual environment.
-
Install AutoGen with the OpenAI-compatible model client.
The upper bound keeps you on the 0.7 API. AutoGen has reorganized its packages across releases, so pin the minor version and test before you upgrade.
-
Set your API key as an environment variable.
Connect AutoGen to SambaCloud
SambaCloud exposes an OpenAI-compatible endpoint, so you connect throughOpenAIChatCompletionClient with base_url set to https://api.sambanova.ai/v1.
Because SambaNova model names are not OpenAI model names, you must also pass a model_info dictionary describing the model’s capabilities. Without it, the client raises ValueError: model_info is required when model name is not a valid OpenAI model.
The following example builds a two-agent team. A writer drafts an explanation and a reviewer either approves it or asks for fixes, and the two take turns until the reviewer replies APPROVED.
Console prints each turn as it arrives, with the agent name in the header, so the writer and reviewer labels are how you confirm both agents ran rather than one answering twice. The run stops as soon as a message contains APPROVED, which is two model calls here, or after four turns if the reviewer never approves. If you only ever see writer turns, the termination string never matched and max_turns ended the run.
AutoGen 0.4 and later is async-first. Agent and team methods must be awaited, which is why the example wraps them in
asyncio.run(). In a Jupyter notebook, drop the asyncio.run(main()) line and await the calls directly in a cell.Choose a model
Pass any SambaCloud model asmodel. Multi-agent workflows that give agents tools also need a model that supports function calling. Check the supported models before you set "function_calling": True, because the client raises ValueError: Model does not support function calling only after you attach a tool.
Example notebooks
Try out some examples with the following notebooks:- Travel planning notebook: Build a comprehensive travel itinerary with a team of agents. This notebook needs only your SambaNova API key, so start here.
- Company research notebook: Use a team of agents to search the web, find stock information, and generate a report. This one also needs a Google Custom Search API key and search engine ID, and it installs
yfinanceandmatplotlib.
SAMBANOVA_API_KEY and SAMBANOVA_URL from a .env file, and prompt you for any value they cannot find. Set SAMBANOVA_URL to https://api.sambanova.ai/v1.
Troubleshooting
ModuleNotFoundError: No module named 'autogen_agentchat'
ModuleNotFoundError: No module named 'autogen_agentchat'
You installed the 0.2 release, which ships an
autogen module instead. On Python 3.9, pip selects it silently because 0.4 and later require Python 3.10.Confirm python --version is 3.10 or later, then reinstall with the bounded command in Installation.ValueError: model_info is required when model name is not a valid OpenAI model
ValueError: model_info is required when model name is not a valid OpenAI model
OpenAIChatCompletionClient looks up capabilities by model name and does not recognize SambaNova model names.Pass the model_info dictionary shown in Connect AutoGen to SambaCloud.ValueError: Missing required field in ModelInfo
ValueError: Missing required field in ModelInfo
vision, function_calling, json_output, and family are each mandatory in model_info.Add the missing key. Omitting structured_output instead prints UserWarning: Missing required field 'structured_output' in ModelInfo and still constructs, but it becomes mandatory in a later release, so set all five as shown above.ValueError: Model does not support function calling
ValueError: Model does not support function calling
You attached tools to an agent whose
model_info sets "function_calling": False.Choose a model from the function calling supported models and set "function_calling": True.401 or 403 from the endpoint
401 or 403 from the endpoint
SAMBANOVA_API_KEY is unset, expired, or the shell that runs your script never received the export.Re-export the key, then confirm it works with:
