-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·353 lines (327 loc) · 10.5 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·353 lines (327 loc) · 10.5 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
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
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'EOF'
Usage:
./setup.sh --base-url URL --api-key KEY --model MODEL [options]
Required:
--base-url URL OpenAI-compatible base URL, e.g. https://ollama.com/v1
--api-key KEY Provider API key
--model MODEL Chat model, e.g. deepseek-v4-flash
Options:
--domain DOMAIN Configure Caddy for DOMAIN
--secret SECRET AgentMemory bearer secret. Default: auto-generate with --domain
--install-dir DIR Default: /opt/agentmemory
--data-dir DIR AgentMemory home path. Default: INSTALL_DIR/agentmemory-home
--iii-data-dir DIR Rust iii-engine state path. Default: INSTALL_DIR/iii-data
--project-name NAME Default: agentmemory
--image IMAGE Default: ghcr.io/randomcodespace/agentmemory-setup-public:latest
--agentmemory-version VERSION Default: 0.9.27
--iii-version VERSION Default: 0.11.2
--build-local Build local image instead of pulling --image
--embedding-provider NAME Default: local
--memory LIMIT Default: 3g
--cpus N Default: 2.5
--rest-port PORT Default: 3111
--stream-port PORT Default: 3112
--viewer-port PORT Default: 3113
--viewer-proxy-port PORT Default: viewer-port + 10000
--no-caddy Skip Caddy config
--no-start Write files only
EOF
}
BASE_URL=""
API_KEY=""
MODEL=""
DOMAIN=""
AGENTMEMORY_SECRET=""
INSTALL_DIR="/opt/agentmemory"
DATA_DIR=""
III_DATA_DIR=""
PROJECT_NAME="agentmemory"
AGENTMEMORY_VERSION="0.9.27"
III_VERSION="0.11.2"
IMAGE="ghcr.io/randomcodespace/agentmemory-setup-public:latest"
EMBEDDING_PROVIDER="local"
BUILD_LOCAL="0"
MEMORY="3g"
CPUS="2.5"
REST_PORT="3111"
STREAM_PORT="3112"
VIEWER_PORT="3113"
VIEWER_PROXY_PORT=""
CONFIGURE_CADDY="auto"
START_STACK="1"
while [ "$#" -gt 0 ]; do
case "$1" in
--base-url) BASE_URL="${2:?}"; shift 2 ;;
--api-key) API_KEY="${2:?}"; shift 2 ;;
--model) MODEL="${2:?}"; shift 2 ;;
--domain) DOMAIN="${2:?}"; shift 2 ;;
--secret) AGENTMEMORY_SECRET="${2:?}"; shift 2 ;;
--install-dir) INSTALL_DIR="${2:?}"; shift 2 ;;
--data-dir) DATA_DIR="${2:?}"; shift 2 ;;
--iii-data-dir) III_DATA_DIR="${2:?}"; shift 2 ;;
--project-name) PROJECT_NAME="${2:?}"; shift 2 ;;
--image) IMAGE="${2:?}"; shift 2 ;;
--agentmemory-version) AGENTMEMORY_VERSION="${2:?}"; IMAGE="local/agentmemory:${2:?}"; BUILD_LOCAL="1"; shift 2 ;;
--iii-version) III_VERSION="${2:?}"; shift 2 ;;
--build-local) BUILD_LOCAL="1"; IMAGE="local/agentmemory:$AGENTMEMORY_VERSION"; shift ;;
--embedding-provider) EMBEDDING_PROVIDER="${2:?}"; shift 2 ;;
--memory) MEMORY="${2:?}"; shift 2 ;;
--cpus) CPUS="${2:?}"; shift 2 ;;
--rest-port) REST_PORT="${2:?}"; shift 2 ;;
--stream-port) STREAM_PORT="${2:?}"; shift 2 ;;
--viewer-port) VIEWER_PORT="${2:?}"; shift 2 ;;
--viewer-proxy-port) VIEWER_PROXY_PORT="${2:?}"; shift 2 ;;
--no-caddy) CONFIGURE_CADDY="0"; shift ;;
--no-start) START_STACK="0"; shift ;;
-h|--help) usage; exit 0 ;;
*) echo "Unknown option: $1" >&2; usage; exit 2 ;;
esac
done
[ -n "$BASE_URL" ] || { usage >&2; exit 2; }
[ -n "$API_KEY" ] || { usage >&2; exit 2; }
[ -n "$MODEL" ] || { usage >&2; exit 2; }
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DATA_DIR="${DATA_DIR:-$INSTALL_DIR/agentmemory-home}"
III_DATA_DIR="${III_DATA_DIR:-$INSTALL_DIR/iii-data}"
VIEWER_PROXY_PORT="${VIEWER_PROXY_PORT:-$((VIEWER_PORT + 10000))}"
RUN_UID="$(id -u)"
RUN_GID="$(id -g)"
if [ -z "$AGENTMEMORY_SECRET" ] && [ -n "$DOMAIN" ]; then
AGENTMEMORY_SECRET="$(openssl rand -base64 32 | tr -d '\n')"
fi
mkdir_owned() {
if ! mkdir -p "$1" 2>/dev/null; then
sudo mkdir -p "$1"
fi
if [ "$(stat -c '%u:%g' "$1")" != "$RUN_UID:$RUN_GID" ]; then
sudo chown -R "$RUN_UID:$RUN_GID" "$1"
fi
}
json_escape() {
python3 -c 'import json,sys; print(json.dumps(sys.stdin.read().rstrip("\n"))[1:-1])'
}
mkdir_owned "$INSTALL_DIR"
mkdir_owned "$DATA_DIR/.agentmemory"
mkdir_owned "$III_DATA_DIR"
install -m 0644 "$SCRIPT_DIR/Dockerfile" "$INSTALL_DIR/Dockerfile"
umask 077
cat > "$INSTALL_DIR/.env" <<EOF
AGENTMEMORY_VERSION=$AGENTMEMORY_VERSION
AGENTMEMORY_III_VERSION=$III_VERSION
OPENAI_API_KEY=$API_KEY
AGENTMEMORY_SECRET=$AGENTMEMORY_SECRET
EOF
cat > "$DATA_DIR/.agentmemory/.env" <<EOF
OPENAI_API_KEY=$API_KEY
AGENTMEMORY_SECRET=$AGENTMEMORY_SECRET
OPENAI_BASE_URL=$BASE_URL
OPENAI_MODEL=$MODEL
OPENAI_REASONING_EFFORT=none
EMBEDDING_PROVIDER=$EMBEDDING_PROVIDER
AGENTMEMORY_AUTO_COMPRESS=true
AGENTMEMORY_SUPPRESS_COST_WARNING=1
AGENTMEMORY_URL=http://127.0.0.1:$REST_PORT
AGENTMEMORY_VIEWER_URL=${DOMAIN:+https://$DOMAIN}
III_ENGINE_URL=ws://127.0.0.1:49134
III_REST_PORT=$REST_PORT
III_STREAMS_PORT=$STREAM_PORT
III_VIEWER_PORT=$VIEWER_PORT
EOF
cat > "$DATA_DIR/.agentmemory/preferences.json" <<EOF
{
"schemaVersion": 1,
"lastAgent": null,
"lastAgents": [],
"lastProvider": "openai",
"skipSplash": true,
"skipNpxHint": true,
"skipGlobalInstall": true,
"skipConsoleInstall": true,
"firstRunAt": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)"
}
EOF
cat > "$INSTALL_DIR/iii-config.docker.yaml" <<EOF
workers:
- name: iii-http
config:
port: $REST_PORT
host: 0.0.0.0
default_timeout: 180000
cors:
allowed_origins: ["http://localhost:$REST_PORT", "http://localhost:$VIEWER_PORT", "http://127.0.0.1:$REST_PORT", "http://127.0.0.1:$VIEWER_PORT"]
allowed_methods: [GET, POST, PUT, DELETE, OPTIONS]
- name: iii-state
config:
adapter:
name: kv
config:
store_method: file_based
file_path: /data/iii/state_store.db
- name: iii-queue
config:
adapter:
name: builtin
- name: iii-pubsub
config:
adapter:
name: local
- name: iii-cron
config:
adapter:
name: kv
- name: iii-stream
config:
port: $STREAM_PORT
host: 0.0.0.0
adapter:
name: kv
config:
store_method: file_based
file_path: /data/iii/stream_store
- name: iii-observability
config:
enabled: true
service_name: agentmemory
exporter: memory
sampling_ratio: 0.1
metrics_enabled: true
logs_enabled: true
logs_console_output: false
- name: iii-exec
config:
watch:
- src/**/*.ts
exec:
- node dist/index.mjs
EOF
BUILD_BLOCK=""
if [ "$BUILD_LOCAL" = "1" ]; then
BUILD_BLOCK=" build:
context: .
args:
AGENTMEMORY_VERSION: $AGENTMEMORY_VERSION
III_VERSION: $III_VERSION"
fi
cat > "$INSTALL_DIR/docker-compose.yml" <<EOF
name: $PROJECT_NAME
services:
agentmemory:
$BUILD_BLOCK
image: $IMAGE
user: "$RUN_UID:$RUN_GID"
ports:
- "127.0.0.1:$REST_PORT:$REST_PORT"
- "127.0.0.1:$STREAM_PORT:$STREAM_PORT"
- "127.0.0.1:$VIEWER_PORT:$VIEWER_PROXY_PORT"
env_file:
- ./.env
environment:
HOME: /data/home
III_CONFIG_PATH: /app/config.yaml
III_ENGINE_URL: ws://127.0.0.1:49134
III_REST_PORT: "$REST_PORT"
III_STREAMS_PORT: "$STREAM_PORT"
III_VIEWER_PORT: "$VIEWER_PORT"
VIEWER_PROXY_PORT: "$VIEWER_PROXY_PORT"
AGENTMEMORY_URL: http://127.0.0.1:$REST_PORT
AGENTMEMORY_VIEWER_URL: ${DOMAIN:+https://$DOMAIN}
EMBEDDING_PROVIDER: $EMBEDDING_PROVIDER
OPENAI_BASE_URL: $BASE_URL
OPENAI_MODEL: $MODEL
OPENAI_REASONING_EFFORT: none
AGENTMEMORY_AUTO_COMPRESS: "true"
AGENTMEMORY_SUPPRESS_COST_WARNING: "1"
AGENTMEMORY_SECRET: "$AGENTMEMORY_SECRET"
volumes:
- "$DATA_DIR:/data/home"
- "$III_DATA_DIR:/data/iii"
- ./iii-config.docker.yaml:/app/config.yaml:ro
restart: unless-stopped
mem_limit: $MEMORY
cpus: "$CPUS"
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
EOF
chmod 600 "$INSTALL_DIR/.env" "$DATA_DIR/.agentmemory/.env"
chmod 644 "$INSTALL_DIR/Dockerfile" "$INSTALL_DIR/docker-compose.yml" "$INSTALL_DIR/iii-config.docker.yaml" "$DATA_DIR/.agentmemory/preferences.json"
if [ -n "$DOMAIN" ]; then
cat > "$INSTALL_DIR/credentials.json" <<EOF
{
"domain": "https://$(printf '%s' "$DOMAIN" | json_escape)",
"web_ui": "https://$(printf '%s' "$DOMAIN" | json_escape)",
"mcp_url": "https://$(printf '%s' "$DOMAIN" | json_escape)",
"agentmemory_secret": "$(printf '%s' "$AGENTMEMORY_SECRET" | json_escape)",
"credential_path": "$INSTALL_DIR/credentials.json"
}
EOF
chmod 600 "$INSTALL_DIR/credentials.json"
fi
if [ "$CONFIGURE_CADDY" != "0" ] && [ -n "$DOMAIN" ]; then
if ! command -v caddy >/dev/null 2>&1; then
echo "Caddy not found; skipped Caddy config." >&2
else
TMP_SITE="$(mktemp)"
cat > "$TMP_SITE" <<EOF
$DOMAIN {
encode zstd gzip
@agentmemory_api path /agentmemory/*
reverse_proxy @agentmemory_api 127.0.0.1:$REST_PORT {
header_up Host 127.0.0.1:$REST_PORT
flush_interval -1
transport http {
read_timeout 24h
response_header_timeout 30s
}
}
@agentmemory_stream path /stream/*
route @agentmemory_stream {
rewrite * /
reverse_proxy 127.0.0.1:$STREAM_PORT {
header_up Host 127.0.0.1:$STREAM_PORT
flush_interval -1
transport http {
read_timeout 24h
response_header_timeout 30s
}
}
}
reverse_proxy 127.0.0.1:$VIEWER_PORT {
header_up Host 127.0.0.1:$VIEWER_PORT
flush_interval -1
transport http {
read_timeout 24h
response_header_timeout 30s
}
}
}
EOF
sudo install -m 0644 -o root -g root "$TMP_SITE" /etc/caddy/agentmemory.caddy
rm -f "$TMP_SITE"
if ! grep -q '^import /etc/caddy/agentmemory.caddy$' /etc/caddy/Caddyfile; then
sudo cp /etc/caddy/Caddyfile "/etc/caddy/Caddyfile.backup-agentmemory-$(date -u +%Y%m%dT%H%M%SZ)"
printf '\nimport /etc/caddy/agentmemory.caddy\n' | sudo tee -a /etc/caddy/Caddyfile >/dev/null
fi
sudo caddy validate --config /etc/caddy/Caddyfile >/dev/null
sudo systemctl reload caddy
fi
fi
if [ "$START_STACK" = "1" ]; then
if [ "$BUILD_LOCAL" = "1" ]; then
docker compose -f "$INSTALL_DIR/docker-compose.yml" up -d --build
else
docker compose -f "$INSTALL_DIR/docker-compose.yml" pull agentmemory
docker compose -f "$INSTALL_DIR/docker-compose.yml" up -d --no-build
fi
fi
echo "Install dir: $INSTALL_DIR"
echo "AgentMemory data dir: $DATA_DIR"
echo "Rust iii-engine data dir: $III_DATA_DIR"
echo "Compose: docker compose -f $INSTALL_DIR/docker-compose.yml ps"
[ -z "$DOMAIN" ] || echo "URL: https://$DOMAIN"
[ -z "$DOMAIN" ] || echo "MCP: AGENTMEMORY_URL=https://$DOMAIN AGENTMEMORY_SECRET=<see $INSTALL_DIR/credentials.json> npx -y @agentmemory/mcp"