Skip to content

Commit

Permalink
Merge pull request wise-agents#370 from maeste/maeste/issue327
Browse files Browse the repository at this point in the history
Maeste/issue327
  • Loading branch information
fjuma authored Sep 27, 2024
2 parents 0596b93 + a32d74d commit a3e3e71
Show file tree
Hide file tree
Showing 39 changed files with 400 additions and 455 deletions.
5 changes: 3 additions & 2 deletions examples/memory_agentic_chatbot/intelligent-agent.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
!wiseagents.agents.ChatWiseAgent
description: This is another test agent
!wiseagents.agents.ChatWiseAgent
metadata: !wiseagents.WiseAgentMetaData
description: This is another test agent
llm: !wiseagents.llm.OpenaiAPIWiseAgentLLM
model_name: llama3.1
remote_address: http://localhost:11434/v1
Expand Down
3 changes: 2 additions & 1 deletion examples/memory_agentic_chatbot/web-interface.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
!wiseagents.agents.AssistantAgent
description: This is a test agent
metadata: !wiseagents.WiseAgentMetaData
description: This is a test agent
name: AssistantAgent
destination_agent_name: WiseIntelligentAgent
transport: !wiseagents.transports.StompWiseAgentTransport
Expand Down
3 changes: 2 additions & 1 deletion examples/memory_agentic_chatbot_groq/intelligent-agent.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
!wiseagents.agents.ChatWiseAgent
description: This is another test agent
metadata: !wiseagents.WiseAgentMetaData
description: This is another test agent
llm: !wiseagents.llm.OpenaiAPIWiseAgentLLM
model_name: llama-3.1-70b-versatile
remote_address: https://api.groq.com/openai/v1
Expand Down
3 changes: 2 additions & 1 deletion examples/memory_agentic_chatbot_groq/web-interface.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
!wiseagents.agents.AssistantAgent
description: This is a test agent
metadata: !wiseagents.WiseAgentMetaData
description: This is a test agent
name: AssistantAgent
destination_agent_name: WiseIntelligentAgent
transport: !wiseagents.transports.StompWiseAgentTransport
Expand Down
10 changes: 5 additions & 5 deletions examples/perceive_and_act/custom_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
from openai.types.chat import ChatCompletionToolParam, ChatCompletionMessageParam
from typing import List, Optional
from wiseagents import WiseAgent, WiseAgentEvent, WiseAgentMessage, WiseAgentTransport
from wiseagents import WiseAgent, WiseAgentEvent, WiseAgentMessage, WiseAgentMetaData, WiseAgentTransport
from wiseagents.yaml import WiseAgentsLoader

class PerceivingAgent(WiseAgent):
Expand All @@ -12,11 +12,11 @@ class PerceivingAgent(WiseAgent):

stop_event = threading.Event()

def __init__(self, name: str, description: str, transport: WiseAgentTransport, file_path: str, check_interval: float, destination_agent_name: str):
def __init__(self, name: str, metadata: WiseAgentMetaData, transport: WiseAgentTransport, file_path: str, check_interval: float, destination_agent_name: str):
self._file_path = file_path
self._check_interval = check_interval
self._destination_agent_name = destination_agent_name
super().__init__(name=name, description=description, transport=transport)
super().__init__(name=name, metadata=metadata, transport=transport)

def start_agent(self):
super().start_agent()
Expand Down Expand Up @@ -86,9 +86,9 @@ class ActionAgent(WiseAgent):
yaml_tag = u'!custom_agents.ActionAgent'
yaml_loader = WiseAgentsLoader

def __init__(self, name: str, description: str, transport: WiseAgentTransport, destination_file_path: str):
def __init__(self, name: str, metadata: WiseAgentMetaData, transport: WiseAgentTransport, destination_file_path: str):
self._destination_file_path = destination_file_path
super().__init__(name=name, description=description, transport=transport)
super().__init__(name=name, metadata=metadata, transport=transport)

