Skip to content

Conversation

@Pavilion4ik
Copy link
Contributor

This PR refactors the LiteLLM-based processors to support streaming responses even when OpenAI function calling (tools) is enabled. Specifically, it includes:

chunk aggregation: Added logic to buffer streaming chunks in LLMProcessor, reconstruct fragmented tool call arguments, and execute the tools once the stream for that specific call is complete.

Recursive Streaming: Implemented yield from recursion in _handle_streaming_tool_calls to allow the LLM to call a function, receive the output, and continue streaming the final text response to the user.

Educator Processor Update: enabled streaming in EducatorAssistantProcessor for general chat, while explicitly forcing non-streaming mode for generate_quiz_questions (since it requires full response JSON validation and retry logic).

Unit Tests: Added comprehensive tests to verify that streaming works correctly with single and multiple tool calls.

Why?
Previously, LitellmProcessor explicitly disabled streaming if any tools were configured. This resulted in a poor User Experience (UX) where users had to wait for the entire generation to finish before seeing any text, simply because a tool might have been used. This change allows for a "best of both worlds" scenario: immediate feedback via streaming for text responses, and correct execution of background functions when the model decides to use them.

- Removed the restriction in LitellmProcessor that disabled streaming when tools are present
- Implemented `_handle_streaming_tool_calls` in LLMProcessor to aggregate chunks, reconstruct tool calls, and handle recursion
- Updated `_completion_with_tools` to delegate to the streaming handler when `stream=True`
- Added unit tests covering streaming tool calls and recursive execution
@openedx-webhooks
Copy link

Thanks for the pull request, @Pavilion4ik!

This repository is currently maintained by @felipemontoya.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Jan 23, 2026
@github-project-automation github-project-automation bot moved this to Needs Triage in Contributions Jan 23, 2026
@codecov
Copy link

codecov bot commented Jan 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.86%. Comparing base (2541c58) to head (6c44596).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #102      +/-   ##
==========================================
+ Coverage   90.74%   90.86%   +0.11%     
==========================================
  Files          48       48              
  Lines        4389     4487      +98     
  Branches      271      284      +13     
==========================================
+ Hits         3983     4077      +94     
- Misses        317      319       +2     
- Partials       89       91       +2     
Flag Coverage Δ
unittests 90.86% <ø> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Jan 27, 2026
@felipemontoya felipemontoya self-assigned this Jan 27, 2026
@felipemontoya
Copy link
Member

Hi @Pavilion4ik I did not notice this was open. I assigned myself to take a look soon.

@Henrrypg
Copy link
Contributor

Hi @Pavilion4ik i haven't checked static code but i tried to run it with an error:

image

My profile's config:

image
/*
Test experience using chat. Ask ChatGPT to answer in a way that forces to use functions
to retrieve context from the current unit and the course outline
*/
{
  "orchestrator_class": "ThreadedLLMResponse",
  "processor_config": {
    "OpenEdXProcessor": {
    },
    "LLMProcessor": {
      "provider": "openai",
      "enabled_tools": [
        "get_context",
        "get_location_content",
        "roll_dice",
        "get_location_link"
      ],
      "stream": true
    }
  }
}

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

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Status: Ready for Review

Development

Successfully merging this pull request may close these issues.

4 participants