Optionaloptions: FilterMessagesFieldsOptional filtering options. Should only be provided if messagesOrOptions is an array of BaseMessage objects.
A list of Messages that meets at least one of the include conditions and none of the exclude conditions, or a RunnableLambda which does the same. If no include conditions are specified then anything that is not explicitly excluded will be included.
If two incompatible arguments are provided.
import { filterMessages, AIMessage, HumanMessage, SystemMessage } from "@langchain/core/messages";
const messages = [
  new SystemMessage("you're a good assistant."),
  new HumanMessage({ content: "what's your name", id: "foo", name: "example_user" }),
  new AIMessage({ content: "steve-o", id: "bar", name: "example_assistant" }),
  new HumanMessage({ content: "what's your favorite color", id: "baz" }),
  new AIMessage({ content: "silicon blue" , id: "blah" }),
];
filterMessages(messages, {
  includeNames: ["example_user", "example_assistant"],
  includeTypes: ["system"],
  excludeIds: ["bar"],
});
The above example would return:
[
  new SystemMessage("you're a good assistant."),
  new HumanMessage({ content: "what's your name", id: "foo", name: "example_user" }),
]
Optionaloptions: FilterMessagesFields
Filter messages based on name, type or id.