createPrompt static method

BasePromptTemplate createPrompt({
  1. SystemChatMessagePromptTemplate systemChatMessage = _systemChatMessagePromptTemplate,
  2. List<ChatMessagePromptTemplate>? extraPromptMessages,
  3. BaseChatMemory? memory,
})

Creates prompt for this agent.

It takes care of adding the necessary placeholders to handle the intermediary work of the agent or the memory.

  • systemChatMessage message to use as the system message that will be the first in the prompt.
  • extraPromptMessages prompt messages that will be placed between the system message and the new human input.
  • memory optional memory to use for the agent.

Implementation

static BasePromptTemplate createPrompt({
  final SystemChatMessagePromptTemplate systemChatMessage =
      _systemChatMessagePromptTemplate,
  final List<ChatMessagePromptTemplate>? extraPromptMessages,
  final BaseChatMemory? memory,
}) {
  return ChatPromptTemplate.fromPromptMessages([
    systemChatMessage,
    ...?extraPromptMessages,
    for (final memoryKey in memory?.memoryKeys ?? {})
      MessagesPlaceholder(variableName: memoryKey),
    const MessagePlaceholder(variableName: agentInputKey),
    if (memory == null)
      const MessagesPlaceholder(
        variableName: BaseActionAgent.agentScratchpadInputKey,
      ),
  ]);
}