Skip to content

feat: add as_generic_chat_history function to convert ant Context to …#1007

Open
akihikokuroda wants to merge 1 commit intogenerative-computing:mainfrom
akihikokuroda:issue932
Open

feat: add as_generic_chat_history function to convert ant Context to …#1007
akihikokuroda wants to merge 1 commit intogenerative-computing:mainfrom
akihikokuroda:issue932

Conversation

@akihikokuroda
Copy link
Copy Markdown
Member

@akihikokuroda akihikokuroda commented May 4, 2026

Misc PR

Type of PR

  • Bug Fix
  • New Feature
  • Documentation
  • Other

Description

Add as_generic_chat_history() function to handle heterogeneous contexts with
configurable formatter. Unlike as_chat_history(), this gracefully handles
arbitrary component types by converting them to strings, with optional logging
for unknown types.

  • as_generic_chat_history(ctx, formatter=None) converts any Context to Messages
  • Default formatter logs warnings for unknown component types
  • Support custom formatter parameter for domain-specific type handling
  • Handle ModelOutputThunk, CBlock, and arbitrary components seamlessly
  • CBlock → Message(role="user"), MOT → Message(role="assistant")
  • Add 7 comprehensive tests covering all conversion scenarios

Testing

  • Tests added to the respective file if code was changed
  • New code has 100% coverage if code as added
  • Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)

Attribution

  • AI coding assistants used: claude

…Message

Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
@akihikokuroda akihikokuroda requested a review from a team as a code owner May 4, 2026 18:59
@akihikokuroda akihikokuroda requested review from markstur and planetf1 May 4, 2026 18:59
@github-actions github-actions Bot added the enhancement New feature or request label May 4, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

The PR description has been updated. Please fill out the template for your PR to be reviewed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: as_chat_history is outdated and functionality doesn't match it's name

1 participant