A multi-agent orchestration SDK for building intelligent workflows
Project description
Kiva SDK
⚠️ Important Notice: This project is currently in a rapid iteration/experimental phase, and the provided API may undergo disruptive changes at any time.
A multi-agent orchestration SDK for building intelligent workflows.
Features
- Three Workflow Patterns: Router (simple), Supervisor (parallel), Parliament (deliberative)
- Automatic Complexity Analysis: Intelligent workflow selection
- Parallel Agent Instances: Spawn multiple instances for parallel execution
- Modular Architecture: AgentRouter for organizing agents
- Rich Console Output: Beautiful terminal visualization
- Streaming Events: Real-time event stream for custom handling
Installation
uv add kiva-sdk
Quick Start
import asyncio
from kiva import Kiva
kiva = Kiva(
base_url="https://api.openai.com/v1",
api_key="your-api-key",
model="gpt-4o",
)
@kiva.agent("weather", "Gets weather information")
def get_weather(city: str) -> str:
"""Get weather for a city."""
return f"Sunny, 25°C in {city}"
@kiva.agent("math", "Performs calculations")
class MathTools:
def add(self, a: int, b: int) -> int:
"""Add two numbers."""
return a + b
async def main():
# Method 1: Rich console output
result = await kiva.run("What's the weather in Tokyo?")
print(result)
# Method 2: Stream events for custom handling
async for event in kiva.stream("Calculate 15 + 8"):
print(f"{event.type.value}: {event.data}")
asyncio.run(main())
MCP 工具源注入
from kiva import Kiva
MCP_SERVERS = {
"math": {
"command": "python",
"args": ["/path/to/math_server.py"],
"transport": "stdio",
}
}
kiva = Kiva(
base_url="https://api.openai.com/v1",
api_key="your-api-key",
model="gpt-4o",
)
@kiva.agent("calculator", "Performs calculations", mcp_servers=MCP_SERVERS)
class Calculator:
def add(self, a: int, b: int) -> int:
return a + b
class SearchTools:
def search(self, query: str) -> str:
return f"Results for {query}"
kiva.add_agent("search", "Searches for information", SearchTools, mcp_servers=MCP_SERVERS)
API
kiva.run(prompt) - Rich Console Output
Returns final result with beautiful terminal visualization.
result = await kiva.run("Your prompt here")
kiva.stream(prompt) - Event Stream
Returns async iterator of StreamEvent objects for custom handling.
async for event in kiva.stream("Your prompt here"):
if event.type.value == "agent_end":
print(f"Agent {event.data['agent_id']} finished")
Streaming Output Formats
StreamEvent supports multiple output formats for different use cases:
async for event in kiva.stream("Your prompt"):
# SSE format for web frontends
sse_string = event.to_sse()
# Output: "event: agent_end\nid: {uuid}\ndata: {json}\n\n"
# NDJSON format for CLI tools and logging
ndjson_string = event.to_ndjson()
# Output: "{json}\n"
# JSON string
json_string = event.to_json()
# Dictionary
event_dict = event.to_dict()
Event Filtering
Filter events at the source to reduce overhead:
from kiva.events import EventType
# Only receive specific event types
event_filter = {EventType.AGENT_START, EventType.AGENT_END}
async for event in kiva.stream("Your prompt", event_filter=event_filter):
print(event.type.value)
Modular Application with AgentRouter
from kiva import AgentRouter, Kiva
# agents/weather.py
weather_router = AgentRouter(prefix="weather")
@weather_router.agent("forecast", "Gets forecasts")
def get_forecast(city: str) -> str:
return f"Sunny in {city}"
# main.py
kiva = Kiva(base_url="...", api_key="...", model="gpt-4o")
kiva.include_router(weather_router)
await kiva.run("What's the weather?")
Documentation
- AgentRouter - Modular Applications
- Parallel Agent Instances
- SSE Integration Guide
- NDJSON Streaming Guide
- Execution Outputs
- E2E Testing Guide
Event Types Reference
| Event Type | Description |
|---|---|
execution_start |
Execution begins |
agent_start |
Agent starts processing |
agent_end |
Agent completes with result |
token |
Streaming token from LLM |
execution_end |
Execution completes |
execution_error |
Error occurred |
See Execution Outputs for complete event documentation.
License
MIT License
Project details
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 kiva_sdk-0.5.0.tar.gz.
File metadata
- Download URL: kiva_sdk-0.5.0.tar.gz
- Upload date:
- Size: 39.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc0a03fbb7d83653319708e1e65a012472d35361358fe8ffc26bc500a217e80c
|
|
| MD5 |
5f0b764eccb28911297add3ecda2ab9e
|
|
| BLAKE2b-256 |
058225d9f75c246f48be6729a1b914e3c7ed0aadd4c0d13a7c12557b75d50e5e
|
File details
Details for the file kiva_sdk-0.5.0-py3-none-any.whl.
File metadata
- Download URL: kiva_sdk-0.5.0-py3-none-any.whl
- Upload date:
- Size: 48.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c33b103d77aa37a7dc6e42cda8dc8ce5a0aa9d80a9a9360102efc5dd36f33de1
|
|
| MD5 |
4f247bcc79a1912a32c99d16bed67a34
|
|
| BLAKE2b-256 |
b38ed9709b85e47073b3b395c383d77bad54861dd6356cb34b43fb62a76258e9
|