kani: a hackable Python microframework for tool-calling chat models, with one extra per model provider
kani is a highly hackable microframework for tool-calling language models. (NLP-OSS @ EMNLP 2023)
At a glance
- What is it?
- zhudotexe/kani is an MIT-licensed Python framework for chat-based language models with function calling. It is less opinionated than larger frameworks, ships one pip extra per engine, and exposes Python methods to the model through a single decorator.
- Who is it for?
- kani suits NLP researchers and developers who want a thin layer over chat models with decorated Python functions as tools, streaming and optional MCP, and who prefer to control the prompt and control flow themselves. It is a poor fit if you want a batteries-included agent framework with retrieval, memory and orchestration built in.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 28 days ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- zhudotexe/kani618 ★ · +9
| Repository | 2026-09-14 | 2026-11-25 |
|---|---|---|
| zhudotexe/kani | 609 | 618 |
9 Stars in the last 72 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Each model provider is a pip extra, so the base install carries only pydantic
The core package depends on pydantic 2 and below 3 and requires Python 3.10 or above. Everything else arrives through extras: openai, anthropic, google, huggingface, cpp for llama.cpp, vllm, multimodal, mcp and an all extra that pulls in everything. The README gives the install lines:
# for OpenAI models
$ pip install "kani[openai]"
# for Hugging Face models
$ pip install "kani[huggingface]" torch
# for multimodal inputs
$ pip install "kani[multimodal]"
# or install everything:
$ pip install "kani[all]"The Hugging Face route needs torch installed separately, and the vllm extra is just the kani-ext-vllm package, which lives outside this repository. The consequence is a light default footprint, and a choice you must make deliberately: install the wrong extra and the engine import fails. The model table in the docs maps each model to its extra.
A Kani object owns chat state, and an Engine talks to the model
The quickstart separates the two roles. An Engine, such as OpenAIEngine, interacts with the language model, and takes model parameters like temperature. The Kani object manages the chat state, prompting and function calling, and accepts options like a system prompt. For a terminal chatbot, you create the engine with your API key and a model name, wrap it in Kani and call chat_in_terminal.
The example in the README uses the model name gpt-5-nano, the function calling example uses gpt-4o-mini, and the multimodal example uses gpt-4.1-nano, so the model names differ from section to section. That is a reminder that they are placeholders: use a model your account can reach. The README also says kani is less opinionated than other frameworks and offers fine-grained customisability over the parts of the control flow that matter, which is the reason to pick it over a heavier one.
The ai_function decorator turns a Python method into a tool, with validated arguments
Function calling lets the model choose when to call a function you provide, based on its documentation. In kani you subclass Kani and mark a method with the ai_function decorator, and you can add parameter documentation with Annotated and AIParam. The README states that kani guarantees function calls are valid by the time they reach your methods, so your code receives arguments that already match the declared types.
That guarantee is about argument validity, not about whether the model calls the right function or calls it at all. You still design the function descriptions so the model picks sensibly. A note in the README says kani supports local and remote MCP servers as well, with documentation under function calling, and the mcp extra requires the mcp package at version 1.15.0 or newer and below 2.
Streaming is a drop-in superset of chat_round and full_round, even with function calls
kani streams responses token by token, including when function calls are involved. The README says streaming is designed as a drop-in superset of the chat_round and full_round methods, so you can refactor gradually without leaving the code broken. The two forms look like this:
async def stream_chat():
stream = ai.chat_round_stream("What does kani mean?")
async for token in stream:
print(token, end="")
print()
msg = await stream.message() # or `await stream`
async def stream_with_function_calling():
async for stream in ai.full_round_stream("What's the weather in Tokyo?"):
async for token in stream:
print(token, end="")
print()
msg = await stream.message()The function-calling variant yields a stream per round, because a single question can involve several model turns. Everything is asynchronous, so a synchronous script must run it inside asyncio.
Multimodal input is an extension package, installed with its own extra
kani optionally accepts images, audio and video for various models. To use it you install the kani-multimodal-core extension package or the multimodal extra, which pulls in kani-multimodal-core below version 2 and transformers between 4.56.1 and 6. The input to chat_round_str becomes a list of parts instead of a single string, for example text followed by ImagePart.from_file and an ImagePart loaded from a URL.
This is separate documentation and a separate package, so multimodal behaviour follows that package's versions. If you only need text, skip it. If you use it, check that your chosen engine supports the modality you send, since support depends on the underlying model.
The examples folder is numbered as a learning path
The examples directory is organised by number. The 1 series covers quickstart, async entry points and few-shot. The 2 series covers function calling with a weather example, few-shot and MCP tools. The 3 series covers customisation, such as exception prompts, keeping the last four messages, logging messages and tracking function calls. The 4 series covers engines, including a model zoo and an fp4 quantisation example. The 5 series covers advanced topics: the API, message parts in chain-of-thought and in tools, retrieval and sub-kanis. There are also colab notebooks, a dice example and a Mistral GGUF example.
The model zoo file is the README's pointer for loading popular models. The advanced retrieval example is the place to look for how the project approaches retrieval.
The project is Beta, with the newest release in August 2026 and pushes since
The pyproject classifier is Development Status 4 - Beta. The recent releases are v1.10.0 on 2026-08-27, v1.9.1 on 2026-03-17 and v1.9.0 on 2026-03-04, and the last push was on 2026-10-29, so the main branch has moved on after the last tag. For the most up-to-date changes and new models, the README suggests installing the development version from the main branch of the Git repository with the all extra.
The framework is also the subject of a paper presented at the NLP-OSS workshop at EMNLP 2023. Installing from Git gives newer engines sooner and no release notes to pin against, so treat it as a development choice and pin a commit if you do it. The authors listed in pyproject are Andrew Zhu, Liam Dugan and Alyssa Hwang.
Editorial conclusion
kani suits NLP researchers and developers who want a thin layer over chat models with decorated Python functions as tools, streaming and optional MCP, and who prefer to control the prompt and control flow themselves. It is a poor fit if you want a batteries-included agent framework with retrieval, memory and orchestration built in. Before adopting it, pick the extra for your engine, check the model name in the README example against your provider, and pin a version, since the project is classified as Beta.
Frequently asked questions
What is kani?
kani is a lightweight and highly hackable framework for chat-based language models with tool usage and function calling. It is model-agnostic and presented at NLP-OSS at EMNLP 2023.
Which Python version does kani need?
kani requires Python 3.10 or above. Model-specific dependencies are installed through extras such as kani[openai] or kani[huggingface].
Which models does kani support?
Out of the box it supports OpenAI, Anthropic, Google AI, Hugging Face transformers, llama.cpp and vLLM through extras, plus more through community extensions.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/zhudotexe-kani)Star history chart for your README
[](https://hysenlabs.com/projects/zhudotexe-kani)Was this useful?