Prompt templates help to translate user input and parameters into instructions for a language model. This can be used to guide a model’s response, helping it understand the context and generate relevant and coherent language-based output.
types of prompt templates
String PromptTemplates
ChatPromptTemplates
These prompt templates are used to format a list of messages.
Chains
chains has support invoke, ainvoke, stream, astream, batch, abatch, astream_log calls
Sequential Chain
A sequential chain is a chain that combines various individual chains, where the output of one chain serves as the input for the next in a continuous sequence. It operates by running a series of chains consecutively.
Parallel Chain
After parallel chain it will return as dict of branches that we provided in to get the the output of that use x["branches"]["pros"]
Chain branching
based on the condition we can choose which branch we can choose for further operation
internal of chains
Agent
Type of agent
ChatAgent
ConversationalAgent
ConversationalChatAgent
OpenAIAssistantFinish
OpenAIFunctionsAgent
create_react_agent
LLMAgent
RetrievalAgent
HybridAgent
ChainAgent
AgentExecutor
is a component that executes an agent’s logic to generate a response to a given input. It’s responsible for managing the agent’s lifecycle, handling input and output, and providing a way to customize the agent’s behavior.
An AgentExecutor is typically used to wrap an Agent instance and provide additional functionality, such as:
Input processing: The AgentExecutor can preprocess the input data before passing it to the agent.
Output processing: The AgentExecutor can postprocess the agent’s output before returning it to the caller.
Error handling: The AgentExecutor can catch and handle errors raised by the agent during execution.
Context management: The AgentExecutor can manage the agent’s context, such as maintaining a conversation history or storing intermediate results.
Customization: The AgentExecutor can provide hooks for customizing the agent’s behavior, such as injecting additional data or modifying the agent’s parameters
AgentExecutor has _call function which is called by the chain and the call function will be responsible for communicating with agent
Retrievers
BM25 retriever: This retriever uses the BM25 algorithm to rank documents based on their relevance to a given query
TF-IDF retriever: This retriever uses the TF-IDF (Term Frequency-Inverse Document Frequency) algorithm to rank documents based on the importance of terms in the document collection
Dense retriever: This retriever uses dense embeddings to retrieve documents. It encodes documents and queries into dense vectors, and calculates the similarity between them using cosine similarity or other distance metrics.
kNN retriever: This utilizes the well-known k-nearest neighbors algorithm to retrieve relevant documents based on their similarity to a given query.
Memory
Conversation buffers
Unlike ConversationBufferMemory , which retains all previous interactions, ConversationBufferWindowMemory only keeps the last k interactions, where k is the window size specified
ZepMemory
Zep persists and recalls chat histories, and automatically generates summaries and other artifacts from these chat histories. It also embeds messages and summaries, enabling you to search Zep for relevant context from past conversations. Zep does all of this asyncronously, ensuring these operations don’t impact your user’s chat experience. Data is persisted to database, allowing you to scale out when growth demands.
Output Parser
PydanticOutputParser
Langgraph
State and graph is core concepts in langgraph
State is dict the data used by agent will be write or read.
In graph each node is agent or tools and the edges connect nodes determine sequence of ops