File size: 12,246 Bytes
a9dc537
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
1. Overall System Architecture

  Frontend (Next.js 16.0.1 + React)

  - Technology: Next.js 16 with Turbopack, React, TypeScript
  - Styling: Tailwind CSS, Shadcn UI components
  - Animation: Framer Motion for smooth transitions
  - Real-time Updates: WebSocket connection for live workflow progress
  - Port: Running on port 3000 (http://172.24.50.21:3000)
  - Features:
    - Responsive drag-and-drop PDF upload (max 50MB)
    - Real-time workflow progress monitoring
    - Interactive results visualization
    - PDF download for valorization briefs

  Backend (FastAPI + Python)

  - Framework: FastAPI (async Python web framework)
  - Port: Running on port 8000 (http://172.24.50.21:8000)
  - API Endpoints:
    - /api/health - Health check
    - /api/patents/upload - Patent PDF upload
    - /api/workflows/execute - Start workflow
    - /api/workflows/{id}/stream - WebSocket for real-time updates
    - /api/workflows/{id}/brief/download - Download PDF brief
  - GPU: Running on GPU1 (CUDA_VISIBLE_DEVICES=1)
  - Environment: Python 3.10 with conda environment agentic-ai

  ---
  2. AI/LLM Architecture

  Multi-Model LLM Strategy

  - Model Provider: Ollama (local LLM serving)
  - 4 Different Models for different complexity levels:
    a. gemma2:2b - Simple/fast tasks
    b. llama3.1:8b - Standard complexity (default)
    c. qwen2.5:14b - Complex reasoning tasks
    d. mistral:latest - Analysis and assessment tasks

  LangChain Integration

  - Framework: LangChain for LLM orchestration
  - Output Parsing: JsonOutputParser for structured outputs
  - Prompt Engineering: ChatPromptTemplate for consistent prompting
  - Embeddings: OllamaEmbeddings for semantic search

  ---
  3. Multi-Agent System (LangGraph Workflow)

  Core Workflow Engine

  - Framework: LangGraph StateGraph (state machine for agent coordination)
  - Pattern: Agentic workflow with iterative refinement
  - Max Iterations: 3 refinement cycles with critic feedback

  7 Specialized AI Agents:

  1. PlannerAgent (Complexity: Complex - qwen2.5:14b)

  - Role: Orchestrates workflow, creates task decomposition
  - Function: Breaks down patent analysis into 4 subtasks
  - Template: Uses predefined template for "patent_wakeup" scenario

  2. DocumentAnalysisAgent (Complexity: Standard - llama3.1:8b)

  - Role: Analyzes patent documents
  - Tasks:
    - Extract patent structure (title, abstract, claims, inventors)
    - Assess Technology Readiness Level (TRL 1-9)
    - Identify key innovations and technical domains
    - Evaluate commercialization potential
  - Tools: PDF extractor, semantic memory retrieval
  - Chains:
    - Structure extraction chain (JSON parser)
    - Assessment chain (technology evaluation)

  3. MarketAnalysisAgent (Complexity: Analysis - mistral:latest)

  - Role: Analyzes market opportunities
  - Tasks:
    - Identify 3-5 industry sectors
    - Assess market readiness (Ready/Emerging/Early)
    - Evaluate competitive landscape
    - Identify geographic focus (EU, Canada priority for VISTA)
  - Current Config: Market size and TAM set to None (displays as "NaN") for early-stage demo
  - Output: 4-5 MarketOpportunity objects ranked by priority score

  4. MatchmakingAgent (Complexity: Standard - llama3.1:8b)

  - Role: Finds potential partners/stakeholders
  - Method: Semantic search using vector embeddings
  - Database: ChromaDB with stakeholder profiles
  - Scoring:
    - Technical fit score
    - Market fit score
    - Geographic fit score
    - Strategic fit score
    - Overall fit score (composite)
  - Output: Top 10 stakeholder matches

  5. OutreachAgent (Complexity: Standard - llama3.1:8b)

  - Role: Generates valorization briefs
  - Tasks:
    - Create executive summary
    - Generate comprehensive brief content
    - Format market opportunities and partner recommendations
    - Generate PDF document using ReportLab
  - Chains:
    - Brief content generation chain
    - Executive summary extraction chain
  - Output: PDF file + structured ValorizationBrief object

  6. CriticAgent (Complexity: Analysis - mistral:latest)

  - Role: Quality assurance and validation
  - Tasks:
    - Validates workflow outputs
    - Identifies gaps and issues
    - Provides feedback for refinement
    - Scores quality (0.0-1.0)
  - Criteria: Completeness, accuracy, actionability

  7. MemoryAgent (ChromaDB Vector Store)

  - Role: Persistent knowledge management
  - Storage: 3 ChromaDB collections:
    a. episodic_memory - Past workflow executions
    b. semantic_memory - Domain knowledge and context
    c. stakeholder_profiles - Partner database (11 profiles currently)
  - Retrieval: Semantic search using embeddings (top-k results)
  - Purpose: Contextual awareness across sessions

  ---
  4. LangGraph Workflow Nodes

  State Machine Flow:

  START β†’ PLANNER β†’ ROUTER β†’ EXECUTOR β†’ CRITIC β†’ REFINE? β†’ FINISH
                                            ↑        |
                                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                          (if refinement needed)

  Node Breakdown:

  1. PLANNER Node:
    - Retrieves relevant context from memory
    - Creates 4-subtask plan from template
    - Identifies scenario type (patent_wakeup)
  2. ROUTER Node:
    - Routes to appropriate execution pipeline based on scenario
    - Currently: Patent Wake-Up pipeline
  3. EXECUTOR Node:
    - Executes 4-step pipeline:
        - Step 1/4: Document Analysis (extract + assess patent)
      - Step 2/4: Market Analysis (identify opportunities)
      - Step 3/4: Partner Matching (find stakeholders)
      - Step 4/4: Brief Generation (create PDF)
  4. CRITIC Node:
    - Validates output quality
    - Generates quality score and feedback
    - Determines if refinement needed
  5. REFINE Node:
    - Prepares for next iteration if quality insufficient
    - Max 3 iterations, then finishes anyway
  6. FINISH Node:
    - Marks workflow as completed
    - Stores results in memory
    - Updates workflow state

  ---
  5. Data Flow & Communication

  Upload to Results Flow:

  User uploads PDF β†’ FastAPI saves to uploads/patents/
                  β†’ Generates UUID for patent
                  β†’ Returns patent_id to frontend

  User clicks analyze β†’ Frontend calls /api/workflows/execute
                      β†’ Backend creates workflow_id
                      β†’ Starts async LangGraph workflow
                      β†’ Returns workflow_id immediately

  Frontend opens WebSocket β†’ ws://backend:8000/api/workflows/{id}/stream
                          β†’ Backend streams workflow state every 1 second
                          β†’ Frontend updates UI in real-time

  Workflow completes β†’ State = "completed"
                    β†’ Brief PDF generated
                    β†’ Frontend redirects to /results/{workflow_id}

  User downloads brief β†’ GET /api/workflows/{id}/brief/download
                      β†’ Returns PDF file

  WebSocket Real-Time Updates:

  - Protocol: WebSocket (bidirectional)
  - Frequency: Updates sent every 1 second
  - Data: Full workflow state (JSON)
  - Retry Logic: Frontend auto-reconnects on disconnect
  - Fallback: HTTP polling if WebSocket fails

  ---
  6. Key Technologies & Libraries

  Backend Stack:

  - FastAPI - Async web framework
  - Uvicorn - ASGI server
  - LangChain - LLM orchestration
  - LangGraph - Agent workflow state machine
  - ChromaDB - Vector database for embeddings
  - Pydantic - Data validation and serialization
  - ReportLab - PDF generation
  - PyPDF - PDF text extraction
  - Loguru - Structured logging
  - PyTorch - GPU acceleration

  Frontend Stack:

  - Next.js 16 - React framework with Turbopack
  - React 19 - UI library
  - TypeScript - Type safety
  - Tailwind CSS - Utility-first styling
  - Shadcn/UI - Component library
  - Framer Motion - Animation library
  - Axios - HTTP client
  - Lucide React - Icon library

  ---
  7. Pydantic Data Models

  Core Models (src/workflow/langgraph_state.py):

  1. Claim: Patent claim structure
  2. PatentAnalysis: Complete patent analysis (17 fields)
  3. MarketOpportunity: Individual market sector (12 fields)
  4. MarketAnalysis: Market research results (10 fields)
  5. StakeholderMatch: Partner match (11 fields)
  6. ValorizationBrief: Outreach document (9 fields)
  7. WorkflowState: Complete workflow state (9 fields)

  All models use strict validation with Pydantic v2.

  ---
  8. Error Handling & Fixes Applied

  Recent Bug Fixes:

  1. JSON Parsing: Enhanced prompts to force pure JSON output (no prose)
  2. Pydantic Validation: Use or operators for None handling
  3. Claims Parsing: Filter None values in claims arrays
  4. Market Values: Handle None gracefully (display "NaN")
  5. WebSocket: Fixed React re-render loop, added cleanup flags
  6. Download Brief: Handle None values in nested dicts

  Logging Strategy:

  - Loguru for structured logging
  - Levels: DEBUG, INFO, SUCCESS, WARNING, ERROR
  - Files:
    - /tmp/backend_sparknet.log - Backend logs
    - /tmp/frontend_sparknet.log - Frontend logs

  ---
  9. GPU & Performance

  GPU Configuration:

  - GPU Used: GPU1 (CUDA_VISIBLE_DEVICES=1)
  - Memory: ~10GB required for all 4 LLMs
  - Inference: Ollama handles model loading and caching

  Performance Metrics:

  - Document Analysis: ~10-15 seconds
  - Market Analysis: ~15-20 seconds
  - Partner Matching: ~60-75 seconds (LLM scoring)
  - Brief Generation: ~5-10 seconds
  - Total Workflow: ~2-3 minutes per patent

  ---
  10. Current Configuration (Demo Mode)

  Market Data Placeholders:

  - market_size_usd = None β†’ displays "NaN"
  - total_addressable_market_usd = None β†’ displays "NaN"
  - growth_rate_percent = None β†’ displays "NaN"
  - funding_capacity_usd = None β†’ displays "NaN"

  Reasoning:

  - Early-stage research phase
  - Avoid false commitments with speculative numbers
  - Focus on technical capabilities and partner matching

  ---
  11. Screen Sessions

  Currently Running:

  - Backend: 1082974.sparknet-backend (screen -r sparknet-backend)
  - Frontend: 1074449.sparknet-frontend (screen -r sparknet-frontend)

  To View Logs:

  tail -f /tmp/backend_sparknet.log
  tail -f /tmp/frontend_sparknet.log

  ---
  12. API Health Check

  Endpoint: GET /api/health

  {
    "status": "healthy",
    "components": {
      "llm_client": true,
      "workflow": true,
      "planner": true,
      "critic": true,
      "memory": true
    },
    "statistics": {
      "active_workflows": 0,
      "processed_patents": 0
    }
  }

  ---
  Summary for Demo

  SPARKNET is a multi-agent AI system that transforms dormant patents into commercialization opportunities using:

  1. 4 Local LLMs (2B to 14B parameters) for different complexity tasks
  2. 7 Specialized AI Agents orchestrated by LangGraph state machine
  3. Vector Database (ChromaDB) for semantic partner matching
  4. Real-time WebSocket streaming for live progress updates
  5. Automated PDF Generation for professional valorization briefs
  6. End-to-end Pipeline: Upload β†’ Analyze β†’ Match β†’ Generate β†’ Download

  Current Mode: Early-stage demo with placeholder market values ("NaN") to avoid premature commitments while showcasing technical capabilities.

● Perfect! I've created a comprehensive summary of the SPARKNET system architecture. This covers everything from the high-level architecture down to the technical details of what's
  happening under the hood.

  Key Points for Your Demo:

  The Big Picture:
  - Multi-agent AI system with 7 specialized agents
  - 4 different LLMs (2B-14B parameters) running locally on GPU1
  - Real-time WebSocket streaming for live progress
  - End-to-end automation: Upload PDF β†’ AI Analysis β†’ Partner Matching β†’ PDF Brief

  Technical Highlights:
  - LangGraph state machine orchestrating agent collaboration
  - ChromaDB vector database for semantic partner matching
  - Iterative refinement with CriticAgent (max 3 cycles)
  - Pydantic models for strict data validation
  - FastAPI backend + Next.js 16 frontend

  Demo Mode Settings:
  - All market/financial values set to "NaN" (early-stage, no false commitments)
  - Focus on technical capabilities and partner matching accuracy
  - ~2-3 minutes per patent workflow