# montycloud/moya architecture

> Architecture diagram of the GitHub repository montycloud/moya, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/montycloud/moya
- Repository: https://github.com/montycloud/moya

## Overview

##### Project type and purpose
- MOYA is a Python-based open-source framework (library/tool) for building and orchestrating LLM-powered AI agents.
- Its goal is to let developers register, configure, and run multiple autonomous agents with memory, classification, and streaming support.

##### File structure
- Top-level package “moya/” contains the core framework.
- agents/ – implementations of different LLM agents (OpenAI, Bedrock, Ollama, remote, etc.)
- classifiers/ – logic for selecting which agent or task to run
- conversation/ – message and thread abstractions
- memory/ – pluggable memory stores (in-memory, file system)
- orchestrators/ – strategies for coordinating multi-agent workflows (simple, multi-agent, React)
- registry/ – agent registry and repository patterns for lookup & registration
- tools/ – auxiliary tools (e.g., ephemeral memory) that agents can call
- utils/ – constants and shared helpers
- examples/ shows usage clients: quick-start scripts for single and multi-agent scenarios.
- docs/ holds design docs, guides and reference – not part of runtime.

##### README for additional insights
- Emphasis on extensibility: add new agents, orchestrators, tools.
- Highlights patterns: registry, orchestrator strategies, memory integration, streaming.
- Customer contexts: interactive chat, autonomous CloudOps tasks.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    Client["Client/Application Layer\nexamples/"]:::frontend
    click Client "https://github.com/montycloud/moya/tree/main/examples/"

    %% Core Framework
    subgraph "MOYA Core Framework"
        subgraph "Registry Layer"
            agentRegistry["agent_registry.py"]:::core
            agentRepository["agent_repository.py"]:::core
            inMemoryAgentRepo["in_memory_agent_repository.py"]:::core
            click agentRegistry "https://github.com/montycloud/moya/blob/main/moya/registry/agent_registry.py"
            click agentRepository "https://github.com/montycloud/moya/blob/main/moya/registry/agent_repository.py"
            click inMemoryAgentRepo "https://github.com/montycloud/moya/blob/main/moya/registry/in_memory_agent_repository.py"
        end
        subgraph "Orchestrator Layer"
            orchestrator["orchestrator.py"]:::core
            simpleOrch["simple_orchestrator.py"]:::core
            multiOrch["multi_agent_orchestrator.py"]:::core
            reactOrch["react_orchestrator.py"]:::core
            click orchestrator "https://github.com/montycloud/moya/blob/main/moya/orchestrators/orchestrator.py"
            click simpleOrch "https://github.com/montycloud/moya/blob/main/moya/orchestrators/simple_orchestrator.py"
            click multiOrch "https://github.com/montycloud/moya/blob/main/moya/orchestrators/multi_agent_orchestrator.py"
            click reactOrch "https://github.com/montycloud/moya/blob/main/moya/orchestrators/react_orchestrator.py"
        end
        subgraph "Classifier Layer"
            classifier["classifier.py"]:::core
            llmClassifier["llm_classifier.py"]:::core
            click classifier "https://github.com/montycloud/moya/blob/main/moya/classifiers/classifier.py"
            click llmClassifier "https://github.com/montycloud/moya/blob/main/moya/classifiers/llm_classifier.py"
        end
        subgraph "Conversation Layer"
            message["message.py"]:::core
            thread["thread.py"]:::core
            click message "https://github.com/montycloud/moya/blob/main/moya/conversation/message.py"
            click thread "https://github.com/montycloud/moya/blob/main/moya/conversation/thread.py"
        end
        subgraph "Memory Layer"
            memRepo["repository.py"]:::memory
            memInMem["in_memory_repository.py"]:::memory
            memFile["file_system_repo.py"]:::memory
            click memRepo "https://github.com/montycloud/moya/blob/main/moya/memory/repository.py"
            click memInMem "https://github.com/montycloud/moya/blob/main/moya/memory/in_memory_repository.py"
            click memFile "https://github.com/montycloud/moya/blob/main/moya/memory/file_system_repo.py"
        end
        subgraph "Tool Layer"
            toolBase["tool.py"]:::tools
            ephemeralTool["ephemeral_memory.py"]:::tools
            toolRegistry["tool_registry.py"]:::tools
            click toolBase "https://github.com/montycloud/moya/blob/main/moya/tools/tool.py"
            click ephemeralTool "https://github.com/montycloud/moya/blob/main/moya/tools/ephemeral_memory.py"
            click toolRegistry "https://github.com/montycloud/moya/blob/main/moya/tools/tool_registry.py"
        end
    end

    %% Agent Implementations
    subgraph "Agent Implementations"
        agentBase["agent.py"]:::agents
        agentInfo["agent_info.py"]:::agents
        openaiAgent["openai_agent.py"]:::agents
        azureAgent["azure_openai_agent.py"]:::agents
        bedrockAgent["bedrock_agent.py"]:::agents
        ollamaAgent["ollama_agent.py"]:::agents
        crewaiAgent["crewai_agent.py"]:::agents
        remoteAgent["remote_agent.py"]:::agents
        click agentBase "https://github.com/montycloud/moya/blob/main/moya/agents/agent.py"
        click agentInfo "https://github.com/montycloud/moya/blob/main/moya/agents/agent_info.py"
        click openaiAgent "https://github.com/montycloud/moya/blob/main/moya/agents/openai_agent.py"
        click azureAgent "https://github.com/montycloud/moya/blob/main/moya/agents/azure_openai_agent.py"
        click bedrockAgent "https://github.com/montycloud/moya/blob/main/moya/agents/bedrock_agent.py"
        click ollamaAgent "https://github.com/montycloud/moya/blob/main/moya/agents/ollama_agent.py"
        click crewaiAgent "https://github.com/montycloud/moya/blob/main/moya/agents/crewai_agent.py"
        click remoteAgent "https://github.com/montycloud/moya/blob/main/moya/agents/remote_agent.py"
    end

    %% External Services
    subgraph "External LLM Services"
        OpenAIAPI["OpenAI API"]:::external
        AWSBedrock["AWS Bedrock"]:::external
        OllamaSvc["Ollama Service"]:::external
        CrewaiSvc["CrewAI Service"]:::external
        RemoteSvc["Remote Agent Server"]:::external
    end

    %% Data Flow
    Client -->|"invoke()/start()"| orchestrator
    orchestrator -->|"get_agents()"| agentRegistry
    orchestrator -->|"classify()"| classifier
    classifier -->|"lookup()"| agentRepository
    orchestrator -->|"send_message()"| message
    message -->|"append_to_thread()"| thread
    message -->|"save_context()"| memRepo
    memRepo --> memInMem
    memRepo --> memFile
    orchestrator -->|"invoke_agent()"| openaiAgent
    orchestrator -->|"invoke_agent()"| azureAgent
    orchestrator -->|"invoke_agent()"| bedrockAgent
    orchestrator -->|"invoke_agent()"| ollamaAgent
    orchestrator -->|"invoke_agent()"| crewaiAgent
    orchestrator -->|"invoke_agent()"| remoteAgent
    openaiAgent -->|"HTTP/gRPC" | OpenAIAPI
    azureAgent -->|"HTTP/gRPC"| AWSBedrock
    bedrockAgent -->|"HTTP/gRPC"| AWSBedrock
    ollamaAgent -->|"HTTP/gRPC"| OllamaSvc
    crewaiAgent -->|"HTTP/gRPC"| CrewaiSvc
    remoteAgent -->|"HTTP/gRPC"| RemoteSvc
    openaiAgent -->|"stream_response()"| orchestrator
    azureAgent -->|"stream_response()"| orchestrator
    bedrockAgent -->|"stream_response()"| orchestrator
    ollamaAgent -->|"stream_response()"| orchestrator
    crewaiAgent -->|"stream_response()"| orchestrator
    remoteAgent -->|"stream_response()"| orchestrator
    openaiAgent -->|"invoke_tool()"| toolBase
    toolBase -->|"register/invoke()"| toolRegistry
    toolRegistry --> ephemeralTool
    ephemeralTool --> memRepo

    %% Styles
    classDef frontend fill:#f9f,stroke:#333,stroke-width:1px
    classDef core fill:#bbf,stroke:#333,stroke-width:1px
    classDef agents fill:#bfb,stroke:#333,stroke-width:1px
    classDef external fill:#fb7,stroke:#333,stroke-width:1px
    classDef memory fill:#ffeb99,stroke:#333,stroke-width:1px
    classDef tools fill:#e3b7ff,stroke:#333,stroke-width:1px
```
