# cafedonggua/pet_agent architecture

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

- Interactive diagram: https://gitdiagram.com/cafedonggua/pet_agent
- Repository: https://github.com/cafedonggua/pet_agent

## Overview

##### Project type and purpose
- From the file tree and README, this project is an open-source AI Agent framework (named “Pet_Agent”) written in Python.
- It provides a standalone agent server, a core planning/memory subsystem, and client scripts (in apiTest/) to drive or simulate interactions over HTTP or WebSocket.

##### File structure
- Top-level files:
- main.py – application entry point, likely starts the agent server
- requirements.txt – lists Python dependencies (e.g., FastAPI, OpenAI SDK, vector DB client)
- agent/ directory – contains the core agent logic broken into:
- agent_core.py & agent_init.py – bootstrap and orchestrate the agent’s lifecycle
- context.py – runtime context and configuration handling
- memory_manager.py, vector_memory.py, summary_memory.py, singleton_memory.py – various memory backends and retrieval strategies
- plan_manager.py, singleton_plan.py – logic for plan generation and stateful plan storage
- server.py – exposes an HTTP/WS API layer (likely via FastAPI or similar)
- tools.py & utils.py – helper functions and external tool adapters
- apiTest/ directory – client-side scripts for testing:
- api_client.py & ws_client.py – call into the running server via REST/WS
- simulate_log_writer.py – generate synthetic events/logs for the agent to consume

##### README for additional insights
- We infer from code names and requirements that it uses a vector database (for memory), an LLM (OpenAI or local model), and a lightweight web framework.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Scripts
    subgraph "Client Scripts"
        API_REST["API Client (REST)"]:::client
        WS_CLIENT["API Client (WebSocket)"]:::client
        SIM_LOG["Simulation Log Writer"]:::client
    end

    %% Server/API Layer
    subgraph "Server/API Layer"
        MAIN["Application Entry Point"]:::server
        SERVER["Agent Server (HTTP/WebSocket API)"]:::server
    end

    %% Core Engine
    subgraph "Core Engine"
        AGENT_INIT["Agent Initialization & Bootstrap"]:::core
        AGENT_CORE["Agent Core Orchestration"]:::core
        CONTEXT["Context Manager"]:::core
        MEM_MGR["Memory Manager"]:::core
        VECTOR_MEM["Vector Memory Backend"]:::core
        SUMMARY_MEM["Summary Memory Backend"]:::core
        SINGLETON_MEM["Singleton Memory Backend"]:::core
        PLAN_MGR["Plan Manager"]:::core
        SINGLETON_PLAN["Singleton Plan Storage"]:::core
        TOOLS["External Tool Adapters"]:::core
        UTILS["Utility Functions & Helpers"]:::core
    end

    %% External Services
    subgraph "External Services"
        LLM["LLM Provider"]:::ext
        VECTOR_DB["Vector DB"]:::ext
        THIRD_PARTY["Third-party APIs/Tools"]:::ext
    end

    %% Connections
    API_REST -->|"HTTP Request"| SERVER
    WS_CLIENT -->|"WebSocket Message"| SERVER
    SIM_LOG -->|"Test Events"| SERVER

    MAIN -->|"startServer()"| SERVER
    SERVER -->|"forwardRequest"| AGENT_CORE
    AGENT_CORE -->|"loadConfig"| CONTEXT
    AGENT_CORE -->|"fetch/storeMemory"| MEM_MGR
    MEM_MGR -->|"useVector"| VECTOR_MEM
    VECTOR_MEM -->|"get_embeddings()"| VECTOR_DB
    MEM_MGR -->|"useSummary"| SUMMARY_MEM
    MEM_MGR -->|"useGlobal"| SINGLETON_MEM
    AGENT_CORE -->|"generatePlan"| PLAN_MGR
    PLAN_MGR -->|"storePlan"| SINGLETON_PLAN
    AGENT_CORE -->|"invokeTool"| TOOLS
    TOOLS -->|"apiCall"| THIRD_PARTY
    AGENT_CORE -->|"getCompletion"| LLM
    SERVER -->|"HTTP Response"| API_REST
    SERVER -->|"WS Response"| WS_CLIENT

    %% Click Events
    click API_REST "https://github.com/cafedonggua/pet_agent/blob/main/apiTest/api_client.py"
    click WS_CLIENT "https://github.com/cafedonggua/pet_agent/blob/main/apiTest/ws_client.py"
    click SIM_LOG "https://github.com/cafedonggua/pet_agent/blob/main/apiTest/simulate_log_writer.py"
    click MAIN "https://github.com/cafedonggua/pet_agent/blob/main/main.py"
    click SERVER "https://github.com/cafedonggua/pet_agent/blob/main/agent/server.py"
    click AGENT_CORE "https://github.com/cafedonggua/pet_agent/blob/main/agent/agent_core.py"
    click AGENT_INIT "https://github.com/cafedonggua/pet_agent/blob/main/agent/agent_init.py"
    click CONTEXT "https://github.com/cafedonggua/pet_agent/blob/main/agent/context.py"
    click MEM_MGR "https://github.com/cafedonggua/pet_agent/blob/main/agent/memory_manager.py"
    click VECTOR_MEM "https://github.com/cafedonggua/pet_agent/blob/main/agent/vector_memory.py"
    click SUMMARY_MEM "https://github.com/cafedonggua/pet_agent/blob/main/agent/summary_memory.py"
    click SINGLETON_MEM "https://github.com/cafedonggua/pet_agent/blob/main/agent/singleton_memory.py"
    click PLAN_MGR "https://github.com/cafedonggua/pet_agent/blob/main/agent/plan_manager.py"
    click SINGLETON_PLAN "https://github.com/cafedonggua/pet_agent/blob/main/agent/singleton_plan.py"
    click TOOLS "https://github.com/cafedonggua/pet_agent/blob/main/agent/tools.py"
    click UTILS "https://github.com/cafedonggua/pet_agent/blob/main/agent/utils.py"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#000
    classDef server fill:#90EE90,stroke:#000
    classDef core fill:#FFA500,stroke:#000
    classDef ext fill:#DDA0DD,stroke:#000
```
