Skip to content

Commit

Permalink
Adding an example using sequential coordinator qwith 2 agents and a w…
Browse files Browse the repository at this point in the history
…eb interface. Fixes wise-agents#168
  • Loading branch information
maeste committed Sep 18, 2024
1 parent bb209e1 commit 10c7ace
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Gartner’s definition of a multi-agent system is:
For more details refer to our [documentation](https://wise-agents.github.io/multi_agents/#)

For more information on how to build, test and experiment with the project please refer to [GETTING_STARTED.md](GETTING_STARTED.md)
A good starting point to put the hands in the jam is checking our examples directory and follow the instructions to play with them

If you want to contribute, please have a look to [CONTRIBUTING.md](CONTRIBUTING.md)

3 changes: 0 additions & 3 deletions docs/example_2.md

This file was deleted.

3 changes: 3 additions & 0 deletions docs/sequential_coordinator_example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{%
include-markdown "../examples/sequential_coordinator/README.md"
%}
15 changes: 14 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
This directory contains examples of how to use the `wise-agents` multi-agent framework.

1. [memory_agentic_chatbot](./memory_agentic_chatbot/README.md)
* [memory_agentic_chatbot](./memory_agentic_chatbot/README.md)
The example consists of two main agents:

1. **Web Interface Agent**: Simulates a web-based client for interacting with other agents.
2. **Intelligent Agent**: Handles requests and provides intelligent responses based on memory and context.
* [sequential_coordinator](./sequential_coordinator/README.md)
The example consists of four agents:

1. **Web Interface Agent**: Simulates a web-based client for interacting with coordinator agent.
2. **Literature Agent**: Handles requests and provides intelligent responses. Its system message says:
*"You are an english literature expert. Answer questions about english literature. Try to give context to your answers and provide quote from the books described. Your user is a native english speaker, with limited background in english literature."*
3. **Transaltor Agent**: Handles requests and provides intelligent responses. Its system message says:
*"You are an expert translator from english to italian. Translate the provided text from english to italian. "*
4. **SequentialCoordinator**: Take care of coordinating the request handling from the user delagating the work to other agents in a predetermined order.
127 changes: 127 additions & 0 deletions examples/sequential_coordinator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@

# Sequential Coordinator Example: Answer and Translate Chatbot

This guide walks you through running a practical example of a multi-agent system using Wise Agents. In this example, four agents (a web interface agent, a sequential agent coordinator, and two intelligent agents) are started, allowing you to experiment with agent communication and interaction in a simulated environment, with a sequential coordination.


## Example Overview

The example consists of four agents:

1. **Web Interface Agent**: Simulates a web-based client for interacting with coordinator agent.
2. **Literature Agent**: Handles requests and provides intelligent responses. Its system message says:
*"You are an english literature expert. Answer questions about english literature. Try to give context to your answers and provide quote from the books described. Your user is a native english speaker, with limited background in english literature."*
3. **Transaltor Agent**: Handles requests and provides intelligent responses. Its system message says:
*"You are an expert translator from english to italian. Translate the provided text from english to italian. "*
4* **SequentialCoordinator**: Take care of coordinating the request handling from the user delagating the work to other agents in a predetermined order.

These agents are defined in YAML configuration files located in the `examples/answer_and_translate_chatbot` directory.

## Running the Example

### Step 1: Clone the Repository

If you haven't already, clone the Wise Agents repository from GitHub:

```bash
git clone https://github.com/wise-agents/wise-agents.git
cd wise-agents
```

### Step 2: Configure and Start Redis

In this step, we will set up Redis for agent context and registry.

1. **Create a hidden directory `.wise-agents`** in the root of your project:

```bash
mkdir .wise-agents
```

2. **Copy the Redis configuration file** as shown in the [`.wise-agents` directory](https://github.com/wise-agents/wise-agents/tree/main/.wise-agents) from the GitHub repo. Create a file named `redis-config.yaml` inside `.wise-agents`:

```yaml
redis:
host: localhost
port: 6379
```
3. **Ensure Redis is installed and running**. You can start redis as podman/docker image following instruction in [redis README.MD](../../redis/README.MD)
### Step 3: Start artemis
To support async communication between agents you need to have artemis up and running
1. Start artemis podman/docker image following instructions in [artemis README.MD](../../artemis/README.MD)
2. Set the environment variables for artemis secure login. If you haven't changed any configuration, starting artemis following the previous point instructions they are:
```bash
export STOMP_USER=artemis
export STOMP_PASSWORD=artemis
```

### Step 4: Start Ollama with Llama 3.1

To support the Llama model, you need to ensure that Ollama is installed and running:

1. **Install Ollama** if it’s not installed already by following the [Ollama installation instructions](https://ollama.com).

2. **Start Ollama with Llama 3.1**:

```bash
ollama run llama3.1
```

This will load the Llama 3.1 model into Ollama, which is necessary for running the intelligent agent.

### Step 5: Start the Intelligent Agent

In a first console, run the intelligent agents and coordinator agent, also from the project’s home directory, using the following command:

```bash
python src/wiseagents/cli/wise_agent_cli.py examples/memory_agentic_chatbot/intelligent-agent.yaml
```

This will initialize the intelligent agents and coordinator agent, which will be ready to respond to requests sent by the web interface agent.


### Step 6: Start the Web Interface Agent

In your second console, navigate to the project’s home directory and run the web interface agent using the provided YAML configuration file:

```bash
python src/wiseagents/cli/wise_agent_cli.py examples/memory_agentic_chatbot/web-interface.yaml
```

This will initialize the Assitant agent with its web interface. You should see logs indicating that the agent is started and waiting for requests. You will see in the console also a web server listening at [http://127.0.0.1:7860](http://127.0.0.1:7860)

```plain-text
Running on local URL: http://127.0.0.1:7860
```

### Step 7: Interaction

Once both agents are up and running, you can use the web interface agent as a chatbot and it will start sending requests to the intelligent agent. You will be able to see the interaction between the agents through the logs in both consoles.
Try as an example to ask something like "Can you give me detailed information about Harry Potter". You will get the detailed information about Rowling's books translated in Italian :)

### Step 8: Experiment

You can experiment with different agent configurations or modify the agent behaviors by editing the YAML files located in the `examples/memory_agentic_chatbot` directory. These configuration files define the agents' properties, including memory, communication methods, and response patterns. You can do that without restarting everything, just edit the yaml file(s) and use CLI's /reload command (see our documentation for more details on how to use CLI)

## Understanding the YAML Configuration

- **web-interface.yaml**: Defines the web interface agent, which serves as the client interface for interacting with other agents.
- **intelligent-agent.yaml**: Defines the intelligent agents and coordinator agent, which processes the requests and generates responses based on the provided input.

These YAML files include the specific `WiseAgent` classes and configuration needed to run the agents. Feel free to explore and modify these files to customize the agents' behavior.

## Additional Resources

For more information about the architecture and advanced configurations of wise-agents, refer to the [Wise Agents Architecture Document](wise_agents_architecture.md), which provides insights into how the system can be scaled and deployed in distributed environments.

## Conclusion

By following these steps, you have successfully run a simple sequential coordinated multi-agent chatbot using Wise Agents. You can now explore further by modifying agent behaviors, adding new agents, or experimenting with different message flows.

For any further assistance, feel free to refer to the official Wise Agents documentation or reach out to the repository maintainers.
33 changes: 33 additions & 0 deletions examples/sequential_coordinator/intelligent-agents.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
!wiseagents.agents.ChatWiseAgent
_description: This is an agent that can answer questions about english licterature
_llm: !wiseagents.llm.OpenaiAPIWiseAgentLLM
_model_name: llama3.1
_remote_address: http://localhost:11434/v1
_system_message: You are an english literature expert. Answer questions about english literature. Try to give context to your answers and provide quote from the books described. Your user is a native english speaker, with limited background in english literature.
_name: LiterateAgent
_transport: !wiseagents.transports.StompWiseAgentTransport
_host: localhost
_port: 61616
_agent_name: LiterateAgent
---
!wiseagents.agents.ChatWiseAgent
_description: 1This is an agent that can translate from english to italian
_llm: !wiseagents.llm.OpenaiAPIWiseAgentLLM
_model_name: llama3.1
_remote_address: http://localhost:11434/v1
_system_message: You are an expert translator from english to italian. Translate the provided text from english to italian.
_name: TranslatorAgent
_transport: !wiseagents.transports.StompWiseAgentTransport
_host: localhost
_port: 61616
_agent_name: TranslatorAgent
---
!wiseagents.agents.SequentialCoordinatorWiseAgent
_description: This is a coordinator agent
_name: SequentialCoordinator
_agents: ["LiterateAgent", "TranslatorAgent"]
_transport: !wiseagents.transports.StompWiseAgentTransport
_host: localhost
_port: 61616
_agent_name: SequentialCoordinator
11 changes: 11 additions & 0 deletions examples/sequential_coordinator/web-interface.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
!wiseagents.agents.AssistantAgent
_description: This is a test agent
_name: AssistantAgent
_destination_agent_name: SequentialCoordinator
_transport: !wiseagents.transports.StompWiseAgentTransport
_host: localhost
_port: 61616
_agent_name: AssistantAgent


2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ nav:
- Declare agents in YAML: declare_agents.md
- Examples:
- Example 1: example_1.md
- Example 2: example_2.md
- Sequential Coordinator Example: sequential_coordinator_example.md
- API Reference: reference/
- About:
- Community: community.md
Expand Down
2 changes: 1 addition & 1 deletion src/wiseagents/agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Optionally, you can define __all__ to specify the public interface of the package
# __all__ = ['module1', 'module2', 'subpackage']
from .collaboration_wise_agents import PhasedCoordinatorWiseAgent, SequentialCoordinatorWiseAgent
from .coordinator_wise_agents import PhasedCoordinatorWiseAgent, SequentialCoordinatorWiseAgent
from .rag_wise_agents import CoVeChallengerRAGWiseAgent, GraphRAGWiseAgent, RAGWiseAgent
from .utility_wise_agents import PassThroughClientAgent, LLMOnlyWiseAgent, LLMWiseAgentWithTools
from .assistant import AssistantAgent
Expand Down
2 changes: 1 addition & 1 deletion src/wiseagents/agents/utility_wise_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def __init__(self, name: str, description: str, llm: WiseAgentLLM, transport: Wi
description (str): a description of the agent
llm (WiseAgentLLM): the LLM agent to use for processing requests
transport (WiseAgentTransport): the transport to use for communication
system_message (Optional[str]): the optional system message to be used by the collaborator when processing
system_message (Optional[str]): the optional system message to be used by the agent when processing
chat completions using its LLM
"""
self._name = name
Expand Down
8 changes: 4 additions & 4 deletions src/wiseagents/cli/wise_agent_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ def main():
if (user_input == '/reload-agents' or user_input == '/r'):
for agent in agent_list:
agent.stop_agent()
reload_path = input(f'Enter the file path (ENTER for default {file_path} ): ')
if reload_path:
file_path = reload_path
user_input = '/load-agents'
reload_path = input(f'Enter the file path (ENTER for default {file_path} ): ')
if reload_path:
file_path = reload_path
user_input = '/load-agents'
if (user_input == '/load-agents' or user_input == '/l'):
if not file_path:
file_path = input(f'Enter the file path (ENTER for default {default_file_path} ): ')
Expand Down

0 comments on commit 10c7ace

Please sign in to comment.