In this lesson, we’ll learn how to create conversational agents that can maintain context across multiple interactions. This is essential for creating assistants that feel natural to interact with.
# Note: TODO: This Feature yet to be developedfrom praisonaiagents import Agent# Create a conversational agentchat_agent = Agent( name="Conversational Assistant", instructions=""" You are a friendly, helpful conversational assistant. When chatting with users: 1. Maintain a warm, friendly tone 2. Remember information shared earlier in the conversation 3. Ask clarifying questions when needed 4. Keep responses concise but informative 5. Be helpful while respecting boundaries """)# Start a conversationresponse = chat_agent.start("Hi there! My name is Jamie.")print(response)# Continue the conversationresponse = chat_agent.continue("What can you help me with today?")print(response)# The agent should remember the user's nameresponse = chat_agent.continue("Can you remember my name?")print(response)
You can customize how your conversational agent behaves:
# Create an agent with specific conversation settingscustom_chat_agent = Agent( name="Custom Chat Assistant", instructions="You are a helpful assistant", memory_size=10, # Remember the last 10 messages temperature=0.7 # Slightly more creative in responses)
Let’s create a specialized customer support agent:
support_agent = Agent( name="Support Agent", instructions=""" You are a customer support specialist for a tech company. When helping customers: 1. Greet them professionally 2. Show empathy for their issues 3. Ask for necessary information to troubleshoot 4. Provide clear step-by-step solutions 5. Confirm if the issue is resolved 6. End with an offer for additional help Remember product details and customer information throughout the conversation. """)# Example conversationprint(support_agent.start("Hi, I'm having trouble logging into my account."))print(support_agent.continue("My username is user123."))print(support_agent.continue("I've tried resetting my password but I'm not receiving the email."))
tutor_agent = Agent( name="Math Tutor", instructions=""" You are a patient, encouraging math tutor. When teaching: 1. Gauge the student's current understanding 2. Explain concepts using clear, simple language 3. Provide examples to illustrate points 4. Ask questions to check understanding 5. Give positive reinforcement for progress Adapt your explanations based on the student's responses. """)# Example tutoring sessionprint(tutor_agent.start("Can you help me understand algebra?"))print(tutor_agent.continue("I'm struggling with equations like 2x + 5 = 13"))print(tutor_agent.continue("So I subtract 5 from both sides first?"))print(tutor_agent.continue("Then I divide by 2 to get x = 4?"))print(tutor_agent.continue("Could you give me another example to practice?"))