CoolFace
Apppublic

kaire-2222/slm-agents-publish-subscribe-components

sourceHugging Facegpl-3.0updated 3mo agoView on Hugging Face
0likes
App README

Pub/Sub Multi-Agent System

A dynamic multi-agent orchestration system using publish/subscribe architecture with small language models.

Overview

This system allows you to create and orchestrate multiple AI agents that communicate through a message bus using the publish/subscribe pattern. Each agent:

  • —Subscribes to specific topics
  • —Processes messages when triggered
  • —Publishes results to new topics
  • —Uses configurable language models

Features

  • —🔄 Dynamic Agent Creation: Add/remove agents on the fly
  • —📡 Pub/Sub Architecture: Event-driven agent orchestration
  • —🤖 Multiple Models: Support for general, medical, coding, and NER models
  • —🎯 Topic-Based Routing: Agents communicate through named topics
  • —📋 Real-Time Logging: Watch the message flow through the bus
  • —⚙️ Customizable Prompts: Each agent has its own prompt template
  • —🏷️ Named Entity Recognition: Dedicated NER agents with formatted output display
  • —💾 Save/Load with Results: Save configurations including execution results and logs
  • —📊 Subscribable Data Sources: Data sources can subscribe to topics and update dynamically during execution

How It Works

1. Agent Configuration

Each agent has:

  • —Title: A descriptive name
  • —Prompt: Template for processing (can use {schema}, {input}, and {question} placeholders)
  • —Model: Which LLM to use
  • —Subscribe Topic: Which topic triggers this agent
  • —Publish Topic: Where to publish results (use "FINAL" for end results)

2. Message Bus

  • —Agents subscribe to topics during initialization
  • —System publishes "START" message to begin
  • —Agents process messages and publish results
  • —Chain continues until no more subscribers

3. Execution Flow

User enters question → Published to START topic
     ↓
Agent1 (subscribes to START) → publishes to TOPIC_A
     ↓
Agent2 (subscribes to TOPIC_A) → publishes to TOPIC_B
     ↓
Agent3 (subscribes to TOPIC_B) → publishes to FINAL
     ↓
Final result displayed to user

Example Use Case: NL to SQL Pipeline

Agent 1: Schema Analyzer

  • —Subscribe: START
  • —Publish: SCHEMA_ANALYZED
  • —Prompt: Analyze database schema and identify relevant tables

Agent 2: SQL Generator

  • —Subscribe: SCHEMA_ANALYZED
  • —Publish: SQL_GENERATED
  • —Prompt: Generate SQL query based on analyzed schema

Agent 3: SQL Validator

  • —Subscribe: SQL_GENERATED
  • —Publish: SQL_VALIDATED
  • —Prompt: Validate and optimize the SQL query

Example Use Case: Medical Analysis (with BioMistral)

Agent 1: Symptom Analyzer

  • —Subscribe: START
  • —Publish: SYMPTOMS_ANALYZED
  • —Model: biomistral:7b-chat
  • —Prompt: Analyze medical symptoms from input

Agent 2: Diagnosis Suggester

  • —Subscribe: SYMPTOMS_ANALYZED
  • —Publish: DIAGNOSIS_SUGGESTED
  • —Model: biomistral:7b-chat
  • —Prompt: Suggest possible diagnoses based on symptoms

Supported Models

This deployment includes five specialized models:

  • —phi4-mini: General-purpose model (3.8B parameters) - Great for text analysis, SQL generation, summarization, reasoning, and general tasks
  • —MedAIBase/MedGemma1.5:4b: Medical/healthcare model (4B parameters) - Specialized for clinical reasoning, medical documentation, and healthcare-related tasks
  • —deepseek-coder:1.3b: Code generation model (1.3B parameters) - Optimized for programming, code analysis, debugging, and technical documentation
  • —samrawal/bert-base-uncased_clinical-ner: Clinical NER model - Extracts medical entities (diseases, symptoms, medications) from clinical text
  • —OpenMed/OpenMed-NER-AnatomyDetect-BioPatient-108M: Anatomy NER model (108M parameters) - Detects anatomical entities and patient-related information

These models provide specialized capabilities for medical, coding, NER, and general-purpose tasks.

Architecture

Web UI (React) → FastAPI Server → Message Bus
                                    ↓
                              Agent 1 (LLM)
                                    ↓
                              Agent 2 (LLM)
                                    ↓
                              Agent 3 (LLM)

Technical Stack

  • —Backend: FastAPI with streaming responses
  • —Frontend: React with Tailwind CSS
  • —LLM Runtime: Ollama
  • —Orchestration: Custom pub/sub message bus

Educational Value

Perfect for learning:

  • —Event-driven architectures
  • —Multi-agent systems design
  • —Pub/Sub messaging patterns
  • —Asynchronous agent orchestration
  • —Dynamic workflow composition