prashantmatlani commited on
Commit
293aeff
·
1 Parent(s): 8c87437

ux change, prompt fix, readme02.md, .yaml, .toml

Browse files
Files changed (4) hide show
  1. README01.md +391 -0
  2. api_server.py +0 -2
  3. config.toml +35 -0
  4. config.yaml +48 -0
README01.md ADDED
@@ -0,0 +1,391 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # CGJI01 — Multi-Agent Jungian Intelligence System
3
+
4
+ CGJI01 is an interactive multi-agent psychological reasoning system designed to simulate deep, multi-perspective inquiry rooted in analytical psychology and related disciplines.
5
+
6
+ At its core, the system begins with a Jungian analytical framework and expands into a network of specialized agents (Dream, Shadow, Myth, Epistemic, Buddhist Psychology, etc.), enabling layered interpretation and synthesis of human inquiry.
7
+
8
+ ---
9
+
10
+ ## 🧠 SYSTEM OVERVIEW
11
+
12
+ ### Flow of Interaction
13
+
14
+ 1. User initiates conversation ("Fire")
15
+ 2. Input is routed to **Agent Jung (default entry point)**
16
+ 3. Jung Agent:
17
+ - Interprets query
18
+ - Retrieves internal knowledge (RAG)
19
+ - Optionally performs web search
20
+ - Produces structured response
21
+ 4. System continues in **Jung follow-up loop**
22
+ 5. User may:
23
+ - Continue dialogue (Fuel)
24
+ - Select another agent (via dynamic choice system — upcoming)
25
+ 6. Selected agent takes control (agent switching)
26
+ 7. Multi-agent perspectives accumulate
27
+ 8. Final synthesis (planned via Synthesizer Agent)
28
+
29
+ ---
30
+
31
+ ## 🧩 ARCHITECTURE
32
+
33
+ ### Backend (FastAPI)
34
+
35
+ api_server.py
36
+
37
+ conversation_engine.py
38
+
39
+ agent (jung_agent.py)
40
+
41
+ LLM (Groq / LLaMA 3.1)
42
+
43
+ ---
44
+
45
+ ### Core Components
46
+
47
+ #### 1. Conversation State (`conversation_manager.py`)
48
+
49
+ Maintains:
50
+
51
+ - Global history
52
+ - Per-agent histories
53
+ - Current active agent
54
+ - Stage tracking
55
+ - Initial query (anchor for agent switching)
56
+
57
+ ```python
58
+ state = {
59
+ history: [],
60
+ agent_histories: {},
61
+ current_agent: "jung",
62
+ initial_query: "...",
63
+ stage: "jung"
64
+ }
65
+
66
+ 2. Conversation Engine (conversation_engine.py)
67
+
68
+ Central router controlling flow.
69
+
70
+ Responsibilities:
71
+
72
+ Handles session lifecycle
73
+ Injects web-search context
74
+ Locks active agent
75
+ Routes to correct agent
76
+ Stores memory
77
+ Returns structured response to UI
78
+
79
+ 3. Agent Layer
80
+
81
+ Each agent is modular:
82
+
83
+ agents/
84
+ jung_agent.py
85
+ dream_agent.py
86
+ shadow_agent.py
87
+ ...
88
+
89
+ 🧠 AGENT JUNG — CORE DESIGN
90
+
91
+ Agent Jung is the primary intelligence layer and philosophical anchor of the system.
92
+
93
+ 🎯 Objective
94
+
95
+ To simulate a Jungian analytical psychologist that:
96
+
97
+ Interprets user input symbolically
98
+ Encourages introspection
99
+ Guides toward individuation
100
+ Avoids shallow informational responses
101
+ Maintains psychological depth
102
+ ⚙️ Functional Pipeline
103
+ 1. Input Extraction
104
+ user_input = state.history[-1]["content"]
105
+ 2. Web Search (Conditional)
106
+
107
+ Triggered via heuristic:
108
+
109
+ should_use_web(query)
110
+
111
+ Adds:
112
+
113
+ state.web_context
114
+ 3. RAG (Retrieval-Augmented Generation)
115
+
116
+ From:
117
+
118
+ /rag/jung/jung.index
119
+ /rag/jung/jung_texts.txt
120
+
121
+ Using:
122
+
123
+ FAISS
124
+ sentence-transformers (MiniLM)
125
+ retrieve(query, k=3)
126
+ 4. Context Constructio# CGJI01 — Multi-Agent Jungian Intelligence System
127
+
128
+ CGJI01 is an interactive multi-agent psychological reasoning system designed to simulate deep, multi-perspective inquiry rooted in analytical psychology and related disciplines.
129
+
130
+ At its core, the system begins with a Jungian analytical framework and expands into a network of specialized agents (Dream, Shadow, Myth, Epistemic, Buddhist Psychology, etc.), enabling layered interpretation and synthesis of human inquiry.
131
+
132
+ ---
133
+
134
+ ## 🧠 SYSTEM OVERVIEW
135
+
136
+ ### Flow of Interaction
137
+
138
+ 1. User initiates conversation ("Fire")
139
+ 2. Input is routed to **Agent Jung (default entry point)**
140
+ 3. Jung Agent:
141
+ - Interprets query
142
+ - Retrieves internal knowledge (RAG)
143
+ - Optionally performs web search
144
+ - Produces structured response
145
+ 4. System continues in **Jung follow-up loop**
146
+ 5. User may:
147
+ - Continue dialogue (Fuel)
148
+ - Select another agent (via dynamic choice system — upcoming)
149
+ 6. Selected agent takes control (agent switching)
150
+ 7. Multi-agent perspectives accumulate
151
+ 8. Final synthesis (planned via Synthesizer Agent)
152
+
153
+ ---
154
+
155
+ ## 🧩 ARCHITECTURE
156
+
157
+ ### Backend (FastAPI)
158
+
159
+ api_server.py
160
+
161
+ conversation_engine.py
162
+
163
+ agent (jung_agent.py)
164
+
165
+ LLM (Groq / LLaMA 3.1)
166
+
167
+ ---
168
+
169
+ ### Core Components
170
+
171
+ #### 1. Conversation State (`conversation_manager.py`)
172
+
173
+ Maintains:
174
+
175
+ - Global history
176
+ - Per-agent histories
177
+ - Current active agent
178
+ - Stage tracking
179
+ - Initial query (anchor for agent switching)
180
+
181
+ ```python
182
+ state = {
183
+ history: [],
184
+ agent_histories: {},
185
+ current_agent: "jung",
186
+ initial_query: "...",
187
+ stage: "jung"
188
+ }
189
+ 2. Conversation Engine (conversation_engine.py)
190
+
191
+ Central router controlling flow.
192
+
193
+ Responsibilities:
194
+
195
+ Handles session lifecycle
196
+ Injects web-search context
197
+ Locks active agent
198
+ Routes to correct agent
199
+ Stores memory
200
+ Returns structured response to UI
201
+ 3. Agent Layer
202
+
203
+ Each agent is modular:
204
+
205
+ agents/
206
+ jung_agent.py
207
+ dream_agent.py
208
+ shadow_agent.py
209
+ ...
210
+
211
+ 🧠 AGENT JUNG — CORE DESIGN
212
+
213
+ Agent Jung is the primary intelligence layer and philosophical anchor of the system.
214
+
215
+ 🎯 Objective
216
+
217
+ To simulate a Jungian analytical psychologist that:
218
+
219
+ Interprets user input symbolically
220
+ Encourages introspection
221
+ Guides toward individuation
222
+ Avoids shallow informational responses
223
+ Maintains psychological depth
224
+ ⚙️ Functional Pipeline
225
+ 1. Input Extraction
226
+ user_input = state.history[-1]["content"]
227
+ 2. Web Search (Conditional)
228
+
229
+ Triggered via heuristic:
230
+
231
+ should_use_web(query)
232
+
233
+ Adds:
234
+
235
+ state.web_context
236
+ 3. RAG (Retrieval-Augmented Generation)
237
+
238
+ From:
239
+
240
+ /rag/jung/jung.index
241
+ /rag/jung/jung_texts.txt
242
+
243
+ Using:
244
+
245
+ FAISS
246
+ sentence-transformers (MiniLM)
247
+ retrieve(query, k=3)
248
+
249
+ Via:
250
+
251
+ context_builder.py
252
+
253
+ Combines:
254
+
255
+ Jungian knowledge (RAG)
256
+ Real-world context (web search)
257
+
258
+ 5. LLM Prompt Injection
259
+
260
+ Final prompt includes:
261
+
262
+ User query
263
+ Retrieved Jungian concepts
264
+ Optional real-world knowledge
265
+ Instructional tone constraints
266
+
267
+ 6. Output Format
268
+ {
269
+ "type": "question",
270
+ "agent": "jung",
271
+ "content": "...",
272
+ "next_stage": "jung_followup"
273
+ }
274
+
275
+ 🧠 Behavioral Characteristics
276
+
277
+ Agent Jung is designed to:
278
+
279
+ Ask reflective questions
280
+ Avoid premature conclusions
281
+ Link ideas to Jungian constructs:
282
+ Persona
283
+ Shadow
284
+ Anima/Animus
285
+ Individuation
286
+ Self
287
+ Integrate cross-disciplinary references:
288
+ Buddhism
289
+ Mythology
290
+ Philosophy
291
+
292
+ ⚠️ Known Issues (Current)
293
+
294
+ Overuse of greeting phrases
295
+ Occasional verbosity
296
+ Weak grounding when RAG is sparse
297
+ Redundant memory entries (fixed in latest patch)
298
+ Web search not yet deeply integrated into reasoning
299
+
300
+ 🌐 WEB SEARCH TOOL
301
+
302
+ Located at:
303
+
304
+ ./core/tools/web_search.py
305
+ Uses Tavily API
306
+ Triggered conditionally
307
+ Injected into prompt as auxiliary context
308
+ Logs usage in backend
309
+
310
+ 📚 RAG SYSTEM
311
+
312
+ Structure
313
+ kb/jung/ → raw text files
314
+ rag/jung/
315
+ jung.index
316
+ jung_texts.txt
317
+ Build Process
318
+ python build_index.py
319
+
320
+ 💻 FRONTEND (Vanilla JS)
321
+
322
+ Interaction Model
323
+ Fire → starts conversation
324
+ Fuel → continues conversation
325
+ Dynamic agent responses
326
+ Per-agent memory panels
327
+ UI Components
328
+ Chat window
329
+ Input box (dynamic placeholder)
330
+ Agent panels (Jung, Dream, etc.)
331
+ Choice buttons (planned)
332
+ End session control
333
+
334
+ 🔁 AGENT MEMORY SYSTEM
335
+
336
+ Maintains:
337
+
338
+ window.agentMemory = {
339
+ jung: [...],
340
+ dream: [...]
341
+ }
342
+
343
+ Synced from backend:
344
+
345
+ agent_log: {
346
+ agent: "jung",
347
+ history: [...]
348
+ }
349
+
350
+ 🔮 FUTURE ROADMAP
351
+
352
+ Immediate
353
+ Remove repetitive greetings (prompt refinement)
354
+ Stabilize RAG grounding
355
+ Clean agent switching UX
356
+
357
+ Mid-Term
358
+ Multi-agent orchestration
359
+ Synthesizer agent
360
+ Better tool-use reasoning
361
+
362
+ Advanced
363
+ Fine-tuning (LoRA) on Jungian corpus
364
+ Personality stabilization
365
+ Long-term memory
366
+
367
+ 🧪 DEVELOPMENT NOTES
368
+
369
+ Built for iterative experimentation
370
+ Modular agent design allows scaling
371
+ RAG per-agent enables specialization
372
+ Web + RAG hybrid = hybrid cognition model
373
+
374
+ 🧭 PHILOSOPHY
375
+
376
+ CGJI01 is an attempt to model:
377
+
378
+ "Dialogue as a path to psychological transformation"
379
+
380
+ Inspired by:
381
+
382
+ Jungian analytical psychology
383
+ Symbolic reasoning
384
+ Multi-perspective cognition
385
+
386
+ ⚙️ SETUP
387
+ pip install -r requirements.txt
388
+
389
+ Run:
390
+
391
+ uvicorn api_server:app --reload
api_server.py CHANGED
@@ -22,10 +22,8 @@ app = FastAPI()
22
  # THEN MOUNT STATIC
