Skip to content

Commit

Permalink
Add bing api key to websurfer and fix documentation warnings (#470)
Browse files Browse the repository at this point in the history
* wip

* wip

* Update links

* Update links

* Update lines

* Update docs

* polishing

* polishing

---------

Co-authored-by: Davor Runje <[email protected]>
  • Loading branch information
rjambrecic and davorrunje authored Oct 23, 2024
1 parent 98bef19 commit ba2e089
Show file tree
Hide file tree
Showing 26 changed files with 109 additions and 318 deletions.
6 changes: 3 additions & 3 deletions docs/docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ search:
- [Toolable](api/fastagency/runtimes/autogen/autogen/Toolable.md)
- tools
- [WebSurferTool](api/fastagency/runtimes/autogen/tools/WebSurferTool.md)
- web_surfer
- [WebSurferAnswer](api/fastagency/runtimes/autogen/tools/web_surfer/WebSurferAnswer.md)
- [WebSurferTool](api/fastagency/runtimes/autogen/tools/web_surfer/WebSurferTool.md)
- websurfer
- [WebSurferAnswer](api/fastagency/runtimes/autogen/tools/websurfer/WebSurferAnswer.md)
- [WebSurferTool](api/fastagency/runtimes/autogen/tools/websurfer/WebSurferTool.md)
- ui
- console
- [ConsoleUI](api/fastagency/ui/console/ConsoleUI.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.runtimes.autogen.tools.web_surfer.WebSurferAnswer
::: fastagency.runtimes.autogen.tools.websurfer.WebSurferAnswer
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.runtimes.autogen.tools.web_surfer.WebSurferTool
::: fastagency.runtimes.autogen.tools.websurfer.WebSurferTool
4 changes: 2 additions & 2 deletions docs/docs/en/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ Once everything is set up, you can run your FastAgency application using the fol

There are two options of running a Mesop application:

1. Using [`fastagency`](../cli/cli/){target="_blank"} command line:
1. Using [`fastagency`](../cli/cli.md){target="_blank"} command line:

!!! note "Terminal (using [fastagency](../cli/cli/){target="_blank"})"
!!! note "Terminal (using [fastagency](../cli/cli.md){target="_blank"})"
```
fastagency run
```
Expand Down
16 changes: 8 additions & 8 deletions docs/docs/en/tutorial/giphy/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Also, we configure the **Giphy API** with the __*GIPHY_API_KEY*__ using __*set_s
{! docs_src/tutorial/giphy/main.py [ln:25-29] !}
```

For more information, visit [**API Integration User Guide**](../../user-guide/api){target="_blank"}.
For more information, visit [**API Integration User Guide**](../../user-guide/api/index.md){target="_blank"}.

### Registering the Workflow

Expand All @@ -118,23 +118,23 @@ This is a core function used by the **GiphyAgent** to either present the task re
### Creating the Giphy and WebSurfer Agents

- **GiphyAgent**: A ***ConversableAgent*** is created with the name "Giphy_Agent". It uses the system message defined earlier and relies on the termination function to end the chat when needed.
- **WebSurferAgent**: The ***WebSurferAgent*** is responsible for scraping web content and passes the retrieved data to the **GiphyAgent**. It’s configured with a summarizer to condense web content, which is useful when presenting concise data to the user. For more information, visit [**WebSurfer User Guide**](../../user-guide/runtimes/autogen/websurfer){target="_blank"}.
- **WebSurferAgent**: The ***WebSurferAgent*** is responsible for scraping web content and passes the retrieved data to the **GiphyAgent**. It’s configured with a summarizer to condense web content, which is useful when presenting concise data to the user. For more information, visit [**WebSurfer User Guide**](../../user-guide/runtimes/autogen/websurfer.md){target="_blank"}.

```python
{! docs_src/tutorial/giphy/main.py [ln:77-91] !}
{! docs_src/tutorial/giphy/main.py [ln:77-92] !}
```

### Registering Functions

The function ***present_completed_task_or_ask_question*** is registered to allow the **GiphyAgent** to ask questions or present completed tasks after receiving data from the **WebSurferAgent**.

```python
{! docs_src/tutorial/giphy/main.py [ln:93-100] !}
{! docs_src/tutorial/giphy/main.py [ln:94-101] !}
```

We specify which Giphy API functions can be used by the **GiphyAgent**: *random_gif*, *search_gifs*, and *trending_gifs*. These functions allow the agent to generate GIFs based on user input or trending content.
```python
{! docs_src/tutorial/giphy/main.py [ln:102-108] !}
{! docs_src/tutorial/giphy/main.py [ln:103-109] !}
```

### Initiating the Chat
Expand All @@ -144,18 +144,18 @@ We initiate the conversation between the user, **WebSurferAgent**, and **GiphyAg
Once the conversation ends, the summary is returned to the user, wrapping up the session.

```python
{! docs_src/tutorial/giphy/main.py [ln:116-123] !}
{! docs_src/tutorial/giphy/main.py [ln:117-124] !}
```

### Starting the Application

The FastAgency app is created, using the registered workflows (***wf***) and web-based user interface (***MesopUI***). This makes the conversation between agents and the user interactive.

```python
{! docs_src/tutorial/giphy/main.py [ln:126] !}
{! docs_src/tutorial/giphy/main.py [ln:127] !}
```

For more information, visit [**Mesop User Guide**](../../user-guide/ui/mesop/basics){target="_blank"}.
For more information, visit [**Mesop User Guide**](../../user-guide/ui/mesop/basics.md){target="_blank"}.

## Running the Application

Expand Down
32 changes: 16 additions & 16 deletions docs/docs/en/tutorial/whatsapp/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

In this tutorial, we will explore how to leverage the **FastAgency** framework to create a dynamic and interactive chatbot that integrates two powerful agents:

1. [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md): A web-scraping agent capable of retrieving relevant content from webpages (learn more [here](../../user-guide/runtimes/autogen/websurfer)).
1. [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer_agent/WebSurferAgent.md): A web-scraping agent capable of retrieving relevant content from webpages (learn more [here](../../user-guide/runtimes/autogen/websurfer.md)).

2. **WhatsApp agent** – An agent that interacts with the [Infobip WhatsApp API](https://www.infobip.com/docs/api/channels/whatsapp){target="_blank"} to send WhatsApp messages based on the user’s request. It will be created using the standard [**`ConversableAgent`**](https://microsoft.github.io/autogen/0.2/docs/reference/agentchat/conversable_agent/){target="_blank"} from [AutoGen](https://microsoft.github.io/autogen){target="_blank"} and the [**`OpenAPI`**](../../api/fastagency/api/openapi/OpenAPI.md) object instantiated with an OpenAPI [specification](https://raw.githubusercontent.com/airtai/fastagency/refs/heads/main/examples/openapi/whatsapp_openapi.json){target="_blank"} of Infobip's [REST API](https://www.infobip.com/docs/api/channels/whatsapp){target="_blank"}.

Expand All @@ -13,7 +13,7 @@ The chat system will operate between these two agents and the user, allowing the
By the end of this tutorial, you will understand how to:

1. Integrate external APIs like [Infobip WhatsApp API](https://www.infobip.com/docs/api/channels/whatsapp){target="_blank"} using [**`OpenAPI`**](../../api/fastagency/api/openapi/OpenAPI.md).
2. Build and register agents that autonomously scrape the web for relevant information using [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md).
2. Build and register agents that autonomously scrape the web for relevant information using [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer_agent/WebSurferAgent.md).
3. Use [**`AutoGenWorkflows`**](../../api/fastagency/runtimes/autogen/AutoGenWorkflows.md) to manage agent interactions and user input.
4. Present scraped content to the user and offer sending that content via WhatsApp.
5. Handle secure API credentials and ensure safe communication between agents using [**`APIKeyHeader`**](../../api/fastagency/api/openapi/security/APIKeyHeader.md).
Expand All @@ -36,7 +36,7 @@ pip install "fastagency[autogen,mesop,openapi]"
```

### API Key Setup
[**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md) requires an **Bing Web Search** API key and **WhatsAppAgent** requires an API key to interact with Infobip's WhatsApp service. Follow these steps to create your API keys:
[**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer_agent/WebSurferAgent.md) requires an **Bing Web Search** API key and **WhatsAppAgent** requires an API key to interact with Infobip's WhatsApp service. Follow these steps to create your API keys:

#### Create Bing Web Search API Key
To create [Bing Web Search](https://www.microsoft.com/en-us/bing/apis/pricing){target="_blank"} API key, follow the guide provided.
Expand Down Expand Up @@ -101,7 +101,7 @@ You can set the API keys in your terminal as an environment variable:

## Code Walkthrough

Now we will go over each key part of the code, explaining its function and purpose within the FastAgency framework. Understanding these components is crucial for building a dynamic interaction between the user, the [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md), and the **WhatsAppAgent**.
Now we will go over each key part of the code, explaining its function and purpose within the FastAgency framework. Understanding these components is crucial for building a dynamic interaction between the user, the [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer_agent/WebSurferAgent.md), and the **WhatsAppAgent**.

### Creating the WhatsApp API Instance
The following lines shows hot to initializes the WhatsApp API by loading the OpenAPI specification from a URL. The OpenAPI spec defines how to interact with the WhatsApp API, including endpoints, parameters, and security details.
Expand All @@ -111,7 +111,7 @@ Also, we configure the **WhatsApp API** with the __*WHATSAPP_API_KEY*__ using __
{! docs_src/tutorial/whatsapp/main.py [ln:24-31] !}
```

For more information, visit [**API Integration User Guide**](../../user-guide/api){target="_blank"}.
For more information, visit [**API Integration User Guide**](../../user-guide/api/index.md){target="_blank"}.


### Registering the Workflow
Expand All @@ -132,46 +132,46 @@ This is a core function used by the **WhatsAppAgent** to either present the task
### Creating the WhatsApp and WebSurfer Agents

- **WhatsAppAgent**: A [**`ConversableAgent`**](https://microsoft.github.io/autogen/0.2/docs/reference/agentchat/conversable_agent/){target="_blank"} is created with the name "WhatsApp_Agent". It uses the system message defined earlier and relies on the termination function to end the chat when needed.
- [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md): The [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md) is responsible for scraping web content and passes the retrieved data to the **WhatsAppAgent**. It’s configured with a summarizer to condense web content, which is useful when presenting concise data to the user. For more information, visit [**WebSurfer User Guide**](../../user-guide/runtimes/autogen/websurfer).
- [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer_agent/WebSurferAgent.md): The [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer_agent/WebSurferAgent.md) is responsible for scraping web content and passes the retrieved data to the **WhatsAppAgent**. It’s configured with a summarizer to condense web content, which is useful when presenting concise data to the user. For more information, visit [**WebSurfer User Guide**](../../user-guide/runtimes/autogen/websurfer.md).

```python
{! docs_src/tutorial/whatsapp/main.py [ln:77-93] !}
{! docs_src/tutorial/whatsapp/main.py [ln:77-94] !}
```


### Registering Functions

The function ***present_completed_task_or_ask_question*** is registered to allow the **WhatsAppAgent** to ask questions or present completed tasks after receiving data from the [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md).
The function ***present_completed_task_or_ask_question*** is registered to allow the **WhatsAppAgent** to ask questions or present completed tasks after receiving data from the [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer_agent/WebSurferAgent.md).

```python
{! docs_src/tutorial/whatsapp/main.py [ln:94-102] !}
{! docs_src/tutorial/whatsapp/main.py [ln:95-103] !}
```


We register the WhatsApp API, which allows the **WhatsAppAgent** to handle tasks like suggesting messages that will be sent to the user.
```python
{! docs_src/tutorial/whatsapp/main.py [ln:104-108] !}
{! docs_src/tutorial/whatsapp/main.py [ln:105-109] !}
```

### Initiating the Chat

We initiate the conversation between the user, [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md), and **WhatsAppAgent**. The user’s initial message is provided, and the system is configured to handle up to 10 turns of interaction. The conversation is summarized using the ***reflection_with_llm*** method, which uses a language model to summarize the chat.
We initiate the conversation between the user, [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer_agent/WebSurferAgent.md), and **WhatsAppAgent**. The user’s initial message is provided, and the system is configured to handle up to 10 turns of interaction. The conversation is summarized using the ***reflection_with_llm*** method, which uses a language model to summarize the chat.

Once the conversation ends, the summary is returned to the user, wrapping up the session.

```python
{! docs_src/tutorial/whatsapp/main.py [ln:116-123] !}
{! docs_src/tutorial/whatsapp/main.py [ln:117-124] !}
```

### Starting the Application

The FastAgency app is created, using the registered workflows (**`wf`**) and web-based user interface ([**`MesopUI`**](../../api/fastagency/ui/mesop/MesopUI.md)). This makes the conversation between agents and the user interactive.

```python
{! docs_src/tutorial/whatsapp/main.py [ln:126] !}
{! docs_src/tutorial/whatsapp/main.py [ln:127] !}
```

For more information, visit [**Mesop User Guide**](../../user-guide/ui/mesop/basics){target="_blank"}.
For more information, visit [**Mesop User Guide**](../../user-guide/ui/mesop/basics.md){target="_blank"}.

## Running the Application

Expand Down Expand Up @@ -261,7 +261,7 @@ In this scenario, the user instructs the agents to scrape [BBC Sport](https://ww

![Initial message](./images/initial_message.png)

Upon receiving the request, [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md) initiates the process by scraping the webpage for relevant updates.
Upon receiving the request, [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer_agent/WebSurferAgent.md) initiates the process by scraping the webpage for relevant updates.

![Scraping](./images/scraping.png)

Expand All @@ -279,4 +279,4 @@ Finally, the results are delivered to the user through a WhatsApp message.

## Conclusion

In summary, connecting **FastAgency** with the **Infobip WhatsApp API** lets you create chat systems that can gather web data and send it straight to users on WhatsApp. By using two agents — [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer/WebSurferAgent.md) to pull web content and **WhatsAppAgent** for messaging, you can build engaging experiences for users. This tutorial covered the essential steps to set up these agents, secure the API, and manage user interactions. With this setup, you can enhance your chatbot’s capabilities, providing real-time information and smooth communication across different platforms.
In summary, connecting **FastAgency** with the **Infobip WhatsApp API** lets you create chat systems that can gather web data and send it straight to users on WhatsApp. By using two agents — [**`WebSurferAgent`**](../../api/fastagency/runtimes/autogen/agents/websurfer_agent/WebSurferAgent.md) to pull web content and **WhatsAppAgent** for messaging, you can build engaging experiences for users. This tutorial covered the essential steps to set up these agents, secure the API, and manage user interactions. With this setup, you can enhance your chatbot’s capabilities, providing real-time information and smooth communication across different platforms.
6 changes: 3 additions & 3 deletions docs/docs/en/user-guide/adapters/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Use the [**`FastAPIAdapter`**](../../api/fastagency/adapters/fastapi/FastAPIAdap
- **Simplified Production Setup**: Choose this adapter if you need a **simple and easy-to-manage** production setup for deploying your FastAgency workflows as a REST API.


[Learn more about **FastAPI adapter**](./fastapi/)
[Learn more about **FastAPI adapter**](./fastapi/index.md)

### FastAPI + Nats.io

Expand All @@ -36,7 +36,7 @@ The [**`FastAPIAdapter`**](../../api/fastagency/adapters/fastapi/FastAPIAdapter.
- **High User Demand**: When your application needs to handle a large number of users or messages and requires high scalability, the FastAPI + NATS Adapter is an excellent choice. It is well-suited for building **scalable custom chat applications for larger companies or external customers**.
- **Conversation Auditing**: If you need the ability to **audit conversations**, the NATS Adapter provides the necessary infrastructure to enable this feature.

[Learn more about **FastAPI + NATS.io adapter**](./fastapi_nats/)
[Learn more about **FastAPI + NATS.io adapter**](./fastapi_nats/index.md)

### Nats.io

Expand All @@ -51,4 +51,4 @@ Utilize the [**`NatsAdapter`**](../../api/fastagency/adapters/nats/NatsAdapter.m
- **Conversation Auditing**: If you need the ability to **audit conversations**, the NATS Adapter provides the necessary infrastructure to enable this feature.


[Learn more about **NATS.io adapter**](./nats/)
[Learn more about **NATS.io adapter**](./nats/index.md)
8 changes: 4 additions & 4 deletions docs/docs/en/user-guide/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ Currently, FastAgency supports importing API functionality from [**OpenAPI**](ht

## API Features in FastAgency

### 1. **[OpenAPI Import](./openapi/)**
### 1. **[OpenAPI Import](./openapi/index.md)**
FastAgency can automatically generate API functions from OpenAPI specifications, streamlining the process of connecting agents to external services. With just a few lines of code, you can import an API specification, and FastAgency will handle the function generation and LLM integration, making it simple for agents to call external APIs.

[Learn more about OpenAPI Import →](./openapi/)
[Learn more about OpenAPI Import →](./openapi/index.md)

### 2. **[API Security](./security/)**
### 2. **[API Security](./security.md)**
FastAgency supports different types of security for REST APIs, including OAuth, API keys, and more. This ensures that your API integrations are secure and can handle sensitive data. Our API security mechanisms are flexible, allowing you to configure and manage secure communication between your agents and external APIs.

[Learn more about API Security →](./security/)
[Learn more about API Security →](./security.md)

---

Expand Down
Loading

0 comments on commit ba2e089

Please sign in to comment.