Multi-turn conversations with agent.chat()
Keep conversation context across turns
agent.start() is great for one-shot tasks. When a user asks follow-up questions ('Make it shorter', 'Now translate that'), use agent.chat() so the agent remembers prior turns inside the same session.
Example
from praisonai import Agent
tutor = Agent(
name='MathTutor',
instructions='Answer clearly in one sentence and remember prior turns.',
)
print('Turn 1:', tutor.chat('What is a prime number?'))
print('Turn 2:', tutor.chat('Give me three examples of them.'))Example explained
- tutor.chat(…) — Appends each user message and assistant reply to the agent's conversation history.
- Turn 2 — Follow-up prompt relies on Turn 1 context without repeating the word 'prime'.
Isolate conversations per user in multi-user apps
Create a fresh Agent per request (or pass distinct session_id values via MemoryConfig) so two users never share the same in-memory chat history.
Common pitfall: letting chat history grow without compaction
Long 50-turn threads inflate token costs and hit context limits. Enable ExecutionConfig(context_compaction=True) for long-running chat assistants.
Reference: documentation