Asynchronous Agent

Code

1import asyncio
2
3from kern.agent import Agent, RunOutput # noqa
4from kern.models.meta import Llama
5
6agent = Agent(
7 model=Llama(id="Llama-4-Maverick-17B-128E-Instruct-FP8"),
8 markdown=True
9)
10
11# Get the response in a variable
12# run: RunOutput = asyncio.run(agent.arun("Share a 2 sentence horror story"))
13# print(run.content)
14
15# Print the response in the terminal
16asyncio.run(agent.aprint_response("Share a 2 sentence horror story"))

Usage

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Set your LLAMA API key

1export LLAMA_API_KEY=YOUR_API_KEY

Install dependencies

1uv pip install llama-api-client kern-ai

Run Agent

1python cookbook/11_models/meta/llama/async_basic.py