Spaces:
Running
ποΈ System Architecture
LifeFlow AI implements a novel "Dual-Brain" architecture combined with a Context-Offloading Protocol to solve the scalability issues of traditional Agentic workflows. This document details the system design, data flow, and infrastructure.
π High-Level Design
The system is built on a modular microservices-like architecture using Agno (Phidata) for orchestration and FastMCP for tool isolation.
graph TD
User[User Interface] -->|Gradio Websocket| App[Application Core]
App -->|Input Analysis| Planner[π Planner Agent]
subgraph "Core Team (State Machine)"
Leader[π¨ββοΈ Team Leader]
Leader -->|Delegates| Scout[πΊοΈ Scout]
Leader -->|Delegates| Optimizer[β‘ Optimizer]
Leader -->|Delegates| Navigator[π§ Navigator]
Leader -->|Delegates| Weatherman[π€οΈ Weatherman]
Leader -->|Delegates| Presenter[π Presenter]
end
Planner -->|Task List JSON| Leader
subgraph "The 'Hot Potato' Data Pipeline"
direction LR
DB[(POI Repository / SQLite)]
Scout -.->|Write Raw POIs| DB
DB -.->|Read Ref ID| Optimizer
Optimizer -.->|Write Ordered List| DB
DB -.->|Read Opt ID| Navigator
Navigator -.->|Write Routes| DB
DB -.->|Read Nav ID| Weatherman
Weatherman -.->|Write Final Timeline| DB
end
π Key Architectural Patterns
- Context Offloading Protocol ("Hot Potato") Traditional agents pass massive JSON blobs (search results, reviews, coordinates) back and forth in the chat context, quickly hitting token limits and causing hallucinations.
LifeFlow's Solution:
- Data Isolation: Agents NEVER see the full data payload.
- Reference Passing: Agents only exchange Reference IDs (e.g., scout_result_123).
- Mechanism:
- Scout finds 50+ locations, saves them to poi_repo, and returns {"scout_ref": "uuid"} to the Leader.
- Leader passes this UUID to the Optimizer.
- Optimizer loads data from the repo, solves the TSPTW problem, and saves the result.
- Result: Reduces token consumption by ~90% for complex trips.
- Exclusive MCP Channels (Tool Isolation) In standard multi-agent setups, all tools are often dumped into a shared context, confusing the LLM (e.g., the "Optimizer" trying to use "Weather" tools).
LifeFlow's Solution (in app.py):
We implement a custom Lifecycle Manager that spins up isolated FastMCP connections for each agent.
- Scout Agent $\leftrightarrow$ Channel A (Only search_and_offload)
- Optimizer Agent $\leftrightarrow$ Channel B (Only optimize_from_ref)
- Navigator Agent $\leftrightarrow$ Channel C (Only calculate_traffic_and_timing) This guarantees 100% Tool Usage Accuracy and prevents agents from hallucinating tool calls.
π The Unifying Link: Shared State via Reference IDs
While the Execution Channels (A, B, C) are strictly isolated to prevent tool hallucinations, they share a Unified State Layer.
The "Glue" connecting these isolated environments is the Database Reference ID (e.g., scout_ref_uuid).
- Mechanism:
- Channel A (Scout) executes a search, writes the heavy JSON payload to the shared POI Repository (DB), and returns only the ID
ref_123. - The Leader Agent passes
ref_123to Channel B (Optimizer). - Channel B uses its tool (
optimize_from_ref) to "hydrate" the data by readingref_123from the same shared DB, processes it, and saves a newref_456.
- Channel A (Scout) executes a search, writes the heavy JSON payload to the shared POI Repository (DB), and returns only the ID
This architecture ensures that while Tools are Private (security & accuracy), Data is Global (accessibility).
graph LR
subgraph Execution ["β‘ Isolated Execution Channels"]
A[Channel A: Scout]
B[Channel B: Optimizer]
C[Channel C: Navigator]
end
subgraph Storage ["πΎ Unified Storage Layer"]
DB[(POI Repository)]
end
%% Data Flow
A -->|Write Data| DB
B <-->|Read/Write Data| DB
C <-->|Read/Write Data| DB
%% ID Passing
A -.->|Pass Ref ID| B
B -.->|Pass Ref ID| C
%% Styling
style DB fill:#f9f,stroke:#333,stroke-width:2px
π οΈ Tech Stack & Components
| Component | Technology | Description |
|---|---|---|
| Frontend | Gradio 5.49.1 | Reactive UI with custom CSS, Stepper, and Map integration. |
| Orchestration | Agno (Phidata) | Manages Agent state, memory, and team coordination. |
| Tool Protocol | FastMCP | Exposes Python functions as standardized AI tools. |
| Models | Google Gemini 2.5 | Flash for Leader/Planner (Reasoning), Flash-Lite for Workers (Speed). |
| Optimization | Google OR-Tools | Solves TSPTW (Traveling Salesperson Problem with Time Windows). |
| Data Layer | SQLite / JSON | Local file-based repository for high-speed context offloading. |
π Data Flow Example
User Input: "Plan a day in SF, visit Pier 39 and get crab."
Planner: Converts to structured JSON Tasks.
Leader: Receives Tasks β Delegates to Scout.
Scout: Calls Google Places API β Saves 20 candidates β Returns ref_scout.
Leader: Delegates to Optimizer.
Optimizer: Loads ref_scout β Runs OR-Tools β Returns ref_opt (Sorted).
Leader: Delegates to Navigator.
Navigator: Loads ref_opt β Calls Google Routes (Traffic) β Returns ref_nav.
Leader: Delegates to Weatherman.
Weatherman: Loads ref_nav β Checks OpenWeather β Returns ref_final.
Leader: Delegates to Presenter.
Presenter: Reads ref_final β Generates UI Report.
User sees a complete, optimized itinerary with maps and weather.