Skip to main content

A highly flexible multi-agent ReAct framework powered by Google Gemini with advanced Memory, RAG, and Network resilience

Project description

🐝 Swarm Intelligence Framework

PyPI version License: MIT GitHub stars

Swarm is a professional, production-ready, highly flexible multi-agent intelligence framework powered by Google's Gemini models. It allows an arbitrary number of autonomous agents to collaborate, use system tools, execute code, perform web searches, and index local data in a shared environmental context with robust transaction safety and memory management.

🚀 Key Features

  • N-Agent Support: Run as many agents as your tasks require.
  • Autonomous Toolchain: Modular, isolated tools returning unified ToolResult wrappers.
  • Dynamic Layered Configuration: Configures any parameter (name, model, temperature, system prompt) via CLI flags, JSON configuration files, or saved session states with hierarchical merging (Defaults ➔ Session Config ➔ CLI Args).
  • Handover Logic: Agents can autonomously pass control to specific peers using the pass_turn tool.
  • Shared Environment: Tool execution outputs are shared with all agents via automatic System Reports.
  • Files API Integration: Agents can upload and analyze local files (PDFs, images, logs) on the fly.
  • Smart Sandboxing: Per-agent regex blacklists for terminal commands and file system paths.
  • Persistent & Secure Sessions: Save and load complete Swarm states. Protected against race conditions and file corruption via SessionLockManager (thread-safe RLock and atomic temp-file swaps).
  • Advanced Memory Hierarchy: Integrated MemoryManager with sliding window history truncation to prevent context window overflow while preserving key interaction states.
  • Built-in RAG (Retrieval-Augmented Generation): Dynamic indexing and querying of local documents via LocalFileRetriever and RAGTool with token-aware truncation.
  • Network Resilience:
    • 429 (Too Many Requests): Automatic API key rotation.
    • 503 (Service Unavailable) / 500: Automatic backoff and retry.

🛠 Installation

pip install swarmai

Requires Python 3.9+ and a Google Gemini API Key.

💻 Quick Start

Basic Two-Agent Discussion

swarm --keys YOUR_API_KEY --agents_count 2

Autonomous Developer & Auditor

swarm --keys YOUR_API_KEY \
      --first_msg "Write a secure Python data scraper" \
      --ai1_name "Dev" --ai1_sys "You are a senior coder." \
      --ai2_name "Security" --ai2_sys "You look for vulnerabilities."

⚙️ Advanced CLI Configuration

Swarm uses a dynamic argument system. You can prefix any standard parameter with aiN_ to target a specific agent:

  • --ai1_model "gemini-1.5-pro" (Use a heavier model for the lead agent)
  • --ai2_temp 0.1 (Make the auditor more deterministic)
  • --ai3_name "Researcher" (Set a custom name for the 3rd agent)
  • --cmd_blacklist "rm" "sudo" (Global security policy)

Global Parameters:

  • --agents_count: Number of agents in session (default: 2).
  • --log_level: DEBUG, INFO, or WARNING.
  • --no_pause: Disable "Press Enter" delays for fully autonomous runs.
  • --config: Path to a JSON file containing all these parameters.

⌨️ Command Center (Ctrl+C)

Press Ctrl+C during execution to pause the Swarm and access the interactive menu:

  1. Change Keys: Rotate or update API keys on the fly.
  2. Toggle Pauses: Switch between manual and autonomous modes.
  3. Save State: Export the entire session to a JSON file (including the active config layer!).
  4. Inject Directive: Manually "whisper" a command to one or all agents.
  5. Log Level: Adjust verbosity without restarting.
  6. Shutdown: Gracefully exit the session.

📄 Tool Documentation

  • web_search: Browses the web for real-time data using DuckDuckGo.
  • shell_exec: Runs bash commands. Supports complex multi-line scripts.
  • upload_file: Uploads local assets to the Google Gemini Files API.
  • rag_query: Queries indexed local documents for relevant context snippets.
  • pass_turn: Moves the turn to a specific agent by name.

🤝 Contributing

Swarm is maintained by ProgVM.

Feel free to open issues or submit pull requests for new features!

License: MIT

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

swarmai-1.1.4.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

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

swarmai-1.1.4-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file swarmai-1.1.4.tar.gz.

File metadata

  • Download URL: swarmai-1.1.4.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for swarmai-1.1.4.tar.gz
Algorithm Hash digest
SHA256 6edec8e2da73cd0e77f8888cee03d6e6775649d00e4e71be9378742d247199e3
MD5 0a9256a707e7c404e6c4bd8207b3936f
BLAKE2b-256 7de7c22958fecb7154fc3b270863c12178874e35cadf0058a965e1de1601c91f

See more details on using hashes here.

File details

Details for the file swarmai-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: swarmai-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for swarmai-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0ecba804c93eb88c38125ee50b39a0f8a703009953fa4ccf0a27f3aad37526b5
MD5 af424b0accc2ca3958a9a5d820060742
BLAKE2b-256 2faea1f04496be05333bd39d92a549a2c9e55bd2e119e5748aff853e6b5fbda3

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