ag2 0.9.6__py3-none-any.whl → 0.9.8.post1__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.6.dist-info → ag2-0.9.8.post1.dist-info}/METADATA +102 -75
- ag2-0.9.8.post1.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 +311 -295
- 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 +58 -61
- 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 +13 -13
- 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 +3 -2
- 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 +118 -138
- autogen/oai/client_utils.py +3 -3
- autogen/oai/cohere.py +34 -11
- autogen/oai/gemini.py +40 -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 +22 -10
- autogen/oai/openai_responses.py +40 -17
- autogen/oai/openai_utils.py +159 -85
- 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 +6 -5
- autogen/types.py +2 -2
- autogen/version.py +1 -1
- ag2-0.9.6.dist-info/RECORD +0 -421
- autogen/llm_config.py +0 -385
- {ag2-0.9.6.dist-info → ag2-0.9.8.post1.dist-info}/WHEEL +0 -0
- {ag2-0.9.6.dist-info → ag2-0.9.8.post1.dist-info}/licenses/LICENSE +0 -0
- {ag2-0.9.6.dist-info → ag2-0.9.8.post1.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -6,7 +6,7 @@ import math
|
|
|
6
6
|
import random
|
|
7
7
|
import re
|
|
8
8
|
import warnings
|
|
9
|
-
from typing import Any, Literal, Optional
|
|
9
|
+
from typing import Any, Literal, Optional
|
|
10
10
|
|
|
11
11
|
from .... import Agent, AssistantAgent, UserProxyAgent
|
|
12
12
|
from ....doc_utils import export_module
|
|
@@ -112,10 +112,10 @@ class ThinkNode:
|
|
|
112
112
|
"""
|
|
113
113
|
self.content: str = content
|
|
114
114
|
self.value: float = 0.0
|
|
115
|
-
self.parent:
|
|
115
|
+
self.parent: ThinkNode | None = parent
|
|
116
116
|
self.reflection: str = ""
|
|
117
117
|
self.rating_details: str = ""
|
|
118
|
-
self.output:
|
|
118
|
+
self.output: str | None = None
|
|
119
119
|
self.depth: int = parent.depth + 1 if parent is not None else 0
|
|
120
120
|
self.children: list[ThinkNode] = []
|
|
121
121
|
self.visits: int = 0
|
|
@@ -156,7 +156,7 @@ class ThinkNode:
|
|
|
156
156
|
Args:
|
|
157
157
|
reward (float): The reward to backpropagate up the tree.
|
|
158
158
|
"""
|
|
159
|
-
node:
|
|
159
|
+
node: ThinkNode | None = self
|
|
160
160
|
while node is not None:
|
|
161
161
|
node.visits += 1
|
|
162
162
|
node.value = (node.value * (node.visits - 1) + reward) / node.visits
|
|
@@ -343,14 +343,14 @@ class ReasoningAgent(AssistantAgent):
|
|
|
343
343
|
def __init__(
|
|
344
344
|
self,
|
|
345
345
|
name: str,
|
|
346
|
-
llm_config:
|
|
347
|
-
grader_llm_config:
|
|
346
|
+
llm_config: LLMConfig | dict[str, Any] | None = None,
|
|
347
|
+
grader_llm_config: LLMConfig | dict[str, Any] | None = None,
|
|
348
348
|
max_depth: int = 4,
|
|
349
349
|
beam_size: int = 3,
|
|
350
350
|
answer_approach: Literal["pool", "best"] = "pool",
|
|
351
|
-
reason_config:
|
|
352
|
-
code_execution_config:
|
|
353
|
-
scope:
|
|
351
|
+
reason_config: dict[str, Any] | None = None,
|
|
352
|
+
code_execution_config: dict[str, Any] | Literal[False] = False,
|
|
353
|
+
scope: str | None = None,
|
|
354
354
|
**kwargs: Any,
|
|
355
355
|
) -> None:
|
|
356
356
|
"""Initialize a ReasoningAgent that uses tree-of-thought reasoning.
|
|
@@ -428,8 +428,8 @@ class ReasoningAgent(AssistantAgent):
|
|
|
428
428
|
code_execution_config=code_execution_config,
|
|
429
429
|
**kwargs,
|
|
430
430
|
)
|
|
431
|
-
self._llm_config:
|
|
432
|
-
self._grader_llm_config:
|
|
431
|
+
self._llm_config: LLMConfig | dict[str, Any] | None = llm_config
|
|
432
|
+
self._grader_llm_config: LLMConfig | dict[str, Any] | None = (
|
|
433
433
|
grader_llm_config if grader_llm_config else llm_config
|
|
434
434
|
)
|
|
435
435
|
|
|
@@ -466,12 +466,12 @@ class ReasoningAgent(AssistantAgent):
|
|
|
466
466
|
self._rating_scale: int = reason_config.get("rating_scale", 10)
|
|
467
467
|
self._interim_execution: bool = reason_config.get("interim_execution", False)
|
|
468
468
|
|
|
469
|
-
self._root:
|
|
469
|
+
self._root: ThinkNode | None = None
|
|
470
470
|
self._lats_context: str = ""
|
|
471
471
|
self.register_reply([Agent, None], ReasoningAgent.generate_forest_response)
|
|
472
472
|
|
|
473
473
|
# Initialize llm agent for interim step execution
|
|
474
|
-
self._executor:
|
|
474
|
+
self._executor: AssistantAgent | None = None
|
|
475
475
|
# Add scope if provided
|
|
476
476
|
executor_msg = self._add_scope(EXECUTOR_MESSAGE)
|
|
477
477
|
if self._interim_execution:
|
|
@@ -482,7 +482,7 @@ class ReasoningAgent(AssistantAgent):
|
|
|
482
482
|
tot_msg = self._add_scope(TREEOFTHOUGHT_MESSAGE)
|
|
483
483
|
|
|
484
484
|
# Initialize user proxy agent for code execution
|
|
485
|
-
self._user_proxy:
|
|
485
|
+
self._user_proxy: UserProxyAgent | None = None
|
|
486
486
|
if self._code_execution_config:
|
|
487
487
|
# to execute code interim_execution should be True
|
|
488
488
|
if not self._interim_execution:
|
|
@@ -525,9 +525,9 @@ class ReasoningAgent(AssistantAgent):
|
|
|
525
525
|
|
|
526
526
|
def generate_forest_response(
|
|
527
527
|
self,
|
|
528
|
-
messages:
|
|
529
|
-
sender:
|
|
530
|
-
config:
|
|
528
|
+
messages: list[dict[str, Any]] | None = None,
|
|
529
|
+
sender: Agent | None = None,
|
|
530
|
+
config: dict[str, Any] | None = None,
|
|
531
531
|
) -> tuple[bool, str]:
|
|
532
532
|
"""Generate a response using tree-of-thought reasoning.
|
|
533
533
|
|
|
@@ -574,12 +574,12 @@ Final Answer:
|
|
|
574
574
|
request_reply=True,
|
|
575
575
|
silent=self.silent,
|
|
576
576
|
)
|
|
577
|
-
last_msg:
|
|
577
|
+
last_msg: dict[str, Any] | None = self.last_message(self)
|
|
578
578
|
if last_msg is None:
|
|
579
579
|
return True, ""
|
|
580
580
|
return True, last_msg["content"].strip()
|
|
581
581
|
|
|
582
|
-
def rate_node(self, node: ThinkNode, ground_truth:
|
|
582
|
+
def rate_node(self, node: ThinkNode, ground_truth: str | None = None, is_outcome: bool = False) -> float:
|
|
583
583
|
"""Rate the quality of a reasoning path or the final answer using the grader agent.
|
|
584
584
|
|
|
585
585
|
Args:
|
|
@@ -663,7 +663,7 @@ Please provide your rating along with a brief explanation of your assessment.
|
|
|
663
663
|
silent=self.silent,
|
|
664
664
|
)
|
|
665
665
|
rating: str = ""
|
|
666
|
-
last_message:
|
|
666
|
+
last_message: dict[str, Any] | None = self._grader.last_message()
|
|
667
667
|
if last_message is not None:
|
|
668
668
|
rating = last_message["content"].strip()
|
|
669
669
|
node.rating_details = rating
|
|
@@ -675,7 +675,7 @@ Please provide your rating along with a brief explanation of your assessment.
|
|
|
675
675
|
reward = 0.0 # Default reward if parsing fails
|
|
676
676
|
return reward
|
|
677
677
|
|
|
678
|
-
def rate_batch_nodes(self, nodes: list[ThinkNode], ground_truth:
|
|
678
|
+
def rate_batch_nodes(self, nodes: list[ThinkNode], ground_truth: str | None = None) -> list[float]:
|
|
679
679
|
"""Rate a batch of nodes using a single call of the grader agent. All the nodes must have the same parent.
|
|
680
680
|
|
|
681
681
|
This method evaluates all given nodes while considering the other available options.
|
|
@@ -745,7 +745,7 @@ Rating: <rating>
|
|
|
745
745
|
silent=self.silent,
|
|
746
746
|
)
|
|
747
747
|
rating: str = ""
|
|
748
|
-
last_message:
|
|
748
|
+
last_message: dict[str, Any] | None = self._grader.last_message()
|
|
749
749
|
if last_message is not None:
|
|
750
750
|
rating = last_message["content"].strip()
|
|
751
751
|
|
|
@@ -772,7 +772,7 @@ Rating: <rating>
|
|
|
772
772
|
rewards.append((float(rating) - 1.0) / (self._rating_scale - 1.0))
|
|
773
773
|
return rewards
|
|
774
774
|
|
|
775
|
-
def execute_node(self, node: ThinkNode) ->
|
|
775
|
+
def execute_node(self, node: ThinkNode) -> str | None:
|
|
776
776
|
"""Execute the node's content to get the response.
|
|
777
777
|
|
|
778
778
|
This method runs the node's content to get the response.
|
|
@@ -805,7 +805,7 @@ Rating: <rating>
|
|
|
805
805
|
request_reply=True,
|
|
806
806
|
silent=self.silent,
|
|
807
807
|
)
|
|
808
|
-
user_proxy_last_msg:
|
|
808
|
+
user_proxy_last_msg: dict[str, Any] | None = self._user_proxy.last_message(self)
|
|
809
809
|
user_proxy_last_msg_content: str = user_proxy_last_msg["content"] if user_proxy_last_msg is not None else ""
|
|
810
810
|
return user_proxy_last_msg_content
|
|
811
811
|
|
|
@@ -822,7 +822,7 @@ Rating: <rating>
|
|
|
822
822
|
)
|
|
823
823
|
|
|
824
824
|
output = ""
|
|
825
|
-
last_message:
|
|
825
|
+
last_message: dict[str, Any] | None = self._executor.last_message()
|
|
826
826
|
|
|
827
827
|
# this agent is not supposed to write Python code, so if there is a need for that ask the thinker to do so
|
|
828
828
|
if last_message is not None:
|
|
@@ -836,8 +836,8 @@ Rating: <rating>
|
|
|
836
836
|
return output
|
|
837
837
|
|
|
838
838
|
def _process_prompt(
|
|
839
|
-
self, messages:
|
|
840
|
-
) -> tuple[
|
|
839
|
+
self, messages: list[dict[str, Any]] | None, sender: Agent | None
|
|
840
|
+
) -> tuple[str | None, str | None]:
|
|
841
841
|
"""Process the incoming messages to extract the prompt and ground truth.
|
|
842
842
|
|
|
843
843
|
This method checks if the provided messages are None and identifies the prompt.
|
|
@@ -892,7 +892,7 @@ CURRENT_QUESTION: *Write the current/last question to be addressed here. In case
|
|
|
892
892
|
request_reply=True,
|
|
893
893
|
silent=self.silent,
|
|
894
894
|
)
|
|
895
|
-
last_msg:
|
|
895
|
+
last_msg: dict[str, Any] | None = self._prompt_rewriter.last_message()
|
|
896
896
|
prompt = last_msg["content"].strip() if last_msg is not None else ""
|
|
897
897
|
|
|
898
898
|
if not prompt:
|
|
@@ -900,7 +900,7 @@ CURRENT_QUESTION: *Write the current/last question to be addressed here. In case
|
|
|
900
900
|
|
|
901
901
|
return prompt, ground_truth
|
|
902
902
|
|
|
903
|
-
def _beam_reply(self, prompt: str, ground_truth:
|
|
903
|
+
def _beam_reply(self, prompt: str, ground_truth: str | None = None) -> str:
|
|
904
904
|
"""Generate a response using tree-of-thought reasoning.
|
|
905
905
|
|
|
906
906
|
Implements beam search through a tree of reasoning steps, using the thinker
|
|
@@ -993,11 +993,11 @@ Final Answer:
|
|
|
993
993
|
request_reply=True,
|
|
994
994
|
silent=self.silent,
|
|
995
995
|
)
|
|
996
|
-
last_msg:
|
|
996
|
+
last_msg: dict[str, Any] | None = self.last_message(self)
|
|
997
997
|
final_answer: str = last_msg["content"].strip() if last_msg is not None else ""
|
|
998
998
|
return final_answer
|
|
999
999
|
|
|
1000
|
-
def _mcts_reply(self, prompt: str, ground_truth:
|
|
1000
|
+
def _mcts_reply(self, prompt: str, ground_truth: str | None = None) -> str:
|
|
1001
1001
|
"""Generate a response using Monte Carlo Tree Search (MCTS) reasoning.
|
|
1002
1002
|
|
|
1003
1003
|
Args:
|
|
@@ -1059,7 +1059,7 @@ Final Answer:
|
|
|
1059
1059
|
request_reply=True,
|
|
1060
1060
|
silent=self.silent,
|
|
1061
1061
|
)
|
|
1062
|
-
last_msg:
|
|
1062
|
+
last_msg: dict[str, Any] | None = self.last_message(self)
|
|
1063
1063
|
_answer: str = last_msg["content"].strip() if last_msg is not None else ""
|
|
1064
1064
|
_ans_node = ThinkNode(content=_answer, parent=node)
|
|
1065
1065
|
reward = self.rate_node(_ans_node, ground_truth, is_outcome=True)
|
|
@@ -1102,7 +1102,7 @@ Final Answer:
|
|
|
1102
1102
|
request_reply=True,
|
|
1103
1103
|
silent=self.silent,
|
|
1104
1104
|
)
|
|
1105
|
-
last_msg:
|
|
1105
|
+
last_msg: dict[str, Any] | None = self._thinker.last_message()
|
|
1106
1106
|
reply: str = last_msg["content"].strip() if last_msg is not None else ""
|
|
1107
1107
|
reflection = re.findall(r"REFLECTION:\s*(.+?)(?=\*\*Possible Options:\*\*|Option \d+:|$)", reply, re.DOTALL)
|
|
1108
1108
|
if reflection:
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
from typing import Any
|
|
5
|
+
from typing import Any
|
|
6
6
|
|
|
7
7
|
from .... import ConversableAgent
|
|
8
8
|
from ....doc_utils import export_module
|
|
@@ -24,7 +24,7 @@ class SlackAgent(ConversableAgent):
|
|
|
24
24
|
def __init__(
|
|
25
25
|
self,
|
|
26
26
|
name: str,
|
|
27
|
-
system_message:
|
|
27
|
+
system_message: str | None = None,
|
|
28
28
|
*,
|
|
29
29
|
bot_token: str,
|
|
30
30
|
channel_id: str,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
from typing import Any
|
|
5
|
+
from typing import Any
|
|
6
6
|
|
|
7
7
|
from .... import ConversableAgent
|
|
8
8
|
from ....doc_utils import export_module
|
|
@@ -24,7 +24,7 @@ class TelegramAgent(ConversableAgent):
|
|
|
24
24
|
def __init__(
|
|
25
25
|
self,
|
|
26
26
|
name: str,
|
|
27
|
-
system_message:
|
|
27
|
+
system_message: str | None = None,
|
|
28
28
|
*,
|
|
29
29
|
api_id: str,
|
|
30
30
|
api_hash: str,
|
|
@@ -43,7 +43,6 @@ class TelegramAgent(ConversableAgent):
|
|
|
43
43
|
has_writing_instructions (bool): Whether to add writing instructions to the system message. Defaults to True.
|
|
44
44
|
**kwargs: Additional keyword arguments passed to the parent ConversableAgent class.
|
|
45
45
|
"""
|
|
46
|
-
|
|
47
46
|
telegram_system_message = system_message or self.DEFAULT_SYSTEM_MESSAGE
|
|
48
47
|
|
|
49
48
|
self._send_tool = TelegramSendTool(api_id=api_id, api_hash=api_hash, chat_id=chat_id)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
from typing import Any, Literal
|
|
5
|
+
from typing import Any, Literal
|
|
6
6
|
|
|
7
7
|
from .... import ConversableAgent
|
|
8
8
|
from ....doc_utils import export_module
|
|
@@ -28,12 +28,12 @@ class WebSurferAgent(ConversableAgent):
|
|
|
28
28
|
def __init__(
|
|
29
29
|
self,
|
|
30
30
|
*,
|
|
31
|
-
llm_config:
|
|
32
|
-
web_tool_llm_config:
|
|
31
|
+
llm_config: LLMConfig | dict[str, Any] | None = None,
|
|
32
|
+
web_tool_llm_config: LLMConfig | dict[str, Any] | None = None,
|
|
33
33
|
web_tool: Literal[
|
|
34
34
|
"browser_use", "crawl4ai", "duckduckgo", "firecrawl", "perplexity", "tavily", "searxng"
|
|
35
35
|
] = "browser_use",
|
|
36
|
-
web_tool_kwargs:
|
|
36
|
+
web_tool_kwargs: dict[str, Any] | None = None,
|
|
37
37
|
**kwargs: Any,
|
|
38
38
|
) -> None:
|
|
39
39
|
"""Initialize the WebSurferAgent.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
from typing import Any
|
|
5
|
+
from typing import Any
|
|
6
6
|
|
|
7
7
|
from .... import ConversableAgent
|
|
8
8
|
from ....doc_utils import export_module
|
|
@@ -11,8 +11,7 @@ from ....tools.experimental import WikipediaPageLoadTool, WikipediaQueryRunTool
|
|
|
11
11
|
|
|
12
12
|
@export_module("autogen.agents.experimental")
|
|
13
13
|
class WikipediaAgent(ConversableAgent):
|
|
14
|
-
"""
|
|
15
|
-
An AI agent that leverages Wikipedia tools to provide accurate, concise answers
|
|
14
|
+
"""An AI agent that leverages Wikipedia tools to provide accurate, concise answers
|
|
16
15
|
to user queries.
|
|
17
16
|
|
|
18
17
|
Tools:
|
|
@@ -44,14 +43,13 @@ class WikipediaAgent(ConversableAgent):
|
|
|
44
43
|
|
|
45
44
|
def __init__(
|
|
46
45
|
self,
|
|
47
|
-
system_message:
|
|
48
|
-
format_instructions:
|
|
46
|
+
system_message: str | list[str] | None = None,
|
|
47
|
+
format_instructions: str | None = None,
|
|
49
48
|
language: str = "en",
|
|
50
49
|
top_k: int = 2,
|
|
51
50
|
**kwargs: Any,
|
|
52
51
|
) -> None:
|
|
53
|
-
"""
|
|
54
|
-
Initialize the WikipediaAgent with optional custom prompts and tools.
|
|
52
|
+
"""Initialize the WikipediaAgent with optional custom prompts and tools.
|
|
55
53
|
|
|
56
54
|
Args:
|
|
57
55
|
system_message (Optional[Union[str, List[str]]]):
|
autogen/browser_utils.py
CHANGED
|
@@ -10,7 +10,7 @@ import os
|
|
|
10
10
|
import re
|
|
11
11
|
import uuid
|
|
12
12
|
from contextlib import suppress
|
|
13
|
-
from typing import Any
|
|
13
|
+
from typing import Any
|
|
14
14
|
from urllib.parse import urljoin, urlparse
|
|
15
15
|
|
|
16
16
|
from .import_utils import optional_import_block, require_optional_import
|
|
@@ -38,12 +38,12 @@ class SimpleTextBrowser:
|
|
|
38
38
|
|
|
39
39
|
def __init__(
|
|
40
40
|
self,
|
|
41
|
-
start_page:
|
|
42
|
-
viewport_size:
|
|
43
|
-
downloads_folder:
|
|
41
|
+
start_page: str | None = None,
|
|
42
|
+
viewport_size: int | None = 1024 * 8,
|
|
43
|
+
downloads_folder: str | None | None = None,
|
|
44
44
|
bing_base_url: str = "https://api.bing.microsoft.com/v7.0/search",
|
|
45
|
-
bing_api_key:
|
|
46
|
-
request_kwargs:
|
|
45
|
+
bing_api_key: str | None | None = None,
|
|
46
|
+
request_kwargs: dict[str, Any] | None | None = None,
|
|
47
47
|
):
|
|
48
48
|
"""Initialize the browser with the given parameters.
|
|
49
49
|
|
|
@@ -59,7 +59,7 @@ class SimpleTextBrowser:
|
|
|
59
59
|
self.viewport_size = viewport_size # Applies only to the standard uri types
|
|
60
60
|
self.downloads_folder = downloads_folder
|
|
61
61
|
self.history: list[str] = list()
|
|
62
|
-
self.page_title:
|
|
62
|
+
self.page_title: str | None = None
|
|
63
63
|
self.viewport_current_page = 0
|
|
64
64
|
self.viewport_pages: list[tuple[int, int]] = list()
|
|
65
65
|
self.set_address(self.start_page)
|
|
@@ -152,7 +152,7 @@ class SimpleTextBrowser:
|
|
|
152
152
|
self.viewport_pages.append((start_idx, end_idx))
|
|
153
153
|
start_idx = end_idx
|
|
154
154
|
|
|
155
|
-
def _bing_api_call(self, query: str) -> dict[str, dict[str, list[dict[str,
|
|
155
|
+
def _bing_api_call(self, query: str) -> dict[str, dict[str, list[dict[str, str | dict[str, str]]]]]:
|
|
156
156
|
# Make sure the key was set
|
|
157
157
|
if self.bing_api_key is None:
|
|
158
158
|
raise ValueError("Missing Bing API key.")
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
# SPDX-License-Identifier: MIT
|
|
7
7
|
import sys
|
|
8
8
|
from types import TracebackType
|
|
9
|
-
from typing import Any,
|
|
9
|
+
from typing import Any, Protocol
|
|
10
10
|
|
|
11
11
|
from ..doc_utils import export_module
|
|
12
12
|
|
|
@@ -23,7 +23,7 @@ class AbstractCache(Protocol):
|
|
|
23
23
|
these methods to handle caching mechanisms.
|
|
24
24
|
"""
|
|
25
25
|
|
|
26
|
-
def get(self, key: str, default:
|
|
26
|
+
def get(self, key: str, default: Any | None = None) -> Any | None:
|
|
27
27
|
"""Retrieve an item from the cache.
|
|
28
28
|
|
|
29
29
|
Args:
|
|
@@ -61,9 +61,9 @@ class AbstractCache(Protocol):
|
|
|
61
61
|
|
|
62
62
|
def __exit__(
|
|
63
63
|
self,
|
|
64
|
-
exc_type:
|
|
65
|
-
exc_value:
|
|
66
|
-
traceback:
|
|
64
|
+
exc_type: type[BaseException] | None,
|
|
65
|
+
exc_value: BaseException | None,
|
|
66
|
+
traceback: TracebackType | None,
|
|
67
67
|
) -> None:
|
|
68
68
|
"""Exit the runtime context and close the cache.
|
|
69
69
|
|
autogen/cache/cache.py
CHANGED
|
@@ -8,7 +8,7 @@ from __future__ import annotations
|
|
|
8
8
|
|
|
9
9
|
from contextvars import ContextVar
|
|
10
10
|
from types import TracebackType
|
|
11
|
-
from typing import Any
|
|
11
|
+
from typing import Any
|
|
12
12
|
|
|
13
13
|
from ..doc_utils import export_module
|
|
14
14
|
from .abstract_cache_base import AbstractCache
|
|
@@ -38,7 +38,7 @@ class Cache(AbstractCache):
|
|
|
38
38
|
]
|
|
39
39
|
|
|
40
40
|
@staticmethod
|
|
41
|
-
def redis(cache_seed:
|
|
41
|
+
def redis(cache_seed: str | int = 42, redis_url: str = "redis://localhost:6379/0") -> Cache:
|
|
42
42
|
"""Create a Redis cache instance.
|
|
43
43
|
|
|
44
44
|
Args:
|
|
@@ -51,7 +51,7 @@ class Cache(AbstractCache):
|
|
|
51
51
|
return Cache({"cache_seed": cache_seed, "redis_url": redis_url})
|
|
52
52
|
|
|
53
53
|
@staticmethod
|
|
54
|
-
def disk(cache_seed:
|
|
54
|
+
def disk(cache_seed: str | int = 42, cache_path_root: str = ".cache") -> Cache:
|
|
55
55
|
"""Create a Disk cache instance.
|
|
56
56
|
|
|
57
57
|
Args:
|
|
@@ -65,10 +65,10 @@ class Cache(AbstractCache):
|
|
|
65
65
|
|
|
66
66
|
@staticmethod
|
|
67
67
|
def cosmos_db(
|
|
68
|
-
connection_string:
|
|
69
|
-
container_id:
|
|
70
|
-
cache_seed:
|
|
71
|
-
client:
|
|
68
|
+
connection_string: str | None = None,
|
|
69
|
+
container_id: str | None = None,
|
|
70
|
+
cache_seed: str | int = 42,
|
|
71
|
+
client: Any | None = None,
|
|
72
72
|
) -> Cache:
|
|
73
73
|
"""Create a Cosmos DB cache instance with 'autogen_cache' as database ID.
|
|
74
74
|
|
|
@@ -131,9 +131,9 @@ class Cache(AbstractCache):
|
|
|
131
131
|
|
|
132
132
|
def __exit__(
|
|
133
133
|
self,
|
|
134
|
-
exc_type:
|
|
135
|
-
exc_value:
|
|
136
|
-
traceback:
|
|
134
|
+
exc_type: type[BaseException] | None,
|
|
135
|
+
exc_value: BaseException | None,
|
|
136
|
+
traceback: TracebackType | None,
|
|
137
137
|
) -> None:
|
|
138
138
|
"""Exit the runtime context related to the cache object.
|
|
139
139
|
|
|
@@ -159,7 +159,7 @@ class Cache(AbstractCache):
|
|
|
159
159
|
|
|
160
160
|
return result
|
|
161
161
|
|
|
162
|
-
def get(self, key: str, default:
|
|
162
|
+
def get(self, key: str, default: Any | None = None) -> Any | None:
|
|
163
163
|
"""Retrieve an item from the cache.
|
|
164
164
|
|
|
165
165
|
Args:
|
|
@@ -189,7 +189,7 @@ class Cache(AbstractCache):
|
|
|
189
189
|
self.cache.close()
|
|
190
190
|
|
|
191
191
|
@classmethod
|
|
192
|
-
def get_current_cache(cls, cache:
|
|
192
|
+
def get_current_cache(cls, cache: Cache | None = None) -> Cache | None:
|
|
193
193
|
"""Get the current cache instance.
|
|
194
194
|
|
|
195
195
|
Returns:
|
autogen/cache/cache_factory.py
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
# SPDX-License-Identifier: MIT
|
|
7
7
|
import logging
|
|
8
8
|
import os
|
|
9
|
-
from typing import Any
|
|
9
|
+
from typing import Any
|
|
10
10
|
|
|
11
11
|
from ..import_utils import optional_import_block
|
|
12
12
|
from .abstract_cache_base import AbstractCache
|
|
@@ -16,10 +16,10 @@ from .disk_cache import DiskCache
|
|
|
16
16
|
class CacheFactory:
|
|
17
17
|
@staticmethod
|
|
18
18
|
def cache_factory(
|
|
19
|
-
seed:
|
|
20
|
-
redis_url:
|
|
19
|
+
seed: str | int,
|
|
20
|
+
redis_url: str | None = None,
|
|
21
21
|
cache_path_root: str = ".cache",
|
|
22
|
-
cosmosdb_config:
|
|
22
|
+
cosmosdb_config: dict[str, Any] | None = None,
|
|
23
23
|
) -> AbstractCache:
|
|
24
24
|
"""Factory function for creating cache instances.
|
|
25
25
|
|
autogen/cache/cosmos_db_cache.py
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
# Install Azure Cosmos DB SDK if not already
|
|
8
8
|
|
|
9
9
|
import pickle
|
|
10
|
-
from typing import Any, Optional, TypedDict
|
|
10
|
+
from typing import Any, Optional, TypedDict
|
|
11
11
|
|
|
12
12
|
from ..import_utils import optional_import_block, require_optional_import
|
|
13
13
|
from .abstract_cache_base import AbstractCache
|
|
@@ -22,7 +22,7 @@ class CosmosDBConfig(TypedDict, total=False):
|
|
|
22
22
|
connection_string: str
|
|
23
23
|
database_id: str
|
|
24
24
|
container_id: str
|
|
25
|
-
cache_seed:
|
|
25
|
+
cache_seed: str | int | None
|
|
26
26
|
client: Optional["CosmosClient"]
|
|
27
27
|
|
|
28
28
|
|
|
@@ -39,7 +39,7 @@ class CosmosDBCache(AbstractCache):
|
|
|
39
39
|
container: The container instance used for caching.
|
|
40
40
|
"""
|
|
41
41
|
|
|
42
|
-
def __init__(self, seed:
|
|
42
|
+
def __init__(self, seed: str | int, cosmosdb_config: CosmosDBConfig):
|
|
43
43
|
"""Initialize the CosmosDBCache instance.
|
|
44
44
|
|
|
45
45
|
Args:
|
|
@@ -58,7 +58,7 @@ class CosmosDBCache(AbstractCache):
|
|
|
58
58
|
)
|
|
59
59
|
|
|
60
60
|
@classmethod
|
|
61
|
-
def create_cache(cls, seed:
|
|
61
|
+
def create_cache(cls, seed: str | int, cosmosdb_config: CosmosDBConfig):
|
|
62
62
|
"""Factory method to create a CosmosDBCache instance based on the provided configuration.
|
|
63
63
|
This method decides whether to use an existing CosmosClient or create a new one.
|
|
64
64
|
"""
|
|
@@ -68,20 +68,20 @@ class CosmosDBCache(AbstractCache):
|
|
|
68
68
|
return cls.from_config(seed, cosmosdb_config)
|
|
69
69
|
|
|
70
70
|
@classmethod
|
|
71
|
-
def from_config(cls, seed:
|
|
71
|
+
def from_config(cls, seed: str | int, cosmosdb_config: CosmosDBConfig):
|
|
72
72
|
return cls(str(seed), cosmosdb_config)
|
|
73
73
|
|
|
74
74
|
@classmethod
|
|
75
|
-
def from_connection_string(cls, seed:
|
|
75
|
+
def from_connection_string(cls, seed: str | int, connection_string: str, database_id: str, container_id: str):
|
|
76
76
|
config = {"connection_string": connection_string, "database_id": database_id, "container_id": container_id}
|
|
77
77
|
return cls(str(seed), config)
|
|
78
78
|
|
|
79
79
|
@classmethod
|
|
80
|
-
def from_existing_client(cls, seed:
|
|
80
|
+
def from_existing_client(cls, seed: str | int, client: "CosmosClient", database_id: str, container_id: str):
|
|
81
81
|
config = {"client": client, "database_id": database_id, "container_id": container_id}
|
|
82
82
|
return cls(str(seed), config)
|
|
83
83
|
|
|
84
|
-
def get(self, key: str, default:
|
|
84
|
+
def get(self, key: str, default: Any | None = None) -> Any | None:
|
|
85
85
|
"""Retrieve an item from the Cosmos DB cache.
|
|
86
86
|
|
|
87
87
|
Args:
|
|
@@ -136,7 +136,7 @@ class CosmosDBCache(AbstractCache):
|
|
|
136
136
|
"""
|
|
137
137
|
return self
|
|
138
138
|
|
|
139
|
-
def __exit__(self, exc_type:
|
|
139
|
+
def __exit__(self, exc_type: type | None, exc_value: Exception | None, traceback: Any | None) -> None:
|
|
140
140
|
"""Context management exit.
|
|
141
141
|
|
|
142
142
|
Perform cleanup actions such as closing the Cosmos DB client.
|
autogen/cache/disk_cache.py
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
# SPDX-License-Identifier: MIT
|
|
7
7
|
import sys
|
|
8
8
|
from types import TracebackType
|
|
9
|
-
from typing import Any
|
|
9
|
+
from typing import Any
|
|
10
10
|
|
|
11
11
|
import diskcache
|
|
12
12
|
|
|
@@ -36,7 +36,7 @@ class DiskCache(AbstractCache):
|
|
|
36
36
|
__exit__(self, exc_type, exc_value, traceback): Context management exit.
|
|
37
37
|
"""
|
|
38
38
|
|
|
39
|
-
def __init__(self, seed:
|
|
39
|
+
def __init__(self, seed: str | int):
|
|
40
40
|
"""Initialize the DiskCache instance.
|
|
41
41
|
|
|
42
42
|
Args:
|
|
@@ -46,7 +46,7 @@ class DiskCache(AbstractCache):
|
|
|
46
46
|
"""
|
|
47
47
|
self.cache = diskcache.Cache(seed)
|
|
48
48
|
|
|
49
|
-
def get(self, key: str, default:
|
|
49
|
+
def get(self, key: str, default: Any | None = None) -> Any | None:
|
|
50
50
|
"""Retrieve an item from the cache.
|
|
51
51
|
|
|
52
52
|
Args:
|
|
@@ -86,9 +86,9 @@ class DiskCache(AbstractCache):
|
|
|
86
86
|
|
|
87
87
|
def __exit__(
|
|
88
88
|
self,
|
|
89
|
-
exc_type:
|
|
90
|
-
exc_value:
|
|
91
|
-
traceback:
|
|
89
|
+
exc_type: type[BaseException] | None,
|
|
90
|
+
exc_value: BaseException | None,
|
|
91
|
+
traceback: TracebackType | None,
|
|
92
92
|
) -> None:
|
|
93
93
|
"""Exit the runtime context related to the object.
|
|
94
94
|
|
autogen/cache/in_memory_cache.py
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
# SPDX-License-Identifier: MIT
|
|
7
7
|
import sys
|
|
8
8
|
from types import TracebackType
|
|
9
|
-
from typing import Any
|
|
9
|
+
from typing import Any
|
|
10
10
|
|
|
11
11
|
from .abstract_cache_base import AbstractCache
|
|
12
12
|
|
|
@@ -17,7 +17,7 @@ else:
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
class InMemoryCache(AbstractCache):
|
|
20
|
-
def __init__(self, seed:
|
|
20
|
+
def __init__(self, seed: str | int = ""):
|
|
21
21
|
self._seed = str(seed)
|
|
22
22
|
self._cache: dict[str, Any] = {}
|
|
23
23
|
|
|
@@ -25,7 +25,7 @@ class InMemoryCache(AbstractCache):
|
|
|
25
25
|
separator = "_" if self._seed else ""
|
|
26
26
|
return f"{self._seed}{separator}{key}"
|
|
27
27
|
|
|
28
|
-
def get(self, key: str, default:
|
|
28
|
+
def get(self, key: str, default: Any | None = None) -> Any | None:
|
|
29
29
|
result = self._cache.get(self._prefixed_key(key))
|
|
30
30
|
if result is None:
|
|
31
31
|
return default
|
|
@@ -46,7 +46,7 @@ class InMemoryCache(AbstractCache):
|
|
|
46
46
|
return self
|
|
47
47
|
|
|
48
48
|
def __exit__(
|
|
49
|
-
self, exc_type:
|
|
49
|
+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
|
50
50
|
) -> None:
|
|
51
51
|
"""Exit the runtime context related to the object.
|
|
52
52
|
|