A tiny agent orchestration engine: task DAG + scheduler + events in ~400 lines
Project description
AgentKube-Mini
A tiny agent orchestration engine. Implements a task DAG, dependency-aware parallel scheduler, and event system for multi-agent pipelines — all in about 400 lines of Python with zero dependencies. The idea is to show how agent orchestration actually works under the hood.
Installation
pip install agentkube-mini
Quick start
Example usage
Define agents as simple functions, wire them into a DAG, and run:
from agentkube_mini import Agent, TaskGraph, Runtime
# define agents — each is just a name + function
research = Agent("research", lambda topic: f"data about {topic}")
analysis = Agent("analysis", lambda topic, deps: f"analysis of {deps['research']}")
writer = Agent("writer", lambda topic, deps: f"article based on {deps['analysis']}")
critic = Agent("critic", lambda topic, deps: f"score=9 for {deps['writer']}")
# wire the DAG
graph = TaskGraph()
graph.add(research)
graph.add(analysis, depends=["research"])
graph.add(writer, depends=["analysis"])
graph.add(critic, depends=["writer"])
# run it
result = Runtime(graph).run("AI agents")
print(result.outputs)
Output:
research → data about AI agents
analysis → analysis of data about AI agents
writer → article based on analysis of data about AI agents
critic → score=9 for article based on analysis of data about AI agents
The scheduler automatically figures out which agents can run in parallel (independent nodes run concurrently via ThreadPoolExecutor) and which must wait for dependencies. Events are emitted at each step (task_started, task_completed, task_failed) so you get observability for free.
Visualization
The task graph can print itself as text or as a Mermaid diagram:
print(graph.visualize())
# research -> analysis
# analysis -> writer
# writer -> critic
print(graph.to_mermaid())
# graph TD
# research
# research --> analysis
# analysis --> writer
# writer --> critic
Events and shared memory
Every run produces an event log and a shared memory dict that all agents write into:
from agentkube_mini import Runtime, EventBus
bus = EventBus()
bus.subscribe("task_failed", lambda e: print(f"ALERT: {e.task} failed"))
result = Runtime(graph, event_bus=bus).run("AI agents")
# event log
for ev in result.events:
print(ev.type, ev.task)
# shared memory — every agent's output is accessible
result.memory["research"] # → "data about AI agents"
Using with existing code
You don't have to rewrite your services. Wrap them with auto_agent, which auto-detects the function signature:
from agentkube_mini import auto_agent
# your existing function, unchanged
def my_research_service(topic: str) -> dict:
return {"topic": topic, "facts": ["f1", "f2"]}
research = auto_agent("research", my_research_service)
See integration_example.py for a full working example with legacy service classes.
How it works
The core abstraction is: agents are nodes, dependencies are edges, the scheduler walks the DAG. That's the whole idea. If you understand this, you understand the center of every real multi-agent runtime — the rest (distributed workers, retries, message queues, state stores) is extensions on top.
Agent graph → Scheduler → Parallel execution + Events
File structure
agent.py — the Agent dataclass (name + callable)
task_graph.py — DAG: add nodes, validate, visualize
scheduler.py — dependency-aware parallel scheduler
runtime.py — thin wrapper around scheduler
events.py — event bus with subscribe/emit/history
example.py — the demo shown above
compat.py — auto_agent adapter for existing code
smoke_test.py — tiny correctness test
integration_example.py — legacy service adapter demo
Running tests
python3 smoke_test.py
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 agentkube_mini-0.1.0.tar.gz.
File metadata
- Download URL: agentkube_mini-0.1.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97fa99bc8779caa63c08d85aef4cc34df8187fa2b051d2814c99b7eb05381eb0
|
|
| MD5 |
f29676ffd684beb8e0cb5085c5413ade
|
|
| BLAKE2b-256 |
918f9f15c2ccca035b722201cbcfbbb672c45243ba9226d3b0c62e79b9d710a3
|
File details
Details for the file agentkube_mini-0.1.0-py3-none-any.whl.
File metadata
- Download URL: agentkube_mini-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8be9d9bb8875bc85a9190f120d14771a861f7deeb79fe9d774518bc6f3983a54
|
|
| MD5 |
1c6ec2585c55a1faab066f35430b62dc
|
|
| BLAKE2b-256 |
e8604cbc6ebd175e05a69bbb3e0df37d8b3b1c7982e736aa7064fd3ada391f90
|