ag2 0.4b1__py3-none-any.whl → 0.4.2b1__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.

Files changed (118) hide show
  1. ag2-0.4.2b1.dist-info/METADATA +19 -0
  2. ag2-0.4.2b1.dist-info/RECORD +6 -0
  3. ag2-0.4.2b1.dist-info/top_level.txt +1 -0
  4. ag2-0.4b1.dist-info/METADATA +0 -496
  5. ag2-0.4b1.dist-info/RECORD +0 -115
  6. ag2-0.4b1.dist-info/top_level.txt +0 -1
  7. autogen/__init__.py +0 -17
  8. autogen/_pydantic.py +0 -116
  9. autogen/agentchat/__init__.py +0 -42
  10. autogen/agentchat/agent.py +0 -142
  11. autogen/agentchat/assistant_agent.py +0 -85
  12. autogen/agentchat/chat.py +0 -306
  13. autogen/agentchat/contrib/__init__.py +0 -0
  14. autogen/agentchat/contrib/agent_builder.py +0 -787
  15. autogen/agentchat/contrib/agent_optimizer.py +0 -450
  16. autogen/agentchat/contrib/capabilities/__init__.py +0 -0
  17. autogen/agentchat/contrib/capabilities/agent_capability.py +0 -21
  18. autogen/agentchat/contrib/capabilities/generate_images.py +0 -297
  19. autogen/agentchat/contrib/capabilities/teachability.py +0 -406
  20. autogen/agentchat/contrib/capabilities/text_compressors.py +0 -72
  21. autogen/agentchat/contrib/capabilities/transform_messages.py +0 -92
  22. autogen/agentchat/contrib/capabilities/transforms.py +0 -565
  23. autogen/agentchat/contrib/capabilities/transforms_util.py +0 -120
  24. autogen/agentchat/contrib/capabilities/vision_capability.py +0 -217
  25. autogen/agentchat/contrib/captainagent.py +0 -487
  26. autogen/agentchat/contrib/gpt_assistant_agent.py +0 -545
  27. autogen/agentchat/contrib/graph_rag/__init__.py +0 -0
  28. autogen/agentchat/contrib/graph_rag/document.py +0 -24
  29. autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +0 -76
  30. autogen/agentchat/contrib/graph_rag/graph_query_engine.py +0 -50
  31. autogen/agentchat/contrib/graph_rag/graph_rag_capability.py +0 -56
  32. autogen/agentchat/contrib/img_utils.py +0 -390
  33. autogen/agentchat/contrib/llamaindex_conversable_agent.py +0 -123
  34. autogen/agentchat/contrib/llava_agent.py +0 -176
  35. autogen/agentchat/contrib/math_user_proxy_agent.py +0 -471
  36. autogen/agentchat/contrib/multimodal_conversable_agent.py +0 -128
  37. autogen/agentchat/contrib/qdrant_retrieve_user_proxy_agent.py +0 -325
  38. autogen/agentchat/contrib/retrieve_assistant_agent.py +0 -56
  39. autogen/agentchat/contrib/retrieve_user_proxy_agent.py +0 -701
  40. autogen/agentchat/contrib/society_of_mind_agent.py +0 -203
  41. autogen/agentchat/contrib/swarm_agent.py +0 -414
  42. autogen/agentchat/contrib/text_analyzer_agent.py +0 -76
  43. autogen/agentchat/contrib/tool_retriever.py +0 -114
  44. autogen/agentchat/contrib/vectordb/__init__.py +0 -0
  45. autogen/agentchat/contrib/vectordb/base.py +0 -243
  46. autogen/agentchat/contrib/vectordb/chromadb.py +0 -326
  47. autogen/agentchat/contrib/vectordb/mongodb.py +0 -559
  48. autogen/agentchat/contrib/vectordb/pgvectordb.py +0 -958
  49. autogen/agentchat/contrib/vectordb/qdrant.py +0 -334
  50. autogen/agentchat/contrib/vectordb/utils.py +0 -126
  51. autogen/agentchat/contrib/web_surfer.py +0 -305
  52. autogen/agentchat/conversable_agent.py +0 -2908
  53. autogen/agentchat/groupchat.py +0 -1668
  54. autogen/agentchat/user_proxy_agent.py +0 -109
  55. autogen/agentchat/utils.py +0 -207
  56. autogen/browser_utils.py +0 -291
  57. autogen/cache/__init__.py +0 -10
  58. autogen/cache/abstract_cache_base.py +0 -78
  59. autogen/cache/cache.py +0 -182
  60. autogen/cache/cache_factory.py +0 -85
  61. autogen/cache/cosmos_db_cache.py +0 -150
  62. autogen/cache/disk_cache.py +0 -109
  63. autogen/cache/in_memory_cache.py +0 -61
  64. autogen/cache/redis_cache.py +0 -128
  65. autogen/code_utils.py +0 -745
  66. autogen/coding/__init__.py +0 -22
  67. autogen/coding/base.py +0 -113
  68. autogen/coding/docker_commandline_code_executor.py +0 -262
  69. autogen/coding/factory.py +0 -45
  70. autogen/coding/func_with_reqs.py +0 -203
  71. autogen/coding/jupyter/__init__.py +0 -22
  72. autogen/coding/jupyter/base.py +0 -32
  73. autogen/coding/jupyter/docker_jupyter_server.py +0 -164
  74. autogen/coding/jupyter/embedded_ipython_code_executor.py +0 -182
  75. autogen/coding/jupyter/jupyter_client.py +0 -224
  76. autogen/coding/jupyter/jupyter_code_executor.py +0 -161
  77. autogen/coding/jupyter/local_jupyter_server.py +0 -168
  78. autogen/coding/local_commandline_code_executor.py +0 -410
  79. autogen/coding/markdown_code_extractor.py +0 -44
  80. autogen/coding/utils.py +0 -57
  81. autogen/exception_utils.py +0 -46
  82. autogen/extensions/__init__.py +0 -0
  83. autogen/formatting_utils.py +0 -76
  84. autogen/function_utils.py +0 -362
  85. autogen/graph_utils.py +0 -148
  86. autogen/io/__init__.py +0 -15
  87. autogen/io/base.py +0 -105
  88. autogen/io/console.py +0 -43
  89. autogen/io/websockets.py +0 -213
  90. autogen/logger/__init__.py +0 -11
  91. autogen/logger/base_logger.py +0 -140
  92. autogen/logger/file_logger.py +0 -287
  93. autogen/logger/logger_factory.py +0 -29
  94. autogen/logger/logger_utils.py +0 -42
  95. autogen/logger/sqlite_logger.py +0 -459
  96. autogen/math_utils.py +0 -356
  97. autogen/oai/__init__.py +0 -33
  98. autogen/oai/anthropic.py +0 -428
  99. autogen/oai/bedrock.py +0 -600
  100. autogen/oai/cerebras.py +0 -264
  101. autogen/oai/client.py +0 -1148
  102. autogen/oai/client_utils.py +0 -167
  103. autogen/oai/cohere.py +0 -453
  104. autogen/oai/completion.py +0 -1216
  105. autogen/oai/gemini.py +0 -469
  106. autogen/oai/groq.py +0 -281
  107. autogen/oai/mistral.py +0 -279
  108. autogen/oai/ollama.py +0 -576
  109. autogen/oai/openai_utils.py +0 -810
  110. autogen/oai/together.py +0 -343
  111. autogen/retrieve_utils.py +0 -487
  112. autogen/runtime_logging.py +0 -163
  113. autogen/token_count_utils.py +0 -257
  114. autogen/types.py +0 -20
  115. autogen/version.py +0 -7
  116. {ag2-0.4b1.dist-info → ag2-0.4.2b1.dist-info}/LICENSE +0 -0
  117. {ag2-0.4b1.dist-info → ag2-0.4.2b1.dist-info}/NOTICE.md +0 -0
  118. {ag2-0.4b1.dist-info → ag2-0.4.2b1.dist-info}/WHEEL +0 -0
@@ -1,305 +0,0 @@
1
- # Copyright (c) 2023 - 2024, Owners of https://github.com/ag2ai
2
- #
3
- # SPDX-License-Identifier: Apache-2.0
4
- #
5
- # Portions derived from https://github.com/microsoft/autogen are under the MIT License.
6
- # SPDX-License-Identifier: MIT
7
- import copy
8
- import json
9
- import logging
10
- import re
11
- from dataclasses import dataclass
12
- from datetime import datetime
13
- from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Union
14
-
15
- from typing_extensions import Annotated
16
-
17
- from ... import Agent, AssistantAgent, ConversableAgent, GroupChat, GroupChatManager, OpenAIWrapper, UserProxyAgent
18
- from ...browser_utils import SimpleTextBrowser
19
- from ...code_utils import content_str
20
- from ...oai.openai_utils import filter_config
21
- from ...token_count_utils import count_token, get_max_token_limit
22
-
23
- logger = logging.getLogger(__name__)
24
-
25
-
26
- class WebSurferAgent(ConversableAgent):
27
- """(In preview) An agent that acts as a basic web surfer that can search the web and visit web pages."""
28
-
29
- DEFAULT_PROMPT = (
30
- "You are a helpful AI assistant with access to a web browser (via the provided functions). In fact, YOU ARE THE ONLY MEMBER OF YOUR PARTY WITH ACCESS TO A WEB BROWSER, so please help out where you can by performing web searches, navigating pages, and reporting what you find. Today's date is "
31
- + datetime.now().date().isoformat()
32
- )
33
-
34
- DEFAULT_DESCRIPTION = "A helpful assistant with access to a web browser. Ask them to perform web searches, open pages, navigate to Wikipedia, answer questions from pages, and or generate summaries."
35
-
36
- def __init__(
37
- self,
38
- name: str,
39
- system_message: Optional[Union[str, List[str]]] = DEFAULT_PROMPT,
40
- description: Optional[str] = DEFAULT_DESCRIPTION,
41
- is_termination_msg: Optional[Callable[[Dict[str, Any]], bool]] = None,
42
- max_consecutive_auto_reply: Optional[int] = None,
43
- human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "TERMINATE",
44
- function_map: Optional[Dict[str, Callable]] = None,
45
- code_execution_config: Union[Dict, Literal[False]] = False,
46
- llm_config: Optional[Union[Dict, Literal[False]]] = None,
47
- summarizer_llm_config: Optional[Union[Dict, Literal[False]]] = None,
48
- default_auto_reply: Optional[Union[str, Dict, None]] = "",
49
- browser_config: Optional[Union[Dict, None]] = None,
50
- **kwargs,
51
- ):
52
- super().__init__(
53
- name=name,
54
- system_message=system_message,
55
- description=description,
56
- is_termination_msg=is_termination_msg,
57
- max_consecutive_auto_reply=max_consecutive_auto_reply,
58
- human_input_mode=human_input_mode,
59
- function_map=function_map,
60
- code_execution_config=code_execution_config,
61
- llm_config=llm_config,
62
- default_auto_reply=default_auto_reply,
63
- **kwargs,
64
- )
65
-
66
- self._create_summarizer_client(summarizer_llm_config, llm_config)
67
-
68
- # Create the browser
69
- self.browser = SimpleTextBrowser(**(browser_config if browser_config else {}))
70
-
71
- inner_llm_config = copy.deepcopy(llm_config)
72
-
73
- # Set up the inner monologue
74
- self._assistant = AssistantAgent(
75
- self.name + "_inner_assistant",
76
- system_message=system_message, # type: ignore[arg-type]
77
- llm_config=inner_llm_config,
78
- is_termination_msg=lambda m: False,
79
- )
80
-
81
- self._user_proxy = UserProxyAgent(
82
- self.name + "_inner_user_proxy",
83
- human_input_mode="NEVER",
84
- code_execution_config=False,
85
- default_auto_reply="",
86
- is_termination_msg=lambda m: False,
87
- )
88
-
89
- if inner_llm_config not in [None, False]:
90
- self._register_functions()
91
-
92
- self.register_reply([Agent, None], WebSurferAgent.generate_surfer_reply, remove_other_reply_funcs=True)
93
- self.register_reply([Agent, None], ConversableAgent.generate_code_execution_reply)
94
- self.register_reply([Agent, None], ConversableAgent.generate_function_call_reply)
95
- self.register_reply([Agent, None], ConversableAgent.check_termination_and_human_reply)
96
-
97
- def _create_summarizer_client(self, summarizer_llm_config: Dict[str, Any], llm_config: Dict[str, Any]) -> None:
98
- # If the summarizer_llm_config is None, we copy it from the llm_config
99
- if summarizer_llm_config is None:
100
- if llm_config is None: # Nothing to copy
101
- self.summarizer_llm_config = None
102
- elif llm_config is False: # LLMs disabled
103
- self.summarizer_llm_config = False
104
- else: # Create a suitable config
105
- self.summarizer_llm_config = copy.deepcopy(llm_config) # type: ignore[assignment]
106
- if "config_list" in self.summarizer_llm_config: # type: ignore[operator]
107
- preferred_models = filter_config( # type: ignore[no-untyped-call]
108
- self.summarizer_llm_config["config_list"], # type: ignore[index]
109
- {"model": ["gpt-3.5-turbo-1106", "gpt-3.5-turbo-16k-0613", "gpt-3.5-turbo-16k"]},
110
- )
111
- if len(preferred_models) == 0:
112
- logger.warning(
113
- "The summarizer did not find the preferred model (gpt-3.5-turbo-16k) in the config list. "
114
- "Semantic operations on webpages (summarization or Q&A) might be costly or ineffective."
115
- )
116
- else:
117
- self.summarizer_llm_config["config_list"] = preferred_models # type: ignore[index]
118
- else:
119
- self.summarizer_llm_config = summarizer_llm_config # type: ignore[assignment]
120
-
121
- # Create the summarizer client
122
- self.summarization_client = (
123
- None if self.summarizer_llm_config is False else OpenAIWrapper(**self.summarizer_llm_config)
124
- ) # type: ignore[arg-type]
125
-
126
- def _register_functions(self) -> None:
127
- """Register the functions for the inner assistant and user proxy."""
128
-
129
- # Helper functions
130
- def _browser_state() -> Tuple[str, str]:
131
- header = f"Address: {self.browser.address}\n"
132
- if self.browser.page_title is not None:
133
- header += f"Title: {self.browser.page_title}\n"
134
-
135
- current_page = self.browser.viewport_current_page
136
- total_pages = len(self.browser.viewport_pages)
137
-
138
- header += f"Viewport position: Showing page {current_page+1} of {total_pages}.\n"
139
- return (header, self.browser.viewport)
140
-
141
- @self._user_proxy.register_for_execution()
142
- @self._assistant.register_for_llm(
143
- name="informational_web_search",
144
- description="Perform an INFORMATIONAL web search query then return the search results.",
145
- )
146
- def _informational_search(query: Annotated[str, "The informational web search query to perform."]) -> str:
147
- self.browser.visit_page(f"bing: {query}")
148
- header, content = _browser_state()
149
- return header.strip() + "\n=======================\n" + content
150
-
151
- @self._user_proxy.register_for_execution()
152
- @self._assistant.register_for_llm(
153
- name="navigational_web_search",
154
- description="Perform a NAVIGATIONAL web search query then immediately navigate to the top result. Useful, for example, to navigate to a particular Wikipedia article or other known destination. Equivalent to Google's \"I'm Feeling Lucky\" button.",
155
- )
156
- def _navigational_search(query: Annotated[str, "The navigational web search query to perform."]) -> str:
157
- self.browser.visit_page(f"bing: {query}")
158
-
159
- # Extract the first linl
160
- m = re.search(r"\[.*?\]\((http.*?)\)", self.browser.page_content)
161
- if m:
162
- self.browser.visit_page(m.group(1))
163
-
164
- # Return where we ended up
165
- header, content = _browser_state()
166
- return header.strip() + "\n=======================\n" + content
167
-
168
- @self._user_proxy.register_for_execution()
169
- @self._assistant.register_for_llm(
170
- name="visit_page", description="Visit a webpage at a given URL and return its text."
171
- )
172
- def _visit_page(url: Annotated[str, "The relative or absolute url of the webapge to visit."]) -> str:
173
- self.browser.visit_page(url)
174
- header, content = _browser_state()
175
- return header.strip() + "\n=======================\n" + content
176
-
177
- @self._user_proxy.register_for_execution()
178
- @self._assistant.register_for_llm(
179
- name="page_up",
180
- description="Scroll the viewport UP one page-length in the current webpage and return the new viewport content.",
181
- )
182
- def _page_up() -> str:
183
- self.browser.page_up()
184
- header, content = _browser_state()
185
- return header.strip() + "\n=======================\n" + content
186
-
187
- @self._user_proxy.register_for_execution()
188
- @self._assistant.register_for_llm(
189
- name="page_down",
190
- description="Scroll the viewport DOWN one page-length in the current webpage and return the new viewport content.",
191
- )
192
- def _page_down() -> str:
193
- self.browser.page_down()
194
- header, content = _browser_state()
195
- return header.strip() + "\n=======================\n" + content
196
-
197
- if self.summarization_client is not None:
198
-
199
- @self._user_proxy.register_for_execution()
200
- @self._assistant.register_for_llm(
201
- name="answer_from_page",
202
- description="Uses AI to read the page and directly answer a given question based on the content.",
203
- )
204
- def _answer_from_page(
205
- question: Annotated[Optional[str], "The question to directly answer."],
206
- url: Annotated[Optional[str], "[Optional] The url of the page. (Defaults to the current page)"] = None,
207
- ) -> str:
208
- if url is not None and url != self.browser.address:
209
- self.browser.visit_page(url)
210
-
211
- # We are likely going to need to fix this later, but summarize only as many tokens that fit in the buffer
212
- limit = 4096
213
- try:
214
- limit = get_max_token_limit(self.summarizer_llm_config["config_list"][0]["model"]) # type: ignore[index]
215
- except ValueError:
216
- pass # limit is unknown
217
- except TypeError:
218
- pass # limit is unknown
219
-
220
- if limit < 16000:
221
- logger.warning(
222
- f"The token limit ({limit}) of the WebSurferAgent.summarizer_llm_config, is below the recommended 16k."
223
- )
224
-
225
- buffer = ""
226
- for line in re.split(r"([\r\n]+)", self.browser.page_content):
227
- tokens = count_token(buffer + line)
228
- if tokens + 1024 > limit: # Leave room for our summary
229
- break
230
- buffer += line
231
-
232
- buffer = buffer.strip()
233
- if len(buffer) == 0:
234
- return "Nothing to summarize."
235
-
236
- messages = [
237
- {
238
- "role": "system",
239
- "content": "You are a helpful assistant that can summarize long documents to answer question.",
240
- }
241
- ]
242
-
243
- prompt = f"Please summarize the following into one or two paragraph:\n\n{buffer}"
244
- if question is not None:
245
- prompt = f"Please summarize the following into one or two paragraphs with respect to '{question}':\n\n{buffer}"
246
-
247
- messages.append(
248
- {"role": "user", "content": prompt},
249
- )
250
-
251
- response = self.summarization_client.create(context=None, messages=messages) # type: ignore[union-attr]
252
- extracted_response = self.summarization_client.extract_text_or_completion_object(response)[0] # type: ignore[union-attr]
253
- return str(extracted_response)
254
-
255
- @self._user_proxy.register_for_execution()
256
- @self._assistant.register_for_llm(
257
- name="summarize_page",
258
- description="Uses AI to summarize the content found at a given url. If the url is not provided, the current page is summarized.",
259
- )
260
- def _summarize_page(
261
- url: Annotated[
262
- Optional[str], "[Optional] The url of the page to summarize. (Defaults to current page)"
263
- ] = None,
264
- ) -> str:
265
- return _answer_from_page(url=url, question=None)
266
-
267
- def generate_surfer_reply(
268
- self,
269
- messages: Optional[List[Dict[str, str]]] = None,
270
- sender: Optional[Agent] = None,
271
- config: Optional[OpenAIWrapper] = None,
272
- ) -> Tuple[bool, Optional[Union[str, Dict[str, str]]]]:
273
- """Generate a reply using autogen.oai."""
274
- if messages is None:
275
- messages = self._oai_messages[sender]
276
-
277
- self._user_proxy.reset() # type: ignore[no-untyped-call]
278
- self._assistant.reset() # type: ignore[no-untyped-call]
279
-
280
- # Clone the messages to give context
281
- self._assistant.chat_messages[self._user_proxy] = list()
282
- history = messages[0 : len(messages) - 1]
283
- for message in history:
284
- self._assistant.chat_messages[self._user_proxy].append(message)
285
-
286
- # Remind the agent where it is
287
- self._user_proxy.send(
288
- f"Your browser is currently open to the page '{self.browser.page_title}' at the address '{self.browser.address}'.",
289
- self._assistant,
290
- request_reply=False,
291
- silent=True,
292
- )
293
-
294
- self._user_proxy.send(messages[-1]["content"], self._assistant, request_reply=True, silent=True)
295
- agent_reply = self._user_proxy.chat_messages[self._assistant][-1]
296
- # print("Agent Reply: " + str(agent_reply))
297
- proxy_reply = self._user_proxy.generate_reply(
298
- messages=self._user_proxy.chat_messages[self._assistant], sender=self._assistant
299
- )
300
- # print("Proxy Reply: " + str(proxy_reply))
301
-
302
- if proxy_reply == "": # Was the default reply
303
- return True, None if agent_reply is None else agent_reply["content"]
304
- else:
305
- return True, None if proxy_reply is None else proxy_reply["content"] # type: ignore[index]