Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-guide-for-chat-protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamgambhir97 authored Dec 20, 2024
2 parents 9a3c295 + 1f94e76 commit 183ed07
Show file tree
Hide file tree
Showing 27 changed files with 455 additions and 225 deletions.
6 changes: 1 addition & 5 deletions pages/examples/agentverse/mailbox-agents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,11 @@ Please check out the example code in our [examples repo ↗️](https://github.c
# First generate a secure seed phrase (e.g. https://pypi.org/project/mnemonic/)
SEED_PHRASE = "put_your_seed_phrase_here"

# Now go to https://agentverse.ai, register your agent in the Mailroom by providing the address you just copied.
# Then, copy the agent's mailbox key and insert it here below inline
AGENT_MAILBOX_KEY = "put_your_AGENT_MAILBOX_KEY_here"

# Now your agent is ready to join the agentverse!
agent = Agent(
name="alice",
seed=SEED_PHRASE,
mailbox=f"{AGENT_MAILBOX_KEY}@https://agentverse.ai",
mailbox=True
)

fund_agent_if_low(agent.wallet.address())
Expand Down
22 changes: 9 additions & 13 deletions pages/guides/agent-courses/agents-for-ai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,11 @@ We can do this by running:


SEED_PHRASE = ""
AGENT_MAILBOX_KEY = ""

sentimentagent = Agent(
name="SentimentAgent", # or any name
seed=SEED_PHRASE,
mailbox=f"{AGENT_MAILBOX_KEY}@https://agentverse.ai",
mailbox=True,
)

print(sentimentAgent.address)
Expand Down Expand Up @@ -190,7 +189,7 @@ We can do this by running:


<Callout type="warning" emoji="⚠️">
Remember that you need to provide the `SEED_PHRASE`, `AGENT_MAILBOX_KEY`, `name`, `seed` and `mailbox` parameters to correctly run this example.
Remember that you need to provide the `SEED_PHRASE`, `name`, `seed` and `mailbox` parameters to correctly run this example.
</Callout>

Okay, we've got the whole code block above for our first agent. Have a look at list of available packages on the Agentverse [here ↗️](/guides/agentverse/allowed-imports) to get started with Agents development on the Agentverse.
Expand Down Expand Up @@ -239,18 +238,16 @@ There are a lot of really cool, neat things you need to know from code above. Le

- `SEED_PHRASE` is our agents unique seed.

- `AGENT_MAILBOX_KEY` mailbox key is our ID of our mailbox hosted on Agentverse.

- `OPENAI_API_KEY` is our API key to OpenAI's APIs.

We can now initialize the Agent and define the [Protocol ↗️](/references/uagents/uagents-protocols/agent-protocols). To read more about **Agent objects**, please check out [the reference docs ↗️](/references/uagents/uagents-api/agent#agent-objects).

Then, we have the **on_message()** [handler ↗️](/guides/agents/intermediate/handlers):
Then, we have the `on_message()` [handler ↗️](/guides/agents/intermediate/handlers):

<GithubCodeSegment digest="4062beca9a7cafff6002e8e8ff9c7a28">
<CodeSegment
path="https://github.com/fetchai/uAgent-Examples/blob/main/5-documentation/guides/agent-courses/agents-for-ai/sentiment_agent.py"
lineStart={35}
lineStart={34}
lineEnd={40}
hosted={true}
/>
Expand Down Expand Up @@ -285,7 +282,7 @@ We can finally run the Agent at the bottom of the script:
<GithubCodeSegment digest="669ae61db8d1e79422c0db593b959609">
<CodeSegment
path="https://github.com/fetchai/uAgent-Examples/blob/main/5-documentation/guides/agent-courses/agents-for-ai/sentiment_agent.py"
lineStart={43}
lineStart={42}
lineEnd={44}
hosted={true}
/>
Expand Down Expand Up @@ -414,7 +411,7 @@ The next agent in the chain is the **Summary agent**. Let's name the script `web
```py copy filename="ubuntu"
touch web_sentiment_agent.py
```
</DocsCode>
</DocsCode>

</CodeGroup>

Expand Down Expand Up @@ -449,13 +446,12 @@ Let's take a look.


SEED_PHRASE = "<your_seed_phrase>"
AGENT_MAILBOX_KEY = "<your_mailbox_key>"
OPENAI_API_KEY = "<your_open_ai_key>"

summaryAgent = Agent(
name="SummaryAgent",
seed=SEED_PHRASE,
mailbox=f"{AGENT_MAILBOX_KEY}@https://agentverse.ai",
mailbox=True,
)

summary_protocol = Protocol("Text Summariser")
Expand Down Expand Up @@ -511,7 +507,7 @@ Let's take a look.


<Callout type="warning" emoji="⚠️">
Remember that you need to provide the `SEED_PHRASE`, `AGENT_MAILBOX_KEY`, `OPENAI_API_KEY`, `name`, `seed` and `mailbox` parameters to correctly run this example.
Remember that you need to provide the `SEED_PHRASE`, `OPENAI_API_KEY`, `name`, `seed` and `mailbox` parameters to correctly run this example.
</Callout>

This Agent is simple again, hopefully you're seeing a pattern here. These Agents while independent of each other can
Expand All @@ -523,7 +519,7 @@ compliment one another.

Aside from the different logic, the primary difference in `web_summary_agent.py` is that this agent does not rely on a separate function, and wraps the whole logic in the message handler.

Let's run this one too. Again, follow the steps for the previous Agent and go and register a Mailbox and update this agent with the new Mailbox. Each agent must have a unique [Mailbox ↗️](/guides/agents/intermediate/mailbox).
Let's run this one too. Again, follow the steps for the previous Agent and go and connect it via a Mailbox Each agent must have a unique [Mailbox ↗️](/guides/agents/intermediate/mailbox)!

## One more Agent Function 🎵

Expand Down
4 changes: 4 additions & 0 deletions pages/guides/agents/intermediate/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
"chat-protocol": {
"title": "Chat protocol",
"tags": ["Intermediate", "Python", "protocols", "fetch.ai SDK"],
},
"search-agent": {
"title": "Search Agent",
"tags": ["Intermediate", "Python", "Search", "Local"],
"timestamp": true
}
}
26 changes: 18 additions & 8 deletions pages/guides/agents/intermediate/agent-functions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,29 @@ Finally, we run our agent as follows: `python simple_function.py`

For this example we set up a really simple Agent Function. For further information on Agent Functions and registration process, see [Register Agent Functions on the Agentverse ↗️](/guides/agentverse/registering-agent-services) resource.

To register **Local Agents and Functions**, you will first need to log in the [Agentverse ↗️](https://agentverse.ai/) and head over to the **My Agents** tab. Then, click on **Local Agents** tab and click one of the **Connect Local Agent** buttons.
To register **Local Agents and Functions**, you will first need to head over to the [local Agent Inspector ↗️](/guides/agents/intermediate/local-agent-inspector) available by clicking on the dedicated link presented within your terminal output after running the above local Agent. Once you do so, click on **Connect** button and select **Mailbox**. Follow the steps closely and provide all needed data required.

![](src/images/guides/uagent/servicefordungeons_1.png)
![](src/images/guides/agentverse/mailbox/agentverse:mailbox/mailbox_1a.png)

You will need to provide the **local agent address** and make sure it is running on your terminal as only running agents can enroll Agent Functions on the Agentverse!
![](src/images/guides/agentverse/mailbox/agentverse:mailbox/mailbox_2a.png)

![](src/images/guides/uagent/servicefordungeons_2.png)
After this, click **Connect**.

![](src/images/guides/agentverse/mailbox/agentverse:mailbox/mailbox_3a.png)

At this point, you do not need to do anything else. Click **Finish**.

<Callout type="warning" emoji="⚠️">
If you see a message saying **"We couldn't find this agent address on Fetch Network"** you will need to wait for some time (around 5 minutes) until the protocols are uploaded successfully on the Fetch Network and your agent is retrievable.
</Callout>
![](src/images/guides/agentverse/mailbox/agentverse:mailbox/mailbox_4a.png)

Once your agent is connected via the Mailbox correctly, you will see a box depicting it within the **My Agents** tab.

![](src/images/guides/uagent/servicefordungeons_1.png)

Click on it and head over to the **Deploy** tab and click on **+ New Function**.

![](src/images/guides/uagent/servicefordungeons_2.png)

Once your agent is retrieved correctly, you will see a box depicting it within the **My Agents** tab. Click on it and head over to the **Deploy** tab and click on **+ New Function**. Here, you can now provide the needed details for your Agent Function in the dedicated fields. Remember to provide detailed descriptions for what your **Agent Function** does and the **Fields** for data Models expected. understanding of Functions fields descriptions.
Here, you can now provide the needed details for your Agent Function in the dedicated fields. Remember to provide detailed descriptions for what your **Agent Function** does and the **Fields** for data Models expected. understanding of Functions fields descriptions.

![](src/images/guides/uagent/servicefordungeons_3.png)

Expand Down
16 changes: 8 additions & 8 deletions pages/guides/agents/intermediate/agent-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The [Agentverse Mailbox feature ↗️](/guides/agents/intermediate/mailbox) mak

**Local Agents can use a Mailbox to ensure that no messages are lost when they are temporarily disconnected from the network**; the Mailbox acts as a message buffer, storing communications until the Agent comes back online and ready to process them. Indeed, this feature enables interaction with other Agents or functions without the Agent being online continuously.

In order to set up a mailbox for a local Agent, you first need to create and configure a local Agent. The Agent's address is used to register it on the Agentverse, and then to generate a **Mailbox API key** for your Agent. For instance, consider the following basic Agent:
In order to set up a mailbox for a local Agent, you first need to create and configure the local Agent. For instance, consider the following basic Agent:

<GithubCodeSegment digest="67d527d8ecb6cc3ea76fdce279b2a78a">
<CodeSegment
Expand All @@ -58,15 +58,13 @@ In order to set up a mailbox for a local Agent, you first need to create and con
class Message(Model):
message: str


AGENT_MAILBOX_KEY = "put_your_AGENT_MAILBOX_KEY_here"
SEED_PHRASE = "put_your_seed_phrase_here"
SEED_PHRASE = "put_your_seed_phrase_here"

# Now your agent is ready to join the agentverse!
agent = Agent(
name="alice",
seed=SEED_PHRASE,
mailbox=f"{AGENT_MAILBOX_KEY}@https://agentverse.ai"
port=8000,
mailbox=True
)

# Copy the address shown below
Expand All @@ -80,8 +78,10 @@ In order to set up a mailbox for a local Agent, you first need to create and con

</CodeGroup>

Now, run this Agent. You will be able to see a link in your terminal output redirecting you towards the [Local Agent Inspector ↗️](/guides/agents/intermediate/local-agent-inspector) for this specific Agent on the [Agentverse ↗️](https://agentverse.ai/). Click on this URL. You will be redirected to the Inspector UI where you can check multiple details about the local Agent you have just run.

![](src/images/guides/inspector/local_agent_inspector.png)

Then, head over to the [Agentverse ↗️](https://agentverse.ai/) and navigate to the **My Agents** tab. Here, select **Local Agents** and click on **Connect Local Agent**. Paste your Agent's address retrieved from running your local Agent and follow the steps until you get a **Mailbox API Key**, which you will use to update your Agent's configuration above. To test your Mailbox setup, you can create another Agent (on Agentverse for instance) that sends messages to the Mailbox while the first Agent is offline. When the first agent comes back online, it will retrieve and process the stored messages. For a complete example, check out this [guide ↗️](/guides/agentverse/agentverse-mailbox/utilising-the-mailbox).
Now, click on **Connect** and then on **Mailbox** options and follow the steps closely in order to correctly set up a mailbox for your local Agent. To test your Mailbox setup, you can create another Agent (on Agentverse for instance) that sends messages to the Mailbox while the first Agent is offline. When the first agent comes back online, it will retrieve and process the stored messages.

For a more complex example of an Agent using a Mailbox, check out the following [guide ↗️](/guides/agents/intermediate/langchain-rag-agent).
For a complete example, check out this [guide ↗️](/guides/agentverse/agentverse-mailbox/utilising-the-mailbox). For a more complex example of an Agent using a Mailbox, check out the following [guide ↗️](/guides/agents/intermediate/langchain-rag-agent).
12 changes: 6 additions & 6 deletions pages/guides/agents/intermediate/langchain-rag-agent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@ Let's start by creating the file within the `agents` directory, under `src` dire
</DocsCode>
</CodeGroup>

The Agent is defined as a [local agent with a Mailbox ↗️](https://fetch.ai/docs/guides/agents/intermediate/options-for-running-local-agents#run-a-local-agent-using-a-mailbox) and it can answer questions by fetching and summarizing information from a given website URL.
The Agent is defined as a [local agent with a Mailbox ↗️](/guides/agents/intermediate/options-for-running-local-agents#run-a-local-agent-using-a-mailbox) and it can answer questions by fetching and summarizing information from a given website URL.

The script for this Agent looks as follows:

<GithubCodeSegment digest="6e1bac7fcd2e972c9e57b0baae58c27c">
<CodeSegment
path="https://github.com/fetchai/uAgent-Examples/blob/main/1-uagents/examples/intermediate/langchain-rag/src/agents/langchain_rag_agent.py"
lineStart={1}
lineEnd={137}
lineEnd={134}
hosted={true}
/>
</GithubCodeSegment>
Expand Down Expand Up @@ -284,13 +284,13 @@ The script for this Agent looks as follows:


LANGCHAIN_RAG_SEED = "YOUR_LANGCHAIN_RAG_SEED"
AGENT_MAILBOX_KEY = "YOUR_MAILBOX_KEY"

agent = Agent(
name="langchain_rag_agent",
seed=LANGCHAIN_RAG_SEED,
mailbox=f"{AGENT_MAILBOX_KEY}@https://agentverse.ai",
mailbox=True,
)

fund_agent_if_low(agent.wallet.address())

docs_bot_protocol = Protocol("DocsBot")
Expand Down Expand Up @@ -407,7 +407,7 @@ The script for this Agent looks as follows:

The Agent fetches and processes information from specified URLs to answer users' questions.

Let's explore the script above in more detail. We start by importing multiple modules, including tools for making HTTP requests, parsing HTML, and handling Natural Language Processing (NLP). The Agent uses **OpenAI's GPT-4o-mini model** to generate answers based on the retrieved documents. We then create an Agent called `langchain_rag_agent()` with a unique `seed` and `mailbox` address. Check out the [Mailbox ↗️](/guides/agents/intermediate/mailbox) guide for additional information on how to set up Mailboxes for your Agents. **Make sure to have enough funds in the Agent's wallet for it to correctly register in the [Almanac contract ↗️](/references/contracts/uagents-almanac/almanac-overview). You can use the `fund_agent_if_low` function on the testnet to add funds to your Agent's wallet if needed.
Let's explore the script above in more detail. We start by importing multiple modules, including tools for making HTTP requests, parsing HTML, and handling Natural Language Processing (NLP). The Agent uses **OpenAI's GPT-4o-mini model** to generate answers based on the retrieved documents. We then create an Agent called `langchain_rag_agent()` with a unique `seed`. Check out the [Mailbox ↗️](/guides/agents/intermediate/mailbox) guide for additional information on how to set up Mailboxes for your Agents. **Make sure to have enough funds in the Agent's wallet for it to correctly register in the [Almanac contract ↗️](/references/contracts/uagents-almanac/almanac-overview)**. You can use the `fund_agent_if_low` function on the testnet to add funds to your Agent's wallet if needed.

Next, we define the `DocsBot` [protocol ↗️](/guides/agents/intermediate/protocols) using the `Protocol` class of the `uagents` library to handle message interactions. This protocol uses a predefined prompt template to structure the questions and context for the language model.

Expand Down Expand Up @@ -594,7 +594,7 @@ It will look as follows:

Cool! All scripts are now set up! You will need to [connect the local Agent to the Agentverse using a Mailbox ↗️](/guides/agents/intermediate/options-for-running-local-agents#run-a-local-agent-using-a-mailbox). The Mailbox enables your Agents to be retrievable for communication and interaction with any other registered Agent on the Almanac contract and Fetch Network. In this example, the `langchain_rag_agent` will be connected to the Agentverse using a [Mailbox ↗️](/guides/agents/intermediate/mailbox). The `langchain_rag_user` Agent is used as a testing Agent for the RAG Agent being registered on the Agentverse and made subsequently available on DeltaV for queries.

By creating an [Agent Function ↗️](https://fetch.ai/docs/guides/agents/intermediate/agent-functions) and [registering it ↗️](https://fetch.ai/docs/guides/agentverse/agentverse-functions/registering-agent-services) via the Agentverse, you will make it retrievable to the [AI Engine ↗️](/concepts/ai-engine/ai-engine-intro) for interaction with users via natural language queries made on [DeltaV ↗️](/concepts/ai-engine/deltav).
By creating an [Agent Function ↗️](/guides/agents/intermediate/agent-functions) and [registering it ↗️](/guides/agentverse/agentverse-functions/registering-agent-services) via the Agentverse, you will make it retrievable to the [AI Engine ↗️](/concepts/ai-engine/ai-engine-intro) for interaction with users via natural language queries made on [DeltaV ↗️](/concepts/ai-engine/deltav).

The `langchain_rag_user` Agent is used as a testing Agent for the RAG Agent being registered on the Agentverse and made subsequently available on DeltaV for queries.

Expand Down
7 changes: 3 additions & 4 deletions pages/guides/agents/intermediate/local-agent-inspector.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For instance, consider the following simple local Agent:
<CodeSegment
path="https://github.com/fetchai/uAgent-Examples/blob/main/5-documentation/guides/agents/intermediate/local-agent-inspector/agent_inspector_example.py"
lineStart={1}
lineEnd={25}
lineEnd={27}
hosted={true}
/>
</GithubCodeSegment>
Expand Down Expand Up @@ -84,7 +84,6 @@ By running the above Agent, the output you get should be similar to the followin

By clicking on the dedicated link depicted here, you will then be redirected to the **Inspector Dashboard**. A pop-up message will appear saying that your Agent was connected successfully.

![](src/images/guides/inspector/inspector_2.png)

Here you can view all the information about your local Agent, including details about all messaged sent and received by the Agent.
![](src/images/guides/inspector/local_agent_inspector.png)

Here you can view all the information about your local Agent, including details about all messaged sent and received by the Agent. Additionally, you can connect you local Agent directly via the Inspector UI, by clicking the **Connect** button and following the steps required. For a better representation of the process, have a look at the following guide [here ↗️](/guides/agents/intermediate/mailbox)
Loading

0 comments on commit 183ed07

Please sign in to comment.