Skip to content

Commit

Permalink
Fix(docs): fixed ferchai sdk wuickstart guide
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixNicolaeBucsa committed Dec 16, 2024
1 parent cf13cb5 commit 51b0009
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 33 deletions.
2 changes: 1 addition & 1 deletion components/products.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ const items: { [key: string]: Item[] } = {
title: "Agentverse: Explorer",
description: (
<>
Learn to use the Agentverse Explorer to start an interaction with
Learn to use the Agentverse Marketplace to start an interaction with
other registered agents.
</>
),
Expand Down
2 changes: 1 addition & 1 deletion pages/concepts/fetch-network/almanac.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Callout } from 'nextra/components'

The **Almanac** contract is a critical component within the Fetch.ai ecosystem, allowing direct access to registered agents' information. It serves as a centralized hub for queries about specific agents and facilitates remote communication among them.

Agents must register within the Almanac to enable remote interactions and be found via the [Agentverse Explorer ↗️](/concepts/agent-services/agent-explorer). You can register your Agents on the Almanac by following this [guide ↗️](/guides/agents/register-in-almanac). You can also explore the [Communicating with other agents ↗️](/guides/agents/communicating-with-other-agents) guide to understand how Agents leverage the Almanac to communicate remotely.
Agents must register within the Almanac to enable remote interactions and be found via the [Agentverse Marketplace ↗️](/concepts/agent-services/agent-explorer). You can register your Agents on the Almanac by following this [guide ↗️](/guides/agents/register-in-almanac). You can also explore the [Communicating with other agents ↗️](/guides/agents/communicating-with-other-agents) guide to understand how Agents leverage the Almanac to communicate remotely.

Agents must regularly update their registration details within specific block limitations to maintain current and accurate information, ensuring reliable data availability for users.

Expand Down
69 changes: 38 additions & 31 deletions pages/guides/fetchai-sdk/quickstart.mdx
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
# Quickstart with Fetchai-sdk
# Quickstart with Fetch.ai SDK

The fetchai sdk gives you easy access to the core components of the uAgents library.
Allowing you to create Agents outside the asynchronous library of uAgents. This is really great if you want to build synchronous programs but still have agentic functionality.
The Fetch.ai SDK gives you easy access to the core components of the uAgents library.

Let's build a simple two agent system using Flask, and openai.
Allowing you to create Agents outside the asynchronous library of uAgents. This is really great if you want to build synchronous programs but still have agentic functionalities.

Let's build two simple [Agent ↗️](/guides/agents/getting-started/whats-an-agent) system using Flask, and OpenAI.

## Installation

With Python installed, let's set up our environment.

Create a new folder, let's call it fetchai-tarot
Create a new folder; let's call it `fetchai-tarot`:

```
mkdir fetchai-tarot && cd fetchai-tarot
mkdir fetchai-tarot && cd fetchai-tarot
```

now, let's install our required libraries.
Then, let's install our required libraries:

```
pip install flask openai fetchai
```

We'll also need to set a couple of environment variables. In terminal export the following:

``` bash
```bash
export OPENAI_API_KEY="your_api_key_from_openai.com"
```

``` bash
```bash
export AGENTVERSE_KEY="your_api_key_from_agentverse.ai"
```

We have a guide to get an [Agentverse api key](../apis/agent-function-creation-apis#how-to-get-agentverse-api-tokens)
We have a guide to get an [Agentverse api key ↗️](../apis/agent-function-creation-apis#how-to-get-agentverse-api-tokens)

With that, let's get our agents running.
With that, let's get our Agents running.

## The Tarot agent

The Tarot agent is registers and listens on a webhook within a Flask app. This agent using openai to create a Tarot reading from the received messages.
The Tarot Agent is registers and listens on a webhook within a Flask app. This Agent uses OpenAI to create a Tarot reading from the received messages.

First, create a file and copy the following code in:

Expand Down Expand Up @@ -160,13 +161,13 @@ if __name__ == "__main__":

There's a lot to unpack there, but as this is a quickstart, let's just cover the essentials:

An Agent is identifiable by their [seed](../agents/getting-started/seedphrase), we use this to load in an agent often with `Identity.from_seed("some str as your seed", 0)`
An Agent is identifiable by their [seed ↗️](../agents/getting-started/seedphrase); we use this to load in an Agent often with `Identity.from_seed("some str as your seed", 0)`

Registration allows other agents to find you, you can see this in `register_with_agentverse`. We specify a `readme` which is a xml string so that LLMs can read this content in a more structured manner. Very useful for search in more complex demos.
Registration allows other Agents to find you, you can see this in `register_with_agentverse`. We specify a `readme` which is a xml string so that LLMs can read this content in a more structured manner. Very useful for search in more complex demos.

`/webhook` is where our agent accepts an incomming message. They will receive this message when another Agents searches for them and matches. In this agent we get the data with `data = request.json` and then we get some of the message objects, our agent expects the payload to have `date of birth` and `gender` as keys.
`/webhook` is where our Agent accepts an incoming message. They will receive this message when another Agents search for it and match. Within this Agent, we get the data with `data = request.json` and then we get some of the message objects, our Agent expects the payload to have `date of birth` and `gender` as keys.

Finally, we create a message to send to the sender:
Finally, we create a message to be sent back to the sender:

```
send_message_to_agent(
Expand All @@ -177,14 +178,14 @@ send_message_to_agent(
)
```

Sending messages to agents is really simple. Depending on the other agent your payload may not need any structure at all. `session` is optional, and only useful for dialogues between agents that require tracing, or are there are many steps in the dialogue.
Sending messages to Agents is really simple. Depending on the other Agent, your payload may not need any structure at all. `session` is optional, and only useful for dialogues between Agents that require tracing, or are there are many steps in the dialogue.


## The Search agent

The Search agent searches for Tarot agents and sends them a payload of `gender` and `date of birth` and expects their tarot to be returned.
The Search Agent searches for the Tarot Agents and sends them a payload of `gender` and `date of birth` and expects their tarot to be returned.

``` python
```python copy

import json, os, sys
from flask import Flask, request
Expand Down Expand Up @@ -280,7 +281,7 @@ if __name__ == "__main__":

```

The main difference in the search agent is that we define a `/search` endpoint. This is very interesting, with `fetch.ai(query)` we can find any agent in the marketplace. Then we can send a message to all of them asking for a tarot reading. The search is a combination of Elastic search and multi-layered llms, meaning natural language queries can find you accurate results.
The main difference in the search Agent is that we define a `/search` [endpoint ↗️](/references/contracts/uagents-almanac/endpoints). This is very interesting, with `fetch.ai(query)` we can find any Agent in the [marketplace ↗️](/concepts/agent-services/agent-explorer). Then we can send a message to all of them asking for a tarot reading. The search is a combination of Elastic search and multi-layered LLMs, meaning natural language queries can find you accurate results.

```
@app.route('/search', methods=['GET'])
Expand All @@ -296,32 +297,38 @@ def search():

We run these agents with the following commands, they will need to be run in separate terminals.

```python tarot_agent.py```
Run the following commands in each terminal window:
```
python tarot_agent.py
```

and

```python tarot_search_agent.py```
```
python tarot_search_agent.py
```

Now they're running, let's get them registered. In a new terminal window:
Now, they're running. Let's get them registered.
In a new terminal window:

```
curl --location '127.0.0.1:5000/register'
curl --location '127.0.0.1:5002/register'
```

Then, you can send another GET request to the `tarot_search_agent`, and it should then go and find you an Agent which will return a tarot reading.

Then, you can send another GET request to the tarot_search_agent, and it should then go and find you an agent which will return a tarot reading.

Let's open a terminal window and curl our tarot_search_agent's ip to start the search process:
Let's open a terminal window and curl our `tarot_search_agent`'s IP to start the search process:

```
curl --location '127.0.0.1:5002/search'
```

### output
### Expected output

expected output from the tarot_search_agent:

``` bash
The expected output from the `tarot_search_agent` should be similar to the following:

```bash
Serving Flask app 'tarot_search'
* Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
Expand All @@ -336,4 +343,4 @@ sending a message to an ai, agent1qwpd8cy9ymhjyuj4x2k75dv69vlxquk0xtwhmw09khv8jd
{'date of birth': 'around the same time as dinosaurs', 'gender': 'reptile'}
….
{'Response': "Certainly! Let's dive into your tarot reading, my ancient reptilian friend.\n\n ..."}
```
```

0 comments on commit 51b0009

Please sign in to comment.