Using Filesystem & State KV

Store files and key-value data using Weavz's built-in Filesystem and State KV integrations.

Weavz includes two built-in workspace integrations for persistent data: Filesystem (storage) for files and State KV (kv-store) for key-value data. Both are accessed through the standard action execution API, can be configured as workspace integrations, and require no additional connections.

For the broader first-party setup flow, see Using Built-In Workspace Integrations.

The examples below assume you configured the built-in integrations with workspace-scoped persistence:

bash
curl -X POST https://api.weavz.io/api/v1/workspaces/YOUR_WORKSPACE_ID/integrations \
  -H "Authorization: Bearer wvz_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "integrationName": "storage",
    "alias": "files",
    "settings": { "persistence": { "scope": "workspace" } }
  }'
 
curl -X POST https://api.weavz.io/api/v1/workspaces/YOUR_WORKSPACE_ID/integrations \
  -H "Authorization: Bearer wvz_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "integrationName": "kv-store",
    "alias": "state",
    "settings": { "persistence": { "scope": "workspace" } }
  }'

For private per-user files or state, keep the default end_user scope and pass endUserId when executing actions.

Filesystem Integration

The Filesystem integration (storage) provides file CRUD operations in Weavz-managed durable files.

Write a File

bash
curl -X POST https://api.weavz.io/api/v1/actions/execute \
  -H "Authorization: Bearer wvz_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "integrationName": "storage",
    "actionName": "write_file",
    "workspaceId": "YOUR_WORKSPACE_ID",
    "input": {
      "path": "reports/monthly.json",
      "content": "{\"revenue\": 50000, \"month\": \"January\"}"
    }
  }'

Read a File

bash
curl -X POST https://api.weavz.io/api/v1/actions/execute \
  -H "Authorization: Bearer wvz_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "integrationName": "storage",
    "actionName": "read_file",
    "workspaceId": "YOUR_WORKSPACE_ID",
    "input": {
      "path": "reports/monthly.json"
    }
  }'

List Files

bash
curl -X POST https://api.weavz.io/api/v1/actions/execute \
  -H "Authorization: Bearer wvz_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "integrationName": "storage",
    "actionName": "list_files",
    "workspaceId": "YOUR_WORKSPACE_ID",
    "input": {
      "prefix": "reports/"
    }
  }'

Delete a File

bash
curl -X POST https://api.weavz.io/api/v1/actions/execute \
  -H "Authorization: Bearer wvz_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "integrationName": "storage",
    "actionName": "delete_file",
    "workspaceId": "YOUR_WORKSPACE_ID",
    "input": {
      "path": "reports/monthly.json"
    }
  }'

Filesystem Actions Summary

ActionInputDescription
write_filepath, contentWrite or overwrite a file
read_filepathRead file contents
list_filesprefixList files matching a prefix
delete_filepathDelete a file

State KV Integration

The State KV integration (kv-store) provides key-value operations for storing structured data.

Put a Value

bash
curl -X POST https://api.weavz.io/api/v1/actions/execute \
  -H "Authorization: Bearer wvz_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "integrationName": "kv-store",
    "actionName": "put",
    "workspaceId": "YOUR_WORKSPACE_ID",
    "input": {
      "key": "user:settings:123",
      "value": "{\"theme\": \"dark\", \"notifications\": true}"
    }
  }'

Get a Value

bash
curl -X POST https://api.weavz.io/api/v1/actions/execute \
  -H "Authorization: Bearer wvz_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "integrationName": "kv-store",
    "actionName": "get",
    "workspaceId": "YOUR_WORKSPACE_ID",
    "input": {
      "key": "user:settings:123"
    }
  }'

Delete a Value

bash
curl -X POST https://api.weavz.io/api/v1/actions/execute \
  -H "Authorization: Bearer wvz_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "integrationName": "kv-store",
    "actionName": "delete",
    "workspaceId": "YOUR_WORKSPACE_ID",
    "input": {
      "key": "user:settings:123"
    }
  }'

List Operations

State KV supports list-based operations on a single key:

bash
# Add to a list
curl -X POST https://api.weavz.io/api/v1/actions/execute \
  -H "Authorization: Bearer wvz_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "integrationName": "kv-store",
    "actionName": "add_to_list",
    "workspaceId": "YOUR_WORKSPACE_ID",
    "input": {
      "key": "processed:emails",
      "value": "msg_abc123"
    }
  }'
 