23
  app.mount("/static", StaticFiles(directory="web"), name="static")
24
 
25
-
26
  # sessions = {}
27
 
28
-
29
  # ---- CORS FIX ----
30
  app.add_middleware(
31
  CORSMiddleware,
 
22
  # THEN MOUNT STATIC
23
  app.mount("/static", StaticFiles(directory="web"), name="static")
24
 
 
25
  # sessions = {}
26
 
 
27
  # ---- CORS FIX ----
28
  app.add_middleware(
29
  CORSMiddleware,
config.toml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [app]
2
+ name = "CGJI01"
3
+ mode = "development"
4
+
5
+ [server]
6
+ host = "0.0.0.0"
7
+ port = 8000
8
+
9
+ [agents]
10
+ default = "jung"
11
+ available = ["jung", "dream", "shadow", "myth", "epistemic", "bpsy", "jred"]
12
+
13
+ [rag]
14
+ enabled = true
15
+ base_path = "rag/"
16
+ top_k = 3
17
+
18
+ [web_search]
19
+ enabled = true
20
+ provider = "tavily"
21
+ max_results = 3
22
+
23
+ [llm]
24
+ provider = "groq"
25
+ model = "llama-3.1-8b-instant"
26
+ temperature = 0.7
27
+
28
+ [memory]
29
+ per_agent = true
30
+ store_history = true
31
+
32
+ [ui]
33
+ mode = "interactive"
34
+ conversation_start_label = "Fire"
35
+ conversation_continue_label = "Fuel"
config.yaml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ---
3
+
4
+ # ⚙️ `config.yaml`
5
+
6
+ ```yaml
7
+ app:
8
+ name: CGJI01
9
+ mode: development
10
+
11
+ server:
12
+ host: 0.0.0.0
13
+ port: 8000
14
+
15
+ agents:
16
+ default: jung
17
+ available:
18
+ - jung
19
+ - dream
20
+ - shadow
21
+ - myth
22
+ - epistemic
23
+ - bpsy
24
+ - jred
25
+
26
+ rag:
27
+ enabled: true
28
+ base_path: rag/
29
+ top_k: 3
30
+
31
+ web_search:
32
+ enabled: true
33
+ provider: tavily
34
+ max_results: 3
35
+
36
+ llm:
37
+ provider: groq
38
+ model: llama-3.1-8b-instant
39
+ temperature: 0.7
40
+
41
+ memory:
42
+ per_agent: true
43
+ store_history: true
44
+
45
+ ui:
46
+ mode: interactive
47
+ conversation_start_label: Fire
48
+ conversation_continue_label: Fuel