A minimalist library with as few dependencies as possible.
Project description
Kiori
A minimalist Python agent library with as few dependencies as possible.
Installation
# Basic installation
pip install kiori
# Installation with memory support
pip install "kiori[memory]"
Quick Start
from kiori.agent import KioriAgent
from kiori.models import Action, ActionExample
# Initialize agent
agent = KioriAgent()
# Define an action
def my_func():
return "Action executed!"
action = Action(
name="my_action",
description="Does something cool",
function_callable=my_func
)
agent.add_action(action)
# Add an example
example = ActionExample(
user_prompt="Do something cool",
expected_action_text="my_action()"
)
agent.add_example(example)
# Run agent
agent.run("Do something cool")
Memory (LTM & STM)
Kiori provides memory modules for both Long-Term Memory (LTM) and Short-Term Memory (STM).
Long-Term Memory (MilvusLTM)
Kiori provides a MilvusLTM class using Milvus Lite.
from kiori.memory import MilvusLTM
from kiori.models import ActionExample
# Initialize memory (auto-creates local Milvus Lite DB)
ltm = MilvusLTM()
example = ActionExample(
user_prompt="Do something cool",
expected_action_text="my_action()"
)
# Add examples to memory
ltm.add_examples([example])
# Search memory
results = ltm.search("Do something cool", top_k=1)
Short-Term Memory (ReplayBuffer)
ReplayBuffer stores examples from the immediate previous conversation turn.
from kiori.memory import ReplayBuffer
replay_buffer = ReplayBuffer()
replay_buffer.update_buffer([example])
Context Integration
KioriAgent automatically merges contexts from both memory sources.
from kiori.agent import KioriAgent
agent = KioriAgent(ltm=ltm, replay_buffer=replay_buffer)
# Automatically searches LTM and samples STM to generate context examples
ctx = agent.get_context_examples("User's new prompt")
print(ctx)
Execution Pipeline
Kiori provides a fully built-in execution pipeline that formats context, calls your LLM, parses the response, and executes the chosen Python function.
from kiori.agent import KioriAgent
from kiori.models import Action
agent = KioriAgent()
def weather_action(location: str) -> str:
return f"Weather in {location} is sunny."
agent.add_action(Action("get_weather", "Get weather for a location", weather_action))
# User provides their own LLM callback function
def my_llm_callback(prompt: str) -> str:
# Call OpenAI, Claude, Gemini, etc.
# The prompt instructs the LLM to output: [ACTION: name, ARGS: {...}]
return '[ACTION: get_weather, ARGS: {"location": "Tokyo"}]'
# The agent automatically retrieves context, formats prompt, calls LLM,
# executes the action, and saves the turn to Short-Term Memory!
result = agent.run("What's the weather in Tokyo?", llm_callback=my_llm_callback)
print(result) # "Weather in Tokyo is sunny."
Routing & Probabilities (MarkovRouter)
Kiori allows combining semantic search (Cosine Similarity) with Markov Chain probabilities to resolve ambiguous prompts based on the conversation history.
from kiori.router import MarkovRouter
from kiori.agent import KioriAgent
# Define transition matrix P(Action_B | Action_A)
transition_matrix = {
"action_A": {"action_B": 0.9, "action_C": 0.1}
}
router = MarkovRouter(
transition_matrix=transition_matrix,
all_actions=["action_A", "action_B", "action_C"]
)
# Initialize agent with alpha (cosine weight) and beta (Markov weight)
agent = KioriAgent(ltm=ltm, router=router, alpha=0.5, beta=0.5)
# If the previous action was "action_A", the agent will scale up "action_B"
# even if a new user prompt semantically looks slightly more like "action_C".
Philosophy
Kiori is built to be lightweight, easy to understand, and independent of bloated external packages.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kiori-0.5.0.tar.gz.
File metadata
- Download URL: kiori-0.5.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e911e796fa78349af0c5a700ebd76762920a58efb1af96a85fbd6f416e8ce367
|
|
| MD5 |
584d9932ec419a59ce4bae1148e0c85e
|
|
| BLAKE2b-256 |
c11e43d51fe03803c6cb4420258e25bc6ba29dc63ed0099b632b295246b1d836
|
File details
Details for the file kiori-0.5.0-py3-none-any.whl.
File metadata
- Download URL: kiori-0.5.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fc5c36039a235687536fe8f7cb30fe00de58adbfd02b5b1ab86361eb2f4c695
|
|
| MD5 |
a0a02bc271779b1ac8ec4249340bf2ea
|
|
| BLAKE2b-256 |
db5790764c7ad6ed4772b0b5464dfee07bf6d4906cc7c2ec57ec7e8029cc898d
|