mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-09-05 08:06:19 +00:00
docs: fix Python examples to use real APIs, remove fabricated imports
- E2B/Daytona: Python tabs now show mount pattern (not @supermemory/bash which is TypeScript-only) - E2B/Daytona: section intros updated to explain per-language approach - Daytona: removed redundant 'Alternative: Mount' section (Python tab already covers the mount pattern with TLS warning) - E2B/Daytona: Python install commands no longer list supermemory package
This commit is contained in:
parent
f955d9e6e7
commit
8b09866bb7
2 changed files with 68 additions and 89 deletions
|
|
@ -60,17 +60,17 @@ Daytona sandboxes run full Linux with shell access, filesystem, and network. The
|
|||
</Tab>
|
||||
<Tab title="Python">
|
||||
```bash
|
||||
pip install supermemory daytona-sdk
|
||||
pip install daytona-sdk
|
||||
```
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
## 3. Build an agent with memory + code execution
|
||||
|
||||
The recommended pattern: your agent code uses `@supermemory/bash` for memory and the Daytona SDK for code execution. The LLM gets both as tools.
|
||||
|
||||
<Tabs>
|
||||
<Tab title="TypeScript">
|
||||
The recommended TypeScript pattern: use `@supermemory/bash` for memory in your orchestrating code and the Daytona SDK for code execution. The LLM gets both as tools.
|
||||
|
||||
```typescript agent.ts
|
||||
import { createBash } from "@supermemory/bash";
|
||||
import { Daytona } from "@daytonaio/sdk";
|
||||
|
|
@ -123,18 +123,17 @@ The recommended pattern: your agent code uses `@supermemory/bash` for memory and
|
|||
```
|
||||
</Tab>
|
||||
<Tab title="Python">
|
||||
In Python, install and mount SMFS inside the Daytona sandbox. The agent reads and writes memory via standard shell commands.
|
||||
|
||||
<Warning>
|
||||
This requires unrestricted outbound HTTPS from the sandbox. If `smfs login` fails with a connection error, see the note at the top of this page.
|
||||
</Warning>
|
||||
|
||||
```python agent.py
|
||||
import os
|
||||
from supermemory import create_bash
|
||||
from daytona_sdk import Daytona, DaytonaConfig
|
||||
|
||||
# 1. Set up memory (SMFS bash tool — runs in your code, not the sandbox)
|
||||
bash = create_bash(
|
||||
api_key=os.environ["SUPERMEMORY_API_KEY"],
|
||||
container_tag="agent_memory",
|
||||
)
|
||||
|
||||
# 2. Set up code execution (Daytona sandbox)
|
||||
# 1. Set up code execution (Daytona sandbox)
|
||||
config = DaytonaConfig(
|
||||
api_key=os.environ["DAYTONA_API_KEY"],
|
||||
api_url="https://app.daytona.io/api",
|
||||
|
|
@ -142,73 +141,36 @@ The recommended pattern: your agent code uses `@supermemory/bash` for memory and
|
|||
daytona = Daytona(config)
|
||||
sandbox = daytona.create()
|
||||
|
||||
# 3. Read memory from your orchestrating code
|
||||
profile = bash.exec("cat /profile.md")
|
||||
print(profile.stdout)
|
||||
# 2. Install SMFS inside the sandbox
|
||||
sandbox.process.exec(
|
||||
"curl -fsSL https://smfs.ai/install | sh"
|
||||
)
|
||||
|
||||
# 4. Execute code in the sandbox
|
||||
response = sandbox.process.exec("python3 -c 'print(\"Hello from Daytona!\")'")
|
||||
# 3. Log in and mount
|
||||
sandbox.process.exec(
|
||||
f"~/.local/bin/smfs login --key {os.environ['SUPERMEMORY_API_KEY']}"
|
||||
)
|
||||
sandbox.process.exec(
|
||||
"~/.local/bin/smfs mount agent_memory --ephemeral"
|
||||
)
|
||||
|
||||
# 4. Read the auto-generated profile
|
||||
response = sandbox.process.exec("cat agent_memory/profile.md")
|
||||
print(response.result)
|
||||
|
||||
# 5. Semantic search across memory
|
||||
results = bash.exec("sgrep 'preferred language'")
|
||||
print(results.stdout)
|
||||
# 5. Semantic search
|
||||
response = sandbox.process.exec(
|
||||
"~/.local/bin/smfs grep 'preferred language'"
|
||||
)
|
||||
print(response.result)
|
||||
|
||||
# 6. Clean up
|
||||
sandbox.process.exec("~/.local/bin/smfs unmount agent_memory")
|
||||
daytona.delete(sandbox)
|
||||
```
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
## Alternative: Mount SMFS inside the sandbox
|
||||
|
||||
If your Daytona sandbox has unrestricted network access, you can install and mount SMFS directly inside it. This gives the agent a real filesystem it can navigate with standard Unix commands.
|
||||
|
||||
<Warning>
|
||||
Some Daytona datacenter IPs are blocked by upstream firewalls. If `smfs login` or `smfs mount` fails with a TLS connection error from inside the sandbox, switch to the **Bash Tool** pattern above — it runs in your orchestrating code where network access is unrestricted.
|
||||
</Warning>
|
||||
|
||||
```python
|
||||
from daytona_sdk import Daytona, DaytonaConfig
|
||||
import os
|
||||
|
||||
config = DaytonaConfig(
|
||||
api_key=os.environ["DAYTONA_API_KEY"],
|
||||
api_url="https://app.daytona.io/api",
|
||||
)
|
||||
daytona = Daytona(config)
|
||||
sandbox = daytona.create()
|
||||
|
||||
# Install SMFS
|
||||
sandbox.process.exec("curl -fsSL https://smfs.ai/install | sh")
|
||||
|
||||
# Log in
|
||||
sandbox.process.exec(
|
||||
f"~/.local/bin/smfs login --key {os.environ['SUPERMEMORY_API_KEY']}"
|
||||
)
|
||||
|
||||
# Mount with ephemeral mode (recommended for sandboxes)
|
||||
sandbox.process.exec(
|
||||
"~/.local/bin/smfs mount agent_memory --ephemeral --path /memory"
|
||||
)
|
||||
|
||||
# Now the agent can use standard Unix commands
|
||||
result = sandbox.process.exec("cat /memory/profile.md")
|
||||
print(result.result)
|
||||
|
||||
# Semantic grep works inside the mount
|
||||
result = sandbox.process.exec("cd /memory && grep 'standup'")
|
||||
print(result.result)
|
||||
|
||||
# Clean up
|
||||
sandbox.process.exec("~/.local/bin/smfs unmount agent_memory")
|
||||
daytona.delete(sandbox)
|
||||
```
|
||||
|
||||
<Note>
|
||||
Use `--ephemeral` when mounting inside sandboxes. It keeps the cache in memory only — nothing persists locally after unmount, but writes still push to Supermemory.
|
||||
</Note>
|
||||
|
||||
## Tips
|
||||
|
||||
- **Use `--ephemeral` for sandboxes.** Sandbox filesystems are temporary. Ephemeral mode avoids writing a local SQLite cache that will be thrown away.
|
||||
|
|
|
|||
|
|
@ -51,17 +51,17 @@ E2B sandboxes are ephemeral Linux microVMs with full shell access and unrestrict
|
|||
</Tab>
|
||||
<Tab title="Python">
|
||||
```bash
|
||||
pip install supermemory e2b-code-interpreter
|
||||
pip install e2b-code-interpreter
|
||||
```
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
## 3. Build an agent with memory + code execution
|
||||
|
||||
The recommended pattern: your agent code uses `@supermemory/bash` for memory and the E2B SDK for code execution. The LLM gets both as tools.
|
||||
|
||||
<Tabs>
|
||||
<Tab title="TypeScript">
|
||||
The recommended TypeScript pattern: use `@supermemory/bash` for memory in your orchestrating code and the E2B SDK for code execution. The LLM gets both as tools.
|
||||
|
||||
```typescript agent.ts
|
||||
import { createBash } from "@supermemory/bash";
|
||||
import { Sandbox } from "@e2b/code-interpreter";
|
||||
|
|
@ -110,33 +110,50 @@ The recommended pattern: your agent code uses `@supermemory/bash` for memory and
|
|||
```
|
||||
</Tab>
|
||||
<Tab title="Python">
|
||||
In Python, mount SMFS inside the E2B sandbox. The agent reads and writes memory via standard shell commands.
|
||||
|
||||
```python agent.py
|
||||
import os
|
||||
from supermemory import create_bash
|
||||
from e2b_code_interpreter import Sandbox
|
||||
|
||||
# 1. Set up memory (SMFS bash tool — runs in your code, not the sandbox)
|
||||
bash = create_bash(
|
||||
api_key=os.environ["SUPERMEMORY_API_KEY"],
|
||||
container_tag="agent_memory",
|
||||
)
|
||||
|
||||
# 2. Set up code execution (E2B sandbox)
|
||||
# 1. Create an E2B sandbox
|
||||
sandbox = Sandbox.create(timeout=300)
|
||||
|
||||
# 3. Read memory from your orchestrating code
|
||||
profile = bash.exec("cat /profile.md")
|
||||
print(profile.stdout)
|
||||
# 2. Fix FUSE permissions (required in E2B sandboxes)
|
||||
sandbox.commands.run("sudo chmod 666 /dev/fuse")
|
||||
sandbox.commands.run(
|
||||
"echo 'user_allow_other' | sudo tee -a /etc/fuse.conf > /dev/null"
|
||||
)
|
||||
|
||||
# 4. Execute code in the sandbox
|
||||
execution = sandbox.run_code("print('Hello from E2B!')")
|
||||
print(execution.text)
|
||||
# 3. Install SMFS and log in
|
||||
sandbox.commands.run("curl -fsSL https://smfs.ai/install | sh")
|
||||
sandbox.commands.run(
|
||||
f"~/.local/bin/smfs login --key {os.environ['SUPERMEMORY_API_KEY']}"
|
||||
)
|
||||
|
||||
# 5. Semantic search across memory
|
||||
results = bash.exec("sgrep 'preferred language'")
|
||||
print(results.stdout)
|
||||
# 4. Mount memory
|
||||
sandbox.commands.run(
|
||||
"bash -c '~/.local/bin/smfs mount agent_memory --ephemeral"
|
||||
" --path /home/user/memory --foreground > /tmp/smfs.log 2>&1"
|
||||
" & sleep 5 && echo MOUNTED'",
|
||||
timeout=15,
|
||||
)
|
||||
|
||||
# 6. Clean up
|
||||
# 5. Read the auto-generated profile
|
||||
result = sandbox.commands.run("cat /home/user/memory/profile.md")
|
||||
print(result.stdout)
|
||||
|
||||
# 6. Semantic search
|
||||
result = sandbox.commands.run(
|
||||
"~/.local/bin/smfs grep 'preferred language'"
|
||||
)
|
||||
print(result.stdout)
|
||||
|
||||
# 7. Clean up
|
||||
sandbox.commands.run(
|
||||
"~/.local/bin/smfs unmount agent_memory 2>/dev/null",
|
||||
timeout=10,
|
||||
)
|
||||
sandbox.kill()
|
||||
```
|
||||
</Tab>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue