const agent = await truffle.deployAgent({ name: 'Support Assistant', instruction: 'You are a customer support specialist who helps users with their questions.', model: 'gpt-4o-mini'});
You can also create agents directly on the platform.
// Create a chat sessionconst chat = agent.chat();// Send messages and get responsesconst response1 = await chat.send('Hi! My name is Alice.');console.log(response1);const response2 = await chat.send("What's my name?"); // Agent remembers "Alice"console.log(response2);// Get chat historyconst history = chat.getHistory();// Clear chat history if neededchat.clearHistory();
Hereβs a complete example showing various agent operations:
Copy
Ask AI
import { TruffleAI } from 'truffle-ai';async function main() { // Initialize client const truffle = new TruffleAI('your-api-key'); // Create an agent const agent = await truffle.deployAgent({ name: 'Support Assistant', instruction: 'You are a customer support specialist who helps users with their questions.', model: 'gpt-4o-mini' }); // Run a one-off task const taskResult = await agent.run('What are your main responsibilities?'); console.log('Task Result:', taskResult); // Start a chat session const chat = agent.chat(); // Have a conversation const responses = await Promise.all([ chat.send('Hi! I need help with my account.'), chat.send('How do I change my password?'), chat.send('Thanks for your help!') ]); // Get chat history const history = chat.getHistory(); console.log('Chat History:', history);}main().catch(console.error);