Skip to content

Commit

Permalink
[bug] Validates If The Role Tool is Handled Correctly after Transforms (
Browse files Browse the repository at this point in the history
  • Loading branch information
WaelKarkoub authored Oct 22, 2024
1 parent c345d41 commit 8a2a40d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions autogen/agentchat/contrib/capabilities/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def apply_transform(self, messages: List[Dict]) -> List[Dict]:
if remaining_count == 0:
break

if not transforms_util.is_tool_call_valid(truncated_messages):
truncated_messages.pop()

return truncated_messages

def get_logs(self, pre_transform_messages: List[Dict], post_transform_messages: List[Dict]) -> Tuple[str, bool]:
Expand Down Expand Up @@ -229,6 +232,9 @@ def apply_transform(self, messages: List[Dict]) -> List[Dict]:
processed_messages_tokens += msg_tokens
processed_messages.insert(0, msg)

if not transforms_util.is_tool_call_valid(processed_messages):
processed_messages.pop()

return processed_messages

def get_logs(self, pre_transform_messages: List[Dict], post_transform_messages: List[Dict]) -> Tuple[str, bool]:
Expand Down
4 changes: 4 additions & 0 deletions autogen/agentchat/contrib/capabilities/transforms_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,7 @@ def should_transform_message(message: Dict[str, Any], filter_dict: Optional[Dict
return True

return len(filter_config([message], filter_dict, exclude)) > 0


def is_tool_call_valid(messages: List[Dict[str, Any]]) -> bool:
return messages[0].get("role") != "tool"

0 comments on commit 8a2a40d

Please sign in to comment.