Labels

Organizing and categorizing your agent's conversations at scale.

What are Labels?

Labels are simple, string-based tags that you can attach to your Messages and Threads. They are the primary mechanism for organizing, categorizing, and managing the state of your conversations, whether its automatically bucketing threads into specific categories for your outbound campaign, to segmenting warm leads for your outreach, to categorizing inbound into low-ticket, medium-ticket, high-ticket customers.

A Message can have multiple Labels, allowing you to create a flexible and powerful system for managing complex workflows.

Use Cases for Labels

By strategically applying Labels, you can build sophisticated agent systems. Here are a few common use cases:

1

State Management

Use Labels to track the state of a conversation. For example, an agent could apply needs-human-review when it’s unsure how to respond, or a supervisor could apply approved-to-send to a Draft.

2

Campaign Tracking

When running outbound campaigns, tag every Message with a unique campaign Label like q4-2024-outreach, or mercor-campaign and adding a second tag as warm-lead. This allows you to easily filter for and analyze the performance of that specific campaign later on.

3

Automated Triage

An inbound agent can classify incoming Messages with Labels like billing-question, feature-request, or bug-report, allowing specialized agents or human teams to handle them efficiently.

Core Capabilities

Here’s how you can programmatically work with Labels.

1. Adding Labels When Sending a Message

You can attach an array of Labels directly when you send a Message.

1sent_message = client.inboxes.messages.send(
2 inbox_id="outbound@agentmail.to",
3 to=["test@example.com"],
4 subject="Following up on our conversation",
5 text="Here is the information you requested.",
6 labels=["follow-up", "q4-campaign"]
7)

2. Adding or Removing Labels on an Existing Message

You can modify the Labels on a Message that has already been sent using the update (PATCH) method. This is perfect for changing the state of a conversation as your agent works on it.

1# Let's add a 'resolved' label to a message
2
3client.messages.update(
4inbox_id='outbound@domain.com',
5message_id='msg_id_123',
6add_labels=["resolved"],
7remove_labels=['unresolved']
8)

3. Filtering by Labels

This is where Labels become truly powerful. You can list Threads, Messages, and Drafts by filtering for one or more Labels, allowing you to create highly targeted queries.

1# Find all threads from a specific campaign that need a follow-up
2client.inboxes.threads.list(
3 inbox_id = 'outbound-agent@domain.com',
4 labels=[
5 "q4-campaign",
6 "follow_up"
7 ]
8)
9
10print(f"Found {len(filtered_threads)} threads that need a follow-up.")

Best Practices

  • Be Consistent: Establish a clear and consistent naming convention for your labels (e.g., kebab-case, snake_case).
  • Use Prefixes: For state management, consider using prefixes like status-pending or priority-high to create an organized system.
  • Don’t Over-Label: While you can add many Labels, aim for a concise and meaningful set to keep your system manageable.
Coming Soon: AI-Powered Auto-Labeling

We are actively developing an AI-powered auto-labeling feature. Soon, your agents will be able to provide a set of Labels and instructions, and AgentMail will automatically apply the correct Labels to incoming Messages based on their content.