ag2 0.9.7__py3-none-any.whl → 0.9.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ag2 might be problematic. Click here for more details.
- {ag2-0.9.7.dist-info → ag2-0.9.9.dist-info}/METADATA +102 -75
- ag2-0.9.9.dist-info/RECORD +387 -0
- autogen/__init__.py +1 -2
- autogen/_website/generate_api_references.py +4 -5
- autogen/_website/generate_mkdocs.py +9 -15
- autogen/_website/notebook_processor.py +13 -14
- autogen/_website/process_notebooks.py +10 -10
- autogen/_website/utils.py +5 -4
- autogen/agentchat/agent.py +13 -13
- autogen/agentchat/assistant_agent.py +7 -6
- autogen/agentchat/contrib/agent_eval/agent_eval.py +3 -3
- autogen/agentchat/contrib/agent_eval/critic_agent.py +3 -3
- autogen/agentchat/contrib/agent_eval/quantifier_agent.py +3 -3
- autogen/agentchat/contrib/agent_eval/subcritic_agent.py +3 -3
- autogen/agentchat/contrib/agent_optimizer.py +3 -3
- autogen/agentchat/contrib/capabilities/generate_images.py +11 -11
- autogen/agentchat/contrib/capabilities/teachability.py +15 -15
- autogen/agentchat/contrib/capabilities/transforms.py +17 -18
- autogen/agentchat/contrib/capabilities/transforms_util.py +5 -5
- autogen/agentchat/contrib/capabilities/vision_capability.py +4 -3
- autogen/agentchat/contrib/captainagent/agent_builder.py +30 -30
- autogen/agentchat/contrib/captainagent/captainagent.py +22 -21
- autogen/agentchat/contrib/captainagent/tool_retriever.py +2 -3
- autogen/agentchat/contrib/gpt_assistant_agent.py +9 -9
- autogen/agentchat/contrib/graph_rag/document.py +3 -3
- autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +3 -3
- autogen/agentchat/contrib/graph_rag/falkor_graph_rag_capability.py +6 -6
- autogen/agentchat/contrib/graph_rag/graph_query_engine.py +3 -3
- autogen/agentchat/contrib/graph_rag/neo4j_graph_query_engine.py +5 -11
- autogen/agentchat/contrib/graph_rag/neo4j_graph_rag_capability.py +6 -6
- autogen/agentchat/contrib/graph_rag/neo4j_native_graph_query_engine.py +7 -7
- autogen/agentchat/contrib/graph_rag/neo4j_native_graph_rag_capability.py +6 -6
- autogen/agentchat/contrib/img_utils.py +1 -1
- autogen/agentchat/contrib/llamaindex_conversable_agent.py +11 -11
- autogen/agentchat/contrib/llava_agent.py +18 -4
- autogen/agentchat/contrib/math_user_proxy_agent.py +11 -11
- autogen/agentchat/contrib/multimodal_conversable_agent.py +8 -8
- autogen/agentchat/contrib/qdrant_retrieve_user_proxy_agent.py +6 -5
- autogen/agentchat/contrib/rag/chromadb_query_engine.py +22 -26
- autogen/agentchat/contrib/rag/llamaindex_query_engine.py +14 -17
- autogen/agentchat/contrib/rag/mongodb_query_engine.py +27 -37
- autogen/agentchat/contrib/rag/query_engine.py +7 -5
- autogen/agentchat/contrib/retrieve_assistant_agent.py +5 -5
- autogen/agentchat/contrib/retrieve_user_proxy_agent.py +8 -7
- autogen/agentchat/contrib/society_of_mind_agent.py +15 -14
- autogen/agentchat/contrib/swarm_agent.py +76 -98
- autogen/agentchat/contrib/text_analyzer_agent.py +7 -7
- autogen/agentchat/contrib/vectordb/base.py +10 -18
- autogen/agentchat/contrib/vectordb/chromadb.py +2 -1
- autogen/agentchat/contrib/vectordb/couchbase.py +18 -20
- autogen/agentchat/contrib/vectordb/mongodb.py +6 -5
- autogen/agentchat/contrib/vectordb/pgvectordb.py +40 -41
- autogen/agentchat/contrib/vectordb/qdrant.py +5 -5
- autogen/agentchat/contrib/web_surfer.py +20 -19
- autogen/agentchat/conversable_agent.py +292 -290
- autogen/agentchat/group/context_str.py +1 -3
- autogen/agentchat/group/context_variables.py +15 -25
- autogen/agentchat/group/group_tool_executor.py +10 -10
- autogen/agentchat/group/group_utils.py +15 -15
- autogen/agentchat/group/guardrails.py +7 -7
- autogen/agentchat/group/handoffs.py +19 -36
- autogen/agentchat/group/multi_agent_chat.py +7 -7
- autogen/agentchat/group/on_condition.py +4 -7
- autogen/agentchat/group/on_context_condition.py +4 -7
- autogen/agentchat/group/patterns/auto.py +8 -7
- autogen/agentchat/group/patterns/manual.py +7 -6
- autogen/agentchat/group/patterns/pattern.py +13 -12
- autogen/agentchat/group/patterns/random.py +3 -3
- autogen/agentchat/group/patterns/round_robin.py +3 -3
- autogen/agentchat/group/reply_result.py +2 -4
- autogen/agentchat/group/speaker_selection_result.py +5 -5
- autogen/agentchat/group/targets/group_chat_target.py +7 -6
- autogen/agentchat/group/targets/group_manager_target.py +4 -4
- autogen/agentchat/group/targets/transition_target.py +2 -1
- autogen/agentchat/groupchat.py +60 -63
- autogen/agentchat/realtime/experimental/audio_adapters/twilio_audio_adapter.py +4 -4
- autogen/agentchat/realtime/experimental/audio_adapters/websocket_audio_adapter.py +4 -4
- autogen/agentchat/realtime/experimental/clients/gemini/client.py +7 -7
- autogen/agentchat/realtime/experimental/clients/oai/base_client.py +8 -8
- autogen/agentchat/realtime/experimental/clients/oai/rtc_client.py +6 -6
- autogen/agentchat/realtime/experimental/clients/realtime_client.py +10 -9
- autogen/agentchat/realtime/experimental/realtime_agent.py +10 -9
- autogen/agentchat/realtime/experimental/realtime_observer.py +3 -3
- autogen/agentchat/realtime/experimental/realtime_swarm.py +44 -44
- autogen/agentchat/user_proxy_agent.py +10 -9
- autogen/agentchat/utils.py +3 -3
- autogen/agents/contrib/time/time_reply_agent.py +6 -5
- autogen/agents/contrib/time/time_tool_agent.py +2 -1
- autogen/agents/experimental/deep_research/deep_research.py +3 -3
- autogen/agents/experimental/discord/discord.py +2 -2
- autogen/agents/experimental/document_agent/chroma_query_engine.py +29 -44
- autogen/agents/experimental/document_agent/docling_doc_ingest_agent.py +9 -14
- autogen/agents/experimental/document_agent/document_agent.py +15 -16
- autogen/agents/experimental/document_agent/document_conditions.py +3 -3
- autogen/agents/experimental/document_agent/document_utils.py +5 -9
- autogen/agents/experimental/document_agent/inmemory_query_engine.py +14 -20
- autogen/agents/experimental/document_agent/parser_utils.py +4 -4
- autogen/agents/experimental/document_agent/url_utils.py +14 -23
- autogen/agents/experimental/reasoning/reasoning_agent.py +33 -33
- autogen/agents/experimental/slack/slack.py +2 -2
- autogen/agents/experimental/telegram/telegram.py +2 -3
- autogen/agents/experimental/websurfer/websurfer.py +4 -4
- autogen/agents/experimental/wikipedia/wikipedia.py +5 -7
- autogen/browser_utils.py +8 -8
- autogen/cache/abstract_cache_base.py +5 -5
- autogen/cache/cache.py +12 -12
- autogen/cache/cache_factory.py +4 -4
- autogen/cache/cosmos_db_cache.py +9 -9
- autogen/cache/disk_cache.py +6 -6
- autogen/cache/in_memory_cache.py +4 -4
- autogen/cache/redis_cache.py +4 -4
- autogen/code_utils.py +18 -18
- autogen/coding/base.py +6 -6
- autogen/coding/docker_commandline_code_executor.py +9 -9
- autogen/coding/func_with_reqs.py +7 -6
- autogen/coding/jupyter/base.py +3 -3
- autogen/coding/jupyter/docker_jupyter_server.py +3 -4
- autogen/coding/jupyter/import_utils.py +3 -3
- autogen/coding/jupyter/jupyter_client.py +5 -5
- autogen/coding/jupyter/jupyter_code_executor.py +3 -4
- autogen/coding/jupyter/local_jupyter_server.py +2 -6
- autogen/coding/local_commandline_code_executor.py +8 -7
- autogen/coding/markdown_code_extractor.py +1 -2
- autogen/coding/utils.py +1 -2
- autogen/doc_utils.py +3 -2
- autogen/environments/docker_python_environment.py +19 -29
- autogen/environments/python_environment.py +8 -17
- autogen/environments/system_python_environment.py +3 -4
- autogen/environments/venv_python_environment.py +8 -12
- autogen/environments/working_directory.py +1 -2
- autogen/events/agent_events.py +106 -109
- autogen/events/base_event.py +6 -5
- autogen/events/client_events.py +15 -14
- autogen/events/helpers.py +1 -1
- autogen/events/print_event.py +4 -5
- autogen/fast_depends/_compat.py +10 -15
- autogen/fast_depends/core/build.py +17 -36
- autogen/fast_depends/core/model.py +64 -113
- autogen/fast_depends/dependencies/model.py +2 -1
- autogen/fast_depends/dependencies/provider.py +3 -2
- autogen/fast_depends/library/model.py +4 -4
- autogen/fast_depends/schema.py +7 -7
- autogen/fast_depends/use.py +17 -25
- autogen/fast_depends/utils.py +10 -30
- autogen/formatting_utils.py +6 -6
- autogen/graph_utils.py +1 -4
- autogen/import_utils.py +38 -27
- autogen/interop/crewai/crewai.py +2 -2
- autogen/interop/interoperable.py +2 -2
- autogen/interop/langchain/langchain_chat_model_factory.py +3 -2
- autogen/interop/langchain/langchain_tool.py +2 -6
- autogen/interop/litellm/litellm_config_factory.py +6 -7
- autogen/interop/pydantic_ai/pydantic_ai.py +4 -7
- autogen/interop/registry.py +2 -1
- autogen/io/base.py +5 -5
- autogen/io/run_response.py +33 -32
- autogen/io/websockets.py +6 -5
- autogen/json_utils.py +1 -2
- autogen/llm_config/__init__.py +11 -0
- autogen/llm_config/client.py +58 -0
- autogen/llm_config/config.py +384 -0
- autogen/llm_config/entry.py +154 -0
- autogen/logger/base_logger.py +4 -3
- autogen/logger/file_logger.py +2 -1
- autogen/logger/logger_factory.py +2 -2
- autogen/logger/logger_utils.py +2 -2
- autogen/logger/sqlite_logger.py +2 -1
- autogen/math_utils.py +4 -5
- autogen/mcp/__main__.py +6 -6
- autogen/mcp/helpers.py +4 -4
- autogen/mcp/mcp_client.py +170 -29
- autogen/mcp/mcp_proxy/fastapi_code_generator_helpers.py +3 -4
- autogen/mcp/mcp_proxy/mcp_proxy.py +23 -26
- autogen/mcp/mcp_proxy/operation_grouping.py +4 -5
- autogen/mcp/mcp_proxy/operation_renaming.py +6 -10
- autogen/mcp/mcp_proxy/security.py +2 -3
- autogen/messages/agent_messages.py +96 -98
- autogen/messages/base_message.py +6 -5
- autogen/messages/client_messages.py +15 -14
- autogen/messages/print_message.py +4 -5
- autogen/oai/__init__.py +1 -2
- autogen/oai/anthropic.py +42 -41
- autogen/oai/bedrock.py +68 -57
- autogen/oai/cerebras.py +26 -25
- autogen/oai/client.py +113 -139
- autogen/oai/client_utils.py +3 -3
- autogen/oai/cohere.py +34 -11
- autogen/oai/gemini.py +39 -17
- autogen/oai/gemini_types.py +11 -12
- autogen/oai/groq.py +22 -10
- autogen/oai/mistral.py +17 -11
- autogen/oai/oai_models/__init__.py +14 -2
- autogen/oai/oai_models/_models.py +2 -2
- autogen/oai/oai_models/chat_completion.py +13 -14
- autogen/oai/oai_models/chat_completion_message.py +11 -9
- autogen/oai/oai_models/chat_completion_message_tool_call.py +26 -3
- autogen/oai/oai_models/chat_completion_token_logprob.py +3 -4
- autogen/oai/oai_models/completion_usage.py +8 -9
- autogen/oai/ollama.py +19 -9
- autogen/oai/openai_responses.py +40 -17
- autogen/oai/openai_utils.py +48 -38
- autogen/oai/together.py +29 -14
- autogen/retrieve_utils.py +6 -7
- autogen/runtime_logging.py +5 -4
- autogen/token_count_utils.py +7 -4
- autogen/tools/contrib/time/time.py +0 -1
- autogen/tools/dependency_injection.py +5 -6
- autogen/tools/experimental/browser_use/browser_use.py +10 -10
- autogen/tools/experimental/code_execution/python_code_execution.py +5 -7
- autogen/tools/experimental/crawl4ai/crawl4ai.py +12 -15
- autogen/tools/experimental/deep_research/deep_research.py +9 -8
- autogen/tools/experimental/duckduckgo/duckduckgo_search.py +5 -11
- autogen/tools/experimental/firecrawl/firecrawl_tool.py +98 -115
- autogen/tools/experimental/google/authentication/credentials_local_provider.py +1 -1
- autogen/tools/experimental/google/drive/drive_functions.py +4 -4
- autogen/tools/experimental/google/drive/toolkit.py +5 -5
- autogen/tools/experimental/google_search/google_search.py +5 -5
- autogen/tools/experimental/google_search/youtube_search.py +5 -5
- autogen/tools/experimental/messageplatform/discord/discord.py +8 -12
- autogen/tools/experimental/messageplatform/slack/slack.py +14 -20
- autogen/tools/experimental/messageplatform/telegram/telegram.py +8 -12
- autogen/tools/experimental/perplexity/perplexity_search.py +18 -29
- autogen/tools/experimental/reliable/reliable.py +68 -74
- autogen/tools/experimental/searxng/searxng_search.py +20 -19
- autogen/tools/experimental/tavily/tavily_search.py +12 -19
- autogen/tools/experimental/web_search_preview/web_search_preview.py +13 -7
- autogen/tools/experimental/wikipedia/wikipedia.py +7 -10
- autogen/tools/function_utils.py +7 -7
- autogen/tools/tool.py +8 -6
- autogen/types.py +2 -2
- autogen/version.py +1 -1
- ag2-0.9.7.dist-info/RECORD +0 -421
- autogen/llm_config.py +0 -385
- {ag2-0.9.7.dist-info → ag2-0.9.9.dist-info}/WHEEL +0 -0
- {ag2-0.9.7.dist-info → ag2-0.9.9.dist-info}/licenses/LICENSE +0 -0
- {ag2-0.9.7.dist-info → ag2-0.9.9.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
import logging
|
|
6
6
|
import os
|
|
7
|
+
from collections.abc import Callable, Sequence
|
|
7
8
|
from pathlib import Path
|
|
8
|
-
from typing import TYPE_CHECKING, Any,
|
|
9
|
+
from typing import TYPE_CHECKING, Any, Optional, Union
|
|
9
10
|
|
|
10
11
|
from autogen.agentchat.contrib.vectordb.base import VectorDBFactory
|
|
11
12
|
from autogen.agentchat.contrib.vectordb.mongodb import MongoDBAtlasVectorDB
|
|
@@ -37,8 +38,7 @@ logger = logging.getLogger(__name__)
|
|
|
37
38
|
@require_optional_import(["pymongo", "llama_index", "sentence_transformers"], "rag")
|
|
38
39
|
@export_module("autogen.agentchat.contrib.rag")
|
|
39
40
|
class MongoDBQueryEngine:
|
|
40
|
-
"""
|
|
41
|
-
A query engine backed by MongoDB Atlas that supports document insertion and querying.
|
|
41
|
+
"""A query engine backed by MongoDB Atlas that supports document insertion and querying.
|
|
42
42
|
|
|
43
43
|
This engine initializes a vector database, builds an index from input documents,
|
|
44
44
|
and allows querying using the chat engine interface.
|
|
@@ -54,13 +54,12 @@ class MongoDBQueryEngine:
|
|
|
54
54
|
self,
|
|
55
55
|
connection_string: str,
|
|
56
56
|
llm: Optional["LLM"] = None,
|
|
57
|
-
database_name:
|
|
58
|
-
embedding_function:
|
|
59
|
-
embedding_model:
|
|
60
|
-
collection_name:
|
|
57
|
+
database_name: str | None = None,
|
|
58
|
+
embedding_function: Union["BaseEmbedding", Callable[..., Any]] | None = None, # type: ignore[type-arg]
|
|
59
|
+
embedding_model: Union["BaseEmbedding", str] | None = None,
|
|
60
|
+
collection_name: str | None = None,
|
|
61
61
|
):
|
|
62
|
-
"""
|
|
63
|
-
Initializes a MongoDBQueryEngine instance.
|
|
62
|
+
"""Initializes a MongoDBQueryEngine instance.
|
|
64
63
|
|
|
65
64
|
Args:
|
|
66
65
|
connection_string (str): Connection string used to connect to MongoDB.
|
|
@@ -89,14 +88,13 @@ class MongoDBQueryEngine:
|
|
|
89
88
|
self.embedding_function = embedding_function or SentenceTransformer("all-MiniLM-L6-v2").encode # type: ignore[call-overload]
|
|
90
89
|
|
|
91
90
|
# These will be initialized later.
|
|
92
|
-
self.vector_db:
|
|
93
|
-
self.vector_search_engine:
|
|
94
|
-
self.storage_context:
|
|
95
|
-
self.index:
|
|
91
|
+
self.vector_db: MongoDBAtlasVectorDB | None = None
|
|
92
|
+
self.vector_search_engine: MongoDBAtlasVectorSearch | None = None # type: ignore[no-any-unimported]
|
|
93
|
+
self.storage_context: StorageContext | None = None # type: ignore[no-any-unimported]
|
|
94
|
+
self.index: VectorStoreIndex | None = None # type: ignore[no-any-unimported]
|
|
96
95
|
|
|
97
96
|
def _set_up(self, overwrite: bool) -> None:
|
|
98
|
-
"""
|
|
99
|
-
Sets up the MongoDB vector database, search engine, and storage context.
|
|
97
|
+
"""Sets up the MongoDB vector database, search engine, and storage context.
|
|
100
98
|
|
|
101
99
|
This method initializes the vector database using the provided connection details,
|
|
102
100
|
creates a vector search engine instance, and sets the storage context for indexing.
|
|
@@ -123,19 +121,17 @@ class MongoDBQueryEngine:
|
|
|
123
121
|
self.storage_context = StorageContext.from_defaults(vector_store=self.vector_search_engine)
|
|
124
122
|
|
|
125
123
|
def _check_existing_collection(self) -> bool:
|
|
126
|
-
"""
|
|
127
|
-
Checks if the specified collection exists in the MongoDB database.
|
|
124
|
+
"""Checks if the specified collection exists in the MongoDB database.
|
|
128
125
|
|
|
129
126
|
Returns:
|
|
130
127
|
bool: True if the collection exists; False otherwise.
|
|
131
128
|
"""
|
|
132
|
-
client:
|
|
129
|
+
client: MongoClient[Any] = MongoClient(self.connection_string) # type: ignore[no-any-unimported]
|
|
133
130
|
db = client[self.database_name] # type: ignore[index]
|
|
134
131
|
return self.collection_name in db.list_collection_names()
|
|
135
132
|
|
|
136
133
|
def connect_db(self, *args: Any, **kwargs: Any) -> bool:
|
|
137
|
-
"""
|
|
138
|
-
Connects to the MongoDB database and initializes the query index from the existing collection.
|
|
134
|
+
"""Connects to the MongoDB database and initializes the query index from the existing collection.
|
|
139
135
|
|
|
140
136
|
This method verifies the existence of the collection, sets up the database connection,
|
|
141
137
|
builds the vector store index, and pings the MongoDB server.
|
|
@@ -168,13 +164,12 @@ class MongoDBQueryEngine:
|
|
|
168
164
|
|
|
169
165
|
def init_db(
|
|
170
166
|
self,
|
|
171
|
-
new_doc_dir:
|
|
172
|
-
new_doc_paths_or_urls:
|
|
167
|
+
new_doc_dir: Path | str | None = None,
|
|
168
|
+
new_doc_paths_or_urls: Sequence[Path | str] | None = None,
|
|
173
169
|
*args: Any,
|
|
174
170
|
**kwargs: Any,
|
|
175
171
|
) -> bool:
|
|
176
|
-
"""
|
|
177
|
-
Initializes the MongoDB database by creating or overwriting the collection and indexing documents.
|
|
172
|
+
"""Initializes the MongoDB database by creating or overwriting the collection and indexing documents.
|
|
178
173
|
|
|
179
174
|
This method loads documents from a directory or provided file paths, sets up the database (optionally
|
|
180
175
|
overwriting any existing collection), builds the vector store index, and inserts the documents.
|
|
@@ -215,8 +210,7 @@ class MongoDBQueryEngine:
|
|
|
215
210
|
return False
|
|
216
211
|
|
|
217
212
|
def _validate_query_index(self) -> None:
|
|
218
|
-
"""
|
|
219
|
-
Validates that the query index is initialized.
|
|
213
|
+
"""Validates that the query index is initialized.
|
|
220
214
|
|
|
221
215
|
Raises:
|
|
222
216
|
Exception: If the query index is not initialized.
|
|
@@ -225,10 +219,9 @@ class MongoDBQueryEngine:
|
|
|
225
219
|
raise Exception("Query index is not initialized. Please call init_db or connect_db first.")
|
|
226
220
|
|
|
227
221
|
def _load_doc( # type: ignore[no-any-unimported]
|
|
228
|
-
self, input_dir:
|
|
222
|
+
self, input_dir: Path | str | None, input_docs: Sequence[Path | str] | None
|
|
229
223
|
) -> Sequence["LlamaDocument"]:
|
|
230
|
-
"""
|
|
231
|
-
Loads documents from a directory or a list of file paths.
|
|
224
|
+
"""Loads documents from a directory or a list of file paths.
|
|
232
225
|
|
|
233
226
|
Args:
|
|
234
227
|
input_dir (Optional[Union[Path, str]]): Directory from which to load documents.
|
|
@@ -260,13 +253,12 @@ class MongoDBQueryEngine:
|
|
|
260
253
|
|
|
261
254
|
def add_docs(
|
|
262
255
|
self,
|
|
263
|
-
new_doc_dir:
|
|
264
|
-
new_doc_paths_or_urls:
|
|
256
|
+
new_doc_dir: Path | str | None = None,
|
|
257
|
+
new_doc_paths_or_urls: Sequence[Path | str] | None = None,
|
|
265
258
|
*args: Any,
|
|
266
259
|
**kwargs: Any,
|
|
267
260
|
) -> None:
|
|
268
|
-
"""
|
|
269
|
-
Adds new documents to the existing vector store index.
|
|
261
|
+
"""Adds new documents to the existing vector store index.
|
|
270
262
|
|
|
271
263
|
This method validates that the index exists, loads documents from the specified directory or file paths,
|
|
272
264
|
and inserts them into the vector store index.
|
|
@@ -283,8 +275,7 @@ class MongoDBQueryEngine:
|
|
|
283
275
|
self.index.insert(doc) # type: ignore[union-attr]
|
|
284
276
|
|
|
285
277
|
def query(self, question: str, *args: Any, **kwargs: Any) -> Any: # type: ignore[no-any-unimported, type-arg]
|
|
286
|
-
"""
|
|
287
|
-
Queries the indexed documents using the provided question.
|
|
278
|
+
"""Queries the indexed documents using the provided question.
|
|
288
279
|
|
|
289
280
|
This method validates that the query index is initialized, creates a query engine from the vector store index,
|
|
290
281
|
and executes the query. If the response is empty, a default reply is returned.
|
|
@@ -307,8 +298,7 @@ class MongoDBQueryEngine:
|
|
|
307
298
|
return str(response)
|
|
308
299
|
|
|
309
300
|
def get_collection_name(self) -> str:
|
|
310
|
-
"""
|
|
311
|
-
Retrieves the name of the MongoDB collection.
|
|
301
|
+
"""Retrieves the name of the MongoDB collection.
|
|
312
302
|
|
|
313
303
|
Returns:
|
|
314
304
|
str: The collection name.
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
+
from collections.abc import Sequence
|
|
5
6
|
from pathlib import Path
|
|
6
|
-
from typing import Any,
|
|
7
|
+
from typing import Any, Protocol, runtime_checkable
|
|
7
8
|
|
|
8
9
|
from ....doc_utils import export_module
|
|
9
10
|
|
|
@@ -20,8 +21,8 @@ class RAGQueryEngine(Protocol):
|
|
|
20
21
|
|
|
21
22
|
def init_db(
|
|
22
23
|
self,
|
|
23
|
-
new_doc_dir:
|
|
24
|
-
new_doc_paths_or_urls:
|
|
24
|
+
new_doc_dir: Path | str | None = None,
|
|
25
|
+
new_doc_paths_or_urls: Sequence[Path | str] | None = None,
|
|
25
26
|
*args: Any,
|
|
26
27
|
**kwargs: Any,
|
|
27
28
|
) -> bool:
|
|
@@ -45,8 +46,8 @@ class RAGQueryEngine(Protocol):
|
|
|
45
46
|
|
|
46
47
|
def add_docs(
|
|
47
48
|
self,
|
|
48
|
-
new_doc_dir:
|
|
49
|
-
new_doc_paths_or_urls:
|
|
49
|
+
new_doc_dir: Path | str | None = None,
|
|
50
|
+
new_doc_paths_or_urls: Sequence[Path | str] | None = None,
|
|
50
51
|
*args: Any,
|
|
51
52
|
**kwargs: Any,
|
|
52
53
|
) -> None:
|
|
@@ -55,6 +56,7 @@ class RAGQueryEngine(Protocol):
|
|
|
55
56
|
|
|
56
57
|
def connect_db(self, *args: Any, **kwargs: Any) -> bool:
|
|
57
58
|
"""Connect to the database.
|
|
59
|
+
|
|
58
60
|
Args:
|
|
59
61
|
*args: Any additional arguments
|
|
60
62
|
**kwargs: Any additional keyword arguments
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
|
|
6
6
|
# SPDX-License-Identifier: MIT
|
|
7
7
|
import warnings
|
|
8
|
-
from typing import Any
|
|
8
|
+
from typing import Any
|
|
9
9
|
|
|
10
10
|
from ..agent import Agent
|
|
11
11
|
from ..assistant_agent import AssistantAgent
|
|
@@ -33,10 +33,10 @@ class RetrieveAssistantAgent(AssistantAgent):
|
|
|
33
33
|
|
|
34
34
|
def _generate_retrieve_assistant_reply(
|
|
35
35
|
self,
|
|
36
|
-
messages:
|
|
37
|
-
sender:
|
|
38
|
-
config:
|
|
39
|
-
) -> tuple[bool,
|
|
36
|
+
messages: list[dict[str, Any]] | None = None,
|
|
37
|
+
sender: Agent | None = None,
|
|
38
|
+
config: Any | None = None,
|
|
39
|
+
) -> tuple[bool, str | dict[str, Any] | None]:
|
|
40
40
|
if config is None:
|
|
41
41
|
config = self
|
|
42
42
|
if messages is None:
|
|
@@ -8,7 +8,8 @@ import hashlib
|
|
|
8
8
|
import os
|
|
9
9
|
import re
|
|
10
10
|
import uuid
|
|
11
|
-
from
|
|
11
|
+
from collections.abc import Callable
|
|
12
|
+
from typing import Any, Literal
|
|
12
13
|
|
|
13
14
|
from ...code_utils import extract_code
|
|
14
15
|
from ...formatting_utils import colored
|
|
@@ -101,8 +102,8 @@ class RetrieveUserProxyAgent(UserProxyAgent):
|
|
|
101
102
|
self,
|
|
102
103
|
name="RetrieveChatAgent", # default set to RetrieveChatAgent
|
|
103
104
|
human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "ALWAYS",
|
|
104
|
-
is_termination_msg:
|
|
105
|
-
retrieve_config:
|
|
105
|
+
is_termination_msg: Callable[[dict[str, Any]], bool] | None = None,
|
|
106
|
+
retrieve_config: dict[str, Any] | None = None, # config for the retrieve agent
|
|
106
107
|
**kwargs: Any,
|
|
107
108
|
):
|
|
108
109
|
r"""Args:
|
|
@@ -522,10 +523,10 @@ class RetrieveUserProxyAgent(UserProxyAgent):
|
|
|
522
523
|
|
|
523
524
|
def _generate_retrieve_user_reply(
|
|
524
525
|
self,
|
|
525
|
-
messages:
|
|
526
|
-
sender:
|
|
527
|
-
config:
|
|
528
|
-
) -> tuple[bool,
|
|
526
|
+
messages: list[dict[str, Any]] | None = None,
|
|
527
|
+
sender: Agent | None = None,
|
|
528
|
+
config: Any | None = None,
|
|
529
|
+
) -> tuple[bool, str | dict[str, Any] | None]:
|
|
529
530
|
"""In this function, we will update the context and reset the conversation based on different conditions.
|
|
530
531
|
We'll update the context and reset the conversation if update_context is True and either of the following:
|
|
531
532
|
(1) the last message contains "UPDATE CONTEXT",
|
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
# ruff: noqa: E722
|
|
8
8
|
import copy
|
|
9
9
|
import traceback
|
|
10
|
+
from collections.abc import Callable
|
|
10
11
|
from contextlib import suppress
|
|
11
|
-
from typing import Any,
|
|
12
|
+
from typing import Any, Literal
|
|
12
13
|
|
|
13
14
|
from ... import Agent, ConversableAgent, GroupChat, GroupChatManager, OpenAIWrapper
|
|
14
15
|
from ...llm_config import LLMConfig
|
|
@@ -39,14 +40,14 @@ class SocietyOfMindAgent(ConversableAgent):
|
|
|
39
40
|
self,
|
|
40
41
|
name: str,
|
|
41
42
|
chat_manager: GroupChatManager,
|
|
42
|
-
response_preparer:
|
|
43
|
-
is_termination_msg:
|
|
44
|
-
max_consecutive_auto_reply:
|
|
43
|
+
response_preparer: str | Callable[..., Any] | None = None,
|
|
44
|
+
is_termination_msg: Callable[[dict[str, Any]], bool] | None = None,
|
|
45
|
+
max_consecutive_auto_reply: int | None = None,
|
|
45
46
|
human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "TERMINATE",
|
|
46
|
-
function_map:
|
|
47
|
-
code_execution_config:
|
|
48
|
-
llm_config:
|
|
49
|
-
default_auto_reply:
|
|
47
|
+
function_map: dict[str, Callable[..., Any]] | None = None,
|
|
48
|
+
code_execution_config: dict[str, Any] | Literal[False] = False,
|
|
49
|
+
llm_config: LLMConfig | dict[str, Any] | Literal[False] | None = False,
|
|
50
|
+
default_auto_reply: str | dict[str, Any] | None = "",
|
|
50
51
|
**kwargs: Any,
|
|
51
52
|
):
|
|
52
53
|
super().__init__(
|
|
@@ -135,11 +136,11 @@ class SocietyOfMindAgent(ConversableAgent):
|
|
|
135
136
|
return extracted_response
|
|
136
137
|
|
|
137
138
|
@property
|
|
138
|
-
def chat_manager(self) ->
|
|
139
|
+
def chat_manager(self) -> GroupChatManager | None:
|
|
139
140
|
"""Return the group chat manager."""
|
|
140
141
|
return self._chat_manager
|
|
141
142
|
|
|
142
|
-
def update_chat_manager(self, chat_manager:
|
|
143
|
+
def update_chat_manager(self, chat_manager: GroupChatManager | None):
|
|
143
144
|
"""Update the chat manager.
|
|
144
145
|
|
|
145
146
|
Args:
|
|
@@ -158,10 +159,10 @@ class SocietyOfMindAgent(ConversableAgent):
|
|
|
158
159
|
|
|
159
160
|
def generate_inner_monologue_reply(
|
|
160
161
|
self,
|
|
161
|
-
messages:
|
|
162
|
-
sender:
|
|
163
|
-
config:
|
|
164
|
-
) -> tuple[bool,
|
|
162
|
+
messages: list[dict[str, Any]] | None = None,
|
|
163
|
+
sender: Agent | None = None,
|
|
164
|
+
config: OpenAIWrapper | None = None,
|
|
165
|
+
) -> tuple[bool, str | dict[str, Any] | None]:
|
|
165
166
|
"""Generate a reply by running the group chat"""
|
|
166
167
|
if self.chat_manager is None:
|
|
167
168
|
return False, None
|