Skip to main content

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())

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

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

kiva_sdk-0.4.0.tar.gz (38.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kiva_sdk-0.4.0-py3-none-any.whl (47.4 kB view details)

Uploaded Python 3

File details

Details for the file kiva_sdk-0.4.0.tar.gz.

File metadata

  • Download URL: kiva_sdk-0.4.0.tar.gz
  • Upload date:
  • Size: 38.4 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

Hashes for kiva_sdk-0.4.0.tar.gz
Algorithm Hash digest
SHA256 59a8ae192a0ef6e69d9b2ed4da0dbf241622dd2cb2a4408cadc2efa9d135ffd2
MD5 0755beec391a9b2723dc78b92a95a82d
BLAKE2b-256 4b729f87708dc808dd7455e944d90b5808e409a542fc7bb0ae25af8f22b08c16

See more details on using hashes here.

File details

Details for the file kiva_sdk-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: kiva_sdk-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 47.4 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

Hashes for kiva_sdk-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b79d72750071095f1a5d329bad950b9fa052bd802af0d9d0a96140adb7997199
MD5 133e9bdb66cfc6d9acfda4eddcb5c45c
BLAKE2b-256 b335b21559dcf91d30d4250a231a72cb04839dd7d7141d7e703771d30c01d927

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page