Skip to main content

Headless framework for multi-agent chat runtime and evaluation.

Project description

SwarmForge

SwarmForge is a Python package for authoring, running, and evaluating multi-agent swarms. You define the swarm graph, provide the model-turn callback, and keep sessions, handoffs, tools, checkpoints, and evaluation artifacts under your control.

  • Explicit graph-based multi-agent runtime
  • Python tool execution with inferred JSON schema
  • OpenRouter, Gemini, and other OpenAI-compatible provider support
  • FastAPI transport for stateless and session-backed HTTP flows
  • Evaluation helpers for graph snapshots, scenario seeds, and artifact scoring

Install

Python 3.11+ is required.

pip install swarmforge

If you want the FastAPI transport too:

pip install "swarmforge[api]"

Provider-backed examples, the demo UI, and local API runs load a nearby .env automatically. Copy .env.example to .env before using them:

cp .env.example .env

Quick Start

The shortest path is a single-node swarm with a stubbed model callback:

import asyncio
import json

from swarmforge.swarm import (
    AgentTurnResult,
    InMemorySessionStore,
    SwarmDefinition,
    SwarmNode,
    SwarmSession,
    process_swarm_stream,
)


class ExampleTurnRunner:
    async def run_turn(self, *, agent_node, contents, config):
        del agent_node, contents, config
        return AgentTurnResult(response_text="Here is a direct answer from SwarmForge.")


swarm = SwarmDefinition(
    id="assistant",
    name="Assistant Swarm",
    nodes=[
        SwarmNode(
            id="assistant",
            node_key="assistant",
            name="Assistant",
            intent="Handle general requests",
            system_prompt="You are a concise assistant.",
            capabilities=["Answer questions"],
            is_entry_node=True,
        )
    ],
)


async def main():
    session = SwarmSession(id="session-1", swarm=swarm)
    store = InMemorySessionStore()
    async for event in process_swarm_stream(
        session,
        "Give me a concise summary.",
        store=store,
        turn_runner=ExampleTurnRunner(),
    ):
        print(json.dumps(event, indent=2))


if __name__ == "__main__":
    asyncio.run(main())

When you are ready to add routing, continue with the multi-agent flow in the docs.

Package Surfaces

  • swarmforge.swarm Runtime models, session state, orchestration, tool execution, and stores.
  • swarmforge.authoring Prompt templates, payload validation, and graph compilation helpers.
  • swarmforge.evaluation Graph snapshots, scenario generation, feasibility checks, and artifact scoring.
  • swarmforge.api FastAPI application factory built on the same runtime primitives.

Providers

SwarmForge ships with an OpenAI-compatible provider wrapper. OpenRouter is the default path, and Gemini is built in as an alternative mode.

Start from the repository .env.example and fill in the provider you want to use.

OpenRouter .env:

MODEL_PROVIDER=openrouter
NORMAL_MODEL=openrouter/auto
OPENROUTER_API_KEY=sk-or-...
OPENROUTER_SITE_URL=https://your-app.example
OPENROUTER_APP_NAME="Your App Name"

Gemini .env:

MODEL_PROVIDER=gemini
NORMAL_MODEL=gemini-3-flash-preview
GEMINI_API_KEY=...

Minimal client setup:

from swarmforge.evaluation.provider import ModelConfig, OpenAIClientWrapper

client = OpenAIClientWrapper(ModelConfig())

ModelConfig() reads MODEL_PROVIDER, NORMAL_MODEL, and the matching API key from .env or the shell environment.

FastAPI Transport

You can expose the runtime over HTTP without changing your swarm definitions:

pip install "swarmforge[api]"
uvicorn swarmforge.api.fastapi:create_fastapi_app --factory --reload

That app exposes both stateless run endpoints and session-backed endpoints with SSE streaming.

Documentation

Source Examples

The repository includes end-to-end example scripts under examples/. Those scripts are useful when you want runnable reference flows for authoring, orchestration, evaluation, provider integration, or FastAPI transport. Provider-backed examples and the local FastAPI example read from .env.example-style settings.

The demo UI under demo-ui/ reads the same root .env for its default API base, provider, and model. Its Vite scripts create .env from .env.example automatically when the file is missing.

Contributing

Core modification, docs development, demo UI work, and PyPI release steps are documented in CONTRIBUTING.md.

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

swarmforge-0.4.0.tar.gz (59.7 kB view details)

Uploaded Source

Built Distribution

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

swarmforge-0.4.0-py3-none-any.whl (54.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: swarmforge-0.4.0.tar.gz
  • Upload date:
  • Size: 59.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for swarmforge-0.4.0.tar.gz
Algorithm Hash digest
SHA256 2104d7b569de47d49f47f0fedc62cd4d7f910df9537bc0aeeae1d7c131138ab3
MD5 e439f405d6540c093d31c5bce40e7b89
BLAKE2b-256 96d50a86be36d6540fc48ad8a5c02d891125a29454b6c1affe678375fe81285d

See more details on using hashes here.

Provenance

The following attestation bundles were made for swarmforge-0.4.0.tar.gz:

Publisher: release.yml on Rvey/swarm-forge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: swarmforge-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 54.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for swarmforge-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83ff36de33b1c1e5fe17da84fb984cdd8e538c6100b7075d4fc38a35873695cc
MD5 fc23c757b5c547ee0602e4e36bb171d3
BLAKE2b-256 42c6fa58a6c401c112e4484d96de7b1b13d61e861d1aff6fa95a88606e750dae

See more details on using hashes here.

Provenance

The following attestation bundles were made for swarmforge-0.4.0-py3-none-any.whl:

Publisher: release.yml on Rvey/swarm-forge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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