Demo
To demonstrate how to configure and use AI Assistants we are going to be using a sample project with a database full of movies.Creating AI Assistants
The first step is to create an AI assistant. You can create an AI assistant by utilizing theinsertAssistant
mutation or by using the dashboard. For instance:

Tools
In order to enhance our AI assistants we are leveraging tools. Tools can be either queries or mutations performed against your project’s GraphQL engine or they can also be any arbitrary endpoint you choose. Using the example above, we added 4 different tools to our AI Assistant:- The GraphQL query
GetMoviesWithScoreHigherThan
, which will allow the AI Assistant to query movies based on their score. - The GraphQL query
SearchMovies
, which leverages auto-embeddings and will allow the AI Assistant to query movies using natural language. - The GraphQL mutation
InsertMovie
, which will let the AI Assistant to insert new movies directly into the database. - The webhook
answer_deep_questions
, which is a serverless function that can respond to deep questions about life and the universe.
- ChatGPT doesn’t actually query the data or perform any action, it tells graphite to execute the tools on its behalf and provide the result.
- graphite will respect the user session when calling tools so permissions are respected.
- GraphQL queries and mutations are performed against the project’s GraphQL endpoint
- For webhooks you can specify any URL you want and graphite will perform a POST with a JSON object as body
Starting a session
To start a session you can use the mutationstartSession
and pass the id of the assistant you want to use. For instance, to start a session using the assistant we created in the previous section:
Interacting with the Assistant
Now that you have started a session you can send your first message:prevMessageID
is used to only return messages after this one. As this is the beginning of the conversation we send an empty string to get all messages back. After executing that mutation we should receive a response like:
answer_deep_questions
so this is roughly what happened:

prevMessageID
:
GetMoviesWithScoreHigherThan
so it requested graphite to run the query and return the data. This is what happened:

Implementing workflows
Interactions are not limited to just one tool or to simply query data. Tools can be combined and they can perform any action you wish. For instance, let’s take a look to the following session:- We asked about comedies in space, which prompted the AI Assistant to leverage tool
SearchMovies
, which leverages auto-embeddings to perform searches using natural language. - Then we asked the Assistant to imagine a sequel and insert it in the database, which prompted the AI assistant to leverage the tool
InsertMovie
to add it to the database.
User session
Interacting with graphite requires a user session (either an Authorization header or the admin secret). When interacting with the GraphQL endpoint or the webhook, graphite will re-use this session, which means that the webhook can use these headers to authorize the request. It also means that the GraphQL query will be performed as the user, so the user will have to have permissions to perform the query and will only get data the user has access to.Other GraphQL queries/mutation
In addition to the queries/mutations shown in this document there are other mutations for listing, deleting and updating assistants, sessions, etc. We recommend you to check the GraphQL schema to see what’s available.Metadata and Permissions
For each assistant and session managed by graphite, a row in the tablesgraphite.assistants
and graphite.sessions
will be made available. The purpose of this metadata is to allow you to set permissions as with any other object in your project. For details on which permissions are needed for each specific query and mutation refer to the GraphQL documentation in the reference section.