Spaces:
Sleeping
Sleeping
File size: 6,421 Bytes
2eef9ea | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | # Architecture Diagram
## System Architecture
```mermaid
graph TB
subgraph Client["π₯οΈ Client Layer"]
WEB["React Frontend<br/>Vite + Dashboard"]
API_CLIENT["API Client<br/>Axios"]
end
subgraph API_LAYER["π API Layer"]
FASTAPI["FastAPI Application"]
ROUTES["Routes<br/>Tasks | Workflows | Health"]
MIDDLEWARE["Middleware<br/>CORS | Auth | Logging"]
end
subgraph ORCHESTRATION["π€ Orchestration Layer"]
GRAPH["LangGraph Workflow"]
STATE_MGR["State Manager"]
end
subgraph AGENTS["π§ Agent Layer"]
MEMORY_AG["Memory Agent<br/>Retrieval"]
PLANNER_AG["Planner Agent<br/>Decomposition"]
EXECUTOR_AG["Executor Agent<br/>Execution"]
CRITIC_AG["Critic Agent<br/>Evaluation"]
end
subgraph TOOLS["π§ Tool Layer"]
WEB_SEARCH["Web Search<br/>DuckDuckGo"]
FETCH_URL["URL Fetch<br/>Content Reader"]
CALCULATOR["Calculator<br/>Math Eval"]
PYTHON_RUN["Python Executor<br/>Sandbox"]
end
subgraph STORAGE["πΎ Storage Layer"]
REDIS["Redis Cache<br/>Hot Memory"]
SQLITE["SQLite DB<br/>Persistent"]
POSTGRES["PostgreSQL<br/>Production"]
end
subgraph MONITORING["π Monitoring"]
LOGGER["Logger<br/>Structured Logs"]
METRICS["Metrics<br/>Prometheus"]
HEALTH["Health Checks<br/>Status"]
end
WEB -->|REST API| API_CLIENT
API_CLIENT -->|HTTP| FASTAPI
FASTAPI --> MIDDLEWARE
MIDDLEWARE --> ROUTES
ROUTES --> ORCHESTRATION
GRAPH -->|Coordinates| MEMORY_AG
GRAPH -->|Coordinates| PLANNER_AG
GRAPH -->|Coordinates| EXECUTOR_AG
GRAPH -->|Coordinates| CRITIC_AG
STATE_MGR -->|Manages| GRAPH
EXECUTOR_AG -->|Uses| WEB_SEARCH
EXECUTOR_AG -->|Uses| FETCH_URL
EXECUTOR_AG -->|Uses| CALCULATOR
EXECUTOR_AG -->|Uses| PYTHON_RUN
MEMORY_AG -->|Read/Write| REDIS
MEMORY_AG -->|Persistent| SQLITE
CRITIC_AG -->|Store Results| REDIS
ORCHESTRATION -->|Monitor| LOGGER
ORCHESTRATION -->|Metrics| METRICS
ROUTES -->|Health| HEALTH
POSTGRES -.->|Production| REDIS
```
## Data Flow Diagram
```mermaid
sequenceDiagram
User->>Frontend: Submit Task
Frontend->>API: POST /tasks
API->>StateManager: Create Initial State
StateManager->>Memory: Retrieve Context
Memory->>Redis: Check Hot Cache
Redis-->>Memory: Return Cached Data
Memory-->>Orchestration: Context Ready
Orchestration->>Planner: Plan Task
Planner-->>StateManager: Update State with Plan
StateManager->>Executor: Execute Step 1
Executor->>Tools: Call Tool
Tools-->>Executor: Tool Result
Executor-->>StateManager: Step Complete
StateManager->>Critic: Evaluate Result
Critic-->>StateManager: Approval/Rejection
alt Approved
StateManager->>Memory: Store Learning
Memory->>SQLite: Persist Memory
else Rejected
StateManager->>Planner: Replan
end
StateManager->>Frontend: Return Result
Frontend->>User: Display Results
```
## Workflow State Machine
```mermaid
stateDiagram-v2
[*] --> PENDING: Task Received
PENDING --> PLANNING: Begin Planning
PLANNING --> PLANNING: Decompose Task
PLANNING --> EXECUTING: Plan Ready
PLANNING --> FAILED: Planning Failed
EXECUTING --> EXECUTING: Execute Step
EXECUTING --> EXECUTING: Retry on Failure
EXECUTING --> EVALUATION: All Steps Done
EXECUTING --> FAILED: Max Retries Exceeded
EVALUATION --> EVALUATION: Critic Evaluates
EVALUATION --> STORING: Quality Approved
EVALUATION --> PLANNING: Needs Replanning
STORING --> STORING: Save to Memory
STORING --> COMPLETED: Success
FAILED --> [*]
COMPLETED --> [*]
```
## Agent Interaction Diagram
```mermaid
graph LR
subgraph Input["Input"]
TASK["π Task"]
end
subgraph Agents["Agent Pipeline"]
MEM["π§ Memory<br/>Retrieve Context"]
PLAN["π Planner<br/>Decompose"]
EXEC["βοΈ Executor<br/>Execute"]
CRIT["π Critic<br/>Evaluate"]
STORE["πΎ Memory Store<br/>Learn"]
end
subgraph Output["Output"]
RESULT["β
Result"]
end
TASK --> MEM
MEM --> PLAN
PLAN --> EXEC
EXEC --> CRIT
CRIT -->|Approved| STORE
CRIT -->|Rejected| PLAN
STORE --> RESULT
```
## Technology Stack
```mermaid
graph TB
subgraph Frontend
REACT["React 18"]
VITE["Vite"]
AXIOS["Axios"]
end
subgraph Backend
FASTAPI["FastAPI"]
LANGGRAPH["LangGraph"]
PYDANTIC["Pydantic"]
end
subgraph LLM
OPENAI["OpenAI API<br/>gpt-4 / gpt-4o-mini"]
end
subgraph Storage
REDIS["Redis"]
SQLITE["SQLite"]
POSTGRES["PostgreSQL"]
end
subgraph DevOps
DOCKER["Docker"]
COMPOSE["Docker Compose"]
K8S["Kubernetes"]
end
REACT --> VITE
VITE --> AXIOS
AXIOS -.->|HTTP| FASTAPI
FASTAPI --> LANGGRAPH
FASTAPI --> PYDANTIC
LANGGRAPH -->|Calls| OPENAI
FASTAPI --> REDIS
FASTAPI --> SQLITE
FASTAPI --> POSTGRES
DOCKER --> COMPOSE
COMPOSE --> K8S
```
## Deployment Architecture
```mermaid
graph TB
subgraph Local["Local Development"]
LOCAL_FRONTEND["Frontend<br/>localhost:3000"]
LOCAL_BACKEND["Backend<br/>localhost:8000"]
LOCAL_REDIS["Redis<br/>localhost:6379"]
end
subgraph Docker["Docker Environment"]
DOCKER_FRONTEND["Frontend Container"]
DOCKER_BACKEND["Backend Container"]
DOCKER_REDIS["Redis Container"]
DOCKER_POSTGRES["PostgreSQL Container"]
end
subgraph Production["Production/Cloud"]
LB["Load Balancer"]
BACKEND_REPLICAS["Backend Replicas<br/>K8s Pods"]
REDIS_CLUSTER["Redis Cluster"]
POSTGRES_MANAGED["Managed PostgreSQL"]
CDN["CDN<br/>Frontend Static"]
end
LOCAL_FRONTEND -.->|Dev| LOCAL_BACKEND
LOCAL_BACKEND -.->|Dev| LOCAL_REDIS
DOCKER_FRONTEND -->|Compose| DOCKER_BACKEND
DOCKER_BACKEND -->|Compose| DOCKER_REDIS
DOCKER_BACKEND -->|Compose| DOCKER_POSTGRES
LB --> BACKEND_REPLICAS
BACKEND_REPLICAS --> REDIS_CLUSTER
BACKEND_REPLICAS --> POSTGRES_MANAGED
CDN -.->|Static| BACKEND_REPLICAS
```
|