You can add tags to a Thread, Step or Generation. Similar to Github labels, you can use tags to filter data both from the Literal AI UI and the clients. Tags are shared between units (Threads, Steps and Generations).

A Thread with Steps and Tags.

A Thread with Steps and Tags.

To add a tag to a Thread or Generation, open the specific item and add the tag on the top of the window. Here, you can also add new tags. Adding tags to Steps is possible in the Step itself.

Add new Tag to a Thread

Add new Tag

Using the SDKs:

Adding Tags

When you add a Tag that doesn’t exist yet, a new Tag will be automatically created.

with literal_client.thread(name="Thread Example") as thread:
    thread.tags = ["to review"]

Note: You can add tags a posteriori too. When you update the Tags in using update_thread() (Python) or upsertThread() (TypeScript), you replace all previous assigned tags to this Thread.

import os
from literalai import LiteralClient

literal_client = LiteralClient(api_key=os.getenv("LITERAL_API_KEY"))

def add_tags():
  updated_thread = literal_client.api.update_thread(
    id="<THREAD_UUID>",
    tags=["outlier", "to review"], # add tags here
)

add_tags()

# Network requests by the SDK are performed asynchronously.
# Invoke flush_and_stop() to guarantee the completion of all requests prior to the process termination.
# WARNING: If you run a continuous server, you should not use this method.
client.flush_and_stop()

Filter by Tags

Next, you can filter Threads or Generations by tags.

Filter Threads by Tag

Filter by Tag

Using the SDKs:

import os
from literalai import LiteralClient

literal_client = LiteralClient(api_key=os.getenv("LITERAL_API_KEY"))

def get_filtered_threads():
    filtered_threads = literal_client.api.list_threads(
        filters = [{
            "operator": "in",
            "field": "tags",
            "value": ["outlier"],
        }]
    )
    return filtered_threads

filtered_threads = get_filtered_threads()

print(filtered_threads.pageInfo)
for thread in filtered_threads.data:
    print(thread.to_dict())

# Network requests by the SDK are performed asynchronously.
# Invoke flush_and_stop() to guarantee the completion of all requests prior to the process termination.
# WARNING: If you run a continuous server, you should not use this method.
client.flush_and_stop()