Skip to content

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.md
index 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 BufferedChatMemory
from agnext.chat.patterns import GroupChatManager
from agnext.chat.types import TextMessage
from 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 data
all_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 similarity
cos_similarity_matrix = cosine_similarity(tfidf_matrix)
-
+
# Checking for near-duplicates based on threshold
for 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 threshold
n = sum(len(paras) for _, paras, _ in files_data) # Total number of paragraphs
- idx = 0
+ idx = 0
for i, (file_i, paragraphs_i, _) in enumerate(files_data):
for index_i, para_i in enumerate(paragraphs_i):
global_idx_i = idx + index_i
diff --git a/python/examples/assistant.py b/python/examples/assistant.py
index 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.py
index 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.py
index 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.py
index 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.py
index 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.py
index 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, Mapping
from ...components import TypeRoutedAgent, message_handler
from ...components.memory import ChatMemory
from ...components.models import ChatCompletionClient
-from ...core import AgentId, AgentProxy, AgentRuntime, CancellationToken
+from ...core import AgentId, AgentProxy, CancellationToken
from ..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 = memory
self._client = model_client
self._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_word
for key, value in transitions.items():
if not value: