-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: address code review feedback for mixin framework #1256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1426,7 +1426,7 @@ def clean_json_output(self, output: str) -> str: | |
| cleaned = cleaned[:-3].strip() | ||
| return cleaned | ||
|
|
||
| async def achat(self, prompt: str, temperature=1.0, tools=None, output_json=None, output_pydantic=None, reasoning_steps=False, task_name=None, task_description=None, task_id=None, attachments=None): | ||
| async def achat(self, prompt: str, temperature: float = 1.0, tools: Optional[List[Any]] = None, output_json: Optional[Any] = None, output_pydantic: Optional[Any] = None, reasoning_steps: bool = False, stream: Optional[bool] = None, task_name: Optional[str] = None, task_description: Optional[str] = None, task_id: Optional[str] = None, config: Optional[Dict[str, Any]] = None, force_retrieval: bool = False, skip_retrieval: bool = False, attachments: Optional[List[str]] = None, tool_choice: Optional[str] = None): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. achat() positional args shifted The achat() signature inserts new parameters (e.g., stream) before existing ones like task_name, which breaks callers that pass arguments positionally. This violates the requirement for zero breaking API changes and consistent chat method signatures when accessed via Agent. Agent Prompt
|
||
| """Async version of chat method with self-reflection support. | ||
|
|
||
| Args: | ||
qodo-code-review[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
@@ -1440,12 +1440,22 @@ async def achat(self, prompt: str, temperature=1.0, tools=None, output_json=None | |
| _trace_emitter.agent_start(self.name, {"role": self.role, "goal": self.goal}) | ||
|
|
||
| try: | ||
| return await self._achat_impl(prompt, temperature, tools, output_json, output_pydantic, reasoning_steps, task_name, task_description, task_id, attachments, _trace_emitter) | ||
| return await self._achat_impl( | ||
| prompt=prompt, temperature=temperature, tools=tools, | ||
| output_json=output_json, output_pydantic=output_pydantic, | ||
| reasoning_steps=reasoning_steps, stream=stream, | ||
| task_name=task_name, task_description=task_description, task_id=task_id, | ||
| config=config, force_retrieval=force_retrieval, skip_retrieval=skip_retrieval, | ||
| attachments=attachments, _trace_emitter=_trace_emitter, tool_choice=tool_choice | ||
| ) | ||
| finally: | ||
| _trace_emitter.agent_end(self.name) | ||
|
|
||
| async def _achat_impl(self, prompt, temperature, tools, output_json, output_pydantic, reasoning_steps, task_name, task_description, task_id, attachments, _trace_emitter): | ||
| async def _achat_impl(self, prompt, temperature, tools, output_json, output_pydantic, reasoning_steps, stream, task_name, task_description, task_id, config, force_retrieval, skip_retrieval, attachments, _trace_emitter, tool_choice=None): | ||
| """Internal async chat implementation (extracted for trace wrapping).""" | ||
| # Use agent's stream setting if not explicitly provided | ||
| if stream is None: | ||
| stream = self.stream | ||
| # Process ephemeral attachments (DRY - builds multimodal prompt) | ||
| # IMPORTANT: Original text 'prompt' is stored in history, attachments are NOT | ||
| llm_prompt = self._build_multimodal_prompt(prompt, attachments) if attachments else prompt | ||
|
|
@@ -1506,7 +1516,7 @@ async def _achat_impl(self, prompt, temperature, tools, output_json, output_pyda | |
| if self._knowledge_sources and not self._knowledge_processed: | ||
| self._ensure_knowledge_processed() | ||
|
|
||
| if self.knowledge: | ||
| if not skip_retrieval and self.knowledge: | ||
| search_results = self.knowledge.search(prompt, agent_id=self.agent_id) | ||
| if search_results: | ||
| if isinstance(search_results, dict) and 'results' in search_results: | ||
|
|
@@ -1580,7 +1590,8 @@ async def _achat_impl(self, prompt, temperature, tools, output_json, output_pyda | |
| task_description=task_description, | ||
| task_id=task_id, | ||
| execute_tool_fn=self.execute_tool_async, | ||
| reasoning_steps=reasoning_steps | ||
| reasoning_steps=reasoning_steps, | ||
| stream=stream | ||
| ) | ||
|
|
||
| self.chat_history.append({"role": "assistant", "content": response_text}) | ||
|
|
@@ -1686,12 +1697,18 @@ async def _achat_impl(self, prompt, temperature, tools, output_json, output_pyda | |
|
|
||
| # Make the API call based on the type of request | ||
| if tools: | ||
| response = await self._openai_client.async_client.chat.completions.create( | ||
| effective_tool_choice = tool_choice or getattr(self, '_yaml_tool_choice', None) | ||
| tool_call_kwargs = dict( | ||
| model=self.llm, | ||
| messages=messages, | ||
| temperature=temperature, | ||
| tools=formatted_tools, | ||
| ) | ||
| if effective_tool_choice: | ||
| tool_call_kwargs['tool_choice'] = effective_tool_choice | ||
| response = await self._openai_client.async_client.chat.completions.create( | ||
| **tool_call_kwargs | ||
| ) | ||
| result = await self._achat_completion(response, tools) | ||
| if get_logger().getEffectiveLevel() == logging.DEBUG: | ||
| total_time = time.time() - start_time | ||
|
|
@@ -1920,7 +1937,7 @@ async def _achat_completion(self, response, tools, reasoning_steps=False): | |
| model=self.llm, | ||
| messages=messages, | ||
| temperature=1.0, | ||
| stream=True | ||
| stream=stream | ||
| ) | ||
| full_response_text = "" | ||
| reasoning_content = "" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The signature of
achathas been aligned withchat, but the implementation is currently incomplete. The new parameters (stream,config,force_retrieval,skip_retrieval,tool_choice) are not passed to the internal_achat_implcall (line 1443), nor is_achat_impl(line 1447) updated to accept or handle them. This makes these parameters non-functional in the async path. Additionally, adding the return type hint-> Optional[str]would improve consistency with the syncchatmethod.