Skip to content

Implement language detection and response handling in the agent#2

Open
n1colasf wants to merge 1 commit intomainfrom
1-bug-assistant-responds-in-spanish-intermittently
Open

Implement language detection and response handling in the agent#2
n1colasf wants to merge 1 commit intomainfrom
1-bug-assistant-responds-in-spanish-intermittently

Conversation

@n1colasf
Copy link
Member

@n1colasf n1colasf commented Mar 18, 2026

Description

Fixes inconsistent response language by adding language detection before generation and enforcing a session language policy based on the first user message. Also adds safe fallbacks for detection and translation failures, updates prompt guidance, and documents setup and behavior.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Related Issues

Fixes #1

Changes Made

  • Added a new pretool named detect_user_language to detect user language from chat history and inject runtime language context before response generation.
  • Implemented pinned session language behavior using the first user message, with fallback to last user message and then English when detection is unreliable.
  • Added dynamic translation for the no-information message with safe fallback to the original message if translation fails.
  • Registered the language detection tool in the agent pretools pipeline.
  • Updated system prompt rules to explicitly follow runtime language context and keep language stable unless user requests a switch.
  • Added dependency declarations for pycld2 and translate.
  • Updated README with dependency installation and language behavior documentation.

Testing Done

  • Tested manually
cogsol-framework-eng

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

@n1colasf n1colasf linked an issue Mar 18, 2026 that may be closed by this pull request
@n1colasf n1colasf self-assigned this Mar 18, 2026
@n1colasf n1colasf added bug Something isn't working labels Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Assistant responds in Spanish intermittently

1 participant