Skip to content

Commit

Permalink
edits: review
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixNicolaeBucsa committed Dec 18, 2024
1 parent 263bb3c commit 1e978c7
Showing 1 changed file with 37 additions and 42 deletions.
79 changes: 37 additions & 42 deletions pages/guides/agents/intermediate/search-agent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,41 @@ import { Callout } from 'nextra/components'
This is currently a work in progress and may be subject to further updates and revisions.
</Callout>

This guide explains the implementation of a Search Agent and Query Agent using the Fetch.ai SDK. These agents work together to handle user queries, search the Fetch.ai network for relevant agents, and return results.
Below, we outline the Search Function and the Complete Agent Implementation in detail.
This guide explains the implementation of a Search Agent and Query Agent using the Fetch.ai SDK. These Agents work together to handle user queries, search the Fetch.ai network for relevant Agents, and return results.

Below, we outline the **Search Function** and the **Complete Agent Implementation** in details.

## Installation

With Python installed, let's set up our environment.
Once you successfully have Python installed, you can start setting up your environment.

Create a new folder; let's call it `fetchai-search-agent`:
Create a new folder; call it `fetchai-search-agent`:

```
mkdir fetchai-search-agent && cd fetchai-search-agent
```
```
mkdir fetchai-search-agent && cd fetchai-search-agent
```

Then, let's install our required libraries:

```
poetry install uagents fetchai openai
```
Then, install the required libraries:

```
poetry install uagents fetchai openai
```

## Search Function

The search function is the core of the Search Agent. It interacts with the Fetch.ai network to find agents matching a specific query and sends them a message. Here's how it works:
The Search Function is the core of the Search Agent. It interacts with the Fetch.ai network to find Agents matching a specific query and sends them a message.

### Functionality
Here's how it works:

- Search the Fetch.ai Network:
The `fetch.ai(query)` method searches for agents that match the user's query.
### Functionalities

- Set Sender Identity:
Each message is sent using a unique sender identity generated by `Identity.from_seed`.
- **Search the Fetch.ai Network**: The `fetch.ai(query)` method searches for Agents that match the user's query.

- Dynamic Payload:
Uses OpenAI's GPT to generate payload based on the query.
- **Set Sender Identity**: Each message is sent using a unique sender identity generated by `Identity.from_seed`.

- Send Messages:
For every matching agent, a payload is constructed and sent using the `send_message_to_agent` function.
- **Dynamic Payload**: Uses OpenAI's GPT to generate payload based on the query.

- **Send Messages**: For every matching Agent, a payload is constructed and sent using the `send_message_to_agent` function.

```py copy
from fetchai import fetch
Expand Down Expand Up @@ -92,28 +88,28 @@ def search(query):

## Complete Agent Implementation

The implementation involves two agents: Query Agent and Search Agent, which interact with each other as follows:
The implementation involves two Agents: **Query Agent** and **Search Agent**, which interact with each other as follows:

### Query Agent:
### Query Agent

- Sends the users query to the Search Agent on startup.
- Waits for a response from the Search Agent.
- It sends the user's query to the Search Agent on startup.
- it then waits for a response from the Search Agent.

```py
query_agent = Agent(name="query_agent", seed="query_agent recovery phrase")
```
```py
query_agent = Agent(name="query_agent", seed="query_agent recovery phrase")
```

### Search Agent:
### Search Agent

- Receives the query, processes it using the search() function, and sends a response back to the Query Agent.
-Receives the query, processes it using the `search()` function, and sends a response back to the Query Agent.

```py
search_agent = Agent(name="search_agent", seed="search_agent recovery phrase")
```
```py
search_agent = Agent(name="search_agent", seed="search_agent recovery phrase")
```

## Overall script

```py copy
```py copy filename="fetchai-search-agent.py"
from fetchai import fetch
from fetchai.crypto import Identity
from fetchai.communication import (
Expand Down Expand Up @@ -199,19 +195,18 @@ if __name__ == "__main__":

```

## Running the agent.
## Running the Agent

We run `fetchai-search-agent` with the following commands:
We run `fetchai-search-agent.py` with the following commands:

```
python fetchai-search-agent
```
```
python fetchai-search-agent.py
```

## Expected output

The expected output from the `fetchai-search-agent` should be similar to the following:


```
Enter your query: Buy me a pair of shoes
[INFO] Starting Bureau with Query Agent and Search Agent...
Expand Down Expand Up @@ -243,4 +238,4 @@ INFO:fetchai:Sent message to agent
INFO: [search_agent]: [PROCESSING] Searching completed. Sending response back to the query agent.
INFO: [bureau]: Starting server on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO: [query_agent]: [RECEIVED] Response received from search agent agent1qgj8y2mswcc4jm275tsnq948fa7aqe8d9v0jd78h0nx9ak6v3fnxj6m6pkj. Status: 'Agent searched'
```
```

0 comments on commit 1e978c7

Please sign in to comment.