Advanced API
In addition to the fundamental methods new CortexStep(name)
, withMemory
, and next
, the CortexStep
class offers a set of advanced capabilities to gain more control over the behavior of the AI's internal monologue. This page explains how to use these advanced features.
Full Constructor Signature
The CortexStep
class accepts an optional CortexStepOptions
object in the constructor. This allows you to provide past steps, a processor, initial memories, or a last generated value.
constructor(entityName: string, options?: CortexStepOptions)
The CortexStepOptions
object includes:
pastCortexStep
: ACortexStep
instance representing the previous step.processor
: ALanguageModelProgramExecutor
instance handling the execution of language model instructions.memories
: An array ofWorkingMemory
instances representing initial memories.lastValue
: The last generated value.id
: a unique identifier of this particular cortext stepparents
: used to keep track of previous cortext steps in a chaintags
: keeps tags on a cortex step that are added to instrumentation calls.
let step = new CortexStep("Assistant", {
pastCortexStep: previousStep,
processor: new OpenAILanguageProgramProcessor(),
memories: [[{ role: "system", content: "You are a helpful assistant." }]],
lastValue: "Solved a complex math problem",
});
Other Methods
toString()
toString()
generates a string representation of the assistant's chat history, including system instructions, user queries, and assistant responses.
let stringRepresentation = step.toString();
Understanding and Utilizing The Value Property
CortexStep
has a value
property which represents the output generated from the last action. This value
is strongly typed depending on the evaluated Cognitive Function.
This value
can be very useful in chaining actions where the output of one action might influence or be used in the next action. To access this value
, simply use:
let value = step.value;
Remember, the CortexStep
class is designed to be functional - that is, none of its methods alter the state of the existing instance. Instead, they return a new instance with the updated state. This design allows for easy chaining of actions and states while maintaining immutability.