Session state, checkpoints, and rollback functionality in the qckfx Agent SDK
The qckfx Agent SDK provides session management capabilities that enable stateful conversations, automatic checkpoint creation, and rollback functionality. This system ensures that agents can maintain context across interactions while providing safety mechanisms for undoing changes.
import { Agent } from '@qckfx/agent';// Create agent instanceconst agent = new Agent({ defaultModel: 'claude-3-5-sonnet-20241022', systemPrompt: 'You are a helpful coding assistant.', environment: { type: 'local' }});// Process a query (session state is managed internally)const result = await agent.processQuery('How many files are in this directory?');console.log(result.response);
The checkpoint system automatically creates git-based snapshots of repository state before potentially destructive operations, enabling safe rollback functionality.
// Rollback to a specific message in the conversationconst messageId = 'msg_xyz789'; // Message ID from conversation historyconst restoredCommits = await agent.performRollback(messageId);console.log('Rollback completed');restoredCommits.forEach((commitSha, repoPath) => { console.log(`Restored ${repoPath} to ${commitSha}`);});
// Get repository count for a sessionconst repoCount = Agent.getRepositoryCount(sessionState);console.log('Tracking repositories:', repoCount);// Get repository paths for a sessionconst repoPaths = Agent.getRepositoryPaths(sessionState);repoPaths.forEach(path => { console.log('Repository path:', path);});
// Abort the current session operationagent.abort();// Check if session is abortedif (agent.isAborted()) { console.log('Session is currently aborted');}// Clear abort statusagent.clearAbort();
// Robust error handling with session managementasync function processWithErrorHandling(agent: Agent, query: string) { try { const result = await agent.processQuery(query); return result; } catch (error) { console.error('Query processing failed:', error); // Check if session was aborted if (agent.isAborted()) { console.log('Operation was aborted by user'); agent.clearAbort(); // Reset for next operation } throw error; }}
Checkpoints are created automatically before potentially destructive operations. The system uses git shadow repositories to ensure your main repository remains clean.
Rollback operations will discard any uncommitted changes in the working directory. The system restores files to the exact state they were in at the checkpoint.
Multi-repository tracking is automatically enabled when multiple git repositories are detected in the working directory. Each repository maintains its own checkpoint history.