Let’s be honest for a second. Building applications with AI right now can feel a bit like trying to build a house on shifting sand.
You spend weeks crafting the perfect AI agent. It’s smart, it’s fast, it uses the latest and greatest model. Then, a new, even better model drops. Or the API you rely on gets an "update" that breaks everything. Suddenly, you're back in the code, rewriting huge chunks of your logic just to keep up.
It’s exhausting. And if you’re building anything serious, it's a maintenance nightmare.
The team at Moonshot AI, the minds behind the Kimi chatbot, clearly felt this pain, too. That’s why they just open-sourced Kosong, the very library they use to power their own Kimi CLI. And honestly, it might just be the simple, pragmatic tool we’ve all been waiting for.
So, What Exactly is This "Kosong"?
Think of Kosong as a universal translator or a travel adapter for your AI agent.
Right now, your agent’s business logic is probably wired directly to a specific API, like OpenAI's or Anthropic's. When you want to switch models or providers, you have to rip out all that wiring and start over.
Kosong sits in the middle. It’s a Python library that acts as an "abstraction layer." It provides a single, consistent way for your agent to talk to any LLM and use any set of tools. You write your agent's logic once, talking to Kosong's simple interface. Then, you can just plug in different LLM providers (like Kimi, and presumably others in the future) on the backend without touching your core code.
It’s designed to be a small, focused solution to a very big problem: how do we build AI apps that can survive in a world where the underlying tech changes every few weeks?
A Tiny API with Two Big Jobs: generate and step
One of the first things I noticed about Kosong is how small its public API is. This is a good thing! It’s not trying to be a massive, complex framework. It focuses on doing two things really, really well.
1. For Simple Chats, There's generate
Need your app to have a straightforward conversation? kosong.generate is your go-to.
You give it a provider (like Kimi), a system prompt, and the conversation history. It handles the rest. It’s the entry point for plain old chat completions.
What’s cool is that it also supports streaming right out of the box. You know when you see a chatbot typing out its response word-by-word? The generate function makes that easy to implement with a simple callback. Your app can display the text as it comes in, and you still get a clean, complete message object at the end.
2. For Agents That Do Things, There's step
This is where things get really interesting for agent developers. kosong.step is designed for agents that need to use tools—things like running a web search, executing a piece of code, or looking something up in a database.
Imagine your agent needs to answer "What is 25 + 17?". The model itself is bad at math, but it knows it needs a calculator.
With step, the model can say, "I need to use the 'add' tool with the numbers 25 and 17." Kosong intercepts this request, finds your add tool, runs the calculation, gets the answer (42), and hands it back to the model.
The best part? Your agent's main logic doesn't have to deal with any of that messy orchestration. Kosong handles the entire dispatch loop—parsing the arguments, calling the right tool, and formatting the result. It’s like a project manager for your agent's tools.
The Building Blocks That Make It All Work
Under the hood, Kosong relies on a few core ideas to keep things clean and flexible.
- ChatProvider: This is the plug-in system. It's an abstraction that represents the connection to a specific LLM. Kosong ships with one for Kimi, but the whole point is that you or the community can easily write new providers for other models without changing your agent.
- Message: This is just a standardized format for conversation turns. By having a consistent
Messageclass, Kosong ensures that your user prompts and the model's replies look the same no matter which backend you're using. - Toolset: This is your agent’s toolbox. You can define your own tools (like that
AddToolexample) using Pydantic for the parameters, which is a huge plus for anyone in the Python world. It makes defining the inputs for your tools super clear and validated. You just bundle them up in aSimpleToolsetand pass it to thestepfunction.
This Isn't Just a Side Project
Here’s the thing that gives me a lot of confidence in Kosong: Moonshot AI is eating its own dog food.
Kosong isn't some theoretical library they thought would be a good idea. It’s the battle-tested engine that powers their own Kimi CLI. This means it’s been built to solve real-world problems they were facing internally.
They even include a built-in demo agent in the repository. With a couple of environment variables and one command, you can fire up a terminal agent that uses Kimi and can even execute shell commands. It’s a great way to see it in action without having to write a single line of code.
My Take: A Pragmatic Move in a Hype-Filled World
So, what's the bottom line?
I think Kosong is a really smart, pragmatic library. It’s not trying to reinvent the wheel or be the biggest, most feature-packed agent framework on the market.
Instead, it cleanly separates your agent's core logic from the ever-changing world of LLM backends and tools. By focusing on a few core abstractions (ChatProvider, Message, Toolset), it gives developers a stable foundation to build on. You can evolve your models and tools without having to constantly rewrite your orchestration code.
If you’re building an AI agent that you plan to maintain for more than a few months, this kind of minimal, focused infrastructure is exactly what you need. It’s a small library that solves a giant headache. It's definitely worth checking out the repo for your next project.




