Skip to content

Commit 49e8053

Browse files
Merge branch 'main' of github.com:WilliamEspegren/autogen
2 parents 9137f2d + 501610b commit 49e8053

File tree

91 files changed

+3149
-862
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+3149
-862
lines changed

.gitattributes

+88
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,91 @@
1+
# Source code
2+
*.bash text eol=lf
3+
*.bat text eol=crlf
4+
*.cmd text eol=crlf
5+
*.coffee text
6+
*.css text diff=css eol=lf
7+
*.htm text diff=html eol=lf
8+
*.html text diff=html eol=lf
9+
*.inc text
10+
*.ini text
11+
*.js text
12+
*.json text eol=lf
13+
*.jsx text
14+
*.less text
15+
*.ls text
16+
*.map text -diff
17+
*.od text
18+
*.onlydata text
19+
*.php text diff=php
20+
*.pl text
21+
*.ps1 text eol=crlf
22+
*.py text diff=python eol=lf
23+
*.rb text diff=ruby eol=lf
24+
*.sass text
25+
*.scm text
26+
*.scss text diff=css
27+
*.sh text eol=lf
28+
.husky/* text eol=lf
29+
*.sql text
30+
*.styl text
31+
*.tag text
32+
*.ts text
33+
*.tsx text
34+
*.xml text
35+
*.xhtml text diff=html
36+
37+
# Docker
38+
Dockerfile text eol=lf
39+
40+
# Documentation
41+
*.ipynb text
42+
*.markdown text diff=markdown eol=lf
43+
*.md text diff=markdown eol=lf
44+
*.mdwn text diff=markdown eol=lf
45+
*.mdown text diff=markdown eol=lf
46+
*.mkd text diff=markdown eol=lf
47+
*.mkdn text diff=markdown eol=lf
48+
*.mdtxt text eol=lf
49+
*.mdtext text eol=lf
50+
*.txt text eol=lf
51+
AUTHORS text eol=lf
52+
CHANGELOG text eol=lf
53+
CHANGES text eol=lf
54+
CONTRIBUTING text eol=lf
55+
COPYING text eol=lf
56+
copyright text eol=lf
57+
*COPYRIGHT* text eol=lf
58+
INSTALL text eol=lf
59+
license text eol=lf
60+
LICENSE text eol=lf
61+
NEWS text eol=lf
62+
readme text eol=lf
63+
*README* text eol=lf
64+
TODO text
65+
66+
# Configs
67+
*.cnf text eol=lf
68+
*.conf text eol=lf
69+
*.config text eol=lf
70+
.editorconfig text
71+
.env text eol=lf
72+
.gitattributes text eol=lf
73+
.gitconfig text eol=lf
74+
.htaccess text
75+
*.lock text -diff
76+
package.json text eol=lf
77+
package-lock.json text eol=lf -diff
78+
pnpm-lock.yaml text eol=lf -diff
79+
.prettierrc text
80+
yarn.lock text -diff
81+
*.toml text eol=lf
82+
*.yaml text eol=lf
83+
*.yml text eol=lf
84+
browserslist text
85+
Makefile text eol=lf
86+
makefile text eol=lf
87+
88+
# Images
189
*.png filter=lfs diff=lfs merge=lfs -text
290
*.jpg filter=lfs diff=lfs merge=lfs -text
391
*.jpeg filter=lfs diff=lfs merge=lfs -text

.github/workflows/build.yml

+2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ jobs:
8888
fi
8989
- name: Test with pytest skipping openai tests
9090
if: matrix.python-version != '3.10' && matrix.os == 'ubuntu-latest'
91+
# Remove the line below once https://github.com/docker/docker-py/issues/3256 is merged
9192
run: |
93+
pip install "requests<2.32.0"
9294
pytest test --ignore=test/agentchat/contrib --skip-openai --durations=10 --durations-min=1.0
9395
- name: Test with pytest skipping openai and docker tests
9496
if: matrix.python-version != '3.10' && matrix.os != 'ubuntu-latest'

.github/workflows/contrib-tests.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ jobs:
107107
run: |
108108
sudo apt-get update
109109
sudo apt-get install -y tesseract-ocr poppler-utils
110-
pip install unstructured[all-docs]==0.13.0
110+
pip install --no-cache-dir unstructured[all-docs]==0.13.0
111111
- name: Install packages and dependencies for RetrieveChat
112112
run: |
113113
pip install -e .[retrievechat]
@@ -418,9 +418,9 @@ jobs:
418418
os: [ubuntu-latest, macos-latest, windows-2019]
419419
python-version: ["3.11"]
420420
steps:
421-
- uses: actions/checkout@v3
421+
- uses: actions/checkout@v4
422422
- name: Set up Python ${{ matrix.python-version }}
423-
uses: actions/setup-python@v4
423+
uses: actions/setup-python@v5
424424
with:
425425
python-version: ${{ matrix.python-version }}
426426
- name: Install packages and dependencies for all tests

autogen/agentchat/chat.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ def initiate_chats(chat_queue: List[Dict[str, Any]]) -> List[ChatResult]:
195195
r.summary for i, r in enumerate(finished_chats) if i not in finished_chat_indexes_to_exclude_from_carryover
196196
]
197197

198-
__post_carryover_processing(chat_info)
198+
if not chat_info.get("silent", False):
199+
__post_carryover_processing(chat_info)
200+
199201
sender = chat_info["sender"]
200202
chat_res = sender.initiate_chat(**chat_info)
201203
finished_chats.append(chat_res)
@@ -236,7 +238,10 @@ async def _dependent_chat_future(
236238
if isinstance(_chat_carryover, str):
237239
_chat_carryover = [_chat_carryover]
238240
chat_info["carryover"] = _chat_carryover + [finished_chats[pre_id].summary for pre_id in finished_chats]
239-
__post_carryover_processing(chat_info)
241+
242+
if not chat_info.get("silent", False):
243+
__post_carryover_processing(chat_info)
244+
240245
sender = chat_info["sender"]
241246
chat_res_future = asyncio.create_task(sender.a_initiate_chat(**chat_info))
242247
call_back_with_args = partial(_on_chat_future_done, chat_id=chat_id)

autogen/agentchat/contrib/capabilities/context_handling.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from autogen import ConversableAgent, token_count_utils
99

1010
warn(
11-
"Context handling with TransformChatHistory is deprecated. "
12-
"Please use TransformMessages from autogen/agentchat/contrib/capabilities/transform_messages.py instead.",
11+
"Context handling with TransformChatHistory is deprecated and will be removed in `0.2.30`. "
12+
"Please use `TransformMessages`, documentation can be found at https://microsoft.github.io/autogen/docs/topics/handling_long_contexts/intro_to_transform_messages",
1313
DeprecationWarning,
1414
stacklevel=2,
1515
)

autogen/agentchat/contrib/capabilities/transforms.py

+39-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from autogen import token_count_utils
1010
from autogen.cache import AbstractCache, Cache
11+
from autogen.oai.openai_utils import filter_config
1112

1213
from .text_compressors import LLMLingua, TextCompressor
1314

@@ -130,6 +131,8 @@ def __init__(
130131
max_tokens: Optional[int] = None,
131132
min_tokens: Optional[int] = None,
132133
model: str = "gpt-3.5-turbo-0613",
134+
filter_dict: Optional[Dict] = None,
135+
exclude_filter: bool = True,
133136
):
134137
"""
135138
Args:
@@ -140,11 +143,17 @@ def __init__(
140143
min_tokens (Optional[int]): Minimum number of tokens in messages to apply the transformation.
141144
Must be greater than or equal to 0 if not None.
142145
model (str): The target OpenAI model for tokenization alignment.
146+
filter_dict (None or dict): A dictionary to filter out messages that you want/don't want to compress.
147+
If None, no filters will be applied.
148+
exclude_filter (bool): If exclude filter is True (the default value), messages that match the filter will be
149+
excluded from token truncation. If False, messages that match the filter will be truncated.
143150
"""
144151
self._model = model
145152
self._max_tokens_per_message = self._validate_max_tokens(max_tokens_per_message)
146153
self._max_tokens = self._validate_max_tokens(max_tokens)
147154
self._min_tokens = self._validate_min_tokens(min_tokens, max_tokens)
155+
self._filter_dict = filter_dict
156+
self._exclude_filter = exclude_filter
148157

149158
def apply_transform(self, messages: List[Dict]) -> List[Dict]:
150159
"""Applies token truncation to the conversation history.
@@ -169,10 +178,15 @@ def apply_transform(self, messages: List[Dict]) -> List[Dict]:
169178

170179
for msg in reversed(temp_messages):
171180
# Some messages may not have content.
172-
if not isinstance(msg.get("content"), (str, list)):
181+
if not _is_content_right_type(msg.get("content")):
173182
processed_messages.insert(0, msg)
174183
continue
175184

185+
if not _should_transform_message(msg, self._filter_dict, self._exclude_filter):
186+
processed_messages.insert(0, msg)
187+
processed_messages_tokens += _count_tokens(msg["content"])
188+
continue
189+
176190
expected_tokens_remained = self._max_tokens - processed_messages_tokens - self._max_tokens_per_message
177191

178192
# If adding this message would exceed the token limit, truncate the last message to meet the total token
@@ -282,6 +296,8 @@ def __init__(
282296
min_tokens: Optional[int] = None,
283297
compression_params: Dict = dict(),
284298
cache: Optional[AbstractCache] = Cache.disk(),
299+
filter_dict: Optional[Dict] = None,
300+
exclude_filter: bool = True,
285301
):
286302
"""
287303
Args:
@@ -293,6 +309,10 @@ def __init__(
293309
dictionary.
294310
cache (None or AbstractCache): The cache client to use to store and retrieve previously compressed messages.
295311
If None, no caching will be used.
312+
filter_dict (None or dict): A dictionary to filter out messages that you want/don't want to compress.
313+
If None, no filters will be applied.
314+
exclude_filter (bool): If exclude filter is True (the default value), messages that match the filter will be
315+
excluded from compression. If False, messages that match the filter will be compressed.
296316
"""
297317

298318
if text_compressor is None:
@@ -303,6 +323,8 @@ def __init__(
303323
self._text_compressor = text_compressor
304324
self._min_tokens = min_tokens
305325
self._compression_args = compression_params
326+
self._filter_dict = filter_dict
327+
self._exclude_filter = exclude_filter
306328
self._cache = cache
307329

308330
# Optimizing savings calculations to optimize log generation
@@ -334,7 +356,10 @@ def apply_transform(self, messages: List[Dict]) -> List[Dict]:
334356
processed_messages = messages.copy()
335357
for message in processed_messages:
336358
# Some messages may not have content.
337-
if not isinstance(message.get("content"), (str, list)):
359+
if not _is_content_right_type(message.get("content")):
360+
continue
361+
362+
if not _should_transform_message(message, self._filter_dict, self._exclude_filter):
338363
continue
339364

340365
if _is_content_text_empty(message["content"]):
@@ -397,7 +422,7 @@ def _cache_set(
397422
self, content: Union[str, List[Dict]], compressed_content: Union[str, List[Dict]], tokens_saved: int
398423
):
399424
if self._cache:
400-
value = (tokens_saved, json.dumps(compressed_content))
425+
value = (tokens_saved, compressed_content)
401426
self._cache.set(self._cache_key(content), value)
402427

403428
def _cache_key(self, content: Union[str, List[Dict]]) -> str:
@@ -427,10 +452,21 @@ def _count_tokens(content: Union[str, List[Dict[str, Any]]]) -> int:
427452
return token_count
428453

429454

455+
def _is_content_right_type(content: Any) -> bool:
456+
return isinstance(content, (str, list))
457+
458+
430459
def _is_content_text_empty(content: Union[str, List[Dict[str, Any]]]) -> bool:
431460
if isinstance(content, str):
432461
return content == ""
433462
elif isinstance(content, list):
434463
return all(_is_content_text_empty(item.get("text", "")) for item in content)
435464
else:
436465
return False
466+
467+
468+
def _should_transform_message(message: Dict[str, Any], filter_dict: Optional[Dict[str, Any]], exclude: bool) -> bool:
469+
if not filter_dict:
470+
return True
471+
472+
return len(filter_config([message], filter_dict, exclude)) > 0

autogen/agentchat/contrib/compressible_agent.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
logger = logging.getLogger(__name__)
1414

1515
warn(
16-
"Context handling with CompressibleAgent is deprecated. "
17-
"Please use `TransformMessages`, documentation can be found at https://microsoft.github.io/autogen/docs/reference/agentchat/contrib/capabilities/transform_messages",
16+
"Context handling with CompressibleAgent is deprecated and will be removed in `0.2.30`. "
17+
"Please use `TransformMessages`, documentation can be found at https://microsoft.github.io/autogen/docs/topics/handling_long_contexts/intro_to_transform_messages",
1818
DeprecationWarning,
1919
stacklevel=2,
2020
)

autogen/agentchat/contrib/gpt_assistant_agent.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from autogen.agentchat.agent import Agent
1212
from autogen.agentchat.assistant_agent import AssistantAgent, ConversableAgent
1313
from autogen.oai.openai_utils import create_gpt_assistant, retrieve_assistants_by_name, update_gpt_assistant
14+
from autogen.runtime_logging import log_new_agent, logging_enabled
1415

1516
logger = logging.getLogger(__name__)
1617

@@ -65,6 +66,8 @@ def __init__(
6566
super().__init__(
6667
name=name, system_message=instructions, human_input_mode="NEVER", llm_config=openai_client_cfg, **kwargs
6768
)
69+
if logging_enabled():
70+
log_new_agent(self, locals())
6871

6972
# GPTAssistantAgent's azure_deployment param may cause NotFoundError (404) in client.beta.assistants.list()
7073
# See: https://github.com/microsoft/autogen/pull/1721
@@ -169,10 +172,11 @@ def __init__(
169172
# Tools are specified but overwrite_tools is False; do not update the assistant's tools
170173
logger.warning("overwrite_tools is False. Using existing tools from assistant API.")
171174

175+
self.update_system_message(self._openai_assistant.instructions)
172176
# lazily create threads
173177
self._openai_threads = {}
174178
self._unread_index = defaultdict(int)
175-
self.register_reply(Agent, GPTAssistantAgent._invoke_assistant, position=2)
179+
self.register_reply([Agent, None], GPTAssistantAgent._invoke_assistant, position=2)
176180

177181
def _invoke_assistant(
178182
self,

0 commit comments

Comments
 (0)