Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/praisonai-agents/praisonaiagents/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ def __init__(
knowledge_config: Optional[Dict[str, Any]] = None,
use_system_prompt: Optional[bool] = True,
markdown: bool = True,
stream: bool = True,
self_reflect: bool = False,
max_reflect: int = 3,
min_reflect: int = 1,
Expand Down Expand Up @@ -435,6 +436,8 @@ def __init__(
conversations to establish agent behavior and context. Defaults to True.
markdown (bool, optional): Enable markdown formatting in agent responses for better
readability and structure. Defaults to True.
stream (bool, optional): Enable streaming responses from the language model. Set to False
for LLM providers that don't support streaming. Defaults to True.
self_reflect (bool, optional): Enable self-reflection capabilities where the agent
evaluates and improves its own responses. Defaults to False.
max_reflect (int, optional): Maximum number of self-reflection iterations to prevent
Expand Down Expand Up @@ -554,6 +557,7 @@ def __init__(
self.use_system_prompt = use_system_prompt
self.chat_history = []
self.markdown = markdown
self.stream = stream
self.max_reflect = max_reflect
self.min_reflect = min_reflect
self.reflect_prompt = reflect_prompt
Expand Down Expand Up @@ -1002,7 +1006,7 @@ def _chat_completion(self, messages, temperature=0.2, tools=None, stream=True, r
tools=formatted_tools if formatted_tools else None,
verbose=self.verbose,
markdown=self.markdown,
stream=True,
stream=stream,
console=self.console,
execute_tool_fn=self.execute_tool,
agent_name=self.name,
Expand All @@ -1018,7 +1022,7 @@ def _chat_completion(self, messages, temperature=0.2, tools=None, stream=True, r
tools=formatted_tools if formatted_tools else None,
verbose=self.verbose,
markdown=self.markdown,
stream=False,
stream=stream,
console=self.console,
execute_tool_fn=self.execute_tool,
agent_name=self.name,
Expand Down Expand Up @@ -1276,7 +1280,7 @@ def chat(self, prompt, temperature=0.2, tools=None, output_json=None, output_pyd
agent_tools=agent_tools
)

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)
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.

high

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).

if not response:
return None

Expand Down Expand Up @@ -1371,7 +1375,7 @@ def chat(self, prompt, temperature=0.2, tools=None, output_json=None, output_pyd

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)
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.

high

Similar to the previous call in this method, using self.stream here ignores the stream parameter passed to the chat method. This is inconsistent with the method's signature and breaks backward compatibility for per-call overrides.

response_text = response.choices[0].message.content.strip()
reflection_count += 1
continue # Continue the loop for more reflections
Expand Down
32 changes: 17 additions & 15 deletions src/praisonai-agents/praisonaiagents/llm/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ def get_response(
agent_role: Optional[str] = None,
agent_tools: Optional[List[str]] = None,
execute_tool_fn: Optional[Callable] = None,
stream: bool = True,
**kwargs
) -> str:
"""Enhanced get_response with all OpenAI-like features"""
Expand Down Expand Up @@ -487,7 +488,7 @@ def get_response(
messages=messages,
tools=formatted_tools,
temperature=temperature,
stream=True,
stream=stream,
**kwargs
)
):
Expand All @@ -503,7 +504,7 @@ def get_response(
messages=messages,
tools=formatted_tools,
temperature=temperature,
stream=True,
stream=stream,
**kwargs
)
):
Expand Down Expand Up @@ -655,7 +656,7 @@ def get_response(
**self._build_completion_params(
messages=follow_up_messages,
temperature=temperature,
stream=True
stream=stream
)
):
if chunk and chunk.choices and chunk.choices[0].delta.content:
Expand All @@ -668,7 +669,7 @@ def get_response(
**self._build_completion_params(
messages=follow_up_messages,
temperature=temperature,
stream=True
stream=stream
)
):
if chunk and chunk.choices and chunk.choices[0].delta.content:
Expand Down Expand Up @@ -755,7 +756,7 @@ def get_response(
messages=messages,
tools=formatted_tools,
temperature=temperature,
stream=True,
stream=stream,
**kwargs
)
):
Expand Down Expand Up @@ -873,7 +874,7 @@ def get_response(
**self._build_completion_params(
messages=reflection_messages,
temperature=temperature,
stream=True,
stream=stream,
response_format={"type": "json_object"},
**{k:v for k,v in kwargs.items() if k != 'reasoning_steps'}
)
Expand All @@ -888,7 +889,7 @@ def get_response(
**self._build_completion_params(
messages=reflection_messages,
temperature=temperature,
stream=True,
stream=stream,
response_format={"type": "json_object"},
**{k:v for k,v in kwargs.items() if k != 'reasoning_steps'}
)
Expand Down Expand Up @@ -1004,6 +1005,7 @@ async def get_response_async(
agent_role: Optional[str] = None,
agent_tools: Optional[List[str]] = None,
execute_tool_fn: Optional[Callable] = None,
stream: bool = True,
**kwargs
) -> str:
"""Async version of get_response with identical functionality."""
Expand Down Expand Up @@ -1204,7 +1206,7 @@ async def get_response_async(
**self._build_completion_params(
messages=messages,
temperature=temperature,
stream=True,
stream=stream,
**kwargs
)
):
Expand All @@ -1218,7 +1220,7 @@ async def get_response_async(
**self._build_completion_params(
messages=messages,
temperature=temperature,
stream=True,
stream=stream,
**kwargs
)
):
Expand Down Expand Up @@ -1355,7 +1357,7 @@ async def get_response_async(
**self._build_completion_params(
messages=follow_up_messages,
temperature=temperature,
stream=True
stream=stream
)
):
if chunk and chunk.choices and chunk.choices[0].delta.content:
Expand All @@ -1369,7 +1371,7 @@ async def get_response_async(
**self._build_completion_params(
messages=follow_up_messages,
temperature=temperature,
stream=True
stream=stream
)
):
if chunk and chunk.choices and chunk.choices[0].delta.content:
Expand Down Expand Up @@ -1437,7 +1439,7 @@ async def get_response_async(
**self._build_completion_params(
messages=messages,
temperature=temperature,
stream=True,
stream=stream,
tools=formatted_tools,
**{k:v for k,v in kwargs.items() if k != 'reasoning_steps'}
)
Expand All @@ -1453,7 +1455,7 @@ async def get_response_async(
**self._build_completion_params(
messages=messages,
temperature=temperature,
stream=True,
stream=stream,
**{k:v for k,v in kwargs.items() if k != 'reasoning_steps'}
)
):
Expand Down Expand Up @@ -1534,7 +1536,7 @@ async def get_response_async(
**self._build_completion_params(
messages=reflection_messages,
temperature=temperature,
stream=True,
stream=stream,
response_format={"type": "json_object"},
**{k:v for k,v in kwargs.items() if k != 'reasoning_steps'}
)
Expand All @@ -1549,7 +1551,7 @@ async def get_response_async(
**self._build_completion_params(
messages=reflection_messages,
temperature=temperature,
stream=True,
stream=stream,
response_format={"type": "json_object"},
**{k:v for k,v in kwargs.items() if k != 'reasoning_steps'}
)
Expand Down
Loading