Threads

Threads are the core unit of execution for Seekrflow Agnets

Threads Overview

Threads are the core unit of execution in our platform. A thread represents the vehicle by which agent are executed. Threads are independent of Agents allowing the user to utilize them to persist state across agents and conversations.

Messages and Threads

When you run an agent it will append a message to the thread. All tool calls output and the final output will be attached as subsequent messages to the thread, creating the agent's "context".

Why threads?

We feel directly exposing threads to the developer gives you the most flexibility when creating and running your agents. Threads allow for concurrent and independent executions using the same agent configuration. This enables you to run multiple, isolated conversations in parallel, all with their own state and context history.

Creating a Thread

To create a thread, use the following code:

from seekrai import SeekrFlowclient = SeekrFlow()

thread = client.agents.threads.create()
print("Thread created: ", thread.id)

List All Threads

This example lists the 20 most recent threads the user created with their status in descending order. If the thread has been attached to an agent, it lists the agent id.

threads = client.agents.threads.list(limit=20, order="desc")
print("Available threads:")

for thread in threads:
  print(f"ID: {thread.id}, Status: {thread.status}")
  if thread.agent_id is not None: 
    print(f"Agent ID: {thread.agent_id})

Retrieve a specific thread

thread = client.agents.threads.retrieve(thread_id=thread.id)
print(f"Thread retrieved: ID={thread.id}, Status={thread.status}")

Delete a Thread

deleted_status = client.agents.threads.delete(thread_id=thread.id)
print(f"Thread {thread_id} deleted: {deleted_status}")

Thread Data Structure

class ThreadStatus(str, Enum):
    AVAILABLE: available
    LOCKED: locked

class Thread(BaseModel):
    id:
    object: str 
    created_at
    status: ThreadStatus
    active_run_id: Optional[str] 
    meta_data: dict[str, Any]