Skip to content

FEAT normalize messages before sending#1613

Draft
hannahwestra25 wants to merge 3 commits intomicrosoft:mainfrom
hannahwestra25:hawestra/normalize_send_prompt
Draft

FEAT normalize messages before sending#1613
hannahwestra25 wants to merge 3 commits intomicrosoft:mainfrom
hannahwestra25:hawestra/normalize_send_prompt

Conversation

@hannahwestra25
Copy link
Copy Markdown
Contributor

Description

Utilize the Normalization Pipeline in the Target Send Path

PR 4 of the TargetConfiguration roadmap

Problem

The TargetConfiguration.normalize_async pipeline (system-squash, history-squash, etc.) was fully built in this PR but never called. Every target independently fetched conversation history, appended the current message, and sent it to the API — some with ad-hoc normalization (AzureMLChatTarget), most with none at all. This meant the centralized normalization pipeline was dead code, and normalization behavior was inconsistent across targets.

Solution

Wire the normalization pipeline into the send path so that every prompt passes through configuration.normalize_async() before reaching the target's API call. This is done by making send_prompt_async a concrete template method on PromptTarget that validates, fetches conversation from memory, runs the normalization pipeline, and delegates to a new _send_prompt_target_async abstract method for wire-format-specific logic.

Changes

  • PromptTarget.send_prompt_async: Now a concrete method that calls self.configuration.normalize_async(messages=...) and passes the result to _send_prompt_target_async
  • All 20 target subclasses: Renamed send_prompt_async_send_prompt_target_async, removed duplicated validation/memory-fetch boilerplate, now receive the pre-normalized conversation directly
  • AzureMLChatTarget: message_normalizer parameter deprecated with auto-translation to TargetConfiguration(policy={SYSTEM_PROMPT: ADAPT}); will be removed in v0.14.0

Breaking Changes

  • Target authors must override _send_prompt_target_async instead of send_prompt_async

Tests and Documentation

  • Tests: Updated all mocks/stubs to new signature; added test_normalize_async_integration.py (395 lines) covering normalize-is-called, normalized-conversation-is-used, memory-not-mutated, and legacy deprecation paths

wip: running integration tests

Comment on lines +118 to +125
warnings.warn(
"Passing GenericSystemSquashNormalizer as message_normalizer is deprecated. "
"Use custom_configuration=TargetConfiguration(capabilities=TargetCapabilities("
"supports_system_prompt=False), policy=CapabilityHandlingPolicy(behaviors={"
"CapabilityName.SYSTEM_PROMPT: UnsupportedCapabilityBehavior.ADAPT})) instead. "
"Will be removed in v0.14.0.",
DeprecationWarning,
stacklevel=2,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be updated

Copy link
Copy Markdown
Contributor

@romanlutz romanlutz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need tests for this?

Nvm didn't render first time I looked!


@limit_requests_per_minute
async def send_prompt_async(self, *, message: Message) -> list[Message]:
async def _send_prompt_target_async(self, *, normalized_conversation: list[Message]) -> list[Message]:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: send_prompt_to_target_async?

As is, it reads a bit strangely.

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