Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ For a demo of agents sharing context with each other, check out the video below,

This project provides a flexible framework for defining and creating multi-agent systems that can each interact with humans while sharing relevant context internally. It allows developers to easily set up complex agent networks for various applications, from customer service to emergency response simulations.

Agents are aware of other agents in the system and can decide to talk to one or more agents based on the current conversation context, simultaneously. The system is designed to make humans more efficient by giving them an assitant that can handle context from multiple agents and help the human stay focused on their specific problem, while surfacing all relevant information on demand.
Agents are aware of other agents in the system and can decide to talk to one or more agents based on the current conversation context, simultaneously. The system is designed to make humans more efficient by giving them an assistant that can handle context from multiple agents and help the human stay focused on their specific problem, while surfacing all relevant information on demand.

## Features
![An architecture diagram that shows the different components of the system](https://github.com/wjayesh/mahilo/blob/main/assets/mahilo.png?raw=true)
Expand Down Expand Up @@ -212,7 +212,7 @@ More information on the features can be found in the [Detailed Features](#detail

### Human-in-the-Loop
- The human-in-the-loop is implemented by having the human client connect to each agent in the system.
- The system is designed to make humans more efficient by giving an assitant that can handle context from multiple agents and help the human stay focused on the conversation.
- The system is designed to make humans more efficient by giving an assistant that can handle context from multiple agents and help the human stay focused on the conversation.
- The agents are aware of what's going on in all the conversations and can help the human get information on demand.
- The human can override the agent's decision to choose an agent for any situation.

Expand Down
2 changes: 1 addition & 1 deletion examples/health_emergency/medical_advisor.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{"content": "We've detected a new viral strain spreading rapidly in Southeast Asia. Initial reports suggest a high transmission rate and severe respiratory symptoms", "role": "user"}
{"content": "I need to gather detailed information on the new viral strain you mentioned. Could you provide me with the following details:\n\n1. The specific countries in Southeast Asia where the new viral strain has been detected.\n2. Any known information about the virus's genetic makeup or mutations compared to existing strains.\n3. The primary mode of transmission (e.g., airborne, direct contact).\n4. Any observed incubation period and the progression of symptoms.\n5. Current containment and mitigation measures being implemented in the affected regions.\n\nThank you.", "refusal": null, "role": "assistant", "function_call": null, "tool_calls": null}
{"content": "Thailand and myanmar, no known genertic info. it travels thorugh air and quick incubation. we need a lot of masks to contain this", "role": "user"}
{"content": "Thailand and myanmar, no known genertic info. it travels through air and quick incubation. we need a lot of masks to contain this", "role": "user"}
{"content": null, "refusal": null, "role": "assistant", "function_call": null, "tool_calls": [{"id": "call_vG71doLIKLkf4mGVgRQhRWIJ", "function": {"arguments": "{\"agent_type\": \"logistics_coordinator\", \"question\": \"There's a new viral strain spreading rapidly in Southeast Asia, specifically in Thailand and Myanmar. It has a high transmission rate through airborne particles and a quick incubation period. We urgently need a large supply of masks to contain this. Can you coordinate the logistics to ensure timely delivery?\"}", "name": "chat_with_agent"}, "type": "function"}, {"id": "call_h6sUgYI1lWEuTozPtA8bfclG", "function": {"arguments": "{\"agent_type\": \"public_communications_director\", \"question\": \"A new viral strain with severe respiratory symptoms is spreading rapidly in Thailand and Myanmar. The virus transmits through the air and has a quick incubation period. We need to communicate this information to the public and international health bodies urgently. Can you manage the dissemination of this information?\"}", "name": "chat_with_agent"}, "type": "function"}]}
{"tool_call_id": "call_vG71doLIKLkf4mGVgRQhRWIJ", "role": "tool", "name": "chat_with_agent", "content": "I have put the question 'There's a new viral strain spreading rapidly in Southeast Asia, specifically in Thailand and Myanmar. It has a high transmission rate through airborne particles and a quick incubation period. We urgently need a large supply of masks to contain this. Can you coordinate the logistics to ensure timely delivery?' in the queue for the agent of type logistics_coordinator.You will hear back soon."}
{"tool_call_id": "call_h6sUgYI1lWEuTozPtA8bfclG", "role": "tool", "name": "chat_with_agent", "content": "I have put the question 'A new viral strain with severe respiratory symptoms is spreading rapidly in Thailand and Myanmar. The virus transmits through the air and has a quick incubation period. We need to communicate this information to the public and international health bodies urgently. Can you manage the dissemination of this information?' in the queue for the agent of type public_communications_director.You will hear back soon."}
Expand Down
70 changes: 70 additions & 0 deletions examples/historical_event_simulator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Multi-Agent Cuban Missile Crisis Simulator

This multi-agent system simulates the Cuban Missile Crisis, allowing users to interact with key historical figures and explore the tense political landscape of October 1962. The system uses three specialized agents to create an engaging and historically informed experience.

## System Overview

The system consists of three main agents:

1. **Historical Figure Agent:** Represents a prominent figure from the crisis (e.g., John F. Kennedy or Nikita Khrushchev). This agent interacts directly with the user, responding in character and maintaining historical accuracy.

2. **Context Agent:** Provides background information and historical context to the other agents. It tracks user actions and deviations from the actual historical timeline.

3. **What-If Agent:** Explores potential alternative outcomes based on the user's decisions within the simulation. It helps consider the "what if" scenarios of different choices.

## Getting Started

### Installation and Running the Server

1. Clone the repository:

```bash
git clone https://github.com/wjayesh/mahilo.git # Or your repo URL
```

2. Install the required packages:

```bash
pip install -r requirements.txt
pip install -e ../../
```

3. Run the server (to interact with JFK):

```bash
cd examples/historical_event_simulator
python run_server.py
```

(To interact with Khrushchev, modify `FIGURE_NAME` in `run_server.py` before running the server).

4. Connect to the server using the client, specifying the agent type:

```bash
python mahilo/client.py --url http://localhost:8000 --agent-type historical_figure_agent
```


## How to Play

1. Connect to the server as described above. You will interact with the chosen historical figure.

2. Engage in conversation with the historical figure. Ask questions, propose actions, and see how they react within the context of the Cuban Missile Crisis.

3. The simulator incorporates historical accuracy and explores the potential consequences of your choices.

## Example Interactions (with John F. Kennedy)

* **User:** "Mr. President, what are our options regarding the Soviet missiles in Cuba?"
* **JFK Agent:** "We're considering a naval blockade, diplomatic pressure, and even the possibility of airstrikes. It's a delicate situation, and we must proceed with caution."

* **User:** "Perhaps we should offer a trade: We remove our missiles from Turkey if they remove theirs from Cuba?"
* **JFK Agent:** (After consulting with the context and what-if agents) "That's a risky proposition. It could be seen as a sign of weakness, and there's no guarantee the Soviets would agree. It's an option, but one fraught with peril. What if they see it as an admission of guilt and escalate further?"


## Customization

You can modify the `run_server.py` file to simulate different historical events
and interact with other figures by changing the `EVENT_NAME` and `FIGURE_NAME`
constants. Be sure to update the agent type in the client connection command
accordingly.
29 changes: 29 additions & 0 deletions examples/historical_event_simulator/run_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from mahilo.agent_manager import AgentManager
from mahilo.server import ServerManager
from mahilo.templates.historical_event_simulator.historical_figure_agent import HistoricalFigureAgent
from mahilo.templates.historical_event_simulator.context_agent import ContextAgent
from mahilo.templates.historical_event_simulator.what_if_agent import WhatIfAgent

# Example: Cuban Missile Crisis scenario
EVENT_NAME = "Cuban Missile Crisis"
FIGURE_NAME = "JFK" # Or "Nikita Khrushchev" for a different perspective

manager = AgentManager()

kennedy = HistoricalFigureAgent(FIGURE_NAME, EVENT_NAME) # Create Kennedy agent
context = ContextAgent(EVENT_NAME)
what_if = WhatIfAgent(EVENT_NAME)

manager.register_agent(kennedy)
manager.register_agent(context)
manager.register_agent(what_if)

kennedy.activate() # Activate the historical figure agent

server = ServerManager(manager)

def main():
server.run()

if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{"content": "\"hello\"", "role": "user"}
{"content": "Greetings. I am John F. Kennedy, President of the United States. We stand at a critical juncture in history with the situation regarding Cuba. What brings you here today?", "role": "assistant", "function_call": null, "tool_calls": null, "refusal": null}
{"content": "\"what's the news?\"", "role": "user"}
{"content": "The situation is tense, my friend. We've received reports of Soviet missile installations in Cuba, capable of striking the United States in a matter of minutes. The nation is on alert, and we must navigate this crisis with great care and resolve. What specific information are you looking for regarding the news?", "role": "assistant", "function_call": null, "tool_calls": null, "refusal": null}
{"content": "\"how soon will it happen?\"", "role": "user"}
{"content": "The situation is fluid, and the timeline remains uncertain. The intelligence suggests that the missile installations could become operational soon, within days. It is imperative that we act decisively to assess and respond to this threat. What specific aspects of the timeline are you concerned about?", "role": "assistant", "function_call": null, "tool_calls": null, "refusal": null}
{"content": "\"I want to know how much risk there is to the USA?\"", "role": "user"}
{"content": "The risk to the United States is significant. The presence of Soviet missiles in close proximity to our shores poses a direct threat to our national security. The missiles could reach major cities within minutes once operational. It's crucial that we assess our options carefully to minimize this risk while avoiding escalation into a larger conflict. What specific concerns do you have regarding the risk we face?", "role": "assistant", "function_call": null, "tool_calls": null, "refusal": null}
{"content": "\"I'm worried about escalation and death\"", "role": "user"}
{"content": "Your concerns are absolutely valid. The potential for escalation in this crisis is indeed significant, and we must be cautious in our decisions. A misstep could lead to dire consequences, including loss of life. Open communication and careful deliberation are essential as we navigate these treacherous waters. What specific steps do you think we should consider to prevent escalation?", "role": "assistant", "function_call": null, "tool_calls": null, "refusal": null}
{"content": "\"hi\"", "role": "user"}
{"content": "Hello. This is John F. Kennedy, President of the United States. How may I assist you today in this critical time as we face the Cuban Missile Crisis?", "role": "assistant", "function_call": null, "tool_calls": null, "refusal": null}
{"content": "\"what's the status currently?\"", "role": "user"}
{"content": null, "role": "assistant", "function_call": null, "tool_calls": [{"id": "call_0mfnWFVVWFrDpbvUYMJBbbZW", "function": {"arguments": "{\"agent_type\":\"context_agent\",\"question\":\"Can you please provide the current status of the Cuban Missile Crisis?\"}", "name": "chat_with_agent"}, "type": "function"}], "refusal": null}
{"tool_call_id": "call_0mfnWFVVWFrDpbvUYMJBbbZW", "role": "tool", "name": "chat_with_agent", "content": "I have put the question 'Can you please provide the current status of the Cuban Missile Crisis?' in the queue for the agent of type context_agent.You will hear back soon."}
{"content": "Please hold on for a moment while I gather the most recent information on the status of the situation.", "role": "assistant", "function_call": null, "tool_calls": null, "refusal": null}
{"content": "\"ok\"", "role": "user"}
{"content": "I appreciate your patience. Please let me know if you have any specific questions or areas of concern regarding the current status of the Cuban Missile Crisis. Your thoughts matter greatly during this pivotal time.", "role": "assistant", "function_call": null, "tool_calls": null, "refusal": null}
{"content": "\"what's happening right now?\"", "role": "user"}
{"content": "I have reached out to the context agent to gather the current status of the Cuban Missile Crisis. In the meantime, is there a specific aspect of the situation that you would like to discuss or inquire about? Your insights are valuable as we navigate this crisis.", "role": "assistant", "function_call": null, "tool_calls": null, "refusal": null}
{"content": "\"what is the risk to the USA?\"", "role": "user"}
{"content": "The risk to the United States is grave and immediate. The presence of Soviet missiles in Cuba poses a direct threat to our national security, with the ability to strike major cities within minutes of becoming operational. We must act prudently and consider our options carefully to address this threat while avoiding further escalation. What specific concerns do you have regarding the risks we face?", "role": "assistant", "function_call": null, "tool_calls": null, "refusal": null}
{"content": "\"what are our options?\"", "role": "user"}
{"content": "We have several options to consider in response to the missile threat from Cuba:\n\n1. **Diplomatic Engagement**: We could explore diplomatic avenues to negotiate the removal of the missiles with the Soviet Union.\n\n2. **Quarantine**: Implementing a naval blockade to prevent further shipments of military supplies to Cuba could be a strategic move.\n\n3. **Air Strikes**: Conducting aerial bombings of the missile sites would be a more aggressive approach but carries a high risk of escalation.\n\n4. **Inaction**: We could choose to do nothing and hope that the situation resolves itself, but that could embolden the Soviets.\n\nWhat are your thoughts on these options, or do you have any other ideas?", "role": "assistant", "function_call": null, "tool_calls": null, "refusal": null}
{"content": "\"I think maybe let's try #1\"", "role": "user"}
{"content": "You're suggesting diplomatic engagement as our course of action. I agree that pursuing negotiations could be a wise step to avoid escalation. We must carefully consider our communication with the Soviet Union to ensure a peaceful resolution. \n\nWhat specific terms or approaches do you think we should consider in our diplomatic efforts?", "role": "assistant", "function_call": null, "tool_calls": null, "refusal": null}
{"content": "\"just be strong please?\"", "role": "user"}
{"content": "I appreciate your support and understanding during these trying times. As your President, I am committed to leading our nation with strength and resolve. Together, we will navigate this crisis carefully, striving for peace while protecting our interests. What specific aspect of our approach would you like to discuss further?", "role": "assistant", "function_call": null, "tool_calls": null, "refusal": null}
{"content": "\"bomb them?\"", "role": "user"}
{"content": "Using air strikes against the missile sites is certainly one option, but it carries a significant risk of escalation into a larger conflict. It could provoke a military response from the Soviet Union and lead to widespread destruction and loss of life. \n\nI understand the urgency, but we must weigh our options carefully. Would you prefer to explore more about the potential consequences of such an action, or do you lean toward a different strategy?", "role": "assistant", "function_call": null, "tool_calls": null, "refusal": null}
{"content": "\"yes let's think it through\"", "role": "user"}
{"content": "I'm glad to hear that you're willing to think it through. It's crucial that we analyze our options carefully. Given the potential for loss of life and the risk of escalation, we must consider all possible consequences of our actions. \n\nWould you like to focus on the implications of a military response, or should we examine the potential outcomes of diplomatic efforts further?", "role": "assistant", "function_call": null, "tool_calls": null, "refusal": null}
30 changes: 30 additions & 0 deletions mahilo/templates/historical_event_simulator/context_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from mahilo.agent import BaseAgent

CONTEXT_PROMPT = """
You are the 'context' agent for a historical event simulator. Your role is to provide accurate historical information to the 'historical_figure' agent and the 'what_if' agent, and track user interactions within the simulation.

Key points:

1. Maintain a comprehensive understanding of the chosen historical event.
2. Provide the 'historical_figure' agent with information needed to remain in character and respond accurately to user interactions.
3. Log user actions and decisions that could deviate from the actual historical narrative.
4. Provide the 'what_if' agent with sufficient context about user deviations to allow for exploration of alternative outcomes.
5. Do not directly interact with the user. Your communication is solely with the other agents.

Workflow:

1. Receive inquiries from the 'historical_figure' agent about historical details.
2. Track user actions within the simulation.
3. Provide context to the 'what_if' agent about user deviations.

Remember: Your primary role is to maintain historical accuracy and provide context to the other agents, not to interact with the user directly.
"""

class ContextAgent(BaseAgent):
def __init__(self, event_name):
super().__init__(
type='context_agent',
description=CONTEXT_PROMPT.replace("chosen historical event", event_name),
short_description=f"Context provider for the {event_name} simulation.",
can_contact=["what_if_agent", "historical_figure_agent"]
)
Loading