Skip to main content

AgentSwarm Orchestrator - Python Implementation

This Python implementation of AgentSwarm Orchestrator was inspired by https://kimik25.com. It provides a simple, intuitive API for managing autonomous agent swarms with async support.

Features

  • Simple API: Easy to use with Pythonic design patterns
  • Async Support: Built on asyncio for efficient concurrent operations
  • 256K Context: Inspired by Kimi K2.5's extended context window
  • Type Hints: Full type annotations for better IDE support
  • Dataclasses: Clean, structured data models

Installation

pip install kimi25-opensource

Usage

import asyncio
from agent_swarm import AgentSwarm, SwarmConfig, TaskMessage
import uuid

async def main():
    # Initialize swarm with 256K context window
    config = SwarmConfig(
        max_agents=100,
        context_window=256000,
        topology='mesh'
    )

    swarm = AgentSwarm(config)

    # Spawn specialized agents
    agent = swarm.spawn_agent('data-processor', 'analysis', 'transform')

    # Dispatch messages
    agent.dispatch_message(TaskMessage(
        id=str(uuid.uuid4()),
        msg_type='process',
        payload={'data': 'example'}
    ))

    # Get swarm statistics
    print(swarm.get_stats())

    # Clean shutdown
    await swarm.shutdown()

asyncio.run(main())

API Reference

Classes

SwarmConfig

Configuration dataclass for swarm initialization.

Parameters:

  • max_agents (int): Maximum number of agents (default: 100)
  • context_window (int): Token context limit (default: 256000)
  • topology (str): Swarm topology (default: 'mesh')

TaskMessage

Message dataclass for inter-agent communication.

Parameters:

  • id (str): Unique message identifier
  • msg_type (str): Message type
  • payload (Dict[str, Any]): Message data
  • from_agent (str): Source agent ID (auto-set)
  • to_agent (str): Target agent ID

Agent

Represents a single autonomous agent.

Methods:

  • dispatch_message(msg: TaskMessage) -> bool: Send a message
  • process_messages(handler: Callable) -> Awaitable: Process queued messages

AgentSwarm

Main swarm coordinator class.

Methods:

  • spawn_agent(agent_id: str, *capabilities) -> Agent: Create a new agent
  • broadcast_message(from_agent, msg_type, payload) -> int: Send to all agents
  • get_agent(agent_id: str) -> Agent: Retrieve agent by ID
  • get_stats() -> Dict: Get swarm statistics
  • shutdown() -> Awaitable: Gracefully shutdown

Enums

TopologyType

Supported swarm topologies:

  • HIERARCHICAL: Tree-based coordination
  • MESH: Peer-to-peer communication
  • HYBRID: Combined approach

Examples

Async Message Processing

import asyncio
from agent_swarm import AgentSwarm, SwarmConfig

async def message_handler(msg):
    print(f"Processing {msg.msg_type}")
    # Handle message asynchronously
    await asyncio.sleep(0.1)

async def main():
    swarm = AgentSwarm(SwarmConfig(max_agents=50))
    agent = swarm.spawn_agent('worker', 'processing')

    await agent.process_messages(message_handler)

asyncio.run(main())

Custom Topology

from agent_swarm import SwarmConfig, TopologyType

config = SwarmConfig(
    max_agents=200,
    context_window=512000,
    topology=TopologyType.HIERARCHICAL.value
)

Development

Running Tests

pip install -e ".[dev]"
pytest

Code Formatting

black agent_swarm/
mypy agent_swarm/

Performance

The Python implementation is optimized for:

  • Async I/O: Efficient concurrent operations via asyncio
  • Memory efficiency: Minimal overhead per agent
  • Developer productivity: Clean, readable code

License

MIT License - See LICENSE file for details.

Metadata

Release files for kimi25-opensource 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kimi25-opensource 1.0.0
File Size Uploaded Provenance
kimi25_opensource-1.0.0.tar.gz 6.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for kimi25-opensource 1.0.0
File Interpreter ABI Platform
kimi25_opensource-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.1 kB

Release files / kimi25_opensource-1.0.0.tar.gz

Download URL kimi25_opensource-1.0.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1b9641d987e9b8d8bd124107af94b18957ecf9e9f73976f78551b404c77ed714
BLAKE2b-256 checksum
How to use checksums
626256e40cc7a19307c0dfa37ccd79399024130e4f373ec9ee954441f70d5d12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release files / kimi25_opensource-1.0.0-py3-none-any.whl

Download URL kimi25_opensource-1.0.0-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e328b44473b34a8d3e071aba062c5a80664bbc3cfc4f27fc89fc8a924b7ac87c
BLAKE2b-256 checksum
How to use checksums
f0cb16ebed6b509e6fac7a8e546e04d873b78d479133650087f5159d0cbfc217
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Security for kimi25-opensource 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page