Create or resume a thread
You identify a thread with a thread key: a string your application already uses for that run, such asorder:ORD-123 or an agent session ID. The first call
with a key creates the thread. Later calls with the same key, from any service or
worker, return the same thread.
In Python use
service_name. In Go use the threadify.ThreadOptions fields of
the same names.
When you resume a thread, Threadify ignores the label, refs and tags you pass and
keeps the stored ones. To add references later, use
addRefs().
Thread key rules
- A key identifies one thread within your Engine.
- Keys are trimmed and must be non-empty, up to 1024 bytes (UTF-8).
- Two services calling
thread()with the same new key at the same moment get the same thread. - Once a thread is completed or cancelled it can’t be reopened or receive more
steps. Use a new key for the next run, such as
order:ORD-123:retry-1.
thread.id). You only need
it for the GraphQL API and for
joining by ID.
Contracted sessions
If a thread should follow a contract, passcontract the first time you call
thread(). After that, any service can resume it with just the key and the
contract comes with it: