Skip to content

Documents dropped in standard chat context path (generate_from_chat_context) #949

Closed

Description

@psschwei

Summary

Documents attached to Message objects via the documents parameter are not included in the API request when using the standard chat context generation path (_generate_from_chat_context_standard in OpenAIBackend).

Details

The intrinsics path (_generate_from_intrinsic_context) correctly calls messages_to_docs() and passes the result as extra_body: {"documents": docs} to the OpenAI-compatible API call.

The standard path (_generate_from_chat_context_standard) never calls messages_to_docs(). The documents are present on the Message objects, but message_to_openai_message() only serializes role and content (and images), so documents are silently lost.

This means that passing documents= on a Message used with generate_from_chat_context (or act with strategy=None) has no effect — the documents never reach the model.

Expected behavior

Documents attached to messages should be extracted and passed to the API in the standard path, the same way they are in the intrinsics path.

Reproduction

  1. Create Document objects and attach them to a Message via documents=
  2. Use mfuncs.act() or backend.generate_from_chat_context() with strategy=None
  3. The model response will not reflect the document content, because the documents were never sent

Activity

  1. kndtran commented on Apr 28, 2026

    @kndtran
    Contributor

    @psschwei We have a similar function for this here: https://github.com/generative-computing/mellea/blob/main/mellea/formatters/granite/intrinsics/input.py#L80

    Some important notes for the Granite models:

    • vLLM's OpenAI-compatible API - uses extra_body to pass documents through to the chat template
    • Ollama's OpenAI-compatible API - documents need to be formatted in a user message to be passed through to the chat template - the chat template is different (but functionally the same) to vLLM and Transformers
      • Use the function above with how="roles".

    I don't know how documents are passed in LiteLLM, but it seems like extra_body is supported in a similar way.

  2. kndtran commented on Apr 28, 2026

    @kndtran
    Contributor

    Document passing through documents in extra_body is a Granite thing. No other model does it through a special token in the chat template afaik. All other LLMs just put the documents as context in a user message in some way, so something similar to move_documents_to_message(..., how="string").

  3. linked a pull request that will close this issuefeat: handle message docs correctly #975on Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions