๐๏ธ GNS3-Copilot Backend Evolution Plan
1. Architectural Vision
Transition from a standalone Streamlit script to a "Dual-Engine" architecture.
- Engine A (Legacy): Streamlit
app.pyfor rapid internal prototyping and debugging. - Engine B (Modern): FastAPI
server.pyacting as a BFF (Backend for Frontend) to serve a modern React UI and mobile voice interaction.
2. Core Technical Strategy
- Concurrency: Use FastAPI's standard
defroutes to leverage the internal thread pool for handling synchronous GNS3 API calls and LangGraph execution. - Configuration: Maintain
.envdriven settings (Local-First). Credentials (LLM Keys, GNS3 URL) are loaded via environment variables; no complex Auth required for local MVP. - Communication: Implement SSE (Server-Sent Events) for real-time AI "typing" effects and tool-calling status updates.
- Voice Integration: Implement a "Relay" pattern:
Browser Mic -> FastAPI -> Commercial STT (Whisper) -> LangGraph -> Commercial TTS -> Browser Speaker.
3. Implementation Roadmap
Phase 1: API Infrastructure (Foundation)
- Goal: Establish the FastAPI project structure and enable cross-origin communication.
- Tasks:
- Install
fastapianduvicorn. - Create
api/main.pywith CORS middleware (essential for React). - Set up the router directory structure for scalability.
Phase 2: LangGraph Integration (The "Brain")
- Goal: Expose the LangGraph agent as a unified, streaming API.
- Tasks:
- Develop the
POST /agent/streamendpoint. - Wrap the synchronous
graph.streamusingasyncio.to_threador an event-pumping queue. - Define a standard SSE message schema (e.g.,
type: textfor content,type: toolfor action status).
Phase 3: Voice Interaction Pipeline
- Goal: Enable voice-to-command capabilities using commercial APIs.
- Tasks:
- Create
POST /agent/voice-chatto receive audio files (.webm/.wav). - Integrate OpenAI Whisper API for STT (Speech-to-Text).
- Connect transcribed text to the existing LangGraph logic and optionally return audio via TTS.
Phase 4: Project & Topology Services
- Goal: Provide the frontend with GNS3 project metadata.
- Tasks:
- Implement
GET /projectsto list available GNS3 topologies. - Implement
GET /projects/{id}/topologyfor React Flow visualization data.
4. Recommended Project Structure
src/gns3_copilot/
โโโ api/
โ โโโ __init__.py
โ โโโ main.py # Entry point & Middleware config
โ โโโ dependencies.py # Shared logic (Context/Config)
โ โโโ routers/
โ โโโ __init__.py
โ โโโ agent.py # Chat, Streaming, and Voice endpoints
โ โโโ projects.py # Project & Topology management
โโโ tools/ # Existing Sync GNS3 Tools (Unchanged)
โโโ agent/ # Existing LangGraph Logic (Unchanged)
โโโ .env # Local API Keys & GNS3 Server config
5. Current Sprint Checklist
- [ ] Setup: Run
pip install fastapi uvicorn pydantic-settings. - [ ] Scaffolding: Create the
api/directory and initializemain.py. - [ ] Core API: Implement the
/agent/streamendpoint and verify via Swagger UI (/docs). - [ ] Testing: Ensure the API correctly reads
.envvariables without manual injection.