Skip to content

Commit

Permalink
修改messageoutput,区分talk to和respond to,respond to用🙋代替
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Jan 15, 2024
1 parent 3f3688c commit b3aaad8
Show file tree
Hide file tree
Showing 73 changed files with 196 additions and 2,706 deletions.
2 changes: 0 additions & 2 deletions agency_swarm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@
from .agents import Agent
from .tools import BaseTool
from .util import set_openai_key
from .util import set_openai_client
from .util import get_openai_client
37 changes: 9 additions & 28 deletions agency_swarm/agency/agency.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@

class Agency:

def __init__(self, agency_chart, shared_instructions="", shared_files=None):
def __init__(self, agency_chart, shared_instructions=""):
"""
Initializes the Agency object, setting up agents, threads, and core functionalities.
Parameters:
agency_chart: The structure defining the hierarchy and interaction of agents within the agency.
shared_instructions (str, optional): A path to a file containing shared instructions for all agents. Defaults to an empty string.
shared_files (list, optional): A list of folder paths with files containing shared resources for all agents. Defaults to an empty list.
This constructor initializes various components of the Agency, including CEO, agents, threads, and user interactions. It parses the agency chart to set up the organizational structure and initializes the messaging tools, agents, and threads necessary for the operation of the agency. Additionally, it prepares a main thread for user interactions.
"""
self.ceo = None
self.agents = []
self.agents_and_threads = {}
self.shared_files = shared_files if shared_files else []

if os.path.isfile(os.path.join(self.get_class_folder_path(), shared_instructions)):
self._read_instructions(os.path.join(self.get_class_folder_path(), shared_instructions))
Expand All @@ -48,19 +46,18 @@ def __init__(self, agency_chart, shared_instructions="", shared_files=None):
self.user = User()
self.main_thread = Thread(self.user, self.ceo)

def get_completion(self, message: str, message_files=None, yield_messages=True):
def get_completion(self, message: str, yield_messages=True):
"""
Retrieves the completion for a given message from the main thread.
Parameters:
message (str): The message for which completion is to be retrieved.
message_files (list, optional): A list of file ids to be sent as attachments with the message. Defaults to None.
yield_messages (bool, optional): Flag to determine if intermediate messages should be yielded. Defaults to True.
Returns:
Generator or final response: Depending on the 'yield_messages' flag, this method returns either a generator yielding intermediate messages or the final response from the main thread.
"""
gen = self.main_thread.get_completion(message=message, message_files=message_files, yield_messages=yield_messages)
gen = self.main_thread.get_completion(message=message, yield_messages=yield_messages)

if not yield_messages:
while True:
Expand Down Expand Up @@ -122,7 +119,6 @@ def bot(history):

# Launch the demo
demo.launch()
return demo

def run_demo(self):
"""
Expand Down Expand Up @@ -299,7 +295,6 @@ def _create_send_message_tool(self, agent: Agent, recipient_agents: List[Agent])
"""
Creates a SendMessage tool to enable an agent to send messages to specified recipient agents.
Parameters:
agent (Agent): The agent who will be sending messages.
recipient_agents (List[Agent]): A list of recipient agents who can receive messages.
Expand All @@ -321,19 +316,14 @@ def _create_send_message_tool(self, agent: Agent, recipient_agents: List[Agent])

class SendMessage(BaseTool):
"""Use this tool to facilitate direct, synchronous communication between specialized agents within your agency. When you send a message using this tool, you receive a response exclusively from the designated recipient agent. To continue the dialogue, invoke this tool again with the desired recipient and your follow-up message. Remember, communication here is synchronous; the recipient agent won't perform any tasks post-response. You are responsible for relaying the recipient agent's responses back to the user, as they do not have direct access to these replies. Keep engaging with the tool for continuous interaction until the task is fully resolved."""
instructions: str = Field(...,
description="Please repeat your instructions step-by-step, including both completed "
"and the following next steps that you need to perfrom. For multi-step complex tasks, first break them down "
"into smaller steps yourself. Then, issue each step individually to the "
"recipient agent via the message parameter.")
chain_of_thought: str = Field(...,
description="Think step by step to determine the correct recipient and "
"message.")
recipient: recipients = Field(..., description=agent_descriptions)
message: str = Field(...,
description="Specify the task required for the recipient agent to complete. Focus on "
"clarifying what the task entails, rather than providing exact "
"instructions.")
message_files: List[str] = Field(default=None,
description="A list of file ids to be sent as attachments to the message. Only use this if you have the file id that starts with 'file-'.",
examples=["file-1234", "file-5678"])
caller_agent_name: str = Field(default=agent.name,
description="The agent calling this tool. Defaults to your name. Do not change it.")

Expand All @@ -352,7 +342,7 @@ def check_caller_agent_name(cls, value):
def run(self):
thread = outer_self.agents_and_threads[self.caller_agent_name][self.recipient.value]

gen = thread.get_completion(message=self.message, message_files=self.message_files)
gen = thread.get_completion(message=self.message)
try:
while True:
yield next(gen)
Expand Down Expand Up @@ -383,17 +373,8 @@ def _init_agents(self):
There are no output parameters as this method is used for internal initialization purposes within the Agency class.
"""
for agent in self.agents:
if "temp_id" in agent.id:
agent.id = None
agent.add_shared_instructions(self.shared_instructions)

if self.shared_files:
if isinstance(agent.files_folder, str):
agent.files_folder = [agent.files_folder]
agent.files_folder += self.shared_files
elif isinstance(agent.files_folder, list):
agent.files_folder += self.shared_files

agent.id = None
agent.add_instructions(self.shared_instructions)
agent.init_oai()

def _init_threads(self):
Expand Down
41 changes: 0 additions & 41 deletions agency_swarm/agency/genesis/GenesisAgency.py

This file was deleted.

1 change: 0 additions & 1 deletion agency_swarm/agency/genesis/__init__.py

This file was deleted.

8 changes: 0 additions & 8 deletions agency_swarm/agency/genesis/manifesto.md

This file was deleted.

Loading

0 comments on commit b3aaad8

Please sign in to comment.