fix: add stream parameter to disable streaming for custom LLMs#701
fix: add stream parameter to disable streaming for custom LLMs#701MervinPraison merged 1 commit intomainfrom
Conversation
- Add stream parameter to Agent class with default True - Add stream parameter to LLM get_response and get_response_async methods - Replace hardcoded stream=True values with configurable stream parameter - Maintains backward compatibility while allowing stream disabling Fixes #615 Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
|
Caution Review failedThe pull request is closed. WalkthroughA new Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Agent
participant LLM
User->>Agent: Instantiate Agent(stream=False)
User->>Agent: Call chat(prompt)
Agent->>LLM: get_response(..., stream=False)
LLM-->>Agent: Response (non-streamed)
Agent-->>User: Final response
Assessment against linked issues
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Summary of Changes
Hello @MervinPraison, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request enhances the praisonai-agents framework by introducing a configurable stream parameter. This allows users to control whether responses from Large Language Models are streamed or returned as a complete block, which is particularly beneficial for compatibility with diverse LLM providers and for scenarios where streaming is not desired. The changes are implemented to ensure seamless backward compatibility.
Highlights
- Configurable Streaming: Introduced a new
streamboolean parameter to theAgentclass constructor and theLLM'sget_responseandget_response_asyncmethods. This parameter allows users to explicitly enable or disable streaming responses from the underlying Large Language Models. - Backward Compatibility: The newly added
streamparameter defaults toTruein all relevant constructors and method signatures, ensuring that existing codebases continue to function without requiring changes and maintaining the default streaming behavior. - Enhanced LLM Integration Flexibility: Replaced hardcoded
stream=Truevalues with the configurablestreamparameter across various internal calls within theAgent's_chat_completionandchatmethods, and theLLM'sget_responseandget_response_asyncmethods. This provides greater flexibility, especially for integrating with custom LLM providers that may not support streaming.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request introduces a configurable stream parameter to the Agent and LLM classes, which is a great addition for handling LLMs that do not support streaming. The implementation is mostly solid, particularly in llm.py.
My main feedback points are in agent.py. There's a high-severity backward compatibility issue in the Agent.chat method where the method-level stream parameter is now ignored, which could cause unexpected behavior for existing users. Additionally, there's an opportunity to refactor a redundant if/else block in _chat_completion to improve code maintainability. Addressing these issues will make this a very strong contribution.
| ) | ||
|
|
||
| response = self._chat_completion(messages, temperature=temperature, tools=tools if tools else None, reasoning_steps=reasoning_steps, stream=stream) | ||
| response = self._chat_completion(messages, temperature=temperature, tools=tools if tools else None, reasoning_steps=reasoning_steps, stream=self.stream) |
There was a problem hiding this comment.
By changing this to stream=self.stream, the stream parameter in the chat method's signature (line 1127) is now ignored. This breaks backward compatibility for any user who was calling agent.chat(..., stream=False), as their setting would be overridden by the agent's self.stream attribute.
To fix this and maintain the ability to override the stream setting per-call, you should use the stream parameter from the method. If the intent is for self.stream to be a default, the chat method's signature and logic should be updated to reflect that (e.g., by setting the default to None and then choosing self.stream if it's None).
| logging.debug(f"{self.name} reflection count {reflection_count + 1}, continuing reflection process") | ||
| messages.append({"role": "user", "content": "Now regenerate your response using the reflection you made"}) | ||
| response = self._chat_completion(messages, temperature=temperature, tools=None, stream=stream) | ||
| response = self._chat_completion(messages, temperature=temperature, tools=None, stream=self.stream) |
There was a problem hiding this comment.
Bug: Agent Chat Stream Parameter Ignored
The Agent.chat method's stream parameter is ignored when using the standard OpenAI client path, as the internal _chat_completion call incorrectly uses self.stream instead of the method's stream argument. This prevents overriding streaming behavior on a per-call basis. This also creates inconsistent behavior, as custom LLM instances correctly respect the stream parameter.
src/praisonai-agents/praisonaiagents/agent/agent.py#L1282-L1378
PraisonAI/src/praisonai-agents/praisonaiagents/agent/agent.py
Lines 1282 to 1378 in 5743127
BugBot free trial expires on July 22, 2025
You have used $0.00 of your $50.00 spend limit so far. Manage your spend limit in the Cursor dashboard.
Was this report helpful? Give feedback by reacting with 👍 or 👎
Summary
Test plan
Fixes #615
🤖 Generated with Claude Code
Summary by CodeRabbit