Back to Mastra

Unified Workspace Example

examples/unified-workspace/README.md

2025-12-184.3 KB
Original Source

Unified Workspace Example

Demonstrates the unified Workspace API that combines filesystem, sandbox, skills, and search.

Quick Start

bash
pnpm install
pnpm mastra:dev

Open http://localhost:4111 to use the Playground UI.

Structure

text
examples/unified-workspace/
├── content/                   # FAQ content (auto-indexed for BM25 search)
│   ├── faq-account.md
│   ├── faq-billing.md
│   └── faq-technical.md
├── skills/                    # Global skills
│   ├── api-design/
│   ├── code-review/
│   └── customer-support/
├── docs-skills/               # Agent-specific skills
│   └── brand-guidelines/
├── src/
│   ├── demo/
│   │   └── index.ts           # Consolidated demo script
│   └── mastra/
│       ├── agents/            # Agent definitions
│       ├── workspaces.ts      # Workspace configurations
│       └── index.ts
└── package.json

Running Demos

bash
# Run all demos
pnpm demo

# Run specific demo
pnpm demo:filesystem    # Read, write, list, delete, mkdir
pnpm demo:skills        # Discovery, search, CRUD, assets
pnpm demo:workspace     # Init, info, BM25 search/index
pnpm demo:agents        # Workspace inheritance, tools
pnpm demo:safety        # Readonly, requireReadBeforeWrite, approval

Workspaces

WorkspaceFeatures
globalWorkspaceFull access, global skills, BM25 search
docsAgentWorkspaceGlobal + agent-specific skills (brand-guidelines)
isolatedDocsWorkspaceAgent-specific skills only
readonlyWorkspacereadOnly: true - blocks all writes
safeWriteWorkspacerequireReadBeforeWrite on write/edit tools
supervisedSandboxWorkspacerequireApproval on execute_command
fsWriteApprovalWorkspacerequireApproval on write operations
fsAllApprovalWorkspacerequireApproval on all operations
testAgentWorkspaceDifferent basePath (/agent-files)
skillsOnlyWorkspaceNo filesystem/sandbox, only skills

Agents

AgentWorkspacePurpose
developerAgentglobalWorkspaceFull access baseline
docsAgentdocsAgentWorkspaceSkill inheritance demo
supportAgentisolatedDocsWorkspaceAgent-specific skills
researchAgentreadonlyWorkspaceReadonly safety
editorAgentsafeWriteWorkspaceRead-before-write
automationAgentsupervisedSandboxWorkspaceSandbox approval
fsWriteApprovalAgentfsWriteApprovalWorkspaceWrite approval
fsAllApprovalAgentfsAllApprovalWorkspaceAll ops approval
testAgenttestAgentWorkspaceDifferent basePath
skillsOnlyAgentskillsOnlyWorkspaceMinimal workspace

Key Concepts

Workspace Configuration

typescript
const workspace = new Workspace({
  id: 'my-workspace',
  filesystem: new LocalFilesystem({ basePath: '.', readOnly: false }),
  sandbox: new LocalSandbox({ workingDirectory: '.' }),
  skills: ['/skills'],
  bm25: true,
  autoIndexPaths: ['/content'],
  tools: {
    requireApproval: false,
    [WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE]: { requireReadBeforeWrite: true },
  },
});

Skill Inheritance

typescript
// Global workspace - has global skills only
const global = new Workspace({ skills: ['/skills'] });

// Agent workspace - inherits global + adds own
const agent = new Workspace({ skills: ['/skills', '/agent-skills'] });

Safety Features

  • readOnly: Block all filesystem write operations
  • requireReadBeforeWrite: Must read file before writing (per-tool)
  • requireApproval: Show approval dialog before execution (per-tool or global)

Testing

See /WORKSPACE_TESTS.md in the repo root for manual test cases.