OpenAI Assistants API
Key Features
The Assistants API allows building AI assistants that can:
- Leverage models, tools and knowledge to respond to users
- Use tools like Code Interpreter and Retrieval
- Store conversation history in persistent Threads
- Invoke assistants on threads via Runs
Usage Flow
- Create an Assistant
- Create a Thread for user conversation
- Add Messages to the Thread
- Make a Run to trigger Assistant response
- Show Assistant replies in the UI
Core Objects
- Assistant - The customizable AI entity
- Thread - Conversation between an assistant and user
- Message - A message in a thread
- Run - An invocation of a thread with an assistant
Creating Assistants
Assistants are configured via parameters like:
- Instructions - Guide assistant personality and goals
- Model - Specify GPT models to use
- Tools - Enable tools like Code Interpreter
Managing Threads
Threads store conversation history between assistant and user:
- Create one thread per user
- Add unlimited messages to thread
- Thread handles context truncation automatically
Making Runs
Runs invoke assistants on threads:
- Trigger assistant to read thread and respond
- Can customize model and tools per run
- Inspect run steps to see assistant's work
Built-in Tools
Tools like:
- Code Interpreter - Write and run Python code
- Retrieval - Incorporate external knowledge
- Function Calling - Call custom functions