def start_agent(self):
super().start_agent()
Expand Down
12 changes: 8 additions & 4 deletions examples/perceive_and_act/intelligent-agents.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
!wiseagents.agents.LLMOnlyWiseAgent
description: This is an agent that can give suggestion on what to read next
metadata: !wiseagents.WiseAgentMetaData
description: This is an agent that can give suggestion on what to read next
llm: !wiseagents.llm.OpenaiAPIWiseAgentLLM
model_name: llama3.1
remote_address: http://localhost:11434/v1
Expand All @@ -12,7 +13,8 @@ transport: !wiseagents.transports.StompWiseAgentTransport
agent_name: LiterateAgent
---
!custom_agents.PerceivingAgent
description: This is an agent that can perceive file changes
metadata: !wiseagents.WiseAgentMetaData
description: This is an agent that can perceive file changes
name: PerceivingAgent
file_path: ./books_read.txt
check_interval: 5
Expand All @@ -23,7 +25,8 @@ transport: !wiseagents.transports.StompWiseAgentTransport
agent_name: PerceivingAgent
---
!custom_agents.ActionAgent
description: This is an agent that can write a file
metadata: !wiseagents.WiseAgentMetaData
description: This is an agent that can write a file
name: ActionAgent
destination_file_path: ./books_suggested.txt
transport: !wiseagents.transports.StompWiseAgentTransport
Expand All @@ -32,7 +35,8 @@ transport: !wiseagents.transports.StompWiseAgentTransport
agent_name: ActionAgent
---
!wiseagents.agents.SequentialCoordinatorWiseAgent
description: This is a coordinator agent
metadata: !wiseagents.WiseAgentMetaData
description: This is a coordinator agent
name: SequentialCoordinator
agents: ["LiterateAgent", "ActionAgent"]
transport: !wiseagents.transports.StompWiseAgentTransport
Expand Down
2 changes: 1 addition & 1 deletion examples/perceive_ask_and_act/books_read.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
King Lear
Lord of the ring
22 changes: 12 additions & 10 deletions examples/perceive_ask_and_act/custom_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@
import time
from openai.types.chat import ChatCompletionToolParam, ChatCompletionMessageParam
from typing import List, Optional
from wiseagents import WiseAgent, WiseAgentEvent, WiseAgentMessage, WiseAgentTransport
from wiseagents import WiseAgent, WiseAgentEvent, WiseAgentMessage, WiseAgentMetaData, WiseAgentTransport
from wiseagents.transports.stomp import StompWiseAgentTransport
from wiseagents.yaml import WiseAgentsLoader


class PerceivingAgent(WiseAgent):
yaml_tag = u'!custom_agents.PerceivingAgent'
yaml_loader = WiseAgentsLoader

stop_event = threading.Event()

def __init__(self, name: str, description: str, transport: WiseAgentTransport, file_path: str, check_interval: float, destination_agent_name: str):
def __init__(self, name: str, metadata: WiseAgentMetaData, transport: WiseAgentTransport, file_path: str, check_interval: float, destination_agent_name: str):
self._file_path = file_path
self._check_interval = check_interval
self._destination_agent_name = destination_agent_name
super().__init__(name=name, description=description, transport=transport)
super().__init__(name=name, metadata=metadata, transport=transport)

def start_agent(self):
super().start_agent()
Expand Down Expand Up @@ -88,12 +89,14 @@ class ActionAgent(WiseAgent):
yaml_tag = u'!custom_agents.ActionAgent'
yaml_loader = WiseAgentsLoader

def __init__(self, name: str, description: str, transport: WiseAgentTransport, destination_file_path: str):
def __init__(self, name: str, metadata: WiseAgentMetaData, transport: WiseAgentTransport, destination_file_path: str):
self._destination_file_path = destination_file_path
super().__init__(name=name, description=description, transport=transport)
super().__init__(name=name, metadata=metadata, transport=transport)

def start_agent(self):
super().start_agent()

