A multi-agent orchestration SDK for building intelligent workflows
Project description
Kiva SDK
A multi-agent orchestration SDK for building intelligent workflows
Features
- Three Workflow Patterns: Router (simple), Supervisor (parallel), and Parliament (deliberative)
- Automatic Complexity Analysis: Intelligent workflow selection based on task complexity
- Streaming Events: Real-time execution monitoring with structured events
- Rich Console Output: Beautiful terminal visualization (optional)
- Error Recovery: Built-in error handling with recovery suggestions
- Flexible API Levels: High-level client, mid-level console, and low-level streaming
Installation
uv add kiva-sdk
Quick Start
High-Level API (Simplest)
from kiva import Kiva
kiva = Kiva(
base_url="https://api.openai.com/v1",
api_key="your-api-key",
model="gpt-4o",
)
# Single-tool agent using decorator
@kiva.agent("weather", "Gets weather information")
def get_weather(city: str) -> str:
"""Get current weather for a city."""
return f"Sunny, 25°C in {city}"
# Multi-tool agent using class decorator
@kiva.agent("math", "Performs calculations")
class MathTools:
def add(self, a: int, b: int) -> int:
"""Add two numbers."""
return a + b
def multiply(self, a: int, b: int) -> int:
"""Multiply two numbers."""
return a * b
# Run with rich console output
kiva.run("What's the weather in Tokyo? Also calculate 15 * 8")
Mid-Level API (Async with Console)
import asyncio
from kiva import run_with_console, create_agent, ChatOpenAI, tool
@tool
def search(query: str) -> str:
"""Search for information."""
return f"Results for: {query}"
async def main():
model = ChatOpenAI(model="gpt-4o", api_key="...")
agent = create_agent(model=model, tools=[search])
agent.name = "search_agent"
agent.description = "Searches for information"
await run_with_console(
prompt="Search for Python tutorials",
agents=[agent],
base_url="https://api.openai.com/v1",
api_key="your-api-key",
model_name="gpt-4o",
)
asyncio.run(main())
Low-Level API (Full Control)
import asyncio
from kiva import run, create_agent, ChatOpenAI, tool
@tool
def calculate(expr: str) -> str:
"""Evaluate a math expression."""
return str(eval(expr))
async def main():
model = ChatOpenAI(model="gpt-4o", api_key="...")
agent = create_agent(model=model, tools=[calculate])
agent.name = "calculator"
agent.description = "Performs calculations"
async for event in run(
prompt="Calculate 100 / 4",
agents=[agent],
base_url="https://api.openai.com/v1",
api_key="your-api-key",
model_name="gpt-4o",
):
match event.type:
case "token":
print(event.data["content"], end="", flush=True)
case "workflow_selected":
print(f"\nWorkflow: {event.data['workflow']}")
case "agent_start":
print(f"\nAgent started: {event.data.get('agent_id')}")
case "agent_end":
print(f"\nAgent finished")
case "final_result":
print(f"\n\nResult: {event.data['result']}")
asyncio.run(main())
Workflow Patterns
Router Workflow
Routes tasks to a single most appropriate agent. Best for simple, single-domain queries.
Supervisor Workflow
Coordinates multiple agents executing in parallel. Ideal for multi-faceted tasks that can be decomposed into independent subtasks.
Parliament Workflow
Implements iterative deliberation with conflict resolution. Designed for complex reasoning tasks requiring consensus or validation.
Event Types
| Event | Description |
|---|---|
token |
Streaming token from LLM |
workflow_selected |
Workflow and complexity determined |
parallel_start |
Parallel agent execution started |
agent_start |
Individual agent started |
agent_end |
Individual agent completed |
parallel_complete |
All parallel agents finished |
final_result |
Final synthesized result |
error |
Error occurred |
Configuration
async for event in run(
prompt="Your task",
agents=agents,
model_name="gpt-4o", # Lead agent model
api_key="...", # API key
base_url="...", # API base URL
workflow_override="supervisor", # Force specific workflow
max_iterations=10, # Parliament max iterations
max_parallel_agents=5, # Max concurrent agents
):
...
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.1.1.tar.gz.
File metadata
- Download URL: kiva_sdk-0.1.1.tar.gz
- Upload date:
- Size: 28.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","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 |
119689e4360f4bd38efe0315812f366bee8e719a4ec0e1edf8690cbf84fe017b
|
|
| MD5 |
d84497b1a0a582b23a715321de1269fb
|
|
| BLAKE2b-256 |
ecdff9596ff2f89b282ec26aabc79cfd9dee8fe2096dda8ca214b23ba263983b
|
File details
Details for the file kiva_sdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: kiva_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 33.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","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 |
b0334671cc3a8b0e6aaa94122330ccae875e4aff8f4dd02aae9a29e9d288128d
|
|
| MD5 |
22f20667dc48388ab4e5c7785d13f517
|
|
| BLAKE2b-256 |
7459d6d17fdaf316c8dc08b102446f587ab1311f116ec0ecaf3ecf34cbc18cea
|