Skip to content

diegogosmar/floor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

64 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Open Floor Protocol (OFP) Multi-Agent System

A Python-based implementation of the Open Floor Protocol 1.1 specification for multi-agent conversation management and floor control.

Overview

This project implements the Floor Manager per Open Floor Protocol (OFP) 1.1 specification, providing:

  • Floor Manager: Core OFP component managing floor control and envelope routing
  • Floor Control Logic: Minimal floor management behaviors (requestFloor β†’ grantFloor, yieldFloor, etc.)
  • Envelope Processing: OFP 1.1 compliant JSON envelope handling
  • Agent Support: Base classes and example agents for testing

Per OFP 1.1: No central agent registry (agents identified only by speakerUri). Dynamic discovery via getManifests/publishManifests events.

Architecture

System Architecture per OFP 1.1

src/
β”œβ”€β”€ floor_manager/     # Floor Manager (core OFP component)
β”‚   β”œβ”€β”€ manager.py       # Main Floor Manager (includes envelope routing)
β”‚   β”œβ”€β”€ floor_control.py # Floor control logic (minimal behaviors)
β”‚   └── envelope.py      # OFP 1.1 envelope models
β”œβ”€β”€ agents/            # Agent implementations (BaseAgent, ExampleAgent, LLMAgent)
β”œβ”€β”€ orchestration/     # Optional orchestration patterns (Convener Agent, etc.)
β”œβ”€β”€ api/               # FastAPI REST endpoints
β”‚   β”œβ”€β”€ floor.py         # Floor control API
β”‚   └── envelope.py      # Envelope processing API
└── main.py            # FastAPI application entry point

Floor Manager (Core OFP 1.1 Component)

The Floor Manager is the central component per OFP Specification Section 0.4.3:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           FLOOR MANAGER                     β”‚
β”‚  (Implements OFP 1.1 Spec Section 2.2)   β”‚
β”‚                                             β”‚
β”‚  β€’ Envelope Processing & Routing (built-in) β”‚
β”‚  β€’ Floor Control Logic (minimal behaviors)  β”‚
β”‚  β€’ Priority Queue Management                β”‚
β”‚  β€’ Conversation State Management            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    ↕
            OFP 1.1 Envelopes
                    ↕
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ Agent A  β”‚  β”‚ Agent B  β”‚  β”‚ Agent C  β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Features:

  1. Envelope Routing (built-in): Routes OFP envelopes between agents (no separate router component)
  2. Floor Control: Implements minimal floor management behaviors (Spec Section 2.2)
  3. Priority Queue: Manages floor requests by priority
  4. State Machine: Floor as autonomous state machine

Important Terminology (per OFP 1.1 Spec):

  • Floor Manager = Our system component (what this project implements)
  • Convener Agent = Optional AGENT that mediates conversations (like a meeting chair)
  • The Floor Manager can work standalone OR delegate to a Convener Agent if present

πŸ“Š Visual Architecture Diagrams: See OFP 1.1 Spec Analysis for detailed architecture based on official specification.

Optional Orchestration Patterns

  • Convener Agent Pattern: Optional agent that mediates conversations (per OFP Spec Section 0.4.3)
  • Collaborative: Autonomous floor negotiation with minimal arbitration
  • Hybrid Delegation: Master agent delegates to specialists while maintaining control

Note: These are optional patterns. The Floor Manager works without them.

Technology Stack

  • Python: 3.11+
  • Web Framework: FastAPI
  • Database: PostgreSQL 15
  • Cache/Queue: Redis 7
  • Testing: pytest, pytest-asyncio

πŸš€ Quick Start - Launch the Floor Manager and Test with Demo Agents

Prerequisites

  • Python 3.11 or higher
  • Docker and Docker Compose
  • PostgreSQL 15 (or use Docker)
  • Redis 7 (or use Docker)

Quick Start (3 Steps)

1. Start Services

# Clone the repository (if not already cloned)
git clone https://github.com/diegogosmar/floor.git
cd floor

# Start services (PostgreSQL, Redis, API)
docker-compose up -d

# Wait a few seconds
sleep 5

2. Verify It Works

# Health check
curl http://localhost:8000/health
# Response: {"status":"healthy"}

3. Test with Demo Agents

Option A: Complete OFP Flow Demo ⭐ RECOMMENDED

# Demonstrates COMPLETE Open Floor Protocol 1.0.1 flow:
# β€’ Agent registration with manifests
# β€’ getManifests (capability discovery)  
# β€’ requestFloor with priority queue
# β€’ grantFloor by autonomous Convener
# β€’ Floor yield and handoff between agents

python examples/agents/complete_ofp_demo.py

This shows the real OFP protocol in action with the Floor Manager API. See Complete OFP Demo Guide for details.

Option B: Interactive GUI Demo 🎨 NEW!

# Install Streamlit (if not already installed)
pip install streamlit

# Launch interactive web GUI
streamlit run streamlit_app.py

Opens in browser at http://localhost:8501. Features:

  • πŸ’¬ Real-time chat with AI agents
  • 🎀 Visual floor status display
  • πŸ‘₯ Multiple agents (Budget Analyst, Travel Agent, Coordinator)
  • πŸ€– AI-powered responses (GPT-4o-mini)
  • 🎯 Priority queue visualization

πŸ“– See: GUI Demo Guide for detailed instructions.

Option C: Basic Floor Control Demo

# Install dependency if needed
pip install httpx

# Test basic multi-agent conversation
python examples/agents/demo_agents.py

# Test floor control priority
python examples/agents/demo_agents.py priority

Option C: Bash Script

