Mangaba AI Multi-Agent Framework

repository·master·Indexed 42 days ago

https://github.com/mangaba-ai/mangaba_ai

A professional multi-agent orchestration framework featuring ReAct reasoning, native function calling, RAG, and persistent memory. Version 4.0.0 supports event-driven flows, agent-to-agent (A2A) communication, MCP interop, and multi-provider fallback configurations for LLMs.

Tokens
79.4K
Snippets
247
Records
299
Agent score
52%

What's inside Mangaba AI

  1. Overview of Mangaba AI

    master

    Mangaba AI is a system for creating intelligent AI agents, primarily based on Google Generative AI (Gemini). It is designed for high scalability and is optimized for Brazilian Portuguese. The system is built around two core communication and management protocols: A2A (Agent-to-Agent) for seamless communication between multiple agents, and MCP (Model Context Protocol) for intelligent context management.

    Core Components

    • Main Agent: Handles Chat, Analysis, and Translation.
    • MCP Protocol: Manages Context, Sessions, and Search.
    • A2A Protocol: Enables P2P communication, Broadcast capabilities, and Handlers.
    • Supporting Modules: Config, Logger, and Utils.
  2. Overview of Mangaba AI Architecture

    master

    The Mangaba AI framework is organized into several functional modules:

    • core/: The engine containing agents (ReAct reasoning), tasks (with guardrails/retries), crew orchestration, workflow engines, and the multi-provider LLM engine.
    • tools/: The tool system, including the @tool decorator for automatic JSON schema generation and various built-in toolkits (File, Web, Math, Text).
    • memory/: Memory management including short-term (sliding window), long-term (SQLite + embeddings), and entity memory.
    • embeddings/ & vectorstores/: Support for various embedding providers (OpenAI, Google, HuggingFace) and vector storage backends (ChromaDB, PostgreSQL/pgvector, Redis, SQLite, In-memory).
    • rag/ & knowledge/: RAG pipelines for document ingestion, splitting, retrieval, and querying.
    • flows/: Event-driven orchestration using @start, @listen, @router, and @persist decorators.
    • observability/: Integration with OpenTelemetry, Langfuse, MLflow, and Phoenix, along with PII redaction and auditing.
    • training/: Tools for iterative human feedback (trainer.py) and task evaluation (evaluator.py).
    • cli/: Command-line interface for managing projects and running agents.
  3. Summary of Best Practices for Mangaba AI

    master

    When building and maintaining applications with Mangaba AI, follow these core principles:

    Architecture

    • Use Factory/Builder patterns for complex agents.
    • Maintain clear separation of responsibilities.
    • Implement specific handlers for Agent-to-Agent (A2A) communication.

    Security

    • Use environment variables for all API keys.
    • Implement rate limiting and input sanitization.
    • Always validate configurations before use.

    Context Management (MCP)

    • Structure contexts using tags and priorities.
    • Implement automatic cleanup for old contexts.
    • Use intelligent search to improve relevance.

    Performance

    • Use optimized prompt templates.
    • Implement caching for repeated responses.
    • Process requests in parallel where possible.

    Quality & Operations

    • Write unit and integration tests.
    • Monitor performance metrics and use structured logs.
    • Implement robust health checks and use separate environments (Dev/Prod/Test).
  4. What is Mangaba AI?

    master

    Mangaba AI is a Brazilian framework for creating AI agents. It is built around three core pillars:

    • Main Agent: Powered by Google Generative AI (Gemini).
    • A2A Protocol: Enables communication between multiple agents.
    • MCP Protocol: Provides intelligent context management.

    It is designed for high scalability and use cases such as document analysis, virtual assistants, process automation, translation, and data analysis.

  5. Understand the Crew execution processes

    master

    When orchestrating multiple agents using a Crew, you can choose from four distinct execution strategies (processes) depending on your workflow requirements:

    • SEQUENTIAL: Tasks are executed one after another in a linear order. Best for linear workflows.
    • HIERARCHICAL: A manager agent delegates tasks and reviews each delivery. Best for teams with a leader.
    • PARALLEL: Tasks are executed concurrently using asyncio. Best for independent tasks.
    • CONSENSUAL: All agents execute every task, and the results are synthesized. Best for critical decision-making processes.
  6. Format of search results from a Vector Store

    master

    When calling the .search() method, the store returns a list of dictionaries. Each dictionary represents a retrieved document and includes the following keys:

    • id: The unique identifier of the vector.
    • content: The original text associated with the vector.
    • score: The similarity score (e.g., cosine similarity).
    • metadata: A dictionary containing any additional metadata provided during the add step.
    # Example return structure:
    [
        {"id": "abc123", "content": "...", "score": 0.95, "metadata": {...}},
        {"id": "def456", "content": "...", "score": 0.87, "metadata": {...}},
    ]
  7. Manage conversation context with MCP (Model Context Protocol)

    master

    The MCPProtocol allows you to manage conversation contexts, maintain history, and inject relevant information into the agent's state. You can add context using the .add_context() method with a content string, a context_type, and a priority level.

    from mangaba_agent import MangabaAgent
    from protocols.mcp import MCPProtocol
    
    # Create agent with MCP
    agent = MangabaAgent()
    mcp = MCPProtocol()
    agent.add_protocol(mcp)
    
    # Add context
    mcp.add_context(
        content="Usuário trabalha em uma empresa de tecnologia",
        context_type="user_info",
        priority=1
    )
    
    # Chat with context
    resposta = agent.chat("Que tipo de projetos posso desenvolver?")
    print(resposta)
  8. Understand the RAG Pipeline workflow

    master

    Mangaba AI provides a complete pipeline for Retrieval-Augmented Generation (RAG). The workflow follows this sequence:

    1. Document: The raw data.
    2. Loader: Converts raw data into Document objects.
    3. Splitter: Breaks large documents into smaller chunks.
    4. Embedding: Converts text chunks into numerical vectors.
    5. VectorStore: Stores the vectors for efficient retrieval.
    6. Retriever: Bridges the embedding model and the vector store to find relevant documents.
    7. RAGChain: Combines the LLM and the Retriever to answer questions based on the retrieved context.

    Data Flow: Document → Loader → Splitter → Embedding → VectorStore Query → Embedding → Retriever → Top-K Documents → RAGChain → Answer

  9. Enable Reasoning, Planning, and Hierarchical Management

    master

    Mangaba supports advanced agent behaviors:

    • Reasoning: Enable an agent to plan and critique its own plan before acting using reasoning=True and max_reasoning_attempts.
    • Planning: A Crew can plan all tasks before execution using planning=True.
    • Hierarchical Process: Use process=Process.HIERARCHICAL with a manager_llm to have a dedicated manager agent choose which agent performs which task and review/reject outputs.
    # Agent with reasoning
    agente = Agent(role="Analista", goal="...", backstory="...",
                   reasoning=True, max_reasoning_attempts=3)
    
    # Crew with hierarchical planning
    crew = Crew(
        agents=[pesquisador, analista, redator],
        tasks=[t1, t2, t3],
        process=Process.HIERARCHICAL,
        planning=True,
        manager_llm=create_llm_client(provider="openai", api_key="..."),
    )
  10. Manage MCP Sessions

    master

    A Session in the Model Context Protocol (MCP) groups related contexts, allowing for the isolation of different conversations or users.

    Available operations for a session include:

    • Creating a new session
    • Adding contexts to the session
    • Searching for contexts within the session
    • Clearing or deleting a session