Skip to content

Conversation

PranjalPragya
Copy link

Problem

Previously, when OpenAI returned a malformed tool_calls response — such as when function.arguments was None, an invalid type, or not a JSON string — it would cause the Autogen agent to crash.
This commonly occurred during tool call processing, especially when relying on external model behavior that couldn’t be guaranteed to be clean or well-formed.

Solution

This PR introduces a new sanitizer in autogen_core/utils/sanitizer.py that:

  • Intercepts and inspects each tool call in the list.
  • Skips calls with missing or malformed function.arguments.
  • Filters out invalid JSON or ill-structured inputs.
  • Ensures that only well-formed, decodable tool calls are passed onward for execution.

This enhances Autogen's fault-tolerance, especially during external API usage and multi-agent orchestration where malformed tool responses can silently derail entire chains.

Testing

A dedicated test (test_sanitizer.py) was added to:

  • Simulate OpenAI-style tool call outputs, including edge cases.
  • Validate that malformed entries are removed while valid ones remain unaffected.
  • Ensure that the sanitizer logic works in isolation, independent of OpenAI API availability.

Notes

  • This PR does not modify agent or model logic— the sanitizer operates as a standalone pre-execution guard.
  • Other test failures (if any) are unrelated and existed before this change.

Checks

  • I've included any doc changes needed for https://microsoft.github.io/autogen/.
  • I've added tests (if relevant) corresponding to the changes introduced in this PR.
  • I've made sure all auto checks have passed.

@PranjalPragya
Copy link
Author

@microsoft-github-policy-service agree

@PranjalPragya
Copy link
Author

@microsoft-github-policy-service agree

@PranjalPragya
Copy link
Author

Hi @ekzhu, just following up on this PR — I’ve made the requested changes and confirmed all CLA requirements are now satisfied. Let me know if there's anything else needed from my side. Thanks!

@PranjalPragya
Copy link
Author

Hi again @ekzhu, just following up in case this PR got buried. Happy to rebase or resolve conflicts if needed — just let me know. Thanks again for reviewing earlier!

@tejas-dharani
Copy link
Contributor

Hi @PranjalPragya,

Could you please resolve the merge conflicts with the main branch?

Thanks!

@PranjalPragya
Copy link
Author

Hi @ekzhu / @tejas-dharani,

I’ve resolved the merge conflicts with the main branch and committed the changes. All CLA requirements are satisfied, and all requested modifications have been applied. Please let me know if anything else is needed from my side for review.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants