Multi Agent Reasoning
The Multi-Agent Reasoning framework creates an interactive chatbot where AI agents collaborate via structured reasoning and Swarm Integration for optimal answers. Simulating a team that discusses, debates, and refines responses, it enables complex problem-solving and precise results. Now with Prompt Caching to reduce latency and costs.
Install / Use
npx skills add AdieLaine/multi-agent-reasoningInstalls into whichever agent you are using.
README
Multi-Agent Reasoning with Memory and Swarm Framework

Table of Contents
- Overview
- Features
- Prerequisites
- Installation
- Usage
- Models
- Agents' Reasoning and Chat Process
- Swarm Integration
- Prompt Caching
- JSON Configuration File
- Code Structure and Logic
- Visual Flow of the Reasoning Process
- Contributing
- License
- Repository Setup
- Directory Structure
- Acknowledgements
- Additional Resources
Overview
The Multi-Agent Reasoning with Memory and Swarm Framework framework creates an interactive chatbot experience where multiple AI agents collaborate through a structured reasoning process to provide optimal answers. Each agent brings unique perspectives and expertise, and through iterative steps of discussion, verification, critique, and refinement, they converge on a high-quality, accurate response.
Additionally, the system integrates the Swarm Framework for Intelligence to enhance collaboration among agents. Swarm allows agents to coordinate efficiently, leveraging collective intelligence to solve complex tasks.
Users can also chat with individual agents. Agents are aware of each other, including their personalities and quirks, and can answer questions about one another, providing a rich and interactive experience.
Features
- Multi-Agent Collaboration: Simulates collaborative reasoning among multiple agents.
- Swarm Framework Integration: Enhances agent coordination and execution.
- Agent Awareness: Agents are aware of each other, including personalities and capabilities.
- Direct Agent Chat: Engage in personalized conversations with individual agents.
- Structured Reasoning Process: Multi-step process including discussion, verification, critique, and refinement.
- Swarm-Based Reasoning: Dynamic agent handoffs and function execution using Swarm.
- Iterative Refinement: Improve responses through multiple iterations for enhanced accuracy.
- Response Blending: Combine refined responses into a single, cohesive answer.
- User Feedback Loop: Incorporate user feedback for further response refinement.
- Context Retention Option: Maintain conversation context for more coherent interactions.
- Customizable Agents: Easily add or modify agents via a JSON configuration file.
- Parallel Processing: Concurrent agent tasks improve efficiency.
- Robust Error Handling: Implements retry mechanisms and extensive logging.
- Token Usage Transparency: Displays detailed token usage information post-response.
- Prompt Caching: Reduces latency and cost for repeated prompts using OpenAI's caching.
Prerequisites
- Python 3.10 or higher
- OpenAI Python Library (compatible with the models used)
- colorama: For colored console output
- tiktoken: For accurate token counting
- Swarm: For agent coordination
Installation
-
Clone the Repository
git clone https://github.com/AdieLaine/multi-agent-reasoning.git -
Navigate to the Project Directory
cd multi-agent-reasoning -
Create a Virtual Environment (Optional but Recommended)
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate -
Install Required Packages
pip install -r requirements.txtAlternatively, install packages individually:
pip install openai colorama tiktoken -
Install Swarm
pip install git+https://github.com/openai/swarm.gitRefer to Swarm's GitHub repository for detailed installation instructions.
-
Set Your OpenAI API Key
Set your API key as an environment variable:
export OPENAI_API_KEY='your-api-key-here'On Windows:
set OPENAI_API_KEY=your-api-key-hereAlternatively, use a
.envfile or set it directly in your script.
Usage
Execute the main script to start the Multi-Agent Reasoning chatbot:
python reasoning.py
Upon running, you'll see the main menu:
═════════════════════════════════════════════════════════════════════════════════════════════
╔════════════════════════════════════════════════════════════════════════════════════╗
║ Multi-Agent Reasoning Chatbot ║
╚════════════════════════════════════════════════════════════════════════════════════╝
Please select an option:
1. Chat with an agent
2. Use reasoning logic
3. Use Swarm-based reasoning
4. Exit
Enter your choice (1/2/3/4):
Option Descriptions
-
Chat with an Agent
- Engage directly with a selected agent.
- Agents possess unique personalities and can answer questions about themselves and others.
-
Use Reasoning Logic
- Initiate a collaborative reasoning process involving multiple agents.
- Follows structured steps: discussion, verification, critique, refinement, and blending.
-
Use Swarm-Based Reasoning
- Utilize the Swarm Framework for Intelligence for dynamic agent coordination.
- Agents can delegate tasks to specialized agents seamlessly.
-
Exit
- Terminate the application.
Models
The system utilizes specific OpenAI models tailored to different functionalities:
- Reasoning Logic:
o1for advanced reasoning tasks is optimal, you can also usegpt-4o.- o1 Model Compatible:
o1is compatible with this current code version, other models may be added in lieu ofo1.
- o1 Model Compatible:
- Chat Interactions:
gpt-4ofor interactive agent conversations. - Swarm Agents: Configurable, defaulting to
gpt-4o.
These models support detailed token usage reporting, aiding in monitoring and optimizing performance.
Agents' Reasoning and Chat Process
Chat Mode
Objective: Engage in direct, personalized conversations with a chosen agent.
- Process:
- Select an agent from the available list.
- Interact with the agent while maintaining conversation context.
- Agents can reference and discuss each other based on their configurations.
Example:
- User: "Tell me about Agent 74."
- Agent 47: "Agent 74 is our creative and empathetic counterpart, specializing in imaginative solutions and understanding user emotions."