# Complete workflow test
./examples/test_workflow.sh

Option D: Swagger UI (Interactive)

# Open in browser
open http://localhost:8000/docs
# Or visit: http://localhost:8000/docs

4. Test with LLM Agents (Optional)

Note: Demo agents use hardcoded responses. For real AI-powered agents, use LLM agents:

# First, install project dependencies (required)
pip install -r requirements.txt

# Then install LLM provider libraries
pip install openai  # For OpenAI
# pip install anthropic  # For Anthropic
# pip install ollama  # For local LLM (optional)

# Set API key (if using OpenAI)
export OPENAI_API_KEY="sk-..."

# Quick test to verify API key works
python examples/agents/quick_llm_test.py

# Full LLM agent examples (OpenAI, Anthropic, Ollama)
python examples/agents/llm_agent_example.py

Supported Providers:

  • OpenAI: GPT-4, GPT-4o, GPT-4o-mini, GPT-3.5-turbo
  • Anthropic: Claude 3 (Haiku, Sonnet, Opus)
  • Ollama: Local LLM models (requires ollama serve)

πŸ“– See: LLM Integration Guide for detailed instructions.

Quick Manual Test

# 1. Register an agent
curl -X POST http://localhost:8000/api/v1/agents/register \
  -H "Content-Type: application/json" \
  -d '{
    "speakerUri": "tag:test.com,2025:agent_1",
    "agent_name": "Test Agent",
    "capabilities": ["text_generation"]
  }'

# 2. Request floor
curl -X POST http://localhost:8000/api/v1/floor/request \
  -H "Content-Type: application/json" \
  -d '{
    "conversation_id": "conv_test",
    "speakerUri": "tag:test.com,2025:agent_1",
    "priority": 5
  }'

# 3. Check floor holder
curl http://localhost:8000/api/v1/floor/holder/conv_test

πŸ“š Complete Documentation

Development

Running Tests

Important: Make sure pytest-asyncio is installed in your virtual environment:

# Install test dependencies (if not already installed)
pip install -r requirements.txt

# Verify pytest-asyncio is installed
pip list | grep pytest-asyncio

# If missing, install it explicitly
pip install pytest-asyncio>=0.23.0

Then run tests:

# Run all tests
pytest

# Run with coverage
pytest --cov=src --cov-report=html

# Run specific test file
pytest tests/test_floor_manager.py

Troubleshooting: If you see "async def functions are not natively supported", see Testing Guide for detailed troubleshooting steps.

Code Quality

# Format code
black src tests

# Sort imports
isort src tests

# Lint
flake8 src tests

# Type checking
mypy src

Project Structure

FLOOR/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ floor_manager/      # Floor control primitives
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ floor_control.py
β”‚   β”‚   └── floor_queue.py
β”‚   β”œβ”€β”€ envelope_router/    # Envelope routing
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ router.py
β”‚   β”‚   └── envelope.py
β”‚   β”œβ”€β”€ agent_registry/     # Agent registry
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ registry.py
β”‚   β”‚   └── capabilities.py
β”‚   β”œβ”€β”€ agents/             # Agent implementations
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ base_agent.py
β”‚   β”‚   └── example_agent.py
β”‚   β”œβ”€β”€ models/            # Data models
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   └── schemas.py
β”‚   β”œβ”€β”€ database/          # Database configuration
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   └── connection.py
β”‚   └── main.py            # FastAPI app
β”œβ”€β”€ tests/                 # Test suite
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ test_floor_manager.py
β”‚   β”œβ”€β”€ test_envelope_router.py
β”‚   β”œβ”€β”€ test_agent_registry.py
β”‚   └── test_agents.py
β”œβ”€β”€ docker/                # Docker files
β”‚   β”œβ”€β”€ Dockerfile
β”‚   └── docker-compose.yml
β”œβ”€β”€ docs/                  # Documentation
β”‚   β”œβ”€β”€ architecture.md
β”‚   └── api.md
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ .env.example          # Environment template
β”œβ”€β”€ docker-compose.yml    # Docker Compose config
└── README.md             # This file

API Documentation

Once the server is running, access the interactive API documentation:

Open Floor Protocol 1.1

This implementation follows the Open Floor Protocol 1.1 specification for:

  • Floor control primitives (autonomous state machine with convener)
  • Conversation envelope format (with assignedFloorRoles and floorGranted)
  • Agent capability discovery
  • Message routing and delivery
  • Privacy flag handling (only for utterance events)

Key OFP 1.1 Features:

  • Floor Manager acts as autonomous Convener
  • assignedFloorRoles and floorGranted in conversation object
  • acceptInvite event support
  • Privacy flag only respected for utterance events

Contributing

We welcome contributions! Here's how to get started:

  1. Fork the repository on GitHub
  2. Clone your fork and create a feature branch
  3. Make your changes following our coding standards
  4. Add tests for new functionality
  5. Ensure all tests pass: pytest
  6. Update documentation if needed
  7. Submit a Pull Request - We'll review and merge it!

πŸ“– For detailed guidelines, see CONTRIBUTING.md - It includes:

  • Complete development setup instructions
  • Pull Request process and best practices
  • Coding standards and style guide
  • Testing requirements
  • Commit message conventions
  • OFP 1.1 compliance guidelines

Quick PR Process:

  • Fork β†’ Branch β†’ Code β†’ Test β†’ PR β†’ Review β†’ Merge βœ…

Related Projects

This implementation is part of the Open Floor Protocol implementations collection:

Support

For issues and questions, please open an issue in the repository.

About

OFP FLOOR implementation

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published