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
autogen/agentchat/chat.py DELETED
@@ -1,306 +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 asyncio
8
- import datetime
9
- import logging
10
- import warnings
11
- from collections import abc, defaultdict
12
- from dataclasses import dataclass
13
- from functools import partial
14
- from typing import Any, Dict, List, Set, Tuple
15
-
16
- from ..formatting_utils import colored
17
- from ..io.base import IOStream
18
- from .utils import consolidate_chat_info
19
-
20
- logger = logging.getLogger(__name__)
21
- Prerequisite = Tuple[int, int]
22
-
23
-
24
- @dataclass
25
- class ChatResult:
26
- """(Experimental) The result of a chat. Almost certain to be changed."""
27
-
28
- chat_id: int = None
29
- """chat id"""
30
- chat_history: List[Dict[str, Any]] = None
31
- """The chat history."""
32
- summary: str = None
33
- """A summary obtained from the chat."""
34
- cost: Dict[str, dict] = None # keys: "usage_including_cached_inference", "usage_excluding_cached_inference"
35
- """The cost of the chat.
36
- The value for each usage type is a dictionary containing cost information for that specific type.
37
- - "usage_including_cached_inference": Cost information on the total usage, including the tokens in cached inference.
38
- - "usage_excluding_cached_inference": Cost information on the usage of tokens, excluding the tokens in cache. No larger than "usage_including_cached_inference".
39
- """
40
- human_input: List[str] = None
41
- """A list of human input solicited during the chat."""
42
-
43
-
44
- def _validate_recipients(chat_queue: List[Dict[str, Any]]) -> None:
45
- """
46
- Validate recipients exits and warn repetitive recipients.
47
- """
48
- receipts_set = set()
49
- for chat_info in chat_queue:
50
- assert "recipient" in chat_info, "recipient must be provided."
51
- receipts_set.add(chat_info["recipient"])
52
- if len(receipts_set) < len(chat_queue):
53
- warnings.warn(
54
- "Repetitive recipients detected: The chat history will be cleared by default if a recipient appears more than once. To retain the chat history, please set 'clear_history=False' in the configuration of the repeating agent.",
55
- UserWarning,
56
- )
57
-
58
-
59
- def __create_async_prerequisites(chat_queue: List[Dict[str, Any]]) -> List[Prerequisite]:
60
- """
61
- Create list of Prerequisite (prerequisite_chat_id, chat_id)
62
- """
63
- prerequisites = []
64
- for chat_info in chat_queue:
65
- if "chat_id" not in chat_info:
66
- raise ValueError("Each chat must have a unique id for async multi-chat execution.")
67
- chat_id = chat_info["chat_id"]
68
- pre_chats = chat_info.get("prerequisites", [])
69
- for pre_chat_id in pre_chats:
70
- if not isinstance(pre_chat_id, int):
71
- raise ValueError("Prerequisite chat id is not int.")
72
- prerequisites.append((chat_id, pre_chat_id))
73
- return prerequisites
74
-
75
-
76
- def __find_async_chat_order(chat_ids: Set[int], prerequisites: List[Prerequisite]) -> List[int]:
77
- """Find chat order for async execution based on the prerequisite chats
78
-
79
- args:
80
- num_chats: number of chats
81
- prerequisites: List of Prerequisite (prerequisite_chat_id, chat_id)
82
-
83
- returns:
84
- list: a list of chat_id in order.
85
- """
86
- edges = defaultdict(set)
87
- indegree = defaultdict(int)
88
- for pair in prerequisites:
89
- chat, pre = pair[0], pair[1]
90
- if chat not in edges[pre]:
91
- indegree[chat] += 1
92
- edges[pre].add(chat)
93
- bfs = [i for i in chat_ids if i not in indegree]
94
- chat_order = []
95
- steps = len(indegree)
96
- for _ in range(steps + 1):
97
- if not bfs:
98
- break
99
- chat_order.extend(bfs)
100
- nxt = []
101
- for node in bfs:
102
- if node in edges:
103
- for course in edges[node]:
104
- indegree[course] -= 1
105
- if indegree[course] == 0:
106
- nxt.append(course)
107
- indegree.pop(course)
108
- edges.pop(node)
109
- bfs = nxt
110
-
111
- if indegree:
112
- return []
113
- return chat_order
114
-
115
-
116
- def _post_process_carryover_item(carryover_item):
117
- if isinstance(carryover_item, str):
118
- return carryover_item
119
- elif isinstance(carryover_item, dict) and "content" in carryover_item:
120
- return str(carryover_item["content"])
121
- else:
122
- return str(carryover_item)
123
-
124
-
125
- def __post_carryover_processing(chat_info: Dict[str, Any]) -> None:
126
- iostream = IOStream.get_default()
127
-
128
- if "message" not in chat_info:
129
- warnings.warn(
130
- "message is not provided in a chat_queue entry. input() will be called to get the initial message.",
131
- UserWarning,
132
- )
133
- print_carryover = (
134
- ("\n").join([_post_process_carryover_item(t) for t in chat_info["carryover"]])
135
- if isinstance(chat_info["carryover"], list)
136
- else chat_info["carryover"]
137
- )
138
- message = chat_info.get("message")
139
- if isinstance(message, str):
140
- print_message = message
141
- elif callable(message):
142
- print_message = "Callable: " + message.__name__
143
- elif isinstance(message, dict):
144
- print_message = "Dict: " + str(message)
145
- elif message is None:
146
- print_message = "None"
147
- iostream.print(colored("\n" + "*" * 80, "blue"), flush=True, sep="")
148
- iostream.print(
149
- colored(
150
- "Starting a new chat....",
151
- "blue",
152
- ),
153
- flush=True,
154
- )
155
- if chat_info.get("verbose", False):
156
- iostream.print(colored("Message:\n" + print_message, "blue"), flush=True)
157
- iostream.print(colored("Carryover:\n" + print_carryover, "blue"), flush=True)
158
- iostream.print(colored("\n" + "*" * 80, "blue"), flush=True, sep="")
159
-
160
-
161
- def initiate_chats(chat_queue: List[Dict[str, Any]]) -> List[ChatResult]:
162
- """Initiate a list of chats.
163
- Args:
164
- chat_queue (List[Dict]): A list of dictionaries containing the information about the chats.
165
-
166
- Each dictionary should contain the input arguments for
167
- [`ConversableAgent.initiate_chat`](/docs/reference/agentchat/conversable_agent#initiate_chat).
168
- For example:
169
- - `"sender"` - the sender agent.
170
- - `"recipient"` - the recipient agent.
171
- - `"clear_history"` (bool) - whether to clear the chat history with the agent.
172
- Default is True.
173
- - `"silent"` (bool or None) - (Experimental) whether to print the messages in this
174
- conversation. Default is False.
175
- - `"cache"` (Cache or None) - the cache client to use for this conversation.
176
- Default is None.
177
- - `"max_turns"` (int or None) - maximum number of turns for the chat. If None, the chat
178
- will continue until a termination condition is met. Default is None.
179
- - `"summary_method"` (str or callable) - a string or callable specifying the method to get
180
- a summary from the chat. Default is DEFAULT_summary_method, i.e., "last_msg".
181
- - `"summary_args"` (dict) - a dictionary of arguments to be passed to the summary_method.
182
- Default is {}.
183
- - `"message"` (str, callable or None) - if None, input() will be called to get the
184
- initial message.
185
- - `**context` - additional context information to be passed to the chat.
186
- - `"carryover"` - It can be used to specify the carryover information to be passed
187
- to this chat. If provided, we will combine this carryover with the "message" content when
188
- generating the initial chat message in `generate_init_message`.
189
- - `"finished_chat_indexes_to_exclude_from_carryover"` - It can be used by specifying a list of indexes of the finished_chats list,
190
- from which to exclude the summaries for carryover. If 'finished_chat_indexes_to_exclude_from_carryover' is not provided or an empty list,
191
- then summary from all the finished chats will be taken.
192
- Returns:
193
- (list): a list of ChatResult objects corresponding to the finished chats in the chat_queue.
194
- """
195
-
196
- consolidate_chat_info(chat_queue)
197
- _validate_recipients(chat_queue)
198
- current_chat_queue = chat_queue.copy()
199
- finished_chats = []
200
- while current_chat_queue:
201
- chat_info = current_chat_queue.pop(0)
202
- _chat_carryover = chat_info.get("carryover", [])
203
- finished_chat_indexes_to_exclude_from_carryover = chat_info.get(
204
- "finished_chat_indexes_to_exclude_from_carryover", []
205
- )
206
-
207
- if isinstance(_chat_carryover, str):
208
- _chat_carryover = [_chat_carryover]
209
- chat_info["carryover"] = _chat_carryover + [
210
- r.summary for i, r in enumerate(finished_chats) if i not in finished_chat_indexes_to_exclude_from_carryover
211
- ]
212
-
213
- if not chat_info.get("silent", False):
214
- __post_carryover_processing(chat_info)
215
-
216
- sender = chat_info["sender"]
217
- chat_res = sender.initiate_chat(**chat_info)
218
- finished_chats.append(chat_res)
219
- return finished_chats
220
-
221
-
222
- def __system_now_str():
223
- ct = datetime.datetime.now()
224
- return f" System time at {ct}. "
225
-
226
-
227
- def _on_chat_future_done(chat_future: asyncio.Future, chat_id: int):
228
- """
229
- Update ChatResult when async Task for Chat is completed.
230
- """
231
- logger.debug(f"Update chat {chat_id} result on task completion." + __system_now_str())
232
- chat_result = chat_future.result()
233
- chat_result.chat_id = chat_id
234
-
235
-
236
- async def _dependent_chat_future(
237
- chat_id: int, chat_info: Dict[str, Any], prerequisite_chat_futures: Dict[int, asyncio.Future]
238
- ) -> asyncio.Task:
239
- """
240
- Create an async Task for each chat.
241
- """
242
- logger.debug(f"Create Task for chat {chat_id}." + __system_now_str())
243
- _chat_carryover = chat_info.get("carryover", [])
244
- finished_chat_indexes_to_exclude_from_carryover = chat_info.get(
245
- "finished_chat_indexes_to_exclude_from_carryover", []
246
- )
247
- finished_chats = dict()
248
- for chat in prerequisite_chat_futures:
249
- chat_future = prerequisite_chat_futures[chat]
250
- if chat_future.cancelled():
251
- raise RuntimeError(f"Chat {chat} is cancelled.")
252
-
253
- # wait for prerequisite chat results for the new chat carryover
254
- finished_chats[chat] = await chat_future
255
-
256
- if isinstance(_chat_carryover, str):
257
- _chat_carryover = [_chat_carryover]
258
- data = [
259
- chat_result.summary
260
- for chat_id, chat_result in finished_chats.items()
261
- if chat_id not in finished_chat_indexes_to_exclude_from_carryover
262
- ]
263
- chat_info["carryover"] = _chat_carryover + data
264
- if not chat_info.get("silent", False):
265
- __post_carryover_processing(chat_info)
266
-
267
- sender = chat_info["sender"]
268
- chat_res_future = asyncio.create_task(sender.a_initiate_chat(**chat_info))
269
- call_back_with_args = partial(_on_chat_future_done, chat_id=chat_id)
270
- chat_res_future.add_done_callback(call_back_with_args)
271
- logger.debug(f"Task for chat {chat_id} created." + __system_now_str())
272
- return chat_res_future
273
-
274
-
275
- async def a_initiate_chats(chat_queue: List[Dict[str, Any]]) -> Dict[int, ChatResult]:
276
- """(async) Initiate a list of chats.
277
-
278
- args:
279
- - Please refer to `initiate_chats`.
280
-
281
-
282
- returns:
283
- - (Dict): a dict of ChatId: ChatResult corresponding to the finished chats in the chat_queue.
284
- """
285
- consolidate_chat_info(chat_queue)
286
- _validate_recipients(chat_queue)
287
- chat_book = {chat_info["chat_id"]: chat_info for chat_info in chat_queue}
288
- num_chats = chat_book.keys()
289
- prerequisites = __create_async_prerequisites(chat_queue)
290
- chat_order_by_id = __find_async_chat_order(num_chats, prerequisites)
291
- finished_chat_futures = dict()
292
- for chat_id in chat_order_by_id:
293
- chat_info = chat_book[chat_id]
294
- prerequisite_chat_ids = chat_info.get("prerequisites", [])
295
- pre_chat_futures = dict()
296
- for pre_chat_id in prerequisite_chat_ids:
297
- pre_chat_future = finished_chat_futures[pre_chat_id]
298
- pre_chat_futures[pre_chat_id] = pre_chat_future
299
- current_chat_future = await _dependent_chat_future(chat_id, chat_info, pre_chat_futures)
300
- finished_chat_futures[chat_id] = current_chat_future
301
- await asyncio.gather(*list(finished_chat_futures.values()))
302
- finished_chats = dict()
303
- for chat in finished_chat_futures:
304
- chat_result = finished_chat_futures[chat].result()
305
- finished_chats[chat] = chat_result
306
- return finished_chats
File without changes