Async Basic

Code

1import asyncio
2
3from kern.agent import Agent
4from kern.models.ollama import Ollama
5
6agent = Agent(
7 model=Ollama(id="llama3.1:8b"),
8 description="You help people with their health and fitness goals.",
9 instructions=["Recipes should be under 5 ingredients"],
10)
11# -*- Print a response to the cli
12asyncio.run(agent.aprint_response("Share a breakfast recipe.", markdown=True))

Usage

Set up your virtual environment

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

Install Ollama

Follow the Ollama installation guide and run:

1ollama pull llama3.1:8b

Install dependencies

1uv pip install -U ollama kern-ai

Run Agent

1python cookbook/11_models/ollama/async_basic.py