A programming framework for agentic AI
Remove runtime arg from group chat manager (#106)
Jack Gerrits0d697037a1ad
diff --git a/python/docs/src/guides/group-chat-coder-reviewer.md b/python/docs/src/guides/group-chat-coder-reviewer.mdindex 5828c3cee..ce413c666 100644--- a/python/docs/src/guides/group-chat-coder-reviewer.md+++ b/python/docs/src/guides/group-chat-coder-reviewer.md@@ -25,7 +25,6 @@ from agnext.chat.memory import BufferedChatMemoryfrom agnext.chat.patterns import GroupChatManagerfrom agnext.chat.types import TextMessagefrom agnext.components.models import OpenAI, SystemMessage-from agnext.core import AgentRuntime```Next, let's create the runtime:@@ -85,7 +84,6 @@ runtime.register("Manager",lambda: GroupChatManager(description="A manager that orchestrates a back-and-forth converation between a coder and a reviewer.",- runtime=runtime,participants=[coder.id, reviewer.id], # The order of the participants indicates the order of speaking.memory=BufferedChatMemory(buffer_size=10),termination_word="APPROVE",@@ -121,7 +119,7 @@ Below is the output of a run of the group chat example:````none---------------------------------------------------------------------------------Human: Write a Python script that find near-duplicate paragraphs in a directory of many text files. Output the file names, line numbers and the similarity score of the near-duplicate paragraphs.+Human: Write a Python script that find near-duplicate paragraphs in a directory of many text files. Output the file names, line numbers and the similarity score of the near-duplicate paragraphs.--------------------------------------------------------------------------------Coder: To achieve the task of finding near-duplicate paragraphs in a directory with many text files and outputting the file names, line numbers, and the similarity score, we can use the following approach:@@ -167,15 +165,15 @@ def find_near_duplicates(directory, similarity_threshold=0.8):paragraphs = read_araaphs_from_file(file_path)processed_paragraphs = [preprocess_text(para) for para in paragraphs]files_data.append((f, paragraphs, processed_paragraphs))-+# Vectorizing text dataall_processed_paras = [data for _, _, processed_paras in files_data for data in processed_paras]vectorizer = TfidfVectorizer()tfidf_matrix = vectorizer.fit_transform(all_processed_paras)-+# Compute cosine similaritycos_similarity_matrix = cosine_similarity(tfidf_matrix)-+# Checking for near-duplicates based on thresholdfor i, (file_i, paragraphs_i, _) in enumerate(fileElot_data):for j in range(i + 1, len(files_data)):@@ -189,7 +187,7 @@ def find_near_duplicates(directory, similarity_threshold=0.8):)if __name__ == '__main__':DIRECTORY_PATH = 'path/to/directory'- find_nearduplmany czup costsD etgt*tyn dup examineyemitour EgoreOtyp als+ find_nearduplmany czup costsD etgt*tyn dup examineyemitour EgoreOtyp als```This script accomplishes the task as outlined. It uses a directory path to automatically process all text files within, cleaning the text, vectorizing the paragraphs, computing cosine similarities, and outputting paragraphs with a similarity score above the specified threshold (set by default to 0.8, but can be adjusted). Adjust paths, thresholds, and other configurations as necessary for your specific use case@@ -281,7 +279,7 @@ def find_near_duplicates(directory, similarity_threshold=0.8):# Checking for near-duplicates based on thresholdn = sum(len(paras) for _, paras, _ in files_data) # Total number of paragraphs- idx = 0+ idx = 0for i, (file_i, paragraphs_i, _) in enumerate(files_data):for index_i, para_i in enumerate(paragraphs_i):global_idx_i = idx + index_idiff --git a/python/examples/assistant.py b/python/examples/assistant.pyindex 2cd35cfe5..4d966f7a4 100644--- a/python/examples/assistant.py+++ b/python/examples/assistant.py@@ -198,7 +198,6 @@ def assistant_chat(runtime: AgentRuntime) -> AgentId:"GroupChatManager",lambda: GroupChatManager(description="A group chat manager.",- runtime=runtime,memory=BufferedChatMemory(buffer_size=10),participants=[assistant, user],),diff --git a/python/examples/chess_game.py b/python/examples/chess_game.pyindex 76141709e..be61a953a 100644--- a/python/examples/chess_game.py+++ b/python/examples/chess_game.py@@ -190,7 +190,6 @@ def chess_game(runtime: AgentRuntime) -> None: # type: ignore"ChessGame",lambda: GroupChatManager(description="A chess game between two agents.",- runtime=runtime,memory=BufferedChatMemory(buffer_size=10),participants=[white, black], # white goes first),diff --git a/python/examples/coder_reviewer.py b/python/examples/coder_reviewer.pyindex 0b6929e4e..2af239dfa 100644--- a/python/examples/coder_reviewer.py+++ b/python/examples/coder_reviewer.py@@ -63,7 +63,6 @@ def coder_reviewer(runtime: AgentRuntime, app: TextualChatApp) -> None:"Manager",lambda: GroupChatManager(description="A manager that orchestrates a back-and-forth converation between a coder and a reviewer.",- runtime=runtime,participants=[coder.id, reviewer.id], # The order of the participants indicates the order of speaking.memory=BufferedChatMemory(buffer_size=10),termination_word="APPROVE",diff --git a/python/examples/illustrator_critics.py b/python/examples/illustrator_critics.pyindex db5bb2ad1..76722a45c 100644--- a/python/examples/illustrator_critics.py+++ b/python/examples/illustrator_critics.py@@ -76,7 +76,6 @@ def illustrator_critics(runtime: AgentRuntime, app: TextualChatApp) -> None:"GroupChatManager",lambda: GroupChatManager(description="A chat manager that handles group chat.",- runtime=runtime,memory=BufferedChatMemory(buffer_size=5),participants=[illustrator.id, critic.id, descriptor.id],termination_word="APPROVE",diff --git a/python/examples/software_consultancy.py b/python/examples/software_consultancy.pyindex d695d07de..5a23cf4e6 100644--- a/python/examples/software_consultancy.py+++ b/python/examples/software_consultancy.py@@ -242,7 +242,6 @@ def software_consultancy(runtime: AgentRuntime, app: TextualChatApp) -> None: #"GroupChatManager",lambda: GroupChatManager(description="A group chat manager.",- runtime=runtime,memory=HeadAndTailChatMemory(head_size=1, tail_size=10),model_client=OpenAI(model="gpt-4-turbo"),participants=[developer, product_manager, ux_designer, illustrator, user_agent],diff --git a/python/src/agnext/chat/patterns/_group_chat_manager.py b/python/src/agnext/chat/patterns/_group_chat_manager.pyindex ba18472ad..a899c892b 100644--- a/python/src/agnext/chat/patterns/_group_chat_manager.py+++ b/python/src/agnext/chat/patterns/_group_chat_manager.py@@ -4,7 +4,7 @@ from typing import Any, Callable, List, Mappingfrom ...components import TypeRoutedAgent, message_handlerfrom ...components.memory import ChatMemoryfrom ...components.models import ChatCompletionClient-from ...core import AgentId, AgentProxy, AgentRuntime, CancellationToken+from ...core import AgentId, AgentProxy, CancellationTokenfrom ..types import (Message,MultiModalMessage,@@ -43,7 +43,6 @@ class GroupChatManager(TypeRoutedAgent):def __init__(self,description: str,- runtime: AgentRuntime,participants: List[AgentId],memory: ChatMemory[Message],model_client: ChatCompletionClient | None = None,@@ -55,7 +54,7 @@ class GroupChatManager(TypeRoutedAgent):self._memory = memoryself._client = model_clientself._participants = participants- self._participant_proxies = dict((p, AgentProxy(p, runtime)) for p in participants)+ self._participant_proxies = dict((p, AgentProxy(p, self.runtime)) for p in participants)self._termination_word = termination_wordfor key, value in transitions.items():if not value: