| 1 | # Getting Started |
| 2 | |
| 3 | The `llama` CLI tool helps you setup and use the Llama toolchain & agentic systems. It should be available on your path after installing the `llama-stack` package. |
| 4 | |
| 5 | This guides allows you to quickly get started with building and running a Llama Stack server in < 5 minutes! |
| 6 | |
| 7 | ## Quick Cheatsheet |
| 8 | - Quick 3 line command to build and start a LlamaStack server using our Meta Reference implementation for all API endpoints with `conda` as build type. |
| 9 | |
| 10 | **`llama stack build`** |
| 11 | - You'll be prompted to enter build information interactively. |
| 12 | ``` |
| 13 | llama stack build |
| 14 | |
| 15 | > Enter an unique name for identifying your Llama Stack build distribution (e.g. my-local-stack): my-local-llama-stack |
| 16 | > Enter the image type you want your distribution to be built with (docker or conda): conda |
| 17 | |
| 18 | Llama Stack is composed of several APIs working together. Let's configure the providers (implementations) you want to use for these APIs. |
| 19 | > Enter the API provider for the inference API: (default=meta-reference): meta-reference |
| 20 | > Enter the API provider for the safety API: (default=meta-reference): meta-reference |
| 21 | > Enter the API provider for the agents API: (default=meta-reference): meta-reference |
| 22 | > Enter the API provider for the memory API: (default=meta-reference): meta-reference |
| 23 | > Enter the API provider for the telemetry API: (default=meta-reference): meta-reference |
| 24 | |
| 25 | > (Optional) Enter a short description for your Llama Stack distribution: |
| 26 | |
| 27 | Build spec configuration saved at ~/.conda/envs/llamastack-my-local-llama-stack/my-local-llama-stack-build.yaml |
| 28 | ``` |
| 29 | |
| 30 | **`llama stack configure`** |
| 31 | - Run `llama stack configure <name>` with the name you have previously defined in `build` step. |
| 32 | ``` |
| 33 | llama stack configure my-local-llama-stack |
| 34 | |
| 35 | Configuring APIs to serve... |
| 36 | Enter comma-separated list of APIs to serve: |
| 37 | |
| 38 | Configuring API `inference`... |
| 39 | |
| 40 | Configuring provider `meta-reference`... |
| 41 | Enter value for model (default: Meta-Llama3.1-8B-Instruct) (required): |
| 42 | Do you want to configure quantization? (y/n): n |
| 43 | Enter value for torch_seed (optional): |
| 44 | Enter value for max_seq_len (required): 4096 |
| 45 | Enter value for max_batch_size (default: 1) (required): |
| 46 | Configuring API `safety`... |
| 47 | |
| 48 | Configuring provider `meta-reference`... |
| 49 | Do you want to configure llama_guard_shield? (y/n): n |
| 50 | Do you want to configure prompt_guard_shield? (y/n): n |
| 51 | Configuring API `agents`... |
| 52 | |
| 53 | Configuring provider `meta-reference`... |
| 54 | Configuring API `memory`... |
| 55 | |
| 56 | Configuring provider `meta-reference`... |
| 57 | Configuring API `telemetry`... |
| 58 | |
| 59 | Configuring provider `meta-reference`... |
| 60 | > YAML configuration has been written to ~/.llama/builds/conda/my-local-llama-stack-run.yaml. |
| 61 | You can now run `llama stack run my-local-llama-stack --port PORT` or `llama stack run ~/.llama/builds/conda/my-local-llama-stack-run.yaml --port PORT |
| 62 | ``` |
| 63 | |
| 64 | **`llama stack run`** |
| 65 | - Run `llama stack run <name>` with the name you have previously defined. |
| 66 | ``` |
| 67 | llama stack run my-local-llama-stack |
| 68 | |
| 69 | ... |
| 70 | > initializing model parallel with size 1 |
| 71 | > initializing ddp with size 1 |
| 72 | > initializing pipeline with size 1 |
| 73 | ... |
| 74 | Finished model load YES READY |
| 75 | Serving POST /inference/chat_completion |
| 76 | Serving POST /inference/completion |
| 77 | Serving POST /inference/embeddings |
| 78 | Serving POST /memory_banks/create |
| 79 | Serving DELETE /memory_bank/documents/delete |
| 80 | Serving DELETE /memory_banks/drop |
| 81 | Serving GET /memory_bank/documents/get |
| 82 | Serving GET /memory_banks/get |
| 83 | Serving POST /memory_bank/insert |
| 84 | Serving GET /memory_banks/list |
| 85 | Serving POST /memory_bank/query |
| 86 | Serving POST /memory_bank/update |
| 87 | Serving POST /safety/run_shields |
| 88 | Serving POST /agentic_system/create |
| 89 | Serving POST /agentic_system/session/create |
| 90 | Serving POST /agentic_system/turn/create |
| 91 | Serving POST /agentic_system/delete |
| 92 | Serving POST /agentic_system/session/delete |
| 93 | Serving POST /agentic_system/session/get |
| 94 | Serving POST /agentic_system/step/get |
| 95 | Serving POST /agentic_system/turn/get |
| 96 | Serving GET /telemetry/get_trace |
| 97 | Serving POST /telemetry/log_event |
| 98 | Listening on :::5000 |
| 99 | INFO: Started server process [587053] |
| 100 | INFO: Waiting for application startup. |
| 101 | INFO: Application startup complete. |
| 102 | INFO: Uvicorn running on http://[::]:5000 (Press CTRL+C to quit) |
| 103 | ``` |
| 104 | |
| 105 | |
| 106 | ## Step 1. Build |
| 107 | In the following steps, imagine we'll be working with a `Meta-Llama3.1-8B-Instruct` model. We will name our build `8b-instruct` to help us remember the config. We will start build our distribution (in the form of a Conda environment, or Docker image). In this step, we will specify: |
| 108 | - `name`: the name for our distribution (e.g. `8b-instruct`) |
| 109 | - `image_type`: our build image type (`conda | docker`) |
| 110 | - `distribution_spec`: our distribution specs for specifying API providers |
| 111 | - `description`: a short description of the configurations for the distribution |
| 112 | - `providers`: specifies the underlying implementation for serving each API endpoint |
| 113 | - `image_type`: `conda` | `docker` to specify whether to build the distribution in the form of Docker image or Conda environment. |
| 114 | |
| 115 | |
| 116 | At the end of build command, we will generate `<name>-build.yaml` file storing the build configurations. |
| 117 | |
| 118 | After this step is complete, a file named `<name>-build.yaml` will be generated and saved at the output file path specified at the end of the command. |
| 119 | |
| 120 | #### Building from scratch |
| 121 | - For a new user, we could start off with running `llama stack build` which will allow you to a interactively enter wizard where you will be prompted to enter build configurations. |
| 122 | ``` |
| 123 | llama stack build |
| 124 | ``` |
| 125 | |
| 126 | Running the command above will allow you to fill in the configuration to build your Llama Stack distribution, you will see the following outputs. |
| 127 | |
| 128 | ``` |
| 129 | > Enter an unique name for identifying your Llama Stack build distribution (e.g. my-local-stack): my-local-llama-stack |
| 130 | > Enter the image type you want your distribution to be built with (docker or conda): conda |
| 131 | |
| 132 | Llama Stack is composed of several APIs working together. Let's configure the providers (implementations) you want to use for these APIs. |
| 133 | > Enter the API provider for the inference API: (default=meta-reference): meta-reference |
| 134 | > Enter the API provider for the safety API: (default=meta-reference): meta-reference |
| 135 | > Enter the API provider for the agents API: (default=meta-reference): meta-reference |
| 136 | > Enter the API provider for the memory API: (default=meta-reference): meta-reference |
| 137 | > Enter the API provider for the telemetry API: (default=meta-reference): meta-reference |
| 138 | |
| 139 | > (Optional) Enter a short description for your Llama Stack distribution: |
| 140 | |
| 141 | Build spec configuration saved at ~/.conda/envs/llamastack-my-local-llama-stack/my-local-llama-stack-build.yaml |
| 142 | ``` |
| 143 | |
| 144 | #### Building from templates |
| 145 | - To build from alternative API providers, we provide distribution templates for users to get started building a distribution backed by different providers. |
| 146 | |
| 147 | The following command will allow you to see the available templates and their corresponding providers. |
| 148 | ``` |
| 149 | llama stack build --list-templates |
| 150 | ``` |
| 151 | |
| 152 |  |
| 153 | |
| 154 | You may then pick a template to build your distribution with providers fitted to your liking. |
| 155 | |
| 156 | ``` |
| 157 | llama stack build --template local-tgi --name my-tgi-stack |
| 158 | ``` |
| 159 | |
| 160 | ``` |
| 161 | $ llama stack build --template local-tgi --name my-tgi-stack |
| 162 | ... |
| 163 | ... |
| 164 | Build spec configuration saved at ~/.conda/envs/llamastack-my-tgi-stack/my-tgi-stack-build.yaml |
| 165 | You may now run `llama stack configure my-tgi-stack` or `llama stack configure ~/.conda/envs/llamastack-my-tgi-stack/my-tgi-stack-build.yaml` |
| 166 | ``` |
| 167 | |
| 168 | #### Building from config file |
| 169 | - In addition to templates, you may customize the build to your liking through editing config files and build from config files with the following command. |
| 170 | |
| 171 | - The config file will be of contents like the ones in `llama_stack/distributions/templates/`. |
| 172 | |
| 173 | ``` |
| 174 | $ cat llama_stack/distribution/templates/local-ollama-build.yaml |
| 175 | |
| 176 | name: local-ollama |
| 177 | distribution_spec: |
| 178 | description: Like local, but use ollama for running LLM inference |
| 179 | providers: |
| 180 | inference: remote::ollama |
| 181 | memory: meta-reference |
| 182 | safety: meta-reference |
| 183 | agents: meta-reference |
| 184 | telemetry: meta-reference |
| 185 | image_type: conda |
| 186 | ``` |
| 187 | |
| 188 | ``` |
| 189 | llama stack build --config llama_stack/distribution/templates/local-ollama-build.yaml |
| 190 | ``` |
| 191 | |
| 192 | #### How to build distribution with Docker image |
| 193 | |
| 194 | To build a docker image, you may start off from a template and use the `--image-type docker` flag to specify `docker` as the build image type. |
| 195 | |
| 196 | ``` |
| 197 | llama stack build --template local --image-type docker --name docker-0 |
| 198 | ``` |
| 199 | |
| 200 | Alternatively, you may use a config file and set `image_type` to `docker` in our `<name>-build.yaml` file, and run `llama stack build <name>-build.yaml`. The `<name>-build.yaml` will be of contents like: |
| 201 | |
| 202 | ``` |
| 203 | name: local-docker-example |
| 204 | distribution_spec: |
| 205 | description: Use code from `llama_stack` itself to serve all llama stack APIs |
| 206 | docker_image: null |
| 207 | providers: |
| 208 | inference: meta-reference |
| 209 | memory: meta-reference-faiss |
| 210 | safety: meta-reference |
| 211 | agentic_system: meta-reference |
| 212 | telemetry: console |
| 213 | image_type: docker |
| 214 | ``` |
| 215 | |
| 216 | The following command allows you to build a Docker image with the name `<name>` |
| 217 | ``` |
| 218 | llama stack build --config <name>-build.yaml |
| 219 | |
| 220 | Dockerfile created successfully in /tmp/tmp.I0ifS2c46A/DockerfileFROM python:3.10-slim |
| 221 | WORKDIR /app |
| 222 | ... |
| 223 | ... |
| 224 | You can run it with: podman run -p 8000:8000 llamastack-docker-local |
| 225 | Build spec configuration saved at ~/.llama/distributions/docker/docker-local-build.yaml |
| 226 | ``` |
| 227 | |
| 228 | |
| 229 | ## Step 2. Configure |
| 230 | After our distribution is built (either in form of docker or conda environment), we will run the following command to |
| 231 | ``` |
| 232 | llama stack configure [ <name> | <docker-image-name> | <path/to/name.build.yaml>] |
| 233 | ``` |
| 234 | - For `conda` environments: <path/to/name.build.yaml> would be the generated build spec saved from Step 1. |
| 235 | - For `docker` images downloaded from Dockerhub, you could also use <docker-image-name> as the argument. |
| 236 | - Run `docker images` to check list of available images on your machine. |
| 237 | |
| 238 | ``` |
| 239 | $ llama stack configure ~/.llama/distributions/conda/8b-instruct-build.yaml |
| 240 | |
| 241 | Configuring API: inference (meta-reference) |
| 242 | Enter value for model (existing: Meta-Llama3.1-8B-Instruct) (required): |
| 243 | Enter value for quantization (optional): |
| 244 | Enter value for torch_seed (optional): |
| 245 | Enter value for max_seq_len (existing: 4096) (required): |
| 246 | Enter value for max_batch_size (existing: 1) (required): |
| 247 | |
| 248 | Configuring API: memory (meta-reference-faiss) |
| 249 | |
| 250 | Configuring API: safety (meta-reference) |
| 251 | Do you want to configure llama_guard_shield? (y/n): y |
| 252 | Entering sub-configuration for llama_guard_shield: |
| 253 | Enter value for model (default: Llama-Guard-3-8B) (required): |
| 254 | Enter value for excluded_categories (default: []) (required): |
| 255 | Enter value for disable_input_check (default: False) (required): |
| 256 | Enter value for disable_output_check (default: False) (required): |
| 257 | Do you want to configure prompt_guard_shield? (y/n): y |
| 258 | Entering sub-configuration for prompt_guard_shield: |
| 259 | Enter value for model (default: Prompt-Guard-86M) (required): |
| 260 | |
| 261 | Configuring API: agentic_system (meta-reference) |
| 262 | Enter value for brave_search_api_key (optional): |
| 263 | Enter value for bing_search_api_key (optional): |
| 264 | Enter value for wolfram_api_key (optional): |
| 265 | |
| 266 | Configuring API: telemetry (console) |
| 267 | |
| 268 | YAML configuration has been written to ~/.llama/builds/conda/8b-instruct-run.yaml |
| 269 | ``` |
| 270 | |
| 271 | After this step is successful, you should be able to find a run configuration spec in `~/.llama/builds/conda/8b-instruct-run.yaml` with the following contents. You may edit this file to change the settings. |
| 272 | |
| 273 | As you can see, we did basic configuration above and configured: |
| 274 | - inference to run on model `Meta-Llama3.1-8B-Instruct` (obtained from `llama model list`) |
| 275 | - Llama Guard safety shield with model `Llama-Guard-3-8B` |
| 276 | - Prompt Guard safety shield with model `Prompt-Guard-86M` |
| 277 | |
| 278 | For how these configurations are stored as yaml, checkout the file printed at the end of the configuration. |
| 279 | |
| 280 | Note that all configurations as well as models are stored in `~/.llama` |
| 281 | |
| 282 | |
| 283 | ## Step 3. Run |
| 284 | Now, let's start the Llama Stack Distribution Server. You will need the YAML configuration file which was written out at the end by the `llama stack configure` step. |
| 285 | |
| 286 | ``` |
| 287 | llama stack run ~/.llama/builds/conda/8b-instruct-run.yaml |
| 288 | ``` |
| 289 | |
| 290 | You should see the Llama Stack server start and print the APIs that it is supporting |
| 291 | |
| 292 | ``` |
| 293 | $ llama stack run ~/.llama/builds/local/conda/8b-instruct.yaml |
| 294 | |
| 295 | > initializing model parallel with size 1 |
| 296 | > initializing ddp with size 1 |
| 297 | > initializing pipeline with size 1 |
| 298 | Loaded in 19.28 seconds |
| 299 | NCCL version 2.20.5+cuda12.4 |
| 300 | Finished model load YES READY |
| 301 | Serving POST /inference/batch_chat_completion |
| 302 | Serving POST /inference/batch_completion |
| 303 | Serving POST /inference/chat_completion |
| 304 | Serving POST /inference/completion |
| 305 | Serving POST /safety/run_shields |
| 306 | Serving POST /agentic_system/memory_bank/attach |
| 307 | Serving POST /agentic_system/create |
| 308 | Serving POST /agentic_system/session/create |
| 309 | Serving POST /agentic_system/turn/create |
| 310 | Serving POST /agentic_system/delete |
| 311 | Serving POST /agentic_system/session/delete |
| 312 | Serving POST /agentic_system/memory_bank/detach |
| 313 | Serving POST /agentic_system/session/get |
| 314 | Serving POST /agentic_system/step/get |
| 315 | Serving POST /agentic_system/turn/get |
| 316 | Listening on :::5000 |
| 317 | INFO: Started server process [453333] |
| 318 | INFO: Waiting for application startup. |
| 319 | INFO: Application startup complete. |
| 320 | INFO: Uvicorn running on http://[::]:5000 (Press CTRL+C to quit) |
| 321 | ``` |
| 322 | |
| 323 | > [!NOTE] |
| 324 | > Configuration is in `~/.llama/builds/local/conda/8b-instruct-run.yaml`. Feel free to increase `max_seq_len`. |
| 325 | |
| 326 | > [!IMPORTANT] |
| 327 | > The "local" distribution inference server currently only supports CUDA. It will not work on Apple Silicon machines. |
| 328 | |
| 329 | > [!TIP] |
| 330 | > You might need to use the flag `--disable-ipv6` to Disable IPv6 support |
| 331 | |
| 332 | This server is running a Llama model locally. |
| 333 | |
| 334 | ## Step 4. Test with Client |
| 335 | Once the server is setup, we can test it with a client to see the example outputs. |
| 336 | ``` |
| 337 | cd /path/to/llama-stack |
| 338 | conda activate <env> # any environment containing the llama-stack pip package will work |
| 339 | |
| 340 | python -m llama_stack.apis.inference.client localhost 5000 |
| 341 | ``` |
| 342 | |
| 343 | This will run the chat completion client and query the distribution’s /inference/chat_completion API. |
| 344 | |
| 345 | Here is an example output: |
| 346 | ``` |
| 347 | User>hello world, write me a 2 sentence poem about the moon |
| 348 | Assistant> Here's a 2-sentence poem about the moon: |
| 349 | |
| 350 | The moon glows softly in the midnight sky, |
| 351 | A beacon of wonder, as it passes by. |
| 352 | ``` |
| 353 | |
| 354 | Similarly you can test safety (if you configured llama-guard and/or prompt-guard shields) by: |
| 355 | |
| 356 | ``` |
| 357 | python -m llama_stack.apis.safety.client localhost 5000 |
| 358 | ``` |
| 359 | |
| 360 | You can find more example scripts with client SDKs to talk with the Llama Stack server in our [llama-stack-apps](https://github.com/meta-llama/llama-stack-apps/tree/main/sdk_examples) repo. |