Reasoning Logic Mode
Objective: Facilitate a comprehensive reasoning process through multi-agent collaboration.
Steps:
-
Initial Discussion
- Each agent generates an independent response to the user's prompt.
- Ensures diverse perspectives without immediate influence from other agents.
-
Verification
- Agents verify the accuracy and validity of their responses.
- Ensures factual correctness and reliability.
-
Critiquing
- Agents critique each other's verified responses.
- Identifies areas for improvement, omissions, or biases.
-
Refinement
- Agents refine their responses based on critiques.
- Enhances completeness and accuracy.
-
Response Blending
- Combines refined responses into a single, cohesive answer.
- Utilizes the
blend_responsesfunction for optimal synthesis.
-
User Feedback Loop
- Users provide feedback on the response's helpfulness and accuracy.
- Allows for further refinement if necessary.
-
Context Retention
- Option to retain conversation context for more coherent future interactions.
Swarm Integration
Overview
Swarm Integration enhances the Multi-Agent Reasoning system by enabling dynamic agent coordination and task delegation. Swarm allows agents to collaborate efficiently, leveraging collective intelligence to solve complex tasks and improve responsiveness.
Swarm focuses on making agent coordination and execution lightweight, highly controllable, and easily testable. It achieves this through two primitive abstractions: Agents and Handoffs. An Agent encompasses instructions and tools and can, at any point, choose to hand off a conversation to another Agent.

How It Works
-
Swarm Client Initialization
from swarm import Agent, Swarm client = Swarm() -
Agent Initialization
- Agents are initialized using Swarm, incorporating configurations from
agents.json. - Each agent has unique instructions and is aware of other agents' capabilities.
- Agents are initialized using Swarm, incorporating configurations from
-
Conversation Handling
- Swarm manages conversation flow, agent selection, and function execution.
- Agents can delegate tasks to specialized agents based on context.
Swarm-Based Reasoning
Objective: Utilize the Swarm Framework for Intelligence to coordinate agents dynamically for efficient collaboration and task delegation.
Steps:
-
Initialization
- Load agents from
agents.json. - Initialize agents with awareness of their counterparts.
- Load agents from
-
Discussion
- Each agent provides an initial response to the user prompt.
- Resp
Related Skills
python-debugpy
385.6kDebug Python with pdb, breakpoint(), post-mortem inspection, and debugpy remote attach.
skill-creator
385.6kCreate, edit, audit, tidy, validate, or restructure AgentSkills and SKILL.md files.
claude-opus-4-5-migration
140.7kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
automl-hyperparameter-optimization
40.5kAutoML and hyperparameter optimization rules for Python ML projects using Ray Tune, Optuna, PyCaret, and time-series AutoML libraries
