async function basicChat() { // Set system prompt for the agent agent.setSystemPrompt('You are a helpful AI assistant.'); const response = await agent.ask('Hello, how can you help me today?'); console.log(response);}basicChat();
async function streamingChat() { agent.setSystemPrompt('You are a creative storyteller.'); const response = await agent.streamChat( 'Tell me a story about AI', (chunk) => { process.stdout.write(chunk); } ); console.log('\nComplete story:', response);}streamingChat();
async function chatWithMemory() { // Store user preferences in persistent memory await agent.remember('user_preferences', { language: 'English', tone: 'friendly' }); // The agent automatically uses memory context in conversations const response = await agent.chatWithContext( 'Remember my preferences and help me with a coding question' ); console.log(response);}chatWithMemory();
// Agents in 0G AI SDK are conversation-based with persistent memoryasync function runAgent() { // Set up the agent's behavior agent.setSystemPrompt(`You are a helpful assistant. When users ask for the time, tell them the current time is ${new Date().toISOString()}`); const response = await agent.chatWithContext('What time is it?'); console.log(response); // Save the conversation for future reference const conversationId = await agent.saveConversation(); console.log('Conversation saved with ID:', conversationId);}runAgent();