# Remove from a list
curl -X POST https://api.weavz.io/api/v1/actions/execute \
  -H "Authorization: Bearer wvz_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "integrationName": "kv-store",
    "actionName": "remove_from_list",
    "workspaceId": "YOUR_WORKSPACE_ID",
    "input": {
      "key": "processed:emails",
      "value": "msg_abc123"
    }
  }'

State KV Actions Summary

ActionInputDescription
putkey, valueStore a value
getkeyRetrieve a value
deletekeyDelete a key
add_to_listkey, valueAppend a value to a list
remove_from_listkey, valueRemove a value from a list

Persistence Scope

Filesystem, State KV, Agent Memory, Agent Scratchpad, and Sequential Thinking read persistence policy from workspace integration settings. The action caller does not pass scope or externalId in input.

ScopeValueDescription
Current end userend_user (default)Private to the end user for the current request. Requires endUserId when running actions.
Shared workspaceworkspaceShared by all users and agents in the workspace.
Custom namespaceexternalScoped to one namespace key in the workspace. Configure the key as settings.persistence.externalId.

Connection strategy still controls which credentials an action uses; persistence scope controls who can read and write the stored state.

Current end user (default)

When you pass endUserId in the request, data is isolated per end user. This is the default persistence policy for stateful tools.

bash
curl -X POST https://api.weavz.io/api/v1/actions/execute \
  -H "Authorization: Bearer wvz_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "integrationName": "storage",
    "actionName": "write_file",
    "workspaceId": "YOUR_WORKSPACE_ID",
    "endUserId": "user_12345",
    "input": {
      "path": "preferences.json",
      "content": "{\"theme\": \"dark\"}"
    }
  }'

Files written by user_12345 are fully isolated from files written by user_67890. This is the recommended approach for multi-tenant applications where each end user should have their own storage namespace.

Custom namespace

Use external for state isolated by a tenant, session, project, or entity. Configure the namespace on the workspace integration:

bash
curl -X POST https://api.weavz.io/api/v1/workspaces/YOUR_WORKSPACE_ID/integrations \
  -H "Authorization: Bearer wvz_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "integrationName": "storage",
    "alias": "tenant_storage",
    "settings": {
      "persistence": { "scope": "external", "externalId": "tenant_456" }
    }
  }'

Calls through tenant_storage read and write the tenant_456 namespace. The same namespace key in different workspaces is isolated.

Practical Examples

Caching API Responses

typescript
const cacheKey = `cache:weather:${city}`
 
// Check cache
const cached = await client.actions.execute('kv-store', 'get', {
  workspaceId: 'YOUR_WORKSPACE_ID',
  input: { key: cacheKey },
})
 
if ('approval' in cached) throw new Error(`Approval required: ${cached.approval.id}`)
 
if (cached.output.value) {
  const data = JSON.parse(cached.output.value)
  const age = Date.now() - new Date(data.cachedAt).getTime()
 
  // Use cache if less than 5 minutes old
  if (age < 300_000) return data.weather
}
 
// Fetch fresh data and cache it
const weather = await fetchWeatherApi(city)
await client.actions.execute('kv-store', 'put', {
  workspaceId: 'YOUR_WORKSPACE_ID',
  input: {
    key: cacheKey,
    value: JSON.stringify({ weather, cachedAt: new Date().toISOString() }),
  },
})

Tracking Processed Items

typescript
// Check if already processed
const processed = await client.actions.execute('kv-store', 'get', {
  workspaceId: 'YOUR_WORKSPACE_ID',
  input: { key: 'processed:webhooks' },
})
 
if ('approval' in processed) throw new Error(`Approval required: ${processed.approval.id}`)
 
const list = JSON.parse(processed.output.value || '[]')
if (list.includes(webhookId)) return // Skip duplicate
 
// Process the webhook
await handleWebhook(payload)
 
// Mark as processed
await client.actions.execute('kv-store', 'add_to_list', {
  workspaceId: 'YOUR_WORKSPACE_ID',
  input: { key: 'processed:webhooks', value: webhookId },
})