import { createSmithersDB } from "smithers-orchestrator";// Create a database at a specific path// .smithers/my-workflow is the default location we recommend for workflow databasesconst db = await createSmithersDB({ path: ".smithers/my-workflow"});// Always close when doneawait db.close();
The database is created as a directory containing SQLite data files.
Path semantics: The path parameter specifies a directory, not a file. Smithers creates SQLite data files inside this directory. For manual queries, use sqlite3 <path>/db.sqlite.
The state API provides key-value storage with history:
Copy
Ask AI
// Set a valueawait db.state.set("phase", "review");// Set with trigger (for tracking what caused the change)await db.state.set("phase", "review", "tests_passed");// Get a valueconst phase = await db.state.get("phase");// Get all stateconst all = await db.state.getAll();// { phase: "review", lastAgent: "abc123", ... }// Set multiple values atomicallyawait db.state.setMany({ phase: "complete", completedAt: Date.now(),});
// Get history for a keyconst history = await db.state.history("phase", 10);// [// { id: "t1", key: "phase", value: "start", trigger: "init", timestamp: ... },// { id: "t2", key: "phase", value: "review", trigger: "tests_passed", ... },// ]// Time-travel: replay to a previous stateawait db.state.replayTo("t1");// State is now back to what it was at transition t1
// Add a factawait db.memories.addFact( "api-endpoint", "The API endpoint is at /api/v2/users", "discovered in auth.ts");// Add a learningawait db.memories.addLearning( "test-pattern", "Use vitest for unit tests in this project", "package.json");// Add a preferenceawait db.memories.addPreference( "commit-style", "Use conventional commits with scope");// Search memoriesconst relevant = await db.memories.search("API endpoint");// Get specific memoryconst memory = await db.memories.get("fact", "api-endpoint");
For advanced use cases, query the database directly:
Copy
Ask AI
// Run a custom queryconst results = await db.query<{ count: number }>( "SELECT COUNT(*) as count FROM agents WHERE model = $1", ["sonnet"]);console.log(`${results[0].count} sonnet agents`);
# List executionssmithers db executions# View current statesmithers db state# View database statisticssmithers db stats# View current executionsmithers db current