-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnorthbridge
More file actions
executable file
·144 lines (131 loc) · 4.2 KB
/
Copy pathnorthbridge
File metadata and controls
executable file
·144 lines (131 loc) · 4.2 KB
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
#!/bin/bash
# ~/_/ai.sh - Parallel AI Cockpit w/ Neuro fractal recursion
export AI_BASE="$HOME/_"
export PATH="$AI_BASE/ai:$PATH"
MEM_DIR="$AI_BASE/memory"
DB_FILE="$MEM_DIR/crew.db"
mkdir -p "$MEM_DIR"
# Python3 memory bridge (qbit store/fetch)
MEMORY_BRIDGE=$(cat <<'PYTHON'
#!/usr/bin/env python3
import sqlite3, sys, json, hashlib, os, datetime
DB_FILE = os.path.expanduser(sys.argv[1])
action = sys.argv[2]
agent = sys.argv[3]
prompt = sys.argv[4] if len(sys.argv) > 4 else ""
qbit = sys.argv[5] if len(sys.argv) > 5 else "{}"
phash = hashlib.sha256(prompt.encode()).hexdigest()
conn = sqlite3.connect(DB_FILE)
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS qbits (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp TEXT NOT NULL,
agent TEXT NOT NULL,
prompt_hash TEXT NOT NULL,
qbit TEXT NOT NULL
)''')
if action=="store":
c.execute("INSERT INTO qbits (timestamp,agent,prompt_hash,qbit) VALUES (?,?,?,?)",
(datetime.datetime.utcnow().isoformat(),agent,phash,qbit))
elif action=="fetch":
c.execute("SELECT * FROM qbits WHERE agent=? AND prompt_hash=?", (agent,phash))
rows = c.fetchall()
print(json.dumps([{"id":r[0],"timestamp":r[1],"agent":r[2],"prompt_hash":r[3],"qbit":r[4]} for r in rows]))
conn.commit()
conn.close()
PYTHON
)
BRIDGE_FILE="$MEM_DIR/memory_bridge.py"
echo "$MEMORY_BRIDGE" > "$BRIDGE_FILE"
chmod +x "$BRIDGE_FILE"
# Agents and models
AGENTS=("core" "loop" "code" "coin" "2244" "neuro")
declare -A MODELS=(
[core]="core:latest"
[loop]="loop:latest"
[code]="code:latest"
[coin]="coin:latest"
[2244]="2244:latest"
[neuro]="gemma3:1b"
)
CREW_POOL="deepseek-coder:latest"
function log() {
local agent=$1; shift
echo "[$agent] $*"
}
function store_qbit() {
local agent=$1 prompt=$2 qbit=$3
python3 "$BRIDGE_FILE" "$DB_FILE" store "$agent" "$prompt" "$qbit" >/dev/null
}
function fetch_qbit() {
local agent=$1 prompt=$2
python3 "$BRIDGE_FILE" "$DB_FILE" fetch "$agent" "$prompt"
}
function stream_agent() {
local agent=$1 prompt=$2
local model=${MODELS[$agent]}
log "$agent" "🚀 Streaming..."
response=$(curl -s -N -X POST "http://localhost:11434/api/generate" \
-H 'Content-Type: application/json' \
-d "{\"model\":\"$model\",\"prompt\":\"$prompt\",\"stream\":true}")
qbit=$(echo "$response" | jq -s '{response:[.[].response]}')
store_qbit "$agent" "$prompt" "$qbit"
log "$agent" "✅ Done."
echo "$qbit"
}
function neuro_fractal() {
local prompt=$1 depth=${2:-2}
local agent="neuro"
local fractal_prompt="$prompt"
log "$agent" "🚀 Fractal recursion start (depth=$depth)..."
for ((i=0;i<depth;i++)); do
# Fetch previous outputs as context
local context=""
for a in "${AGENTS[@]}"; do
context+=$(fetch_qbit "$a" "$fractal_prompt")
done
fractal_prompt="$prompt\nFractal-Depth:$i\nContext:$context"
response=$(curl -s -N -X POST "http://localhost:11434/api/generate" \
-H 'Content-Type: application/json' \
-d "{\"model\":\"${MODELS[$agent]}\",\"prompt\":\"$fractal_prompt\",\"stream\":true}")
qbit=$(echo "$response" | jq -s '{response:[.[].response]}')
store_qbit "$agent" "$fractal_prompt" "$qbit"
log "$agent" "✅ Depth $i complete."
done
echo "$qbit"
}
function stream_crew_pool() {
local prompt=$1
local agent="Crew-AI"
log "$agent" "🚀 Start streaming..."
response=$(curl -s -N -X POST "http://localhost:11434/api/generate" \
-H 'Content-Type: application/json' \
-d "{\"model\":\"$CREW_POOL\",\"prompt\":\"$prompt\",\"stream\":true}")
qbit=$(echo "$response" | jq -s '{response:[.[].response]}')
store_qbit "$agent" "$prompt" "$qbit"
log "$agent" "✅ Done."
echo "$qbit"
}
function crew_send() {
local prompt=$1
log "Cockpit" "Sending prompt to all agents..."
# Parallel agent streams
for agent in "${AGENTS[@]}"; do
stream_agent "$agent" "$prompt" &
done
# Crew pool stream
stream_crew_pool "$prompt" &
wait
# Neuro fractal reasoning (pre-processing)
neuro_fractal "$prompt" 3
log "Cockpit" "All streams & Neuro reasoning completed."
}
# CLI interactive
if [[ -t 1 ]]; then
echo "-- 2244 AI Cockpit CLI --"
while true; do
read -p "Enter prompt> " PROMPT
[[ -z "$PROMPT" ]] && continue
crew_send "$PROMPT"
done
fi