def process_request(self, request: WiseAgentMessage, conversation_history: List[ChatCompletionMessageParam]) -> Optional[str]:
def process_request(self, request: WiseAgentMessage, conversation_history: List[ChatCompletionMessageParam]) -> str | None:
with open(self._destination_file_path, 'w') as f:
f.write(request.message)
self.send_response(WiseAgentMessage("File updated", self.name), request.sender)
Expand All @@ -107,13 +110,12 @@ def process_event(self, event: WiseAgentEvent):

def process_error(self, error: WiseAgentMessage):
pass

class UserQuestionAgent(WiseAgent):
yaml_tag = u'!custom_agents.UserQuestionAgent'
yaml_loader = WiseAgentsLoader

def __init__(self, name: str, description: str, transport: WiseAgentTransport):
super().__init__(name=name, description=description, transport=transport)
def __init__(self, name: str, metadata: WiseAgentMetaData, transport: WiseAgentTransport):
super().__init__(name=name, metadata=metadata, transport=transport)


def process_request(self, request: WiseAgentMessage, conversation_history: List[ChatCompletionMessageParam]) -> Optional[str]:
Expand Down Expand Up @@ -143,7 +145,7 @@ def main():
global user_question_agent
stomp_transport = StompWiseAgentTransport("localhost", 61616, "UserQuestionAgent")
#create and start the agent
user_question_agent = UserQuestionAgent(name="UserQuestionAgent", description="Asks the user a question", transport=stomp_transport)
user_question_agent = UserQuestionAgent(name="UserQuestionAgent", metadata=WiseAgentMetaData(description="Asks the user a question"), transport=stomp_transport)

signal.signal(signal.SIGINT, signal_handler)
print('Press Ctrl+C to exit')
Expand Down
92 changes: 49 additions & 43 deletions examples/perceive_ask_and_act/intelligent-agents.yaml
Original file line number Diff line number Diff line change
@@ -1,53 +1,59 @@
---
!wiseagents.agents.ChatWiseAgent
_description: This is an agent that can give suggestion on what to read next
_llm: !wiseagents.llm.OpenaiAPIWiseAgentLLM
_model_name: llama3.1
_remote_address: http://localhost:11434/v1
_system_message: You are an english literature expert. The user will provide you with a list of books they have read. Suggest the next 5 books they should read and ask user for their favorite one in this list
_name: LiterateAgent
_transport: !wiseagents.transports.StompWiseAgentTransport
_host: localhost
_port: 61616
_agent_name: LiterateAgent
metadata: !wiseagents.WiseAgentMetaData
description: This is an agent that can give suggestion on what to read next
llm: !wiseagents.llm.OpenaiAPIWiseAgentLLM
model_name: llama3.1
remote_address: http://localhost:11434/v1
system_message: You are an english literature expert. The user will provide you with a list of books they have read. Suggest the next 5 books they should read and ask user for their favorite one in this list
name: LiterateAgent
transport: !wiseagents.transports.StompWiseAgentTransport
host: localhost
port: 61616
agent_name: LiterateAgent
---
!custom_agents.PerceivingAgent
_description: This is an agent that can perceive file changes
_name: PerceivingAgent
_file_path: ./books_read.txt
_check_interval: 5
_destination_agent_name: SequentialCoordinator
_transport: !wiseagents.transports.StompWiseAgentTransport
_host: localhost
_port: 61616
_agent_name: PerceivingAgent
metadata: !wiseagents.WiseAgentMetaData
description: This is an agent that can perceive file changes
name: PerceivingAgent
file_path: ./books_read.txt
check_interval: 5
destination_agent_name: SequentialCoordinator
transport: !wiseagents.transports.StompWiseAgentTransport
host: localhost
port: 61616
agent_name: PerceivingAgent
---
!custom_agents.ActionAgent
_description: This is an agent that can write a file
_name: ActionAgent
_destination_file_path: ./books_suggested.txt
_transport: !wiseagents.transports.StompWiseAgentTransport
_host: localhost
_port: 61616
_agent_name: ActionAgent
metadata: !wiseagents.WiseAgentMetaData
description: This is an agent that can write a file
name: ActionAgent
destination_file_path: ./books_suggested.txt
transport: !wiseagents.transports.StompWiseAgentTransport
host: localhost
port: 61616
agent_name: ActionAgent
---
!wiseagents.agents.ChatWiseAgent
_description: This is an agent that can give suggestion on what to read next
_llm: !wiseagents.llm.OpenaiAPIWiseAgentLLM
_model_name: llama3.1
_remote_address: http://localhost:11434/v1
_system_message: You will receive a preference from the user. Considering the previous books read , the user's preference on your first list of suggestion, suggest the next 3 books they should read.
_name: FinalLiterateAgent
_transport: !wiseagents.transports.StompWiseAgentTransport
_host: localhost
_port: 61616
_agent_name: FinalLiterateAgent
metadata: !wiseagents.WiseAgentMetaData
description: This is an agent that can give suggestion on what to read next
llm: !wiseagents.llm.OpenaiAPIWiseAgentLLM
model_name: llama3.1
remote_address: http://localhost:11434/v1
system_message: You will receive a preference from the user. Considering the previous books read , the user's preference on your first list of suggestion, suggest the next 3 books they should read.
name: FinalLiterateAgent
transport: !wiseagents.transports.StompWiseAgentTransport
host: localhost
port: 61616
agent_name: FinalLiterateAgent
---
!wiseagents.agents.SequentialMemoryCoordinatorWiseAgent
_description: This is a coordinator agent
_name: SequentialCoordinator
_agents: ["LiterateAgent", "UserQuestionAgent", "FinalLiterateAgent", "ActionAgent"]
_transport: !wiseagents.transports.StompWiseAgentTransport
_host: localhost
_port: 61616
_agent_name: SequentialCoordinator
metadata: !wiseagents.WiseAgentMetaData
description: This is a coordinator agent
system_message: This agent will coordinate the interaction between the agents
name: SequentialCoordinator
agents: ["LiterateAgent", "UserQuestionAgent", "FinalLiterateAgent", "ActionAgent"]
transport: !wiseagents.transports.StompWiseAgentTransport
host: localhost
port: 61616
agent_name: SequentialCoordinator
9 changes: 6 additions & 3 deletions examples/sequential_coordinator/intelligent-agents.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
!wiseagents.agents.ChatWiseAgent
description: This is an agent that can answer questions about english literature
metadata: !wiseagents.WiseAgentMetaData
description: This is an agent that can answer questions about english literature
llm: !wiseagents.llm.OpenaiAPIWiseAgentLLM
model_name: llama3.1
remote_address: http://localhost:11434/v1
Expand All @@ -12,7 +13,8 @@ transport: !wiseagents.transports.StompWiseAgentTransport
agent_name: LiterateAgent
---
!wiseagents.agents.ChatWiseAgent
description: This is an agent that can translate from english to italian
metadata: !wiseagents.WiseAgentMetaData
description: This is an agent that can translate from english to italian
llm: !wiseagents.llm.OpenaiAPIWiseAgentLLM
model_name: llama3.1
remote_address: http://localhost:11434/v1
Expand All @@ -24,7 +26,8 @@ transport: !wiseagents.transports.StompWiseAgentTransport
agent_name: TranslatorAgent
---
!wiseagents.agents.SequentialCoordinatorWiseAgent
description: This is a coordinator agent
metadata: !wiseagents.WiseAgentMetaData
description: This is a coordinator agent
name: SequentialCoordinator
agents: ["LiterateAgent", "TranslatorAgent"]
transport: !wiseagents.transports.StompWiseAgentTransport
Expand Down
3 changes: 2 additions & 1 deletion examples/sequential_coordinator/web-interface.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
!wiseagents.agents.AssistantAgent
description: This is a test agent
metadata: !wiseagents.WiseAgentMetaData
description: This is a test agent
name: AssistantAgent
destination_agent_name: SequentialCoordinator
transport: !wiseagents.transports.StompWiseAgentTransport
Expand Down
3 changes: 2 additions & 1 deletion src/wiseagents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from wiseagents.core import WiseAgentContext
from wiseagents.core import WiseAgentRegistry
from wiseagents.core import WiseAgentTool
from wiseagents.core import WiseAgentMetaData
from wiseagents.wise_agent_messaging import WiseAgentEvent
from wiseagents.wise_agent_messaging import WiseAgentMessage
from wiseagents.wise_agent_messaging import WiseAgentMessageType
Expand All @@ -17,7 +18,7 @@

# Optionally, you can define __all__ to specify the public interface of the package
# __all__ = ['module1', 'module2', 'subpackage']
__all__ = ['WiseAgentRegistry', 'WiseAgentContext', 'WiseAgent', 'WiseAgentTool',
__all__ = ['WiseAgentRegistry', 'WiseAgentContext', 'WiseAgent', 'WiseAgentTool', 'WiseAgentMetaData',
'WiseAgentMessage', 'WiseAgentMessageType', 'WiseAgentTransport', 'WiseAgentEvent',
'WiseAgentCollaborationType',
'AbstractClassError', 'enforce_no_abstract_class_instances']
4 changes: 2 additions & 2 deletions src/wiseagents/agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

# Optionally, you can define __all__ to specify the public interface of the package
# __all__ = ['module1', 'module2', 'subpackage']
from .coordinator_wise_agents import PhasedCoordinatorWiseAgent, SequentialCoordinatorWiseAgent
from .coordinator_wise_agents import PhasedCoordinatorWiseAgent, SequentialCoordinatorWiseAgent, SequentialMemoryCoordinatorWiseAgent
from .rag_wise_agents import BaseCoVeChallengerWiseAgent, CoVeChallengerRAGWiseAgent, GraphRAGWiseAgent, RAGWiseAgent
from .utility_wise_agents import PassThroughClientAgent, LLMOnlyWiseAgent, LLMWiseAgentWithTools
from .assistant import AssistantAgent

__all__ = ['PhasedCoordinatorWiseAgent', 'SequentialCoordinatorWiseAgent', 'RAGWiseAgent',
__all__ = ['PhasedCoordinatorWiseAgent', 'SequentialCoordinatorWiseAgent', 'SequentialMemoryCoordinatorWiseAgent', 'RAGWiseAgent',
'GraphRAGWiseAgent', 'CoVeChallengerRAGWiseAgent', 'PassThroughClientAgent', 'LLMOnlyWiseAgent',
'LLMWiseAgentWithTools', 'AssistantAgent', 'BaseCoVeChallengerWiseAgent']
10 changes: 5 additions & 5 deletions src/wiseagents/agents/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import uuid

from openai.types.chat import ChatCompletionMessageParam
from wiseagents import WiseAgent, WiseAgentCollaborationType, WiseAgentRegistry, WiseAgentTransport
from wiseagents import WiseAgent, WiseAgentCollaborationType, WiseAgentMetaData, WiseAgentRegistry, WiseAgentTransport
from wiseagents.wise_agent_messaging import WiseAgentMessage
import gradio

Expand All @@ -28,25 +28,25 @@ def __new__(cls, *args, **kwargs):
obj = super().__new__(cls)
return obj

def __init__(self, name: str, description: str , transport: WiseAgentTransport,
def __init__(self, name: str, metadata: WiseAgentMetaData , transport: WiseAgentTransport,
destination_agent_name: str):
"""
Initialize the agent.
Args:
name (str): the name of the agent
description (str): a description of the agent
metadata (WiseAgentMetaData): the metadata for the agent
transport (WiseAgentTransport): the transport to use for communication
destination_agent_name (str): the name of the agent to send requests to
"""
self._name = name
self._destination_agent_name = destination_agent_name
super().__init__(name=name, description=description, transport=transport, llm=None)
super().__init__(name=name, metadata=metadata, transport=transport, llm=None)

def __repr__(self):
"""Return a string representation of the agent."""
return f"{self.__class__.__name__}(name={self.name}, \
description={self.description}, transport={self.transport}, \
metadata={self.metadata}, transport={self.transport}, \
destination_agent_name={self.destination_agent_name},\
response_delivery={self.response_delivery}"

Expand Down
Loading

0 comments on commit a3e3e71

Please sign in to comment.