Skip to content

Commit

Permalink
Adding lecture notes
Browse files Browse the repository at this point in the history
  • Loading branch information
ajosh0504 committed Jun 14, 2024
1 parent b58fb7c commit beced3a
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 1 deletion.
57 changes: 56 additions & 1 deletion docs/10-ai-agents/3-components-of-agents.mdx
Original file line number Diff line number Diff line change
@@ -1 +1,56 @@
# 📘 Components of AI agents
# 📘 Components of AI agents

AI agents have three main components: **planning and reasoning**, **memory**, and **tools**.


## Planning and reasoning

AI agents use user prompts, self-prompting and feedback loops to break down complex tasks, reason through their execution plan and refine it as needed.

Some common design patterns for planning and reasoning in AI agents are as follows:

### Chain of Thought (Cot) Prompting

In this approach, the LLM is prompted to generate a step-by-step explanation or reasoning process for a given task or problem.

Here is an example of a zero-shot CoT prompt:

> Given a question, write out in a step-by-step manner your reasoning for how you will solve the problem to be sure that your conclusion is correct. Avoid simply stating the correct answer at the outset.
### ReAct (Reason + Act)

In this approach, the LLM is prompted to generate reasoning traces and task-specific actions in an interleaved manner, allowing for greater synergy between the two: reasoning traces help the model induce, track, and update action plans, while actions allow it to interface with external sources or tools, to gather additional information.

Here is an example of a ReAct prompt:

```
Answer the following questions as best you can. You have access to the following tools:{tools}
##
Use the following format:
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
```

### Reflection

Reflection involves prompting an LLM to reflect on and critique past actions, sometimes incorporating additional external information such as tool observations. The generation-reflection loop is run several times before returning the final response to the user. Reflection trades a bit of extra compute for a shot at better output quality.

## Memory

The memory component allows AI agents to store and recall past conversations, enabling them to learn from these interactions.

There are two main types of memory for AI agents:

* **Short-term memory**: Stores and retrieves information from a specific conversation.

* **Long-term memory**: Stores, retrieves and updates information based on multiple conversations had over a period of time.

## Tools

Tools are interfaces for AI agents to interact with the external world and achieve their objectives. These can be APIs, vector databases, or even specialized ML models.
33 changes: 33 additions & 0 deletions docs/50-agent-tools/1-concepts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 📘 Tools, libraries, and concepts

Here is a quick overview of tools, libraries and concepts that you will come across in this section of the lab:

## [datasets](https://huggingface.co/docs/datasets/en/index)

Library used to download a dataset of Arxiv papers from Hugging Face.

## [ArxivLoader](https://python.langchain.com/v0.2/docs/integrations/document_loaders/arxiv/)

Document loader class in LangChain that used to load research papers from Arxiv.org as LangChain Document objects.

## [PyMongo](https://pymongo.readthedocs.io/en/stable/)

Python driver for MongoDB. Used to connect to MongoDB databases, delete and insert documents into a MongoDB collection.

## LangChain integrations

Standalone `langchain-{provider}` packages for improved versioning, dependency management and testing. You will come across the following in this lab:

* [langchain-mongodb](https://python.langchain.com/v0.2/docs/integrations/providers/mongodb_atlas/): Used to create a MongoDB Atlas vector store and also to store and retrieve chat message history from MongoDB

* [langchain-huggingface](https://python.langchain.com/v0.2/docs/integrations/platforms/huggingface/): To access open-source embedding models from HuggingFace

* [langchain-fireworks](https://python.langchain.com/v0.2/docs/integrations/providers/fireworks/): To use Firework AI's chat completion models

## [LangChain Expression Language (LCEL)](https://python.langchain.com/v0.1/docs/expression_language/)

LCEL provides a declarative way to chain together prompts, data processing steps, calls to LLMs, and tools. Each unit in a chain is called a Runnable and can be invoked, streamed and transformed on its own.

## [Retriever](https://python.langchain.com/v0.1/docs/modules/data_connection/retrievers/)

In LangChain, a retriever is an interface that returns documents given an unstructured query. It is a Runnable that can be used on its own or as a part of a chain.
File renamed without changes.
37 changes: 37 additions & 0 deletions docs/60-create-agents/1-concepts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 📘 Tools, libraries, and concepts

Here is a quick overview of tools, libraries and concepts that you will come across in this section of the lab:

## [create_tool_calling_agent](https://api.python.langchain.com/en/latest/agents/langchain.agents.tool_calling_agent.base.create_tool_calling_agent.html)

LangChain abstraction to create a basic tool-calling agent. It is essentially a sequence of Runnables that represents an agent:

```
(
RunnablePassthrough.assign(
agent_scratchpad=lambda x: format_to_tool_messages(x["intermediate_steps"])
)
| prompt
| llm_with_tools
| ToolsAgentOutputParser()
)
```

## [create_react_agent](https://api.python.langchain.com/en/latest/agents/langchain.agents.react.agent.create_react_agent.html)

LangChain abstraction to create a ReAct agent. It is essentially a sequence of Runnables that represents a ReAct agent:

```
(
RunnablePassthrough.assign(
agent_scratchpad=lambda x: format_to_tool_messages(x["intermediate_steps"])
)
| react_prompt
| llm_with_stop
| ReActSingleInputOutputParser()
)
```

## [AgentExecutor](https://api.python.langchain.com/en/latest/agents/langchain.agents.agent.AgentExecutor.html)

AgentExecutor is the runtime for an agent in LangChain. It is responsible for calling the agent, executing the actions it chooses, passing action outputs back to the agent, and repeating actions as needed.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions docs/70-adding-memory/1-concepts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 📘 Tools, libraries, and concepts

Here is a quick overview of tools, libraries and concepts that you will come across in this section of the lab:

## [RunnableWithMessageHistory](https://api.python.langchain.com/en/latest/runnables/langchain_core.runnables.history.RunnableWithMessageHistory.html)

Runnable that manages (reads, updates) chat message history for another Runnable. By default, it organizes chat history based on a session ID.
File renamed without changes.
Binary file added static/img/screenshots/10-ai-agents/react.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit beced3a

Please sign in to comment.