-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move WebSurfer Autogen code out of the studio module (#253)
* Move WebSurfer Autogen code out of the studio module * WIP * Move web_surfer related tests outside of studio * WIP: revert changes and check CI build * Fix failing test * wip * wip * bug fix * Add websurfer example in docs * Install docker on mac os ci runner * add tests * polishing * WIP: Polish docs * WIP: Polish docs * Polish docs * Install Colima as Docker runtime on macOS for GitHub Actions * Install Docker on macOS for GitHub Actions * Revert changes * Set AUTOGEN_USE_DOCKER to False in test-macos-latest job * Clean up * Polishing --------- Co-authored-by: Davor Runje <davor@airt.ai>
- Loading branch information
1 parent
1fc698e
commit 8758c98
Showing
26 changed files
with
748 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
docs/docs/en/api/fastagency/runtime/autogen/base/Toolable.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
# 0.5 - API | ||
# 2 - Release | ||
# 3 - Contributing | ||
# 5 - Template Page | ||
# 10 - Default | ||
search: | ||
boost: 0.5 | ||
--- | ||
|
||
::: fastagency.runtime.autogen.base.Toolable |
11 changes: 11 additions & 0 deletions
11
docs/docs/en/api/fastagency/runtime/autogen/tools/WebSurferTool.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
# 0.5 - API | ||
# 2 - Release | ||
# 3 - Contributing | ||
# 5 - Template Page | ||
# 10 - Default | ||
search: | ||
boost: 0.5 | ||
--- | ||
|
||
::: fastagency.runtime.autogen.tools.WebSurferTool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
docs/docs/en/api/fastagency/runtime/autogen/tools/web_surfer/WebSurferTool.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
# 0.5 - API | ||
# 2 - Release | ||
# 3 - Contributing | ||
# 5 - Template Page | ||
# 10 - Default | ||
search: | ||
boost: 0.5 | ||
--- | ||
|
||
::: fastagency.runtime.autogen.tools.web_surfer.WebSurferTool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,250 @@ | ||
# WebSurfer | ||
|
||
FastAgency allows you to quickly create workflows with capabilities like live browsing, automatic data retrieval, and tasks requiring up-to-date web information, making it easy to integrate web functionality. | ||
|
||
## Adding Web Surfing Capabilities to Agents | ||
|
||
FastAgency provides two ways to add web surfing capabilities to agents. You can either: | ||
|
||
1. Use a WebSurferAgent, which comes with built-in web surfing capabilities (recommended) | ||
2. Enhance an existing agent with web surfing capability | ||
|
||
In this guide, we'll demonstrate both methods with a real-world example. We’ll create a workflow where agents search the web for real-time data. | ||
|
||
We’ll build agents and assign them the task: “Search for information about Microsoft AutoGen and summarize the results” to showcase its ability to browse and gather real-time data in action. | ||
|
||
## Installation | ||
|
||
Before getting started, make sure you have installed FastAgency with support for the AutoGen runtime by running the following command: | ||
|
||
```bash | ||
pip install "fastagency[autogen]" | ||
``` | ||
|
||
This command installs FastAgency with support for the Console interface and AutoGen framework. | ||
|
||
## Example: Search for information about Microsoft AutoGen and summarize the results | ||
|
||
### Step-by-Step Breakdown | ||
|
||
#### 1. **Import Required Modules** | ||
The example starts by importing the necessary modules from **AutoGen** and **FastAgency**. These imports lay the foundation for building and running multi-agent workflows. | ||
|
||
=== "Using WebSurferAgent" | ||
```python hl_lines="7" | ||
{!> docs_src/user_guide/runtime/autogen/websurfer.py [ln:1-9] !} | ||
``` | ||
|
||
To create a new web surfing agent, simply import `WebSurferAgent`, which comes with built-in web surfing capabilities, and use it as needed. | ||
|
||
=== "Enhancing an existing agent" | ||
```python hl_lines="4 8" | ||
{!> docs_src/user_guide/runtime/autogen/websurfer_tool.py [ln:1-9] !} | ||
``` | ||
|
||
To enhance existing agents with web surfing capability, import `WebSurferTool` from FastAgency and `ConversableAgent` from AutoGen. | ||
|
||
|
||
#### 2. **Configure the Language Model (LLM)** | ||
Here, the large language model is configured to use the `gpt-4o` model, and the API key is retrieved from the environment. This setup ensures that both the user and websurfer agents can interact effectively. | ||
|
||
```python | ||
{! docs_src/user_guide/runtime/autogen/websurfer.py [ln:10-19] !} | ||
``` | ||
|
||
#### 3. **Define the Workflow and Agents** | ||
|
||
=== "Using WebSurferAgent" | ||
|
||
In this step, we are going to create two agents: | ||
|
||
- **UserProxyAgent**: This agent simulates the user interacting with the system. | ||
|
||
- **WebSurferAgent**: This agent functions as a web surfer, with built-in capability to browse the web and fetch real-time data as required. | ||
|
||
```python hl_lines="18" | ||
{!> docs_src/user_guide/runtime/autogen/websurfer.py [ln:20-38] !} | ||
``` | ||
|
||
When initiating the `WebSurferAgent`, the executor parameter must be provided. This can be either a single instance of `ConversableAgent` or a `list of ConversableAgent` instances. | ||
|
||
The `WebSurferAgent` relies on the executor agent(s) to execute the web surfing tasks. In this example, the `web_surfer` agent will call the `user_agent` agent with the necessary instructions when web surfing is required, and the `user_agent` will execute those instructions. | ||
|
||
=== "Enhancing an existing agent" | ||
|
||
In this step, we create two agents and a web surfer tool: | ||
|
||
- **UserProxyAgent**: This agent simulates the user interacting with the system. | ||
|
||
- **ConversableAgent**: This is the conversable agent to which we will be adding web surfing capabilities. | ||
|
||
- **WebSurferTool**: The tool that gives the ConversableAgent the ability to browse the web after it has been registered. | ||
|
||
```python | ||
{!> docs_src/user_guide/runtime/autogen/websurfer_tool.py [ln:20-45] !} | ||
``` | ||
|
||
Now, we need to register the WebSurferAgent with a caller and executor. This setup allows the caller to use the WebSurferAgent for performing real-time web interactions. | ||
|
||
```python hl_lines="2 3" | ||
{!> docs_src/user_guide/runtime/autogen/websurfer_tool.py [ln:46-50] !} | ||
``` | ||
|
||
The `executor` can be either a single instance of `ConversableAgent` or a `list of ConversableAgent` instances. | ||
|
||
The `caller` relies on the executor agent(s) to execute the web surfing tasks. In this example, the `assistant_agent` agent will call the `user_agent` agent with the necessary instructions when web surfing is required, and the `user_agent` will execute those instructions. | ||
|
||
#### 4. **Enable Agent Interaction and Chat** | ||
Here, the user agent starts a conversation with the websurfer agent, which performs a web search and returns summarized information. The conversation is then summarized using a method provided by the LLM. | ||
|
||
=== "Using WebSurferAgent" | ||
|
||
```python | ||
{! docs_src/user_guide/runtime/autogen/websurfer.py [ln:39-48] !} | ||
``` | ||
|
||
=== "Enhancing an existing agent" | ||
|
||
```python | ||
{! docs_src/user_guide/runtime/autogen/websurfer_tool.py [ln:51-60] !} | ||
``` | ||
|
||
#### 5. **Create and Run the Application** | ||
Finally, we create the FastAgency application and launch it using the console interface. | ||
|
||
```python | ||
{! docs_src/user_guide/runtime/autogen/websurfer.py [ln:50] !} | ||
``` | ||
|
||
### Complete Application Code | ||
|
||
=== "Using WebSurferAgent" | ||
|
||
<details> | ||
<summary>websurfer_agent.py</summary> | ||
```python | ||
{!> docs_src/user_guide/runtime/autogen/websurfer.py !} | ||
``` | ||
</details> | ||
|
||
=== "Enhancing an existing agent" | ||
|
||
<details> | ||
<summary>websurfer_tool.py</summary> | ||
```python | ||
{!> docs_src/user_guide/runtime/autogen/websurfer_tool.py !} | ||
``` | ||
</details> | ||
|
||
|
||
### Running the Application | ||
|
||
|
||
=== "Using WebSurferAgent" | ||
|
||
```bash | ||
fastagency run websurfer_agent.py | ||
``` | ||
|
||
=== "Enhancing an existing agent" | ||
|
||
```bash | ||
fastagency run websurfer_tool.py | ||
``` | ||
|
||
Ensure you have set your OpenAI API key in the environment. The command will launch a console interface where users can input their requests and interact with the websurfer agent. | ||
|
||
### Output | ||
|
||
Once you run it, FastAgency automatically detects the appropriate app to execute and runs it. The application will then prompt you with: "Please enter an initial message:". | ||
|
||
=== "Using WebSurferAgent" | ||
|
||
```console | ||
╭── Python module file ───╮ | ||
│ │ | ||
│ 🐍 websurfer_agent.py │ | ||
│ │ | ||
╰─────────────────────────╯ | ||
|
||
[INFO] Importing autogen.base.py | ||
|
||
╭──── Importable FastAgency app ────╮ | ||
│ │ | ||
│ from websurfer_agent import app │ | ||
│ │ | ||
╰───────────────────────────────────╯ | ||
|
||
╭─ FastAgency -> user [text_input] ────────────────────────────────────────────╮ | ||
│ │ | ||
│ Starting a new workflow 'simple_websurfer' with the following │ | ||
│ description: │ | ||
│ │ | ||
│ WebSurfer chat │ | ||
│ │ | ||
│ Please enter an initial message: │ | ||
╰──────────────────────────────────────────────────────────────────────────────╯ | ||
``` | ||
|
||
=== "Enhancing an existing agent" | ||
|
||
```console | ||
╭── Python module file ──╮ | ||
│ │ | ||
│ 🐍 websurfer_tool.py │ | ||
│ │ | ||
╰────────────────────────╯ | ||
|
||
[INFO] Importing autogen.base.py | ||
|
||
╭─── Importable FastAgency app ────╮ | ||
│ │ | ||
│ from websurfer_tool import app │ | ||
│ │ | ||
╰──────────────────────────────────╯ | ||
|
||
╭─ FastAgency -> user [text_input] ────────────────────────────────────────────╮ | ||
│ │ | ||
│ Starting a new workflow 'simple_websurfer' with the following │ | ||
│ description: │ | ||
│ │ | ||
│ WebSurfer chat │ | ||
│ │ | ||
│ Please enter an initial message: │ | ||
╰──────────────────────────────────────────────────────────────────────────────╯ | ||
``` | ||
|
||
|
||
In the prompt, type **Search for information about Microsoft AutoGen and summarize the results** and press Enter. | ||
|
||
This will initiate the task, allowing you to see the real-time conversation between the agents as they collaborate to complete it. Once the task is finished, you’ll see an output similar to the one below. | ||
|
||
```console | ||
╭─ workflow -> user [workflow_completed] ──────────────────────────────────────╮ | ||
│ │ | ||
│ { │ | ||
│ "result": "Microsoft AutoGen is an open-source framework designed │ | ||
│ to simplify the orchestration, optimization, and automation of large │ | ||
│ language model (LLM) workflows. It features customizable agents, │ | ||
│ multi-agent conversations, tool integration, and human involvement, │ | ||
│ making it suitable for complex AI applications. Key resources include │ | ||
│ the Microsoft Research Blog and the GitHub repository for AutoGen." │ | ||
│ } │ | ||
╰──────────────────────────────────────────────────────────────────────────────╯ | ||
|
||
╭─ FastAgency -> user [text_input] ────────────────────────────────────────────╮ | ||
│ │ | ||
│ Starting a new workflow 'simple_websurfer' with the following │ | ||
│ description: │ | ||
│ │ | ||
│ WebSurfer chat │ | ||
│ │ | ||
│ Please enter an initial message: │ | ||
╰──────────────────────────────────────────────────────────────────────────────╯ | ||
``` | ||
|
||
The agent will summarize its findings and then prompt you again with "Please enter an initial message:", allowing you to continue the conversation with the web surfer agent. | ||
|
||
--- | ||
|
||
This example demonstrates the power of the AutoGen runtime within FastAgency, showcasing how easily LLM-powered agents can be integrated with browsing capabilities to fetch and process real-time information. By leveraging FastAgency, developers can quickly build interactive, scalable applications that interact with live data sources. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import os | ||
|
||
from autogen import UserProxyAgent | ||
|
||
from fastagency import UI, FastAgency | ||
from fastagency.runtime.autogen import AutoGenWorkflows | ||
from fastagency.runtime.autogen.agents.websurfer import WebSurferAgent | ||
from fastagency.ui.console import ConsoleUI | ||
|
||
llm_config = { | ||
"config_list": [ | ||
{ | ||
"model": "gpt-4o", | ||
"api_key": os.getenv("OPENAI_API_KEY"), | ||
} | ||
], | ||
"temperature": 0.0, | ||
} | ||
|
||
wf = AutoGenWorkflows() | ||
|
||
@wf.register(name="simple_websurfer", description="WebSurfer chat") # type: ignore[type-var] | ||
def websurfer_workflow( | ||
wf: AutoGenWorkflows, ui: UI, initial_message: str, session_id: str | ||
) -> str: | ||
user_agent = UserProxyAgent( | ||
name="User_Agent", | ||
system_message="You are a user agent", | ||
llm_config=llm_config, | ||
human_input_mode="NEVER", | ||
) | ||
web_surfer = WebSurferAgent( | ||
name="Assistant_Agent", | ||
llm_config=llm_config, | ||
summarizer_llm_config=llm_config, | ||
human_input_mode="NEVER", | ||
executor=user_agent, | ||
) | ||
|
||
chat_result = user_agent.initiate_chat( | ||
web_surfer, | ||
message=initial_message, | ||
summary_method="reflection_with_llm", | ||
max_turns=3, | ||
) | ||
|
||
return chat_result.summary # type: ignore[no-any-return] | ||
|
||
|
||
app = FastAgency(wf=wf, ui=ConsoleUI()) |
Oops, something went wrong.