adaptive-memory-multi-model-router 1.2.2 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +146 -66
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/integrations/airtable.js +20 -0
- package/dist/integrations/discord.js +18 -0
- package/dist/integrations/github.js +23 -0
- package/dist/integrations/gmail.js +19 -0
- package/dist/integrations/google-calendar.js +18 -0
- package/dist/integrations/index.js +61 -0
- package/dist/integrations/jira.js +21 -0
- package/dist/integrations/linear.js +19 -0
- package/dist/integrations/notion.js +19 -0
- package/dist/integrations/slack.js +18 -0
- package/dist/integrations/telegram.js +19 -0
- package/dist/providers/registry.js +7 -3
- package/docs/ARCHITECTURAL-IMPROVEMENTS-2025.md +1391 -0
- package/docs/ARCHITECTURAL-IMPROVEMENTS-REVISED-2025.md +1051 -0
- package/docs/CONFIGURATION.md +476 -0
- package/docs/COUNCIL_DECISION.json +308 -0
- package/docs/COUNCIL_SUMMARY.md +265 -0
- package/docs/COUNCIL_V2.2_DECISION.md +416 -0
- package/docs/IMPROVEMENT_ROADMAP.md +515 -0
- package/docs/LLM_COUNCIL_DECISION.md +508 -0
- package/docs/QUICK_START_VISIBILITY.md +782 -0
- package/docs/REDDIT_GAP_ANALYSIS.md +299 -0
- package/docs/RESEARCH_BACKED_IMPROVEMENTS.md +1180 -0
- package/docs/TMLPD_QNA.md +751 -0
- package/docs/TMLPD_V2.1_COMPLETE.md +763 -0
- package/docs/TMLPD_V2.2_RESEARCH_ROADMAP.md +754 -0
- package/docs/V2.2_IMPLEMENTATION_COMPLETE.md +446 -0
- package/docs/V2_IMPLEMENTATION_GUIDE.md +388 -0
- package/docs/VISIBILITY_ADOPTION_PLAN.md +1005 -0
- package/docs/launch-content/LAUNCH_EXECUTION_CHECKLIST.md +421 -0
- package/docs/launch-content/README.md +457 -0
- package/docs/launch-content/assets/cost_comparison_100_tasks.png +0 -0
- package/docs/launch-content/assets/cumulative_savings.png +0 -0
- package/docs/launch-content/assets/parallel_speedup.png +0 -0
- package/docs/launch-content/assets/provider_pricing_comparison.png +0 -0
- package/docs/launch-content/assets/task_breakdown_comparison.png +0 -0
- package/docs/launch-content/generate_charts.py +313 -0
- package/docs/launch-content/hn_show_post.md +139 -0
- package/docs/launch-content/partner_outreach_templates.md +745 -0
- package/docs/launch-content/reddit_posts.md +467 -0
- package/docs/launch-content/twitter_thread.txt +460 -0
- package/examples/QUICKSTART.md +1 -1
- package/openclaw-alexa-bridge/ALL_REMAINING_FIXES_PLAN.md +313 -0
- package/openclaw-alexa-bridge/REMAINING_FIXES_SUMMARY.md +277 -0
- package/openclaw-alexa-bridge/src/alexa_handler_no_tmlpd.js +1234 -0
- package/openclaw-alexa-bridge/test_fixes.js +77 -0
- package/package.json +120 -29
- package/package.json.tmp +0 -0
- package/qna/TMLPD_QNA.md +3 -3
- package/skill/SKILL.md +2 -2
- package/src/__tests__/integration/tmpld_integration.test.py +540 -0
- package/src/agents/skill_enhanced_agent.py +318 -0
- package/src/memory/__init__.py +15 -0
- package/src/memory/agentic_memory.py +353 -0
- package/src/memory/semantic_memory.py +444 -0
- package/src/memory/simple_memory.py +466 -0
- package/src/memory/working_memory.py +447 -0
- package/src/orchestration/__init__.py +52 -0
- package/src/orchestration/execution_engine.py +353 -0
- package/src/orchestration/halo_orchestrator.py +367 -0
- package/src/orchestration/mcts_workflow.py +498 -0
- package/src/orchestration/role_assigner.py +473 -0
- package/src/orchestration/task_planner.py +522 -0
- package/src/providers/__init__.py +67 -0
- package/src/providers/anthropic.py +304 -0
- package/src/providers/base.py +241 -0
- package/src/providers/cerebras.py +373 -0
- package/src/providers/registry.py +476 -0
- package/src/routing/__init__.py +30 -0
- package/src/routing/universal_router.py +621 -0
- package/src/skills/TMLPD-QUICKREF.md +210 -0
- package/src/skills/TMLPD-SETUP-SUMMARY.md +157 -0
- package/src/skills/TMLPD.md +540 -0
- package/src/skills/__tests__/skill_manager.test.ts +328 -0
- package/src/skills/skill_manager.py +385 -0
- package/src/skills/test-tmlpd.sh +108 -0
- package/src/skills/tmlpd-category.yaml +67 -0
- package/src/skills/tmlpd-monitoring.yaml +188 -0
- package/src/skills/tmlpd-phase.yaml +132 -0
- package/src/state/__init__.py +17 -0
- package/src/state/simple_checkpoint.py +508 -0
- package/src/tmlpd_agent.py +464 -0
- package/src/tmpld_v2.py +427 -0
- package/src/workflows/__init__.py +18 -0
- package/src/workflows/advanced_difficulty_classifier.py +377 -0
- package/src/workflows/chaining_executor.py +417 -0
- package/src/workflows/difficulty_integration.py +209 -0
- package/src/workflows/orchestrator.py +469 -0
- package/src/workflows/orchestrator_executor.py +456 -0
- package/src/workflows/parallelization_executor.py +382 -0
- package/src/workflows/router.py +311 -0
- package/test_integration_simple.py +86 -0
- package/test_mcts_workflow.py +150 -0
- package/test_templd_integration.py +262 -0
- package/test_universal_router.py +275 -0
- package/tmlpd-pi-extension/README.md +36 -0
- package/tmlpd-pi-extension/dist/cache/prefixCache.d.ts +114 -0
- package/tmlpd-pi-extension/dist/cache/prefixCache.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/cache/prefixCache.js +285 -0
- package/tmlpd-pi-extension/dist/cache/prefixCache.js.map +1 -0
- package/tmlpd-pi-extension/dist/cache/responseCache.d.ts +58 -0
- package/tmlpd-pi-extension/dist/cache/responseCache.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/cache/responseCache.js +153 -0
- package/tmlpd-pi-extension/dist/cache/responseCache.js.map +1 -0
- package/tmlpd-pi-extension/dist/cli.js +59 -0
- package/tmlpd-pi-extension/dist/cost/costTracker.d.ts +95 -0
- package/tmlpd-pi-extension/dist/cost/costTracker.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/cost/costTracker.js +240 -0
- package/tmlpd-pi-extension/dist/cost/costTracker.js.map +1 -0
- package/tmlpd-pi-extension/dist/index.d.ts +723 -0
- package/tmlpd-pi-extension/dist/index.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/index.js +239 -0
- package/tmlpd-pi-extension/dist/index.js.map +1 -0
- package/tmlpd-pi-extension/dist/memory/episodicMemory.d.ts +82 -0
- package/tmlpd-pi-extension/dist/memory/episodicMemory.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/memory/episodicMemory.js +145 -0
- package/tmlpd-pi-extension/dist/memory/episodicMemory.js.map +1 -0
- package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.d.ts +102 -0
- package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.js +207 -0
- package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.js.map +1 -0
- package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.d.ts +85 -0
- package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.js +210 -0
- package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.js.map +1 -0
- package/tmlpd-pi-extension/dist/providers/localProvider.d.ts +102 -0
- package/tmlpd-pi-extension/dist/providers/localProvider.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/providers/localProvider.js +338 -0
- package/tmlpd-pi-extension/dist/providers/localProvider.js.map +1 -0
- package/tmlpd-pi-extension/dist/providers/registry.d.ts +55 -0
- package/tmlpd-pi-extension/dist/providers/registry.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/providers/registry.js +138 -0
- package/tmlpd-pi-extension/dist/providers/registry.js.map +1 -0
- package/tmlpd-pi-extension/dist/routing/advancedRouter.d.ts +68 -0
- package/tmlpd-pi-extension/dist/routing/advancedRouter.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/routing/advancedRouter.js +332 -0
- package/tmlpd-pi-extension/dist/routing/advancedRouter.js.map +1 -0
- package/tmlpd-pi-extension/dist/tools/tmlpdTools.d.ts +101 -0
- package/tmlpd-pi-extension/dist/tools/tmlpdTools.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/tools/tmlpdTools.js +368 -0
- package/tmlpd-pi-extension/dist/tools/tmlpdTools.js.map +1 -0
- package/tmlpd-pi-extension/dist/utils/batchProcessor.d.ts +96 -0
- package/tmlpd-pi-extension/dist/utils/batchProcessor.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/utils/batchProcessor.js +170 -0
- package/tmlpd-pi-extension/dist/utils/batchProcessor.js.map +1 -0
- package/tmlpd-pi-extension/dist/utils/compression.d.ts +61 -0
- package/tmlpd-pi-extension/dist/utils/compression.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/utils/compression.js +281 -0
- package/tmlpd-pi-extension/dist/utils/compression.js.map +1 -0
- package/tmlpd-pi-extension/dist/utils/reliability.d.ts +74 -0
- package/tmlpd-pi-extension/dist/utils/reliability.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/utils/reliability.js +177 -0
- package/tmlpd-pi-extension/dist/utils/reliability.js.map +1 -0
- package/tmlpd-pi-extension/dist/utils/speculativeDecoding.d.ts +117 -0
- package/tmlpd-pi-extension/dist/utils/speculativeDecoding.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/utils/speculativeDecoding.js +246 -0
- package/tmlpd-pi-extension/dist/utils/speculativeDecoding.js.map +1 -0
- package/tmlpd-pi-extension/dist/utils/tokenUtils.d.ts +50 -0
- package/tmlpd-pi-extension/dist/utils/tokenUtils.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/utils/tokenUtils.js +124 -0
- package/tmlpd-pi-extension/dist/utils/tokenUtils.js.map +1 -0
- package/tmlpd-pi-extension/examples/QUICKSTART.md +183 -0
- package/tmlpd-pi-extension/package-lock.json +75 -0
- package/tmlpd-pi-extension/package.json +172 -0
- package/tmlpd-pi-extension/python/examples.py +53 -0
- package/tmlpd-pi-extension/python/integrations.py +330 -0
- package/tmlpd-pi-extension/python/setup.py +28 -0
- package/tmlpd-pi-extension/python/tmlpd.py +369 -0
- package/tmlpd-pi-extension/qna/REDDIT_GAP_ANALYSIS.md +299 -0
- package/tmlpd-pi-extension/qna/TMLPD_QNA.md +751 -0
- package/tmlpd-pi-extension/skill/SKILL.md +238 -0
- package/{src → tmlpd-pi-extension/src}/index.ts +1 -1
- package/tmlpd-pi-extension/tsconfig.json +18 -0
- package/demo/research-demo.js +0 -266
- package/notebooks/quickstart.ipynb +0 -157
- package/rust/tmlpd.h +0 -268
- package/src/cache/prefixCache.ts +0 -365
- package/src/routing/advancedRouter.ts +0 -406
- package/src/utils/speculativeDecoding.ts +0 -344
- /package/{src → tmlpd-pi-extension/src}/cache/responseCache.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/cost/costTracker.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/memory/episodicMemory.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/orchestration/haloOrchestrator.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/orchestration/mctsWorkflow.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/providers/localProvider.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/providers/registry.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/tools/tmlpdTools.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/utils/batchProcessor.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/utils/compression.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/utils/reliability.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/utils/tokenUtils.ts +0 -0
|
@@ -0,0 +1,1391 @@
|
|
|
1
|
+
# TMLPD Architectural Improvements Roadmap
|
|
2
|
+
## Based on 2025 State-of-the-Art Multi-Agent Research
|
|
3
|
+
|
|
4
|
+
**Document Version:** 1.0
|
|
5
|
+
**Last Updated:** January 2025
|
|
6
|
+
**Research Sources:** Latest papers, benchmarks, and production systems
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Executive Summary
|
|
11
|
+
|
|
12
|
+
This document outlines architectural improvements to transform TMLPD from a parallel task execution tool into a state-of-the-art multi-agent system with advanced memory, communication, and reasoning capabilities.
|
|
13
|
+
|
|
14
|
+
**Key Improvements:**
|
|
15
|
+
1. **Agentic RAG Integration** - Dynamic, multi-step retrieval vs. single-shot RAG
|
|
16
|
+
2. **Memory Hierarchy** - Short-term, long-term, and episodic memory layers
|
|
17
|
+
3. **Vector Database Integration** - Pinecone/Qdrant/Weaviate for semantic memory
|
|
18
|
+
4. **Cross-Agent Communication** - Shared memory and message passing protocols
|
|
19
|
+
5. **State Management** - Checkpointing with LangGraph-style persistence
|
|
20
|
+
|
|
21
|
+
**Expected Impact:**
|
|
22
|
+
- 3-5x improvement in complex task handling
|
|
23
|
+
- 10x better context retention across sessions
|
|
24
|
+
- Enable multi-hop reasoning and research
|
|
25
|
+
- Support for 100+ agent deployments
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 1. Memory Architecture Transformation
|
|
30
|
+
|
|
31
|
+
### Current State (TMLPD v1.0)
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
┌─────────────────────────────────────┐
|
|
35
|
+
│ TMLPD Current Architecture │
|
|
36
|
+
├─────────────────────────────────────┤
|
|
37
|
+
│ • No persistent memory │
|
|
38
|
+
│ • Context per session only │
|
|
39
|
+
│ • No cross-agent memory sharing │
|
|
40
|
+
│ • Checkpointing: local filesystem │
|
|
41
|
+
└─────────────────────────────────────┘
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Limitations:**
|
|
45
|
+
- Agents can't learn from past executions
|
|
46
|
+
- No shared knowledge between agents
|
|
47
|
+
- Context lost after session ends
|
|
48
|
+
- Can't handle multi-hop queries
|
|
49
|
+
|
|
50
|
+
### Proposed State (TMLPD v2.0)
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
54
|
+
│ TMLPD Enhanced Memory Architecture │
|
|
55
|
+
├─────────────────────────────────────────────────────────────┤
|
|
56
|
+
│ │
|
|
57
|
+
│ ┌──────────────────┐ ┌──────────────────┐ │
|
|
58
|
+
│ │ Short-Term │ │ Long-Term │ │
|
|
59
|
+
│ │ Memory │◄────►│ Memory │ │
|
|
60
|
+
│ │ (Session) │ │ (Persistent) │ │
|
|
61
|
+
│ │ │ │ │ │
|
|
62
|
+
│ │ • Context │ │ • Vector DB │ │
|
|
63
|
+
│ │ • Conversation │ │ • Knowledge │ │
|
|
64
|
+
│ │ • Working Set │ │ • Patterns │ │
|
|
65
|
+
│ └──────────────────┘ └──────────────────┘ │
|
|
66
|
+
│ ▲ ▲ │
|
|
67
|
+
│ │ │ │
|
|
68
|
+
│ └──────────┬─────────────┘ │
|
|
69
|
+
│ ▼ │
|
|
70
|
+
│ ┌──────────────────────┐ │
|
|
71
|
+
│ │ Episodic Memory │ │
|
|
72
|
+
│ │ (Task History) │ │
|
|
73
|
+
│ │ │ │
|
|
74
|
+
│ │ • Past Executions │ │
|
|
75
|
+
│ │ • Success Patterns │ │
|
|
76
|
+
│ │ • Failure Modes │ │
|
|
77
|
+
│ └──────────────────────┘ │
|
|
78
|
+
│ │ │
|
|
79
|
+
│ ▼ │
|
|
80
|
+
│ ┌──────────────────────┐ │
|
|
81
|
+
│ │ Agentic RAG Layer │ │
|
|
82
|
+
│ │ (Dynamic Retrieval) │ │
|
|
83
|
+
│ └──────────────────────┘ │
|
|
84
|
+
└─────────────────────────────────────────────────────────────┘
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## 2. Agentic RAG Integration
|
|
90
|
+
|
|
91
|
+
### Traditional RAG vs. Agentic RAG
|
|
92
|
+
|
|
93
|
+
**Traditional RAG (Current approach in most tools):**
|
|
94
|
+
```python
|
|
95
|
+
# Single-shot retrieval
|
|
96
|
+
query = "Build a React login form"
|
|
97
|
+
context = vector_db.search(query, top_k=5)
|
|
98
|
+
response = llm.generate(query + context)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Limitations:**
|
|
102
|
+
- One-shot retrieval (can't refine)
|
|
103
|
+
- Static queries (no reformulation)
|
|
104
|
+
- Single pass through data
|
|
105
|
+
- Limited reasoning
|
|
106
|
+
|
|
107
|
+
**Agentic RAG (Proposed for TMLPD v2.0):**
|
|
108
|
+
```python
|
|
109
|
+
# Multi-step, adaptive retrieval
|
|
110
|
+
agent = AgenticRAGAgent()
|
|
111
|
+
|
|
112
|
+
# Step 1: Initial retrieval
|
|
113
|
+
context = agent.retrieve("Build a React login form")
|
|
114
|
+
|
|
115
|
+
# Step 2: Analyze and refine
|
|
116
|
+
if not context.sufficient():
|
|
117
|
+
# Step 3: Query reformulation
|
|
118
|
+
refined_query = agent.refine_query(
|
|
119
|
+
original_query,
|
|
120
|
+
missing_info="authentication patterns"
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
# Step 4: Targeted retrieval
|
|
124
|
+
additional_context = agent.retrieve(refined_query)
|
|
125
|
+
|
|
126
|
+
# Step 5: Synthesize
|
|
127
|
+
response = agent.synthesize(context + additional_context)
|
|
128
|
+
else:
|
|
129
|
+
response = agent.generate(context)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Benefits:**
|
|
133
|
+
- ✅ Multi-step reasoning
|
|
134
|
+
- ✅ Dynamic query reformulation
|
|
135
|
+
- ✅ Can pivot between data sources
|
|
136
|
+
- ✅ Handles complex, multi-part queries
|
|
137
|
+
- ✅ Active context maintenance
|
|
138
|
+
|
|
139
|
+
**Research Sources:**
|
|
140
|
+
- [Agentic RAG vs. Traditional RAG](https://medium.com/@gaddam.rahul.kumar/agentic-rag-vs-traditional-rag-b1a156f72167)
|
|
141
|
+
- [Redis Blog: Agentic RAG](https://redis.io/blog/agentic-rag-how-enterprises-are-surmounting-the-limits-of-traditional-rag/)
|
|
142
|
+
- [What is Agentic RAG? 2025 Guide](https://www.lyzr.ai/blog/agentic-rag/)
|
|
143
|
+
|
|
144
|
+
### Implementation Plan
|
|
145
|
+
|
|
146
|
+
**Phase 1: Basic Agentic RAG (Weeks 1-4)**
|
|
147
|
+
```python
|
|
148
|
+
# File: src/agentic_rag/basic_agent.py
|
|
149
|
+
|
|
150
|
+
class AgenticRAGAgent:
|
|
151
|
+
"""Multi-step retrieval agent"""
|
|
152
|
+
|
|
153
|
+
def __init__(self, vector_db, llm, max_retrievals=3):
|
|
154
|
+
self.vector_db = vector_db
|
|
155
|
+
self.llm = llm
|
|
156
|
+
self.max_retrievals = max_retrievals
|
|
157
|
+
self.retrieval_history = []
|
|
158
|
+
|
|
159
|
+
def query(self, question: str) -> str:
|
|
160
|
+
"""Multi-step retrieval process"""
|
|
161
|
+
|
|
162
|
+
# Step 1: Initial retrieval
|
|
163
|
+
context = self._retrieve(question)
|
|
164
|
+
self.retrieval_history.append(context)
|
|
165
|
+
|
|
166
|
+
# Step 2: Assess sufficiency
|
|
167
|
+
for i in range(self.max_retrievals):
|
|
168
|
+
if self._is_sufficient(context, question):
|
|
169
|
+
break
|
|
170
|
+
|
|
171
|
+
# Step 3: Reformulate query
|
|
172
|
+
refined_question = self._refine_query(
|
|
173
|
+
question,
|
|
174
|
+
context,
|
|
175
|
+
self._identify_gaps(context, question)
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
# Step 4: Additional retrieval
|
|
179
|
+
additional_context = self._retrieve(refined_question)
|
|
180
|
+
self.retrieval_history.append(additional_context)
|
|
181
|
+
context = self._merge_contexts(context, additional_context)
|
|
182
|
+
|
|
183
|
+
# Step 5: Generate final response
|
|
184
|
+
return self._generate(question, context)
|
|
185
|
+
|
|
186
|
+
def _is_sufficient(self, context, question) -> bool:
|
|
187
|
+
"""Check if current context answers the question"""
|
|
188
|
+
prompt = f"""
|
|
189
|
+
Context: {context}
|
|
190
|
+
Question: {question}
|
|
191
|
+
|
|
192
|
+
Does the context contain enough information to answer the question?
|
|
193
|
+
Respond with YES or NO.
|
|
194
|
+
"""
|
|
195
|
+
response = self.llm.generate(prompt)
|
|
196
|
+
return "YES" in response.upper()
|
|
197
|
+
|
|
198
|
+
def _refine_query(self, original_query, context, gaps) -> str:
|
|
199
|
+
"""Reformulate query based on missing information"""
|
|
200
|
+
prompt = f"""
|
|
201
|
+
Original query: {original_query}
|
|
202
|
+
Current context: {context}
|
|
203
|
+
Missing information: {gaps}
|
|
204
|
+
|
|
205
|
+
Reformulate the query to find the missing information.
|
|
206
|
+
"""
|
|
207
|
+
return self.llm.generate(prompt)
|
|
208
|
+
|
|
209
|
+
def _identify_gaps(self, context, question) -> str:
|
|
210
|
+
"""Identify what information is missing"""
|
|
211
|
+
prompt = f"""
|
|
212
|
+
Context: {context}
|
|
213
|
+
Question: {question}
|
|
214
|
+
|
|
215
|
+
What specific information is missing from the context to answer the question?
|
|
216
|
+
"""
|
|
217
|
+
return self.llm.generate(prompt)
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
**Phase 2: Multi-Agent Agentic RAG (Weeks 5-8)**
|
|
221
|
+
```python
|
|
222
|
+
# File: src/agentic_rag/multi_agent.py
|
|
223
|
+
|
|
224
|
+
class MultiAgentAgenticRAG:
|
|
225
|
+
"""Coordinated retrieval across specialized agents"""
|
|
226
|
+
|
|
227
|
+
def __init__(self):
|
|
228
|
+
self.agents = {
|
|
229
|
+
'code': CodeRAGAgent(),
|
|
230
|
+
'docs': DocumentationRAGAgent(),
|
|
231
|
+
'patterns': PatternRAGAgent(),
|
|
232
|
+
'architecture': ArchitectureRAGAgent()
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
def query(self, question: str) -> str:
|
|
236
|
+
"""Route to appropriate agents and synthesize"""
|
|
237
|
+
|
|
238
|
+
# Step 1: Classify query type
|
|
239
|
+
agent_types = self._classify_query(question)
|
|
240
|
+
|
|
241
|
+
# Step 2: Parallel retrieval
|
|
242
|
+
contexts = {}
|
|
243
|
+
with ThreadPoolExecutor() as executor:
|
|
244
|
+
futures = {
|
|
245
|
+
agent_type: executor.submit(
|
|
246
|
+
self.agents[agent_type].query,
|
|
247
|
+
question
|
|
248
|
+
)
|
|
249
|
+
for agent_type in agent_types
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
for agent_type, future in futures.items():
|
|
253
|
+
contexts[agent_type] = future.result()
|
|
254
|
+
|
|
255
|
+
# Step 3: Synthesize across agents
|
|
256
|
+
return self._synthesize(question, contexts)
|
|
257
|
+
|
|
258
|
+
def _classify_query(self, question: str) -> List[str]:
|
|
259
|
+
"""Determine which agents should handle the query"""
|
|
260
|
+
# Simple keyword-based classification
|
|
261
|
+
classifications = []
|
|
262
|
+
|
|
263
|
+
if any(word in question.lower() for word in ['code', 'function', 'class']):
|
|
264
|
+
classifications.append('code')
|
|
265
|
+
|
|
266
|
+
if any(word in question.lower() for word in ['doc', 'readme', 'guide']):
|
|
267
|
+
classifications.append('docs')
|
|
268
|
+
|
|
269
|
+
if any(word in question.lower() for word in ['pattern', 'architecture', 'design']):
|
|
270
|
+
classifications.append('patterns')
|
|
271
|
+
classifications.append('architecture')
|
|
272
|
+
|
|
273
|
+
return classifications if classifications else ['code']
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## 3. Vector Database Integration
|
|
279
|
+
|
|
280
|
+
### Recommended Vector Databases (2025 Comparison)
|
|
281
|
+
|
|
282
|
+
Based on 2025 benchmarks and research:
|
|
283
|
+
|
|
284
|
+
| Database | Latency | Best For | Cost | Open Source |
|
|
285
|
+
|----------|---------|----------|------|-------------|
|
|
286
|
+
| **Qdrant** | 10-20ms | Performance, self-hosted | Free/Enterprise | ✅ Yes |
|
|
287
|
+
| **Pinecone** | 15-30ms | Ease of use, managed | Paid only | ❌ No |
|
|
288
|
+
| **Weaviate** | 20-40ms | Enterprise AI features | Free/Cloud | ✅ Yes |
|
|
289
|
+
| **Milvus** | 8-15ms | Lowest latency | Free/Cloud | ✅ Yes |
|
|
290
|
+
|
|
291
|
+
**Sources:**
|
|
292
|
+
- [Best 17 Vector Databases for 2025](https://lakefs.io/blog/best-vector-databases/)
|
|
293
|
+
- [Pinecone vs Qdrant vs Weaviate Comparison](https://xenoss.io/blog/vector-database-comparison-pinecone-qdrant-weaviate)
|
|
294
|
+
- [OpenSearch vs Pinecone vs Qdrant vs Weaviate](https://medium.com/@elisheba.t.anderson/choosing-the-right-vector-database-opensearch-vs-pinecone-vs-qdrant-vs-weaviate-vs-milvus-vs-037343926d7e)
|
|
295
|
+
|
|
296
|
+
### Recommendation for TMLPD
|
|
297
|
+
|
|
298
|
+
**Primary Choice: Qdrant**
|
|
299
|
+
- Open source (fits TMLPD philosophy)
|
|
300
|
+
- Excellent performance (10-20ms)
|
|
301
|
+
- Self-hostable (privacy-friendly)
|
|
302
|
+
- Active community (2025 growth)
|
|
303
|
+
- Python SDK (fits TMLPD tech stack)
|
|
304
|
+
|
|
305
|
+
**Alternative: Pinecone**
|
|
306
|
+
- If users prefer managed service
|
|
307
|
+
- Easiest setup (serverless)
|
|
308
|
+
- Good for non-technical users
|
|
309
|
+
|
|
310
|
+
### Implementation
|
|
311
|
+
|
|
312
|
+
```python
|
|
313
|
+
# File: src/memory/vector_store.py
|
|
314
|
+
|
|
315
|
+
from qdrant_client import QdrantClient
|
|
316
|
+
from qdrant_client.models import Distance, VectorParams, PointStruct
|
|
317
|
+
import os
|
|
318
|
+
from typing import List, Dict, Any
|
|
319
|
+
|
|
320
|
+
class TMLPDVectorStore:
|
|
321
|
+
"""Vector database wrapper for agent memory"""
|
|
322
|
+
|
|
323
|
+
def __init__(self, collection_name="tmlpd_memory"):
|
|
324
|
+
# Initialize Qdrant client
|
|
325
|
+
self.client = QdrantClient(
|
|
326
|
+
url=os.getenv("QDRANT_URL", "http://localhost:6333")
|
|
327
|
+
)
|
|
328
|
+
|
|
329
|
+
self.collection_name = collection_name
|
|
330
|
+
|
|
331
|
+
# Create collection if not exists
|
|
332
|
+
self._ensure_collection()
|
|
333
|
+
|
|
334
|
+
def _ensure_collection(self):
|
|
335
|
+
"""Create collection with proper schema"""
|
|
336
|
+
collections = self.client.get_collections().collections
|
|
337
|
+
collection_names = [c.name for c in collections]
|
|
338
|
+
|
|
339
|
+
if self.collection_name not in collection_names:
|
|
340
|
+
self.client.create_collection(
|
|
341
|
+
collection_name=self.collection_name,
|
|
342
|
+
vectors_config=VectorParams(
|
|
343
|
+
size=1536, # OpenAI embedding size
|
|
344
|
+
distance=Distance.COSINE
|
|
345
|
+
)
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
def store_execution(
|
|
349
|
+
self,
|
|
350
|
+
agent_id: str,
|
|
351
|
+
task: str,
|
|
352
|
+
result: str,
|
|
353
|
+
metadata: Dict[str, Any]
|
|
354
|
+
):
|
|
355
|
+
"""Store task execution in vector database"""
|
|
356
|
+
|
|
357
|
+
# Generate embedding
|
|
358
|
+
embedding = self._generate_embedding(task + result)
|
|
359
|
+
|
|
360
|
+
# Store with metadata
|
|
361
|
+
point = PointStruct(
|
|
362
|
+
id=self._generate_point_id(agent_id, task),
|
|
363
|
+
vector=embedding,
|
|
364
|
+
payload={
|
|
365
|
+
"agent_id": agent_id,
|
|
366
|
+
"task": task,
|
|
367
|
+
"result": result,
|
|
368
|
+
"timestamp": metadata.get("timestamp"),
|
|
369
|
+
"success": metadata.get("success", True),
|
|
370
|
+
"execution_time": metadata.get("execution_time"),
|
|
371
|
+
"cost": metadata.get("cost"),
|
|
372
|
+
"model": metadata.get("model"),
|
|
373
|
+
**metadata
|
|
374
|
+
}
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
self.client.upsert(
|
|
378
|
+
collection_name=self.collection_name,
|
|
379
|
+
points=[point]
|
|
380
|
+
)
|
|
381
|
+
|
|
382
|
+
def search_similar_executions(
|
|
383
|
+
self,
|
|
384
|
+
query: str,
|
|
385
|
+
agent_id: str = None,
|
|
386
|
+
limit: int = 5
|
|
387
|
+
) -> List[Dict]:
|
|
388
|
+
"""Find similar past executions"""
|
|
389
|
+
|
|
390
|
+
# Generate query embedding
|
|
391
|
+
query_embedding = self._generate_embedding(query)
|
|
392
|
+
|
|
393
|
+
# Build filter
|
|
394
|
+
query_filter = None
|
|
395
|
+
if agent_id:
|
|
396
|
+
query_filter = {
|
|
397
|
+
"must": [
|
|
398
|
+
{"key": "agent_id", "match": {"value": agent_id}}
|
|
399
|
+
]
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
# Search
|
|
403
|
+
results = self.client.search(
|
|
404
|
+
collection_name=self.collection_name,
|
|
405
|
+
query_vector=query_embedding,
|
|
406
|
+
query_filter=query_filter,
|
|
407
|
+
limit=limit
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
return [
|
|
411
|
+
{
|
|
412
|
+
"task": hit.payload["task"],
|
|
413
|
+
"result": hit.payload["result"],
|
|
414
|
+
"agent_id": hit.payload["agent_id"],
|
|
415
|
+
"score": hit.score,
|
|
416
|
+
"metadata": {
|
|
417
|
+
k: v for k, v in hit.payload.items()
|
|
418
|
+
if k not in ["task", "result", "agent_id"]
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
for hit in results
|
|
422
|
+
]
|
|
423
|
+
|
|
424
|
+
def _generate_embedding(self, text: str) -> List[float]:
|
|
425
|
+
"""Generate embedding using OpenAI or local model"""
|
|
426
|
+
from openai import OpenAI
|
|
427
|
+
|
|
428
|
+
client = OpenAI()
|
|
429
|
+
response = client.embeddings.create(
|
|
430
|
+
model="text-embedding-3-small",
|
|
431
|
+
input=text
|
|
432
|
+
)
|
|
433
|
+
return response.data[0].embedding
|
|
434
|
+
|
|
435
|
+
def _generate_point_id(self, agent_id: str, task: str) -> str:
|
|
436
|
+
"""Generate unique point ID"""
|
|
437
|
+
import hashlib
|
|
438
|
+
content = f"{agent_id}:{task}"
|
|
439
|
+
return hashlib.sha256(content.encode()).hexdigest()
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
### Memory Hierarchy Implementation
|
|
443
|
+
|
|
444
|
+
```python
|
|
445
|
+
# File: src/memory/memory_hierarchy.py
|
|
446
|
+
|
|
447
|
+
from typing import Optional, Dict, Any
|
|
448
|
+
from datetime import datetime, timedelta
|
|
449
|
+
|
|
450
|
+
class MemoryHierarchy:
|
|
451
|
+
"""
|
|
452
|
+
Three-tier memory system:
|
|
453
|
+
1. Short-term: Session context (minutes)
|
|
454
|
+
2. Long-term: Vector database (persistent)
|
|
455
|
+
3. Episodic: Task history (patterns)
|
|
456
|
+
"""
|
|
457
|
+
|
|
458
|
+
def __init__(self, vector_store, agent_id: str):
|
|
459
|
+
self.vector_store = vector_store
|
|
460
|
+
self.agent_id = agent_id
|
|
461
|
+
|
|
462
|
+
# Short-term memory (in-memory)
|
|
463
|
+
self.short_term = {
|
|
464
|
+
"context": [],
|
|
465
|
+
"conversation": [],
|
|
466
|
+
"working_set": {}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
# Episodic memory (recent executions)
|
|
470
|
+
self.episodic = []
|
|
471
|
+
|
|
472
|
+
def remember(
|
|
473
|
+
self,
|
|
474
|
+
task: str,
|
|
475
|
+
result: str,
|
|
476
|
+
metadata: Dict[str, Any],
|
|
477
|
+
memory_type: str = "all"
|
|
478
|
+
):
|
|
479
|
+
"""Store memory across all three tiers"""
|
|
480
|
+
|
|
481
|
+
memory_entry = {
|
|
482
|
+
"task": task,
|
|
483
|
+
"result": result,
|
|
484
|
+
"metadata": metadata,
|
|
485
|
+
"timestamp": datetime.now()
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
# Short-term (everything)
|
|
489
|
+
if memory_type in ["all", "short_term"]:
|
|
490
|
+
self.short_term["context"].append(memory_entry)
|
|
491
|
+
# Keep only last 10 entries
|
|
492
|
+
if len(self.short_term["context"]) > 10:
|
|
493
|
+
self.short_term["context"].pop(0)
|
|
494
|
+
|
|
495
|
+
# Episodic (successful patterns)
|
|
496
|
+
if memory_type in ["all", "episodic"] and metadata.get("success"):
|
|
497
|
+
self.episodic.append(memory_entry)
|
|
498
|
+
# Keep last 50 episodes
|
|
499
|
+
if len(self.episodic) > 50:
|
|
500
|
+
self.episodic.pop(0)
|
|
501
|
+
|
|
502
|
+
# Long-term (vector DB)
|
|
503
|
+
if memory_type in ["all", "long_term"]:
|
|
504
|
+
self.vector_store.store_execution(
|
|
505
|
+
agent_id=self.agent_id,
|
|
506
|
+
task=task,
|
|
507
|
+
result=result,
|
|
508
|
+
metadata=metadata
|
|
509
|
+
)
|
|
510
|
+
|
|
511
|
+
def recall(
|
|
512
|
+
self,
|
|
513
|
+
query: str,
|
|
514
|
+
memory_tier: str = "all"
|
|
515
|
+
) -> Dict[str, Any]:
|
|
516
|
+
"""Retrieve from appropriate memory tier(s)"""
|
|
517
|
+
|
|
518
|
+
results = {
|
|
519
|
+
"short_term": [],
|
|
520
|
+
"episodic": [],
|
|
521
|
+
"long_term": []
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
if memory_tier in ["all", "short_term"]:
|
|
525
|
+
# Simple keyword search in short-term
|
|
526
|
+
results["short_term"] = [
|
|
527
|
+
entry for entry in self.short_term["context"]
|
|
528
|
+
if query.lower() in str(entry).lower()
|
|
529
|
+
]
|
|
530
|
+
|
|
531
|
+
if memory_tier in ["all", "episodic"]:
|
|
532
|
+
# Recent successful patterns
|
|
533
|
+
results["episodic"] = [
|
|
534
|
+
entry for entry in self.episodic
|
|
535
|
+
if query.lower() in str(entry).lower()
|
|
536
|
+
]
|
|
537
|
+
|
|
538
|
+
if memory_tier in ["all", "long_term"]:
|
|
539
|
+
# Vector similarity search
|
|
540
|
+
results["long_term"] = self.vector_store.search_similar_executions(
|
|
541
|
+
query=query,
|
|
542
|
+
agent_id=self.agent_id,
|
|
543
|
+
limit=5
|
|
544
|
+
)
|
|
545
|
+
|
|
546
|
+
return results
|
|
547
|
+
|
|
548
|
+
def forget_old(self, days: int = 30):
|
|
549
|
+
"""Clean up old memories from episodic memory"""
|
|
550
|
+
|
|
551
|
+
cutoff = datetime.now() - timedelta(days=days)
|
|
552
|
+
|
|
553
|
+
self.episodic = [
|
|
554
|
+
entry for entry in self.episodic
|
|
555
|
+
if entry["timestamp"] > cutoff
|
|
556
|
+
]
|
|
557
|
+
|
|
558
|
+
# Long-term cleanup handled by vector DB TTL
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
---
|
|
562
|
+
|
|
563
|
+
## 4. Cross-Agent Communication Protocol
|
|
564
|
+
|
|
565
|
+
### Current Limitation
|
|
566
|
+
- Agents work in isolation
|
|
567
|
+
- No knowledge sharing
|
|
568
|
+
- Can't leverage each other's learnings
|
|
569
|
+
|
|
570
|
+
### Proposed Communication Layer
|
|
571
|
+
|
|
572
|
+
```python
|
|
573
|
+
# File: src/communication/message_bus.py
|
|
574
|
+
|
|
575
|
+
from enum import Enum
|
|
576
|
+
from typing import Callable, Dict, Any
|
|
577
|
+
from queue import Queue
|
|
578
|
+
import threading
|
|
579
|
+
|
|
580
|
+
class MessageType(Enum):
|
|
581
|
+
"""Types of inter-agent messages"""
|
|
582
|
+
KNOWLEDGE_SHARE = "knowledge_share"
|
|
583
|
+
QUERY_REQUEST = "query_request"
|
|
584
|
+
QUERY_RESPONSE = "query_response"
|
|
585
|
+
STATUS_UPDATE = "status_update"
|
|
586
|
+
ERROR_ALERT = "error_alert"
|
|
587
|
+
PATTERN_DISCOVERY = "pattern_discovery"
|
|
588
|
+
|
|
589
|
+
class Message:
|
|
590
|
+
"""Structured message between agents"""
|
|
591
|
+
|
|
592
|
+
def __init__(
|
|
593
|
+
self,
|
|
594
|
+
sender: str,
|
|
595
|
+
receiver: str,
|
|
596
|
+
message_type: MessageType,
|
|
597
|
+
content: Any,
|
|
598
|
+
timestamp: datetime = None
|
|
599
|
+
):
|
|
600
|
+
self.sender = sender
|
|
601
|
+
self.receiver = receiver
|
|
602
|
+
self.message_type = message_type
|
|
603
|
+
self.content = content
|
|
604
|
+
self.timestamp = timestamp or datetime.now()
|
|
605
|
+
|
|
606
|
+
class AgentMessageBus:
|
|
607
|
+
"""Communication fabric for multi-agent coordination"""
|
|
608
|
+
|
|
609
|
+
def __init__(self):
|
|
610
|
+
self.queues: Dict[str, Queue] = {}
|
|
611
|
+
self.subscriptions: Dict[str, List[Callable]] = {}
|
|
612
|
+
self.lock = threading.Lock()
|
|
613
|
+
|
|
614
|
+
def register_agent(self, agent_id: str):
|
|
615
|
+
"""Register an agent to the message bus"""
|
|
616
|
+
with self.lock:
|
|
617
|
+
if agent_id not in self.queues:
|
|
618
|
+
self.queues[agent_id] = Queue()
|
|
619
|
+
|
|
620
|
+
def subscribe(
|
|
621
|
+
self,
|
|
622
|
+
agent_id: str,
|
|
623
|
+
message_type: MessageType,
|
|
624
|
+
handler: Callable
|
|
625
|
+
):
|
|
626
|
+
"""Subscribe to specific message types"""
|
|
627
|
+
|
|
628
|
+
key = f"{agent_id}:{message_type.value}"
|
|
629
|
+
|
|
630
|
+
if key not in self.subscriptions:
|
|
631
|
+
self.subscriptions[key] = []
|
|
632
|
+
|
|
633
|
+
self.subscriptions[key].append(handler)
|
|
634
|
+
|
|
635
|
+
def send(self, message: Message):
|
|
636
|
+
"""Send message to specific agent"""
|
|
637
|
+
|
|
638
|
+
if message.receiver not in self.queues:
|
|
639
|
+
raise ValueError(f"Agent {message.receiver} not registered")
|
|
640
|
+
|
|
641
|
+
self.queues[message.receiver].put(message)
|
|
642
|
+
|
|
643
|
+
# Notify subscribers
|
|
644
|
+
key = f"{message.receiver}:{message.message_type.value}"
|
|
645
|
+
|
|
646
|
+
if key in self.subscriptions:
|
|
647
|
+
for handler in self.subscriptions[key]:
|
|
648
|
+
handler(message)
|
|
649
|
+
|
|
650
|
+
def broadcast(self, sender: str, message_type: MessageType, content: Any):
|
|
651
|
+
"""Broadcast message to all agents"""
|
|
652
|
+
|
|
653
|
+
for agent_id in self.queues:
|
|
654
|
+
if agent_id != sender:
|
|
655
|
+
message = Message(
|
|
656
|
+
sender=sender,
|
|
657
|
+
receiver=agent_id,
|
|
658
|
+
message_type=message_type,
|
|
659
|
+
content=content
|
|
660
|
+
)
|
|
661
|
+
self.send(message)
|
|
662
|
+
|
|
663
|
+
def receive(self, agent_id: str, timeout: float = 0.1) -> Optional[Message]:
|
|
664
|
+
"""Receive message for specific agent"""
|
|
665
|
+
|
|
666
|
+
if agent_id not in self.queues:
|
|
667
|
+
raise ValueError(f"Agent {agent_id} not registered")
|
|
668
|
+
|
|
669
|
+
try:
|
|
670
|
+
return self.queues[agent_id].get(timeout=timeout)
|
|
671
|
+
except:
|
|
672
|
+
return None
|
|
673
|
+
|
|
674
|
+
# Usage Example
|
|
675
|
+
class EnhancedAgent:
|
|
676
|
+
"""Agent with communication capabilities"""
|
|
677
|
+
|
|
678
|
+
def __init__(self, agent_id: str, message_bus: AgentMessageBus):
|
|
679
|
+
self.agent_id = agent_id
|
|
680
|
+
self.message_bus = message_bus
|
|
681
|
+
self.message_bus.register_agent(agent_id)
|
|
682
|
+
|
|
683
|
+
# Subscribe to knowledge shares
|
|
684
|
+
self.message_bus.subscribe(
|
|
685
|
+
agent_id,
|
|
686
|
+
MessageType.KNOWLEDGE_SHARE,
|
|
687
|
+
self._handle_knowledge_share
|
|
688
|
+
)
|
|
689
|
+
|
|
690
|
+
def _handle_knowledge_share(self, message: Message):
|
|
691
|
+
"""Handle incoming knowledge from other agents"""
|
|
692
|
+
|
|
693
|
+
sender = message.sender
|
|
694
|
+
knowledge = message.content
|
|
695
|
+
|
|
696
|
+
# Store in memory
|
|
697
|
+
self.memory.remember(
|
|
698
|
+
task=f"Knowledge from {sender}",
|
|
699
|
+
result=str(knowledge),
|
|
700
|
+
metadata={"source": "agent_communication", "sender": sender}
|
|
701
|
+
)
|
|
702
|
+
|
|
703
|
+
def share_knowledge(self, knowledge: Any):
|
|
704
|
+
"""Broadcast knowledge to all agents"""
|
|
705
|
+
|
|
706
|
+
self.message_bus.broadcast(
|
|
707
|
+
sender=self.agent_id,
|
|
708
|
+
message_type=MessageType.KNOWLEDGE_SHARE,
|
|
709
|
+
content=knowledge
|
|
710
|
+
)
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
### Knowledge Sharing Protocol
|
|
714
|
+
|
|
715
|
+
```python
|
|
716
|
+
# File: src/communication/knowledge_sharing.py
|
|
717
|
+
|
|
718
|
+
class KnowledgeSharingProtocol:
|
|
719
|
+
"""
|
|
720
|
+
Protocol for agents to share discoveries and patterns
|
|
721
|
+
"""
|
|
722
|
+
|
|
723
|
+
def __init__(self, message_bus: AgentMessageBus):
|
|
724
|
+
self.message_bus = message_bus
|
|
725
|
+
|
|
726
|
+
def share_success_pattern(
|
|
727
|
+
self,
|
|
728
|
+
agent_id: str,
|
|
729
|
+
task_type: str,
|
|
730
|
+
pattern: Dict[str, Any]
|
|
731
|
+
):
|
|
732
|
+
"""Share successful execution pattern"""
|
|
733
|
+
|
|
734
|
+
message = Message(
|
|
735
|
+
sender=agent_id,
|
|
736
|
+
receiver="broadcast",
|
|
737
|
+
message_type=MessageType.PATTERN_DISCOVERY,
|
|
738
|
+
content={
|
|
739
|
+
"task_type": task_type,
|
|
740
|
+
"pattern": pattern,
|
|
741
|
+
"success_rate": pattern.get("success_rate", 1.0),
|
|
742
|
+
"timestamp": datetime.now()
|
|
743
|
+
}
|
|
744
|
+
)
|
|
745
|
+
|
|
746
|
+
self.message_bus.broadcast(
|
|
747
|
+
sender=agent_id,
|
|
748
|
+
message_type=MessageType.PATTERN_DISCOVERY,
|
|
749
|
+
content=message.content
|
|
750
|
+
)
|
|
751
|
+
|
|
752
|
+
def query_agents(
|
|
753
|
+
self,
|
|
754
|
+
requester_id: str,
|
|
755
|
+
query: str,
|
|
756
|
+
agent_types: List[str] = None
|
|
757
|
+
) -> Dict[str, Any]:
|
|
758
|
+
"""Query other agents for information"""
|
|
759
|
+
|
|
760
|
+
responses = {}
|
|
761
|
+
|
|
762
|
+
# Send query requests
|
|
763
|
+
for agent_id in self.message_bus.queues:
|
|
764
|
+
if agent_id != requester_id:
|
|
765
|
+
message = Message(
|
|
766
|
+
sender=requester_id,
|
|
767
|
+
receiver=agent_id,
|
|
768
|
+
message_type=MessageType.QUERY_REQUEST,
|
|
769
|
+
content={"query": query}
|
|
770
|
+
)
|
|
771
|
+
self.message_bus.send(message)
|
|
772
|
+
|
|
773
|
+
# Collect responses (with timeout)
|
|
774
|
+
import time
|
|
775
|
+
time.sleep(2) # Wait for responses
|
|
776
|
+
|
|
777
|
+
while True:
|
|
778
|
+
response = self.message_bus.receive(requester_id, timeout=0.1)
|
|
779
|
+
if response is None:
|
|
780
|
+
break
|
|
781
|
+
|
|
782
|
+
if response.message_type == MessageType.QUERY_RESPONSE:
|
|
783
|
+
responses[response.sender] = response.content
|
|
784
|
+
|
|
785
|
+
return responses
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
---
|
|
789
|
+
|
|
790
|
+
## 5. Enhanced State Management
|
|
791
|
+
|
|
792
|
+
### Current Checkpointing
|
|
793
|
+
```yaml
|
|
794
|
+
# Current: Simple JSON file
|
|
795
|
+
{
|
|
796
|
+
"agent_id": "frontend",
|
|
797
|
+
"completed_tasks": [1, 2, 3],
|
|
798
|
+
"current_task": 4,
|
|
799
|
+
"timestamp": "2025-01-02T10:30:00Z"
|
|
800
|
+
}
|
|
801
|
+
```
|
|
802
|
+
|
|
803
|
+
### Proposed State Management (LangGraph-inspired)
|
|
804
|
+
|
|
805
|
+
```python
|
|
806
|
+
# File: src/state/checkpoint_manager.py
|
|
807
|
+
|
|
808
|
+
from typing import TypedDict, Optional
|
|
809
|
+
import json
|
|
810
|
+
import pickle
|
|
811
|
+
from datetime import datetime
|
|
812
|
+
|
|
813
|
+
class AgentState(TypedDict):
|
|
814
|
+
"""Comprehensive agent state"""
|
|
815
|
+
|
|
816
|
+
# Task state
|
|
817
|
+
completed_tasks: List[int]
|
|
818
|
+
current_task: Optional[int]
|
|
819
|
+
task_results: Dict[int, Any]
|
|
820
|
+
|
|
821
|
+
# Memory state
|
|
822
|
+
short_term_memory: List[Dict]
|
|
823
|
+
episodic_memory: List[Dict]
|
|
824
|
+
|
|
825
|
+
# Communication state
|
|
826
|
+
received_messages: List[Dict]
|
|
827
|
+
sent_messages: List[Dict]
|
|
828
|
+
|
|
829
|
+
# Performance state
|
|
830
|
+
total_cost: float
|
|
831
|
+
total_tokens: int
|
|
832
|
+
execution_time: float
|
|
833
|
+
|
|
834
|
+
# Metadata
|
|
835
|
+
timestamp: str
|
|
836
|
+
checkpoint_version: int
|
|
837
|
+
|
|
838
|
+
class CheckpointManager:
|
|
839
|
+
"""
|
|
840
|
+
Enhanced checkpointing with:
|
|
841
|
+
- State versioning
|
|
842
|
+
- Rollback capability
|
|
843
|
+
- Cross-session persistence
|
|
844
|
+
- LangGraph-compatible format
|
|
845
|
+
"""
|
|
846
|
+
|
|
847
|
+
def __init__(self, agent_id: str, storage_backend="local"):
|
|
848
|
+
self.agent_id = agent_id
|
|
849
|
+
self.storage_backend = storage_backend
|
|
850
|
+
|
|
851
|
+
if storage_backend == "redis":
|
|
852
|
+
import redis
|
|
853
|
+
self.redis_client = redis.Redis(
|
|
854
|
+
host=os.getenv("REDIS_HOST", "localhost"),
|
|
855
|
+
port=6379,
|
|
856
|
+
db=0
|
|
857
|
+
)
|
|
858
|
+
else:
|
|
859
|
+
self.storage_path = f".checkpoints/{agent_id}/"
|
|
860
|
+
os.makedirs(self.storage_path, exist_ok=True)
|
|
861
|
+
|
|
862
|
+
def save_checkpoint(self, state: AgentState) -> str:
|
|
863
|
+
"""Save state checkpoint"""
|
|
864
|
+
|
|
865
|
+
checkpoint = {
|
|
866
|
+
"agent_id": self.agent_id,
|
|
867
|
+
"state": state,
|
|
868
|
+
"timestamp": datetime.now().isoformat(),
|
|
869
|
+
"version": state.get("checkpoint_version", 0) + 1
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
if self.storage_backend == "redis":
|
|
873
|
+
checkpoint_id = self._save_to_redis(checkpoint)
|
|
874
|
+
else:
|
|
875
|
+
checkpoint_id = self._save_to_file(checkpoint)
|
|
876
|
+
|
|
877
|
+
return checkpoint_id
|
|
878
|
+
|
|
879
|
+
def load_checkpoint(self, checkpoint_id: str) -> Optional[AgentState]:
|
|
880
|
+
"""Load specific checkpoint"""
|
|
881
|
+
|
|
882
|
+
if self.storage_backend == "redis":
|
|
883
|
+
return self._load_from_redis(checkpoint_id)
|
|
884
|
+
else:
|
|
885
|
+
return self._load_from_file(checkpoint_id)
|
|
886
|
+
|
|
887
|
+
def list_checkpoints(self) -> List[Dict]:
|
|
888
|
+
"""List all available checkpoints"""
|
|
889
|
+
|
|
890
|
+
if self.storage_backend == "redis":
|
|
891
|
+
return self._list_from_redis()
|
|
892
|
+
else:
|
|
893
|
+
return self._list_from_files()
|
|
894
|
+
|
|
895
|
+
def rollback_to_checkpoint(self, checkpoint_id: str):
|
|
896
|
+
"""Rollback agent to specific checkpoint"""
|
|
897
|
+
|
|
898
|
+
state = self.load_checkpoint(checkpoint_id)
|
|
899
|
+
if state:
|
|
900
|
+
# Restore state
|
|
901
|
+
self._restore_state(state)
|
|
902
|
+
return True
|
|
903
|
+
return False
|
|
904
|
+
|
|
905
|
+
def _save_to_file(self, checkpoint: Dict) -> str:
|
|
906
|
+
"""Save checkpoint to file"""
|
|
907
|
+
|
|
908
|
+
checkpoint_id = f"checkpoint_{checkpoint['version']}_{int(datetime.now().timestamp())}"
|
|
909
|
+
file_path = os.path.join(self.storage_path, f"{checkpoint_id}.pkl")
|
|
910
|
+
|
|
911
|
+
with open(file_path, "wb") as f:
|
|
912
|
+
pickle.dump(checkpoint, f)
|
|
913
|
+
|
|
914
|
+
# Also save JSON for readability
|
|
915
|
+
json_path = os.path.join(self.storage_path, f"{checkpoint_id}.json")
|
|
916
|
+
with open(json_path, "w") as f:
|
|
917
|
+
json.dump(checkpoint, f, indent=2, default=str)
|
|
918
|
+
|
|
919
|
+
return checkpoint_id
|
|
920
|
+
|
|
921
|
+
def _load_from_file(self, checkpoint_id: str) -> Optional[AgentState]:
|
|
922
|
+
"""Load checkpoint from file"""
|
|
923
|
+
|
|
924
|
+
file_path = os.path.join(self.storage_path, f"{checkpoint_id}.pkl")
|
|
925
|
+
|
|
926
|
+
try:
|
|
927
|
+
with open(file_path, "rb") as f:
|
|
928
|
+
checkpoint = pickle.load(f)
|
|
929
|
+
return checkpoint["state"]
|
|
930
|
+
except FileNotFoundError:
|
|
931
|
+
return None
|
|
932
|
+
|
|
933
|
+
def _restore_state(self, state: AgentState):
|
|
934
|
+
"""Restore agent state from checkpoint"""
|
|
935
|
+
|
|
936
|
+
# Restore task state
|
|
937
|
+
for task_id in state["completed_tasks"]:
|
|
938
|
+
# Mark tasks as completed
|
|
939
|
+
pass
|
|
940
|
+
|
|
941
|
+
# Restore memory
|
|
942
|
+
if "short_term_memory" in state:
|
|
943
|
+
self.agent.memory.short_term = state["short_term_memory"]
|
|
944
|
+
|
|
945
|
+
if "episodic_memory" in state:
|
|
946
|
+
self.agent.memory.episodic = state["episodic_memory"]
|
|
947
|
+
|
|
948
|
+
# Continue from current task
|
|
949
|
+
if state["current_task"]:
|
|
950
|
+
self.agent.execute_task(state["current_task"])
|
|
951
|
+
```
|
|
952
|
+
|
|
953
|
+
---
|
|
954
|
+
|
|
955
|
+
## 6. Integration with Existing TMLPD
|
|
956
|
+
|
|
957
|
+
### Migration Path
|
|
958
|
+
|
|
959
|
+
**Phase 1: Add Memory Layer (Weeks 1-4)**
|
|
960
|
+
```yaml
|
|
961
|
+
# Enhanced YAML config with memory
|
|
962
|
+
deployment:
|
|
963
|
+
name: "Full-Stack Development with Memory"
|
|
964
|
+
|
|
965
|
+
# Existing config
|
|
966
|
+
agents:
|
|
967
|
+
- id: "frontend"
|
|
968
|
+
provider: "anthropic"
|
|
969
|
+
model: "claude-sonnet-4"
|
|
970
|
+
focus: "UI components"
|
|
971
|
+
|
|
972
|
+
# NEW: Memory configuration
|
|
973
|
+
memory:
|
|
974
|
+
enabled: true
|
|
975
|
+
vector_db:
|
|
976
|
+
provider: "qdrant" # or "pinecone"
|
|
977
|
+
url: "http://localhost:6333"
|
|
978
|
+
collection: "tmlpd_memory"
|
|
979
|
+
|
|
980
|
+
short_term:
|
|
981
|
+
max_entries: 10
|
|
982
|
+
ttl_minutes: 60
|
|
983
|
+
|
|
984
|
+
long_term:
|
|
985
|
+
enabled: true
|
|
986
|
+
retention_days: 30
|
|
987
|
+
|
|
988
|
+
episodic:
|
|
989
|
+
max_episodes: 50
|
|
990
|
+
success_only: true
|
|
991
|
+
|
|
992
|
+
# NEW: Communication
|
|
993
|
+
communication:
|
|
994
|
+
enabled: true
|
|
995
|
+
message_bus:
|
|
996
|
+
backend: "memory" # or "redis"
|
|
997
|
+
|
|
998
|
+
knowledge_sharing:
|
|
999
|
+
enabled: true
|
|
1000
|
+
share_patterns: true
|
|
1001
|
+
share_errors: true
|
|
1002
|
+
|
|
1003
|
+
# NEW: Enhanced checkpointing
|
|
1004
|
+
checkpointing:
|
|
1005
|
+
backend: "redis" # or "file"
|
|
1006
|
+
interval_seconds: 600 # 10 minutes
|
|
1007
|
+
max_checkpoints: 10
|
|
1008
|
+
```
|
|
1009
|
+
|
|
1010
|
+
**Phase 2: Enhance Agent Execution (Weeks 5-8)**
|
|
1011
|
+
```python
|
|
1012
|
+
# File: src/agents/memory_enhanced_agent.py
|
|
1013
|
+
|
|
1014
|
+
class MemoryEnhancedAgent:
|
|
1015
|
+
"""Agent with memory and communication capabilities"""
|
|
1016
|
+
|
|
1017
|
+
def __init__(
|
|
1018
|
+
self,
|
|
1019
|
+
agent_config: Dict,
|
|
1020
|
+
memory_hierarchy: MemoryHierarchy,
|
|
1021
|
+
message_bus: AgentMessageBus,
|
|
1022
|
+
checkpoint_manager: CheckpointManager
|
|
1023
|
+
):
|
|
1024
|
+
self.config = agent_config
|
|
1025
|
+
self.memory = memory_hierarchy
|
|
1026
|
+
self.message_bus = message_bus
|
|
1027
|
+
self.checkpoint_manager = checkpoint_manager
|
|
1028
|
+
|
|
1029
|
+
# Load previous state if available
|
|
1030
|
+
self._load_state()
|
|
1031
|
+
|
|
1032
|
+
def execute_task(self, task: Dict) -> Dict:
|
|
1033
|
+
"""Execute task with memory enhancement"""
|
|
1034
|
+
|
|
1035
|
+
task_description = task["description"]
|
|
1036
|
+
|
|
1037
|
+
# Step 1: Recall relevant past executions
|
|
1038
|
+
recalled = self.memory.recall(
|
|
1039
|
+
query=task_description,
|
|
1040
|
+
memory_tier="all"
|
|
1041
|
+
)
|
|
1042
|
+
|
|
1043
|
+
# Step 2: Use past success patterns
|
|
1044
|
+
context = self._build_context(recalled, task)
|
|
1045
|
+
|
|
1046
|
+
# Step 3: Check with other agents
|
|
1047
|
+
if self.message_bus:
|
|
1048
|
+
agent_responses = self._query_other_agents(task_description)
|
|
1049
|
+
context = self._merge_agent_responses(context, agent_responses)
|
|
1050
|
+
|
|
1051
|
+
# Step 4: Execute with enhanced context
|
|
1052
|
+
result = self._execute_with_context(task, context)
|
|
1053
|
+
|
|
1054
|
+
# Step 5: Remember successful execution
|
|
1055
|
+
self.memory.remember(
|
|
1056
|
+
task=task_description,
|
|
1057
|
+
result=str(result),
|
|
1058
|
+
metadata={
|
|
1059
|
+
"success": result.get("success", True),
|
|
1060
|
+
"execution_time": result.get("execution_time"),
|
|
1061
|
+
"cost": result.get("cost"),
|
|
1062
|
+
"model": self.config["model"]
|
|
1063
|
+
}
|
|
1064
|
+
)
|
|
1065
|
+
|
|
1066
|
+
# Step 6: Share learnings
|
|
1067
|
+
if result.get("success"):
|
|
1068
|
+
self._share_success_pattern(task, result)
|
|
1069
|
+
|
|
1070
|
+
# Step 7: Checkpoint
|
|
1071
|
+
self._save_checkpoint()
|
|
1072
|
+
|
|
1073
|
+
return result
|
|
1074
|
+
|
|
1075
|
+
def _build_context(
|
|
1076
|
+
self,
|
|
1077
|
+
recalled: Dict[str, Any],
|
|
1078
|
+
task: Dict
|
|
1079
|
+
) -> str:
|
|
1080
|
+
"""Build enhanced context from memory"""
|
|
1081
|
+
|
|
1082
|
+
context_parts = []
|
|
1083
|
+
|
|
1084
|
+
# Add short-term context
|
|
1085
|
+
if recalled["short_term"]:
|
|
1086
|
+
context_parts.append("Recent Context:")
|
|
1087
|
+
context_parts.append(
|
|
1088
|
+
"\n".join([
|
|
1089
|
+
f"- {entry['task']}: {entry['result']}"
|
|
1090
|
+
for entry in recalled["short_term"][-3:]
|
|
1091
|
+
])
|
|
1092
|
+
)
|
|
1093
|
+
|
|
1094
|
+
# Add successful patterns
|
|
1095
|
+
if recalled["episodic"]:
|
|
1096
|
+
context_parts.append("Successful Patterns:")
|
|
1097
|
+
context_parts.append(
|
|
1098
|
+
"\n".join([
|
|
1099
|
+
f"- {entry['task']}: {entry['metadata'].get('approach', 'N/A')}"
|
|
1100
|
+
for entry in recalled["episodic"][-3:]
|
|
1101
|
+
])
|
|
1102
|
+
)
|
|
1103
|
+
|
|
1104
|
+
# Add similar long-term executions
|
|
1105
|
+
if recalled["long_term"]:
|
|
1106
|
+
context_parts.append("Similar Past Executions:")
|
|
1107
|
+
context_parts.append(
|
|
1108
|
+
"\n".join([
|
|
1109
|
+
f"- {entry['task']} (similarity: {entry['score']:.2f})"
|
|
1110
|
+
for entry in recalled["long_term"][:3]
|
|
1111
|
+
])
|
|
1112
|
+
)
|
|
1113
|
+
|
|
1114
|
+
return "\n\n".join(context_parts)
|
|
1115
|
+
|
|
1116
|
+
def _query_other_agents(self, task: str) -> Dict[str, Any]:
|
|
1117
|
+
"""Query other agents for assistance"""
|
|
1118
|
+
|
|
1119
|
+
message = Message(
|
|
1120
|
+
sender=self.agent_id,
|
|
1121
|
+
receiver="broadcast",
|
|
1122
|
+
message_type=MessageType.QUERY_REQUEST,
|
|
1123
|
+
content={"query": task}
|
|
1124
|
+
)
|
|
1125
|
+
|
|
1126
|
+
self.message_bus.broadcast(
|
|
1127
|
+
sender=self.agent_id,
|
|
1128
|
+
message_type=MessageType.QUERY_REQUEST,
|
|
1129
|
+
content=message.content
|
|
1130
|
+
)
|
|
1131
|
+
|
|
1132
|
+
# Collect responses
|
|
1133
|
+
responses = {}
|
|
1134
|
+
timeout = time.time() + 5 # 5 second timeout
|
|
1135
|
+
|
|
1136
|
+
while time.time() < timeout:
|
|
1137
|
+
response = self.message_bus.receive(self.agent_id, timeout=0.5)
|
|
1138
|
+
if response and response.message_type == MessageType.QUERY_RESPONSE:
|
|
1139
|
+
responses[response.sender] = response.content
|
|
1140
|
+
|
|
1141
|
+
return responses
|
|
1142
|
+
|
|
1143
|
+
def _share_success_pattern(self, task: Dict, result: Dict):
|
|
1144
|
+
"""Share successful execution pattern"""
|
|
1145
|
+
|
|
1146
|
+
pattern = {
|
|
1147
|
+
"task_type": task.get("type"),
|
|
1148
|
+
"approach": result.get("approach"),
|
|
1149
|
+
"model": self.config["model"],
|
|
1150
|
+
"execution_time": result.get("execution_time"),
|
|
1151
|
+
"cost": result.get("cost")
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
self.message_bus.broadcast(
|
|
1155
|
+
sender=self.agent_id,
|
|
1156
|
+
message_type=MessageType.PATTERN_DISCOVERY,
|
|
1157
|
+
content={
|
|
1158
|
+
"task_type": task.get("type"),
|
|
1159
|
+
"pattern": pattern
|
|
1160
|
+
}
|
|
1161
|
+
)
|
|
1162
|
+
```
|
|
1163
|
+
|
|
1164
|
+
---
|
|
1165
|
+
|
|
1166
|
+
## 7. Performance Impact Analysis
|
|
1167
|
+
|
|
1168
|
+
### Expected Improvements
|
|
1169
|
+
|
|
1170
|
+
**Complex Task Handling:**
|
|
1171
|
+
- **Current:** Linear performance degradation with complexity
|
|
1172
|
+
- **With Memory:** 3-5x better (learns from past)
|
|
1173
|
+
- **Reason:** Reuses successful patterns, avoids failures
|
|
1174
|
+
|
|
1175
|
+
**Context Retention:**
|
|
1176
|
+
- **Current:** Session-only (lost after restart)
|
|
1177
|
+
- **With Memory:** 10x better (persistent across sessions)
|
|
1178
|
+
- **Reason:** Long-term vector database storage
|
|
1179
|
+
|
|
1180
|
+
**Multi-Agent Coordination:**
|
|
1181
|
+
- **Current:** No communication
|
|
1182
|
+
- **With Communication:** 2-3x better (shared knowledge)
|
|
1183
|
+
- **Reason:** Agents learn from each other's successes/failures
|
|
1184
|
+
|
|
1185
|
+
**Recovery from Failures:**
|
|
1186
|
+
- **Current:** Restart from scratch
|
|
1187
|
+
- **With Enhanced Checkpointing:** Near-zero downtime
|
|
1188
|
+
- **Reason:** State versioning and rollback
|
|
1189
|
+
|
|
1190
|
+
### Benchmarks to Run
|
|
1191
|
+
|
|
1192
|
+
**Test Suite 1: Memory Effectiveness**
|
|
1193
|
+
```python
|
|
1194
|
+
# Test: Task similarity and learning rate
|
|
1195
|
+
tasks = [
|
|
1196
|
+
"Build React login form",
|
|
1197
|
+
"Build React signup form", # Similar
|
|
1198
|
+
"Build React profile form", # Similar
|
|
1199
|
+
"Build Node.js API", # Different
|
|
1200
|
+
]
|
|
1201
|
+
|
|
1202
|
+
# Metric: Execution time reduction for similar tasks
|
|
1203
|
+
# Expected: 50% reduction by 3rd similar task
|
|
1204
|
+
```
|
|
1205
|
+
|
|
1206
|
+
**Test Suite 2: Cross-Agent Learning**
|
|
1207
|
+
```python
|
|
1208
|
+
# Test: Knowledge sharing between agents
|
|
1209
|
+
# Agent 1 solves problem, shares pattern
|
|
1210
|
+
# Agent 2 encounters similar problem
|
|
1211
|
+
|
|
1212
|
+
# Metric: Time savings for Agent 2
|
|
1213
|
+
# Expected: 30-50% faster with knowledge sharing
|
|
1214
|
+
```
|
|
1215
|
+
|
|
1216
|
+
**Test Suite 3: Long-Term Memory**
|
|
1217
|
+
```python
|
|
1218
|
+
# Test: Recall across sessions
|
|
1219
|
+
# Execute tasks in session 1
|
|
1220
|
+
# Restart system
|
|
1221
|
+
# Execute similar tasks in session 2
|
|
1222
|
+
|
|
1223
|
+
# Metric: Context retention accuracy
|
|
1224
|
+
# Expected: >80% recall accuracy
|
|
1225
|
+
```
|
|
1226
|
+
|
|
1227
|
+
---
|
|
1228
|
+
|
|
1229
|
+
## 8. Implementation Roadmap
|
|
1230
|
+
|
|
1231
|
+
### Phase 1: Foundation (Weeks 1-4)
|
|
1232
|
+
**Goal:** Basic memory layer
|
|
1233
|
+
|
|
1234
|
+
- [ ] Set up Qdrant vector database
|
|
1235
|
+
- [ ] Implement `TMLPDVectorStore` class
|
|
1236
|
+
- [ ] Add memory config to YAML schema
|
|
1237
|
+
- [ ] Implement basic `MemoryHierarchy`
|
|
1238
|
+
- [ ] Add embeddings generation (OpenAI or local)
|
|
1239
|
+
- [ ] Unit tests for memory operations
|
|
1240
|
+
|
|
1241
|
+
**Deliverables:**
|
|
1242
|
+
- Working vector database integration
|
|
1243
|
+
- Agents can store and retrieve past executions
|
|
1244
|
+
- Basic similarity search
|
|
1245
|
+
|
|
1246
|
+
### Phase 2: Agentic RAG (Weeks 5-8)
|
|
1247
|
+
**Goal:** Multi-step retrieval
|
|
1248
|
+
|
|
1249
|
+
- [ ] Implement `AgenticRAGAgent`
|
|
1250
|
+
- [ ] Add query reformulation logic
|
|
1251
|
+
- [ ] Implement sufficiency assessment
|
|
1252
|
+
- [ ] Add multi-retrieval loop
|
|
1253
|
+
- [ ] Integration with existing agents
|
|
1254
|
+
- [ ] Benchmarks vs. baseline
|
|
1255
|
+
|
|
1256
|
+
**Deliverables:**
|
|
1257
|
+
- Agents can refine queries dynamically
|
|
1258
|
+
- Multi-step retrieval for complex tasks
|
|
1259
|
+
- 2-3x improvement on complex queries
|
|
1260
|
+
|
|
1261
|
+
### Phase 3: Communication (Weeks 9-12)
|
|
1262
|
+
**Goal:** Cross-agent coordination
|
|
1263
|
+
|
|
1264
|
+
- [ ] Implement `AgentMessageBus`
|
|
1265
|
+
- [ ] Add `MessageType` enums and handlers
|
|
1266
|
+
- [ ] Implement knowledge sharing protocol
|
|
1267
|
+
- [ ] Add agent discovery and registration
|
|
1268
|
+
- [ ] Implement query/response protocol
|
|
1269
|
+
- [ ] Integration tests
|
|
1270
|
+
|
|
1271
|
+
**Deliverables:**
|
|
1272
|
+
- Agents can communicate asynchronously
|
|
1273
|
+
- Knowledge sharing between agents
|
|
1274
|
+
- Pattern discovery and sharing
|
|
1275
|
+
|
|
1276
|
+
### Phase 4: Enhanced State (Weeks 13-16)
|
|
1277
|
+
**Goal:** Production-grade checkpointing
|
|
1278
|
+
|
|
1279
|
+
- [ ] Implement `CheckpointManager`
|
|
1280
|
+
- [ ] Add Redis backend option
|
|
1281
|
+
- [ ] Implement state versioning
|
|
1282
|
+
- [ ] Add rollback functionality
|
|
1283
|
+
- [ ] LangGraph compatibility
|
|
1284
|
+
- [ ] Migration tools
|
|
1285
|
+
|
|
1286
|
+
**Deliverables:**
|
|
1287
|
+
- Robust checkpointing with rollback
|
|
1288
|
+
- Cross-session state persistence
|
|
1289
|
+
- Compatible with LangGraph format
|
|
1290
|
+
|
|
1291
|
+
### Phase 5: Integration & Testing (Weeks 17-20)
|
|
1292
|
+
**Goal:** Production readiness
|
|
1293
|
+
|
|
1294
|
+
- [ ] End-to-end integration
|
|
1295
|
+
- [ ] Performance benchmarking
|
|
1296
|
+
- [ ] Documentation
|
|
1297
|
+
- [ ] Migration guide for v1.0 users
|
|
1298
|
+
- [ ] Example configurations
|
|
1299
|
+
- [ ] Load testing
|
|
1300
|
+
|
|
1301
|
+
**Deliverables:**
|
|
1302
|
+
- Fully integrated v2.0 system
|
|
1303
|
+
- Comprehensive documentation
|
|
1304
|
+
- Migration tools
|
|
1305
|
+
- Performance report
|
|
1306
|
+
|
|
1307
|
+
---
|
|
1308
|
+
|
|
1309
|
+
## 9. Migration Strategy for Existing Users
|
|
1310
|
+
|
|
1311
|
+
### Backward Compatibility
|
|
1312
|
+
|
|
1313
|
+
```yaml
|
|
1314
|
+
# v1.0 config still works
|
|
1315
|
+
deployment:
|
|
1316
|
+
name: "My Project"
|
|
1317
|
+
agents:
|
|
1318
|
+
- id: "frontend"
|
|
1319
|
+
provider: "anthropic"
|
|
1320
|
+
model: "claude-sonnet-4"
|
|
1321
|
+
```
|
|
1322
|
+
|
|
1323
|
+
### Opt-in v2.0 Features
|
|
1324
|
+
|
|
1325
|
+
```yaml
|
|
1326
|
+
# Enable v2.0 features progressively
|
|
1327
|
+
deployment:
|
|
1328
|
+
name: "My Project v2"
|
|
1329
|
+
|
|
1330
|
+
# v1.0: Still works
|
|
1331
|
+
agents:
|
|
1332
|
+
- id: "frontend"
|
|
1333
|
+
provider: "anthropic"
|
|
1334
|
+
model: "claude-sonnet-4"
|
|
1335
|
+
|
|
1336
|
+
# v2.0: Opt-in additions
|
|
1337
|
+
memory:
|
|
1338
|
+
enabled: true
|
|
1339
|
+
# ... config
|
|
1340
|
+
```
|
|
1341
|
+
|
|
1342
|
+
---
|
|
1343
|
+
|
|
1344
|
+
## 10. Research References
|
|
1345
|
+
|
|
1346
|
+
### Memory Architecture
|
|
1347
|
+
- [2025年Memory最全综述!AI Agent记忆统一分类体系](https://zhuanlan.zhihu.com/p/1985435669187825983) - Comprehensive memory classification
|
|
1348
|
+
- [MARFT: Multi-Agent Reinforcement Fine-Tuning](https://arxiv.org/html/2504.16129v4) - Multi-agent RL approaches
|
|
1349
|
+
|
|
1350
|
+
### Agentic RAG
|
|
1351
|
+
- [Agentic RAG vs. Traditional RAG](https://medium.com/@gaddam.rahul.kumar/agentic-rag-vs-traditional-rag-b1a156f72167)
|
|
1352
|
+
- [Redis Blog: Agentic RAG](https://redis.io/blog/agentic-rag-how-enterprises-are-surmounting-the-limits-of-traditional-rag/)
|
|
1353
|
+
- [What is Agentic RAG? 2025 Guide](https://www.lyzr.ai/blog/agentic-rag/)
|
|
1354
|
+
|
|
1355
|
+
### Vector Databases
|
|
1356
|
+
- [Best 17 Vector Databases for 2025](https://lakefs.io/blog/best-vector-databases/)
|
|
1357
|
+
- [Pinecone vs Qdrant vs Weaviate](https://xenoss.io/blog/vector-database-comparison-pinecone-qdrant-weaviate)
|
|
1358
|
+
|
|
1359
|
+
### Multi-Agent Frameworks
|
|
1360
|
+
- [LangGraph Memory Guide](https://medium.com/fundamentals-of-artificial-intelligence/langgraph-memory-a7794effc5d5)
|
|
1361
|
+
- [Orchestrating Multi-Agent Systems with LangGraph](https://healthark.ai/orchestrating-multi-agent-systems-with-lang-graph-mcp/)
|
|
1362
|
+
- [Agentic AI Frameworks Comparison](https://arxiv.org/html/2508.10146)
|
|
1363
|
+
|
|
1364
|
+
### Next-Generation Systems
|
|
1365
|
+
- [Towards Next-Generation Agent Systems (VLDB)](https://www.vldb.org/2025/Workshops/VLDB-Workshops-2025/LLM+Graph/LLMGraph-8.pdf)
|
|
1366
|
+
- [Cognitive Orchestration Layer](https://medium.com/@raktims2210/cognitive-orchestration-layer-the-next-enterprise-ai-architecture-that-lets-hundreds-of-agents-35dd427811f3)
|
|
1367
|
+
|
|
1368
|
+
---
|
|
1369
|
+
|
|
1370
|
+
## Conclusion
|
|
1371
|
+
|
|
1372
|
+
These architectural improvements will transform TMLPD from a parallel task execution tool into a state-of-the-art multi-agent system with:
|
|
1373
|
+
|
|
1374
|
+
1. **Persistent Memory** - Learn from every execution
|
|
1375
|
+
2. **Dynamic Reasoning** - Multi-step Agentic RAG
|
|
1376
|
+
3. **Collaborative Intelligence** - Cross-agent knowledge sharing
|
|
1377
|
+
4. **Production Reliability** - Enhanced checkpointing and rollback
|
|
1378
|
+
|
|
1379
|
+
**Next Steps:**
|
|
1380
|
+
1. Review and prioritize features
|
|
1381
|
+
2. Set up development environment for Phase 1
|
|
1382
|
+
3. Begin implementation with Qdrant integration
|
|
1383
|
+
4. Establish benchmarks for measuring improvement
|
|
1384
|
+
|
|
1385
|
+
**Expected Impact:**
|
|
1386
|
+
- 3-5x improvement on complex tasks
|
|
1387
|
+
- 10x better context retention
|
|
1388
|
+
- Enable new use cases (research, multi-hop reasoning)
|
|
1389
|
+
- Support for 100+ agent deployments
|
|
1390
|
+
|
|
1391
|
+
This roadmap positions TMLPD at the forefront of 2025 multi-agent system capabilities.
|