🔄 Big News! bazed.ai is now sagentic.ai. Same vision, new name!

Skip to content

@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) ​

ts
new Thread(parent, topic?): Thread

Create new thread.

Parameters ​

• parent: Agent

• topic?: string

Returns ​

Thread

Thread

Source ​

src/thread.ts:266

Properties ​

interaction ​

ts
interaction: Interaction;

last interaction in this thread

Source ​

src/thread.ts:252


metadata ​

ts
metadata: Metadata;

Metadata for this thread

Implementation of ​

Conclusible.metadata

Source ​

src/thread.ts:249

Accessors ​

assistantResponse ​

ts
get assistantResponse(): string

Last assistant text message in this thread

Returns ​

string

Source ​

src/thread.ts:476


complete ​

ts
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 ​

src/thread.ts:293


empty ​

ts
get empty(): boolean

Returns ​

boolean

Source ​

src/thread.ts:297


expectsToolResponse ​

ts
get expectsToolResponse(): boolean

Does this thread want a tool response?

Returns ​

boolean

Source ​

src/thread.ts:310


isSendable ​

ts
get isSendable(): boolean

Is this thread suitable to be sent to the LLM?

Returns ​

boolean

Source ​

src/thread.ts:305


messages ​

ts
get messages(): Message[]

Get messages in this thread. This includes system prompt from the owning agent if present.

Returns ​

Message[]

Array of messages

Source ​

src/thread.ts:276


parent ​

ts
get parent(): Agent

Agent owning this thread

Returns ​

Agent

Source ​

src/thread.ts:255

Methods ​

appendAssistantMessage() ​

ts
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 ​

Thread

new Thread object with the message appended

Throws ​

Error if the thread is complete

Source ​

src/thread.ts:448


appendAssistantToolCalls() ​

ts
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 ​

Thread

new Thread object with the tool call appended

Throws ​

Error if the thread is complete

Source ​

src/thread.ts:463


appendToolResult() ​

ts
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 ​

Thread

new Thread object with the tool result appended

Throws ​

Error if the the thread does not end with a tool call

Source ​

src/thread.ts:413


appendUserImage() ​

ts
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 ​

Thread

new Thread object with the image appended

Throws ​

Error if the thread is complete

Source ​

src/thread.ts:357


appendUserMessage() ​

ts
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 ​

Thread

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 ​

src/thread.ts:323


conclude() ​

ts
conclude(): void

Concludes the object. Finishes the timing object in metadata.

Returns ​

void

Implementation of ​

Conclusible.conclude

Source ​

src/thread.ts:565


edit() ​

ts
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 ​

Thread

new Thread object with the last user message replaced

Throws ​

Error if the thread is incomplete

Source ​

src/thread.ts:513


rollup() ​

ts
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 ​

Thread

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 ​

src/thread.ts:536


undo() ​

ts
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 ​

Thread

new Thread object with the last interaction undone

Throws ​

Error if the thread is incomplete

Source ​

src/thread.ts:494