Cortex

Cortexes are AI agents that can be easily customized to accomplish specific tasks. Cortexes can be customized with custom instructions about the task it should accomplish, and catalogs of documents that it has access to when generating content and answers.

Create or update a cortex

Cortexes are created and updated through the same configureCortex method available on the client:

const cortex = await client.configureCortex("slack-support", {
  // data sources that this cortex has access to when generating responses
  catalogs: ["docs", "previous-support-cases"],
  friendlyName: "ACME Support",
  instructions: [
    "You will recieve messages from users that are asked via Slack. Respond to their questions to the best of your ability.",
    "When appropriate, provide links to help articles",
    'If you cannot answer a question, or sense that the user becomes frustrated, send a reponse with "@acme-support please engage"',
  ],
  public: true,
  customizations: {
    rules: ["never offer any discounts or information on pricing"],
  },
});

Cortex configuration reference

CortexConfig

The CortexConfig type defines the configuration options for a Cortex instance.

FieldTypeDescription
friendlyNamestringThe name that this Cortex should refer to itself as (e.g., "Acme Assistant", "Acme AI").
catalogsstring[](Optional) The catalogs that should be referenced when generating content and answering questions.
instructionsstring[]A complete description of the goal task and a list of steps this cortex should follow when generating content and answering questions.
publicbooleanWhether or not this Cortex should be available on the internet without authentication. Common for scenarios like publishing blog content and customer support.
customizationsobject(Optional) Fine-tuned control over the verbosity, tone, and rules used to generate content.
chatConfigobject(Optional) Configuration for the embedded hosted chat UI.
overridesobject(Optional) Override org-level defaults.

CortexConfig.customizations

FieldTypeDescription
rulesstring[](Optional) A list of "dos and don'ts" that the cortex should follow.
personalitystring[](Optional) Personality traits or characteristics for the cortex.

CortexConfig.chatConfig

FieldTypeDescription
greetingstringThe initial greeting message rendered in chat.
introstringAn introductory message that explains the purpose of this Cortex and what it can help with.
examplesstring[]A list of questions that will be rendered and suggested to users when they load the chat window.

CortexConfig.overrides

FieldTypeDescription
inheritRulesboolean(Optional) Whether or not global org-level rules should be followed. Defaults to 'true'.
companyNamestring(Optional) The company name.
companyInfostring(Optional) A description of your company, industry, and products and services provided.

Get a cortex

const cortex = await client.getCortex("support-engineer");

Chat

The Cortex class exposes convenient methods for starting a streaming or synchornous chat:

Streaming chat

To stream chat responses, set the stream parameter to true:

const cortex = await client.getCortex("support-engineer");
 
// ask questions and stream responses
const streamingChatResponse = await cortex.chat({
  message: "What kind of hammers are best to use on my ACME anvil?",
  stream: true,
});
streamingChatResponse.responseStream.on("data", (data) => {
  process.stdout.write(data.toString());
});
 
const chat = await streamingChatResponse.chat;
 
// respond to chats maintaining memory of previous responses
const respondResponse = await chat.respond({
  message: "Is it safe to use my copper mallet hammer on my anvil?",
  stream: true,
});
respondResponse.responseStream.on("data", (data) => {
  process.stdout.write(data.toString());
});
 
await respondResponse.chat;

Synchronous chat

const cortex = await client.getCortex("support-engineer");
 
const chat = await cortex.chat({
  message: "What kind of hammers are best to use on my ACME anvil?",
});
 
console.log(JSON.stringify(chat.messages));
 
await chat.respond({
  message: "Is it safe to use my copper mallet hammer on my anvil?",
});

Generate content

The Cortex class exposes methods for generating content via streaming and synchronous methods:

Streaming content generation

To stream content as it is generated, set the stream parameter to true:

const title = "Building a Support Slackbot for your Online Community";
const prompt = `Write a blog post about using the Cortex Click SDK to index developer documentation, 
into a catalog, create a cortex that consumes it, and finally auto-repsonds to community questions in slack with answers.
`;
 
let contentStream = await cortex.generateContent({
  title,
  prompt,
  stream: true,
});
 
contentStream.contentStream.on("data", (data) => {
  process.stdout.write(data);
});
 
let content = await contentStream.content;

Synchronous content generation

const title = "Building a Support Slackbot for your Online Community";
const prompt = `Write a blog post about using the Cortex Click SDK to index developer documentation, 
into a catalog, create a cortex that consumes it, and finally auto-repsonds to community questions in slack with answers.
`;
 
let blogPost = await cortex.generateContent({
  title,
  prompt,
});
 
console.log(blogPost.content);