Skip to content

Commit

Permalink
Merge pull request #2 from mongodb-developer/langgraph_updates
Browse files Browse the repository at this point in the history
LangGraph updates
  • Loading branch information
ajosh0504 authored Oct 31, 2024
2 parents 6f606d7 + d971245 commit 2c15f3c
Show file tree
Hide file tree
Showing 52 changed files with 446 additions and 645 deletions.
4 changes: 3 additions & 1 deletion docs/10-ai-agents/1-what-are-ai-agents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

An AI agent is a system that uses an LLM to **reason** through a problem, create a **plan** to solve the problem, and **execute** the plan with the help of a set of tools.

In agentic systems, one or multiple LLMs go through multiple iterations of reasoning and action-taking to reach the final answer to a user question. This means agents can handle complex, multi-step queries, and also self-revise and refine responses.
In multi-agent systems, two or more agents collaborate or orchestrate and delegate tasks to solve problems.

This way, agentic systems can handle complex, multi-step queries, and also self-revise and refine responses.
2 changes: 1 addition & 1 deletion docs/30-fireworks-ai/1-create-account.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Screenshot from "@site/src/components/Screenshot";

# 👐 Create an account

In this lab, we will use _FireFunction V1_, a free and open-source function calling model from Fireworks AI.
In this lab, we will use _FireFunction V2_, a free and open-source function calling model from Fireworks AI.

The easiest way to use this model is via the Fireworks API. But first, you will need to create a Fireworks account. **If you already have an account, you can skip the following steps and move on to the next section.**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ You will be working in a Jupyter Notebook throughout this lab. The easiest and r

Navigate to the notebook on [GitHub](https://github.com/mongodb-developer/ai-agents-lab-notebooks/blob/main/notebook_template.ipynb) and click the **Open in Colab** badge at the top of the notebook to open it in Google Colab.

<Screenshot url="https://github.com/mongodb-developer/ai-agents-lab-notebooks" src="img/screenshots/50-dev-env/1-open-colab.png" alt="Open in Colab" />
<Screenshot url="https://github.com/mongodb-developer/ai-agents-lab-notebooks" src="img/screenshots/40-dev-env/1-open-colab.png" alt="Open in Colab" />

:::tip
The notebook will open in Google Colab in read-only mode. Please **make a copy of the notebook** to keep the code changes you will make during this workshop for future reference.
Expand All @@ -16,7 +16,11 @@ To do this, choose one of the **Save a copy** options in the **File** menu.

That's it! You're ready for the lab!

## Local setup
## [Backup] Local setup

:::caution
Run the notebook locally ONLY IF Google Colab is not an option/doesn't work for you.
:::

If you want to run the notebook locally, follow the steps below:

Expand Down Expand Up @@ -48,4 +52,4 @@ jupyter notebook

* In the browser tab that pops up, open the notebook named `notebook_template.ipynb`.

<Screenshot url="localhost:8888/tree" src="img/screenshots/50-dev-env/2-jupyter-notebook.png" alt="Jupyter Notebook" />
<Screenshot url="localhost:8888/tree" src="img/screenshots/40-dev-env/2-jupyter-notebook.png" alt="Jupyter Notebook" />
3 changes: 3 additions & 0 deletions docs/40-dev-env/2-setup-pre-reqs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 👐 Setup prerequisites

Fill in any placeholders and run the cells under the **Step 1: Install libraries** and **Step 2: Setup prerequisites** sections in the notebook.
File renamed without changes.
17 changes: 0 additions & 17 deletions docs/40-langsmith/1-create-account.mdx

This file was deleted.

15 changes: 0 additions & 15 deletions docs/40-langsmith/2-create-api-key.mdx

This file was deleted.

8 changes: 0 additions & 8 deletions docs/40-langsmith/_category_.json

This file was deleted.

31 changes: 31 additions & 0 deletions docs/50-agent-tools/1-concepts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 📘 Concepts

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

## Tool calling

Tool calling, interchangeably called function calling allows an LLM to use external tools such as APIs, databases, specialized machine learning models etc.

In AI agents, an LLM can have access to multiple tools. Given a user query, the LLM decides which tool to invoke and the arguments for the tool call. These arguments are used to execute the tool call and the output is returned back to the LLM to inform its next steps.

The easiest way to define tools in LangChain is using the `@tool` decorator. The decorator makes tools out of functions by using the function name as the tool name by default, and the function's docstring as the tool's description. The tool call inturn consists of a tool name, arguments, and an optional identifier.

An example of a tool in LangChain is as follows:

```
@tool("search-tool", return_direct=True)
def search(query: str) -> str:
"""Look up things online."""
return "MongoDB"
```
An example of a tool call is as follows:

```
{
"name": "search-tool",
"args": {
"query": "What is MongoDB?"
},
"id": "call_H5TttXb423JfoulF1qVfPN3m"
}
```
7 changes: 7 additions & 0 deletions docs/50-agent-tools/2-import-data.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 👐 Import data

The MongoDB learning assistant has two tools- a vector search tool to retrieve information to answer questions about MongoDB, and another tool to get the content of articles in our Developer Center for summarization.

Let's import the data required by these tools into two MongoDB collections. This is as simple as making a `GET` request to a serverless function that we have created for you.

Run the cells under the **Step 3: Import data** section in the notebook to import the data required by our agent's tools, into MongoDB collections.
29 changes: 29 additions & 0 deletions docs/50-agent-tools/3-create-vector-search-index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 👐 Create a vector search index

To retrieve documents using vector search, you must configure a vector search index on the collection you want to perform vector search against.

Fill in any `<CODE_BLOCK_N>` placeholders and run the cells under the **Step 4: Create a vector search index** section in the notebook to create a vector search index.

The answers for code blocks in this section are as follows:

**CODE_BLOCK_1**

<details>
<summary>Answer</summary>
<div>
```python
mongodb_client[DB_NAME][VS_COLLECTION_NAME]
```
</div>
</details>

**CODE_BLOCK_2**

<details>
<summary>Answer</summary>
<div>
```python
vs_collection.create_search_index(model=model)
```
</div>
</details>
118 changes: 118 additions & 0 deletions docs/50-agent-tools/4-create-agent-tools.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# 👐 Create agent tools

The easiest way to define custom tools for agents in LangChain is using the `@tool` decorator. The decorator makes tools out of functions by using the function name as the tool name by default, and the function's docstring as the tool's description.

We want the MongoDB learning assistant to have access to the following tools:

* `get_information_for_question_answering`: Uses vector search to retrieve information to answer questions

* `get_article_content_for_summarization`: Gets the content of articles for summarization

Fill in any `<CODE_BLOCK_N>` placeholders and run the cells under the **Step 5: Create agent tools** section in the notebook to create tools for the agent to use.

The answers for code blocks in this section are as follows:

**CODE_BLOCK_3**

<details>
<summary>Answer</summary>
<div>
```python
embedding_model.encode(text)
```
</div>
</details>

**CODE_BLOCK_4**

<details>
<summary>Answer</summary>
<div>
```python
get_embedding(user_query)
```
</div>
</details>

**CODE_BLOCK_5**

<details>
<summary>Answer</summary>
<div>
```python
[
{
"$vectorSearch": {
"index": VS_INDEX_NAME,
"path": "embedding",
"queryVector": query_embedding,
"numCandidates": 150,
"limit": 5,
}
},
{
"$project": {
"_id": 0,
"body": 1,
"score": {"$meta": "vectorSearchScore"},
}
},
]
```
</div>
</details>

**CODE_BLOCK_6**

<details>
<summary>Answer</summary>
<div>
```python
vs_collection.aggregate(pipeline)
```
</div>
</details>

**CODE_BLOCK_7**

<details>
<summary>Answer</summary>
<div>
```python
mongodb_client[DB_NAME][FULL_COLLECTION_NAME]
```
</div>
</details>

**CODE_BLOCK_8**

<details>
<summary>Answer</summary>
<div>
```python
{"title": user_query}
```
</div>
</details>

**CODE_BLOCK_9**

<details>
<summary>Answer</summary>
<div>
```python
{"_id": 0, "body": 1}
```
</div>
</details>

**CODE_BLOCK_10**

<details>
<summary>Answer</summary>
<div>
```python
full_collection.find_one(query, projection)
```
</div>
</details>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"position": 6,
"link": {
"type": "generated-index",
"description": "Create tools for the AI research agent."
"description": "Create tools for the agent."
}
}
3 changes: 0 additions & 3 deletions docs/50-dev-env/2-setup-pre-reqs.mdx

This file was deleted.

33 changes: 0 additions & 33 deletions docs/60-agent-tools/1-concepts.mdx

This file was deleted.

51 changes: 0 additions & 51 deletions docs/60-agent-tools/2-knowledge-base.mdx

This file was deleted.

Loading

0 comments on commit 2c15f3c

Please sign in to comment.