import { AgentFS } from 'agentfs-sdk';
// Initialize AgentFS with a local database
const agent = await AgentFS.open(
'./my-agent.db'
);
// Store agent configuration
await agent.kv.set('agent:id', 'assistant-001');
await agent.kv.set(
'agent:created',
new Date().toISOString()
);
// Create a conversation history
const conversations = [];
async function addMessage(role: string, content: string) {
const message = {
role,
content,
timestamp: Date.now()
};
conversations.push(message);
// Persist to AgentFS
await agent.kv.set('conversations', conversations);
// Also save as a file for easy access
const filename = `/conversations/${Date.now()}.json`;
await agent.fs.writeFile(
filename,
JSON.stringify(message, null, 2)
);
// Track this as a tool call
await agent.tools.record(
'save_message',
Date.now() / 1000,
Date.now() / 1000 + 0.1,
{ role, contentLength: content.length },
{ saved: true, filename }
);
}
// Example usage
await addMessage(
'user',
'Hello, can you help me with a task?'
);
await addMessage(
'assistant',
'Of course! I'd be happy to help.'
);
// Retrieve conversation history
const history = await agent.kv.get('conversations');
console.log('Conversation history:', history);
// List all conversation files
const files = await agent.fs.readdir('/conversations');
console.log('Saved conversations:', files);