OpenAI Assistant Component — sgcAI | eSeGeCe

OpenAI Assistant

TsgcAIOpenAIAssistant wraps the OpenAI Assistants API. Create an assistant with its instructions and tools, open a thread, post messages and launch runs, blocking or streamed. File Search, Code Interpreter and your own functions are configured as properties.

TsgcAIOpenAIAssistant

A stateful agent on the OpenAI Assistants API. The component manages assistants, threads, messages, runs and vector stores, and dispatches tool calls back to your code.

Component class

TsgcAIOpenAIAssistant

Purpose

OpenAI Assistants API agent

Family

Chat & agents

Platforms

Win32 and Win64

sgcAI is self-contained. This component ships inside sgcAI together with the sgcWebSockets Core runtime it is built on, so there is no base license to buy.

Create an assistant, run a thread

Configure the assistant, open a thread, post a message, run it. Streamed runs raise events as the answer is produced.

uses
  sgcAI, sgcAI_OpenAI_Audio_Assistant;

var
  oAssistant: TsgcAIOpenAIAssistant;
  oThread: TsgcOpenAIClass_Thread;
begin
  oAssistant := TsgcAIOpenAIAssistant.Create(nil);
  oAssistant.OpenAIOptions.ApiKey := 'sk-...';

  oAssistant.AssistantOptions.Name  := 'Support Agent';
  oAssistant.AssistantOptions.Model := 'gpt-4o';
  oAssistant.AssistantOptions.Instructions.Text :=
    'Answer support questions from the product manual only.';
  oAssistant.AssistantOptions.Tools.FileSearch.Enabled := True;

  oAssistant.OnStreamMessageDelta := AssistantDelta;
  oAssistant.OnFunctionCall       := AssistantFunctionCall;

  oAssistant.CreateAssistant;
  oThread := oAssistant.CreateThread;
  oAssistant.CreateMessageText(oThread.Id, 'How do I reset the device?');
  oAssistant.CreateRunAndWait(oThread.Id, 60000, True);
end;
// includes: sgcAI.hpp, sgcAI_OpenAI_Audio_Assistant.hpp

TsgcAIOpenAIAssistant *oAssistant = new TsgcAIOpenAIAssistant(NULL);
oAssistant->OpenAIOptions->ApiKey = "sk-...";

oAssistant->AssistantOptions->Name  = "Support Agent";
oAssistant->AssistantOptions->Model = "gpt-4o";
oAssistant->AssistantOptions->Tools->FileSearch->Enabled = true;

oAssistant->OnStreamMessageDelta = AssistantDelta;
oAssistant->CreateAssistant();

TsgcOpenAIClass_Thread *oThread = oAssistant->CreateThread();
oAssistant->CreateMessageText(oThread->Id, "How do I reset the device?");
oAssistant->CreateRunAndWait(oThread->Id, 60000, true);

Key properties & methods

The members you reach for most often.

AssistantOptions

Name, Model, Instructions, Temperature and TopP describe the assistant. Tools.FileSearch, Tools.CodeInterpreter and Tools.Functions enable the built-in and custom tools.

Assistants

CreateAssistant, GetAssistant and ListAssistants manage the assistant definitions on your OpenAI account.

Threads and messages

CreateThread and GetThread open a conversation. CreateMessageText posts a turn and GetMessages pages through the transcript with limit, order and cursor arguments.

Runs

CreateRun starts a run, GetRun polls it and CreateRunAndWait blocks until it finishes with a timeout. Any of them can be streamed.

UploadVectorStoreFile adds a document to a named vector store and GetVectorStoreFiles lists what is already there, which is how the assistant grounds its answers in your own files.

Events

OnStreamMessage, OnStreamMessageDelta, OnStreamRun, OnStreamError and OnStreamDone follow a streamed run. OnFunctionCall dispatches tool calls to your code.

Voice front-end

The component also accepts an AudioRecorder and a TextToSpeech link, so the same assistant can be driven by speech instead of typed input.

Specifications & references

Authoritative sources for the services and protocols this component uses.

Keep exploring

Online HelpFull API reference and usage guide for the sgcAI components.
All sgcAI ComponentsBrowse the full feature matrix of all 15 components.
Download Free TrialBuild a tool-using assistant against your own OpenAI key.
PricingSingle, Team and Site licenses, full source code, no base product required.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Get Started?

Download the free trial and give your application an agent with tools and your own documents.