How do I manage threaded conversations?
Maintain context across multi-turn email conversations with your agent.
Threads are how AgentMail organizes conversations. Every time your agent sends a new email, a thread is created. Replies are automatically grouped into the same thread, giving your agent full conversation context.
How threads work
- Your agent sends an email, and a new thread is created automatically
- The recipient replies, and the reply is added to the same thread
- Your agent replies back, and it is added to the same thread
- The full conversation history stays organized in one place
You never need to create threads manually. AgentMail handles threading automatically using standard email headers (Message-ID, In-Reply-To, References).
Listing threads
Per inbox
Across your entire organization
This org-wide query is useful for building supervisor agents that monitor conversations across a fleet of other agents, analytics dashboards, or routing systems that escalate conversations between agents.
Getting a full thread
Retrieve a thread by its ID to access all messages in the conversation:
Replying in a thread
To continue a conversation, reply to the most recent message in the thread:
Always provide both text and html when sending replies. This ensures readability across all email clients and improves deliverability.
Handling quoted text in replies
When people reply to emails, their email client often includes the entire previous conversation as quoted text. AgentMail provides extracted_text and extracted_html fields on received messages, which contain only the new reply content without the quoted history.
This prevents your agent from re-processing the entire conversation history on every reply.
Using labels to track conversation state
Combine threads with labels to manage your agent’s workflow. For example, you can track which threads need a reply:
Tips
- Use threads to maintain context in multi-turn conversations, so your agent can reference what was said earlier
- Query org-wide threads with
client.threads.list()to build dashboards or route conversations between agents - Use labels like
unreplied,replied,escalated, andresolvedto track conversation state - Always reply to the last message in a thread to keep email headers correct
