@sagentic-ai/sagentic-af / Thread
Thread ​
Thread is a single thread of conversation. In practice Thread just points to the last interaction in the thread. Threads are only partially mutable, meaning that appending messages to a thread creates a new thread if the last interaction tn the thread is complete.
Implements ​
Constructors ​
new Thread(parent, topic) ​
new Thread(parent, topic?): Thread
Create new thread.
Parameters ​
• parent: Agent
• topic?: string
Returns ​
Thread
Source ​
Properties ​
interaction ​
interaction: Interaction;
last interaction in this thread
Source ​
metadata ​
metadata: Metadata;
Metadata for this thread
Implementation of ​
Source ​
Accessors ​
assistantResponse ​
get assistantResponse(): string
Last assistant text message in this thread
Returns ​
string
Source ​
complete ​
get complete(): boolean
Is this thread complete? A thread is complete if the last interaction is complete. In practice this means that if the last message in the thread is from us, the thread is not complete. If the last message in the thread is from OpenAI, the thread is complete. Completing a thread is done by appending a message from assistant to it.
Returns ​
boolean
true if complete, false otherwise
Source ​
empty ​
get empty(): boolean
Returns ​
boolean
Source ​
expectsToolResponse ​
get expectsToolResponse(): boolean
Does this thread want a tool response?
Returns ​
boolean
Source ​
isSendable ​
get isSendable(): boolean
Is this thread suitable to be sent to the LLM?
Returns ​
boolean
Source ​
messages ​
get messages(): Message[]
Get messages in this thread. This includes system prompt from the owning agent if present.
Returns ​
Message
[]
Array of messages
Source ​
parent ​
get parent(): Agent
Agent owning this thread
Returns ​
Source ​
Methods ​
appendAssistantMessage() ​
appendAssistantMessage(message): Thread
Append an assistant message to this thread. Beware: this method mutates the thread when it's incomplete. Always use the return value. It is only legal to append assistant message if the thread is not complete.
Parameters ​
• message: string
Message to append
Returns ​
new Thread object with the message appended
Throws ​
Error if the thread is complete
Source ​
appendAssistantToolCalls() ​
appendAssistantToolCalls(toolCalls): Thread
Append a tool calls to this thread. It is only legal to append tool call if the thread is not complete.
Parameters ​
• toolCalls: ToolCall
[]
Tool calls to append
Returns ​
new Thread object with the tool call appended
Throws ​
Error if the thread is complete
Source ​
appendToolResult() ​
appendToolResult(toolCallID, result): Thread
Append a tool result to this thread. Beware: this method mutates the thread when it's incomplete. Always use the return value. It is only legal if the thread is complete and the last message in the thread is a tool call.
Parameters ​
• toolCallID: string
ID of the tool call
• result: string
Result of the tool call
Returns ​
new Thread object with the tool result appended
Throws ​
Error if the the thread does not end with a tool call
Source ​
appendUserImage() ​
appendUserImage(url, options?): Thread
Append an image to this thread. Beware: this method mutates the thread when it's incomplete. Always use the return value. It is only legal to append image if the thread is not complete.
Parameters ​
• url: string
• options?
• options.detail?: "auto"
| "high"
| "low"
Returns ​
new Thread object with the image appended
Throws ​
Error if the thread is complete
Source ​
appendUserMessage() ​
appendUserMessage(message): Thread
Append a user message to this thread. Beware: this method mutates the thread when it's incomplete. Always use the return value. It is always legal to append user message. In case the thread is complete, a new thread is created with the message appended. In case the thread is incomplete, the message is appended to the last user message in the thread.
Parameters ​
• message: string
Message to append
Returns ​
new Thread object with the message appended
Throws ​
Error if the thread does not end in user text prompt or if the thread is complete and expects tool response
Source ​
conclude() ​
conclude(): void
Concludes the object. Finishes the timing object in metadata.
Returns ​
void
Implementation of ​
Source ​
edit() ​
edit(newUserMessage): Thread
Create new thread with last user message edited. Beware: this method does not mutate the thread. Always use the return value.
Parameters ​
• newUserMessage: string
New message to replace the last user message with
Returns ​
new Thread object with the last user message replaced
Throws ​
Error if the thread is incomplete
Source ​
rollup() ​
rollup(to, edit?): Thread
Create new thread by taking the last user message from to
and last assistant message from this thread. Beware: this method does not mutate the thread. Always use the return value.
Parameters ​
• to: Thread
Thread to rollup to
• edit?: string
Returns ​
new Thread object with messages between to
and this
rolled up
Throws ​
Error if the thread is incomplete
Throws ​
Error if to
thread is incomplete
Source ​
undo() ​
undo(): Thread
Create new thread with last response from agent removed. Beware: this method does not mutate the thread. Always use the return value.
Returns ​
new Thread object with the last interaction undone
Throws ​
Error if the thread is incomplete