Skip to content

docs: add agent loop example — durable sessions on Cloudflare Artifacts via exgit#46

Open
ivarvong wants to merge 1 commit into
mainfrom
examples/artifacts-agent-session
Open

docs: add agent loop example — durable sessions on Cloudflare Artifacts via exgit#46
ivarvong wants to merge 1 commit into
mainfrom
examples/artifacts-agent-session

Conversation

@ivarvong

@ivarvong ivarvong commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Adds examples/agent_artifacts_session.exs: durable, forkable agent memory — pure Elixir top to bottom. The sandbox is JustBash, the git client is exgit (clone, commit, push implemented in Elixir), and each session is one Cloudflare Artifacts repo. No git binary, no subprocess, no host filesystem, no credential in argv.

The session repo is cloned in memory and mounted into the sandbox at /work, so the agent's bash writes land directly in a git workspace. A checkpoint is Workspace.commit + Exgit.push — one commit per turn, labeled with the commands that ran. Kill the process, switch machines, come back later:

$ elixir examples/agent_artifacts_session.exs demo "create a csv with sample sales data at sales.csv"
$ elixir examples/agent_artifacts_session.exs demo "add a total_arr column (mrr*12) using awk"   # remembers everything

Memory is a plain git repo — commits pushed by exgit are cloned and audited with stock git, one commit per command:

$ git log --oneline
f5a8630 turn 1: cd /work && awk -F',' 'BEGIN{OFS=","} NR==1{print $0,"total_arr"; next} ...' sales.csv
845b4a0 turn 1: mkdir -p /work && cat > /work/sales.csv << 'EOF' sale_id,customer_name,company,plan,...

State flows both ways (push files with a write-scoped token; the agent sees them on resume), and sessions fork like repos do:

$ elixir examples/agent_artifacts_session.exs demo --fork demo-experiment
$ elixir examples/agent_artifacts_session.exs demo-experiment "try the risky transformation here"

Robustness: sandbox output is scrubbed to valid UTF-8 (arbitrary bytes and truncation cannot corrupt the transcript), the durable transcript is complete while the model sees a recent window cut at prompt boundaries, and a rejected push (concurrent run of one session) fails with a clear error instead of merging.

Depends on two fixes now in flight: ivarvong/exgit#9 (Workspace.write over an unborn ref, for the first checkpoint of a fresh repo) and #48 (mkdir/rm report backend errors instead of crashing — git trees cannot hold empty directories, and agents love mkdir -p). The example installs both libraries from GitHub main, so it runs once those merge.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FpxHS5iGm9ktgpnL9QZu9x

@ivarvong
ivarvong force-pushed the examples/artifacts-agent-session branch from 54d7aba to fa0b265 Compare July 2, 2026 20:03
…ts via exgit

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FpxHS5iGm9ktgpnL9QZu9x
@ivarvong
ivarvong force-pushed the examples/artifacts-agent-session branch from f89905b to b4a4a1a Compare July 2, 2026 21:17
@ivarvong ivarvong changed the title docs: add agent loop example with session state in Cloudflare Artifacts docs: add agent loop example — durable sessions on Cloudflare Artifacts via exgit Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant