Skip to content

feat(agent): add chat sanitizer and strict chat structure support #1109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Peleton-011
Copy link

Features

  • Add sanitize_message_history: Introduced a helper method to sanitize the chat history by inserting an acknowledgement message when a tool message is immediately followed by a user message. This ensures compatibility with APIs like Mistral that require strict message alternation between roles.
  • Add strict_chat_structure flag: Added an optional strict_chat_structure boolean field to agents. It is set during creation based on configuration and can be used to enforce stricter validation or formatting rules when interacting with certain LLMs. If the flag is not set at all then it goes ahead just as it would before it was implemented.

Feature Docs

  • N/A (small utility and configuration update for internal consistency and API compatibility).
  • Use case: When integrating with APIs like Mistral, which expect strict alternation between assistant/user messages.

Influence

  • Backwards compatible: These changes are non-breaking and opt-in (default behavior is unchanged unless strict_chat_structure is enabled).
  • Extensibility: Prepares the system to better support LLMs that have stricter chat format requirements.
  • Internal agent behavior: Slight modification of message history prior to sending a request, but only when necessary.

Result

  • The system correctly sanitizes message history during agent think steps without user intervention.
  • Agents can now be optionally configured to operate in strict chat structure mode.

Other

  • Future improvements might include dynamically toggling strictness per model or endpoint.
  • Related cleanup or enhancements could make this sanitizer more generic across the app.

@Peleton-011 Peleton-011 changed the title feat(agent): add chat sanitizer and strict chat structure support Add chat sanitizer and strict chat structure support to the agent Apr 28, 2025
@Peleton-011 Peleton-011 changed the title Add chat sanitizer and strict chat structure support to the agent feat(agent): add chat sanitizer and strict chat structure support Apr 28, 2025
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.

2 participants