Skip to main content
Cerebras has developed the world’s largest and fastest AI processor, the Wafer-Scale Engine-3 (WSE-3). Notably, the CS-3 system can run large language models like Llama-3.1-8B and Llama-3.1-70B at extremely fast speeds, making it an ideal platform for demanding AI workloads. While it’s technically possible to adapt AG2 to work with Cerebras’ API by updating the base_url, this approach may not fully account for minor differences in parameter support. Using this library will also allow for tracking of the API costs based on actual token usage. For more information about Cerebras Cloud, visit cloud.cerebras.ai. Their API reference is available at inference-docs.cerebras.ai.

Requirements

To use Cerebras with AG2, install the ag2[cerebras] extra.
If you have been using autogen or ag2, all you need to do is upgrade it using:
or
as autogen and ag2 are aliases for the same PyPI package.

Getting Started

Cerebras provides a number of models to use. See the list of models here. See the sample OAI_CONFIG_LIST below showing how the Cerebras client class is used by specifying the api_type as cerebras.

Credentials

Get an API Key from cloud.cerebras.ai and add it to your environment variables:

API parameters

The following parameters can be added to your config for the Cerebras API. See this link for further information on them and their default values.
  • max_tokens (null, integer >= 0)
  • seed (number)
  • stream (True or False)
  • temperature (number 0..1.5)
  • top_p (number)
Example:

Two-Agent Coding Example

In this example, we run a two-agent chat with an AssistantAgent (primarily a coding agent) to generate code to count the number of prime numbers between 1 and 10,000 and then it will be executed. We’ll use Meta’s LLama-3.1-70B model which is suitable for coding.
We can see that the Cerebras Wafer-Scale Engine-3 (WSE-3) completed the query in 74ms — faster than the blink of an eye!