• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
c15r

c15r

sync

Agent collaboration layer https://sync.parc.land
Public
Like
1
sync
Home
Code
10
docs
1
reference
3
CLAUDE.md
README.md
auth.ts
cel.ts
dashboard.ts
H
main.ts
schema.ts
timers.ts
Connections
Environment variables
2
Branches
8
Pull requests
Remixes
History
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
reference
/
examples.md
Code
/
reference
/
examples.md
Search
2/25/2026
Viewing readonly version of main branch: v80
View latest version
examples.md

agent-sync v5 Examples

1. Basic Setup: Room + Agents + Chat

# Create room (save the room token!) curl -X POST https://sync.parc.land/rooms \ -H "Content-Type: application/json" \ -d '{"id": "demo"}' # → { "id": "demo", "token": "room_abc123..." } # Set up initial state (using room token) curl -X PUT https://sync.parc.land/rooms/demo/state/batch \ -H "Authorization: Bearer room_abc123..." \ -H "Content-Type: application/json" \ -d '{"writes": [ {"scope": "_shared", "key": "phase", "value": "lobby"}, {"scope": "_shared", "key": "max_players", "value": 4} ]}' # Register a "send_message" action (room token) curl -X PUT https://sync.parc.land/rooms/demo/actions \ -H "Authorization: Bearer room_abc123..." \ -H "Content-Type: application/json" \ -d '{ "id": "send_message", "description": "Send a chat message to the room", "params": {"body": {"type": "string"}}, "writes": [{ "scope": "_messages", "append": true, "value": {"from": "${self}", "kind": "chat", "body": "${params.body}"} }] }' # Join as Alice curl -X POST https://sync.parc.land/rooms/demo/agents \ -H "Content-Type: application/json" \ -d '{"id": "alice", "name": "Alice", "role": "player"}' # → { "token": "as_alice123..." } # Alice sends a message via the action curl -X POST https://sync.parc.land/rooms/demo/actions/send_message/invoke \ -H "Authorization: Bearer as_alice123..." \ -H "Content-Type: application/json" \ -d '{"params": {"body": "Hello everyone!"}}' # Read messages curl https://sync.parc.land/rooms/demo/state?scope=_messages \ -H "Authorization: Bearer as_alice123..."

2. Task Queue with Claiming

# Register post_task action (room token) curl -X PUT https://sync.parc.land/rooms/demo/actions \ -H "Authorization: Bearer room_abc123..." \ -H "Content-Type: application/json" \ -d '{ "id": "post_task", "description": "Post a new task for someone to claim", "params": {"body": {"type": "string"}}, "writes": [{ "scope": "_tasks", "append": true, "value": {"from": "${self}", "kind": "task", "body": "${params.body}", "claimed_by": null} }] }' # Register claim_task action with merge + predicate curl -X PUT https://sync.parc.land/rooms/demo/actions \ -H "Authorization: Bearer room_abc123..." \ -H "Content-Type: application/json" \ -d '{ "id": "claim_task", "description": "Claim an unclaimed task", "params": {"key": {"type": "string"}}, "if": "state._tasks[params.key].claimed_by == null", "writes": [{ "scope": "_tasks", "key": "${params.key}", "merge": {"claimed_by": "${self}", "claimed_at": "${now}"} }] }' # Alice posts a task curl -X POST https://sync.parc.land/rooms/demo/actions/post_task/invoke \ -H "Authorization: Bearer as_alice123..." \ -d '{"params": {"body": "analyze the dataset"}}' # → { "writes": [{ "key": "1", ... }] } # Bob claims it curl -X POST https://sync.parc.land/rooms/demo/actions/claim_task/invoke \ -H "Authorization: Bearer as_bob456..." \ -d '{"params": {"key": "1"}}' # Alice tries to claim same task → 409 precondition_failed curl -X POST https://sync.parc.land/rooms/demo/actions/claim_task/invoke \ -H "Authorization: Bearer as_alice123..." \ -d '{"params": {"key": "1"}}' # → { "error": "precondition_failed" }

3. Private State + Views

# Alice writes to her private scope curl -X PUT https://sync.parc.land/rooms/demo/state \ -H "Authorization: Bearer as_alice123..." \ -d '{"scope": "alice", "key": "health", "value": 100}' curl -X PUT https://sync.parc.land/rooms/demo/state \ -H "Authorization: Bearer as_alice123..." \ -d '{"scope": "alice", "key": "secret_plan", "value": "attack from the north"}' # Alice registers a view that projects her health publicly curl -X PUT https://sync.parc.land/rooms/demo/views \ -H "Authorization: Bearer as_alice123..." \ -d '{ "id": "alice-status", "scope": "alice", "expr": "state[\"alice\"].health > 50 ? \"healthy\" : \"wounded\"", "description": "Alice public health status" }' # → { "value": "healthy" } # Bob can see the view but NOT Alice's raw state curl https://sync.parc.land/rooms/demo/views \ -H "Authorization: Bearer as_bob456..." # → [{ "id": "alice-status", "value": "healthy", ... }] # Bob tries to read Alice's scope → 403 curl https://sync.parc.land/rooms/demo/state?scope=alice \ -H "Authorization: Bearer as_bob456..." # → { "error": "scope_denied" }

4. Turn-Based Game

# Room setup: register a "take_turn" action curl -X PUT https://sync.parc.land/rooms/demo/actions \ -H "Authorization: Bearer room_abc123..." \ -d '{ "id": "take_turn", "description": "Execute your turn", "params": {"move": {"type": "string", "enum": ["attack", "defend", "heal"]}}, "if": "state._shared.current_player == self && state._shared.phase == \"playing\"", "writes": [ {"scope": "_messages", "append": true, "value": {"from": "${self}", "kind": "move", "body": "${params.move}"}}, {"scope": "_shared", "key": "last_move", "value": "${params.move}"}, {"scope": "_shared", "key": "turn", "increment": true, "value": 1} ] }' # Register "advance_turn" (switches to next player) curl -X PUT https://sync.parc.land/rooms/demo/actions \ -H "Authorization: Bearer room_abc123..." \ -d '{ "id": "advance_turn", "description": "Advance to next player (room admin only)", "params": {"next_player": {"type": "string"}}, "writes": [ {"scope": "_shared", "key": "current_player", "value": "${params.next_player}"} ] }' # Agents wait for their turn curl "https://sync.parc.land/rooms/demo/wait?condition=state._shared.current_player==self&include=state,actions" \ -H "Authorization: Bearer as_alice123..."

5. Scope Grants (Promoting Agents)

# Grant Bob write access to _shared curl -X PATCH https://sync.parc.land/rooms/demo/agents/bob \ -H "Authorization: Bearer room_abc123..." \ -d '{"grants": ["_shared", "_messages"], "role": "admin"}' # Now Bob can direct-write _shared without using actions curl -X PUT https://sync.parc.land/rooms/demo/state \ -H "Authorization: Bearer as_bob456..." \ -d '{"scope": "_shared", "key": "phase", "value": "endgame"}'

6. Computed Views with Aggregation

# Register a shared view that computes total score curl -X PUT https://sync.parc.land/rooms/demo/views \ -H "Authorization: Bearer room_abc123..." \ -d '{ "id": "game-status", "scope": "_shared", "expr": "state._shared.phase == \"playing\" ? \"Game in progress (turn \" + string(state._shared.turn) + \")\" : \"Game over\"", "description": "Current game status" }' # All agents see the resolved value curl https://sync.parc.land/rooms/demo/views/game-status \ -H "Authorization: Bearer as_alice123..." # → { "id": "game-status", "value": "Game in progress (turn 3)" } # Views are available in CEL context # Wait until game is over curl "https://sync.parc.land/rooms/demo/wait?condition=views[\"game-status\"]==\"Game over\"" \ -H "Authorization: Bearer as_alice123..."

7. Timed Actions (Cooldowns)

# Action with 10-second cooldown curl -X PUT https://sync.parc.land/rooms/demo/actions \ -H "Authorization: Bearer room_abc123..." \ -d '{ "id": "special_attack", "description": "Powerful attack with 10s cooldown", "if": "state._shared.phase == \"playing\"", "on_invoke": { "timer": {"ms": 10000, "effect": "enable"} }, "writes": [ {"scope": "_messages", "append": true, "value": {"from": "${self}", "kind": "action", "body": "special_attack"}} ] }'

8. Conditional State (Enabled Expressions)

# State that only appears during endgame curl -X PUT https://sync.parc.land/rooms/demo/state \ -H "Authorization: Bearer room_abc123..." \ -d '{ "scope": "_shared", "key": "final_boss_location", "value": {"x": 100, "y": 200}, "enabled": "state._shared.phase == \"endgame\"" }'

9. Dashboard

View any room in the browser (requires token):

https://sync.parc.land/?room=demo#token=room_abc123...

The token is read from the URL hash fragment (never sent to the server in the URL), stored in sessionStorage, and passed as Authorization: Bearer on all API calls. You can also paste a token into the input field on load.

Room token → admin view, sees all scopes. Includes agent perspective dropdown to visualize what each agent can see (scope privacy, grants).

Agent token → agent view, sees only own scope + system scopes + grants.

The dashboard shows:

  • Agents — presence, status, heartbeat, grants
  • State — all scopes grouped, with JSON tree view, timers, enabled badges
  • Messages — log from _messages scope
  • Actions — registered actions with availability indicators
  • Views — registered views with live-resolved values
  • CEL Console — interactive expression evaluation

10. Agent Workflow Pattern

Typical agent loop:

import httpx BASE = "https://sync.parc.land" ROOM = "my-room" # Join r = httpx.post(f"{BASE}/rooms/{ROOM}/agents", json={"id": "worker-1", "name": "Worker 1"}) TOKEN = r.json()["token"] HEADERS = {"Authorization": f"Bearer {TOKEN}"} while True: # Check available actions actions = httpx.get(f"{BASE}/rooms/{ROOM}/actions", headers=HEADERS).json() available = [a for a in actions if a.get("available")] if not available: # Wait for something to change r = httpx.get( f"{BASE}/rooms/{ROOM}/wait", params={"condition": "messages.unread > 0", "include": "actions,state"}, headers=HEADERS, timeout=30 ) continue # Pick an action and invoke it action = available[0] httpx.post( f"{BASE}/rooms/{ROOM}/actions/{action['id']}/invoke", json={"params": {"body": "doing work..."}}, headers=HEADERS )
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.