-
Notifications
You must be signed in to change notification settings - Fork 6.1k
refactor: Optimize agent component for efficiency and readability #5593
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
base: main
Are you sure you want to change the base?
Conversation
- Reduced redundancy by avoiding repeated `hasattr` checks and simplifying `get_agent_kwargs`. - Improved error handling with consolidated exceptions and early validation. - Enhanced readability with docstrings and consistent formatting. - Removed deprecated features and combined redundant methods.
- Reduced redundancy by avoiding repeated `hasattr` checks and simplifying `get_agent_kwargs`. - Improved error handling with consolidated exceptions and early validation. - Enhanced readability with docstrings and consistent formatting. - Removed deprecated features and combined redundant methods.
CodSpeed Performance ReportMerging #5593 will degrade performances by 31.88%Comparing Summary
Benchmarks breakdown
|
filtered_messages = [msg for msg in messages if msg.get("content", "").strip()] | ||
if not filtered_messages: | ||
error_message = "No valid messages to process in chat history." | ||
raise ValueError(error_message) | ||
input_dict["chat_history"] = filtered_messages |
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.
There's no problem in having 0 messages.
|
||
if hasattr(self, "chat_history") and self.chat_history: | ||
messages = data_to_messages(self.chat_history) | ||
filtered_messages = [msg for msg in messages if msg.get("content", "").strip()] |
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.
Error details:
AttributeError
Details: 'HumanMessage' object has no attribute 'get'
Overview
This PR refactors the
LCAgentComponent
andLCToolsAgentComponent
classes to improve code efficiency, readability, and maintainability. The changes focus on reducing redundancy, optimizing data handling, improving error handling, and simplifying logic.Changes Made
Reduced Redundancy:
hasattr
checks by storing results in variables.get_agent_kwargs
method to return a single dictionary.Optimized Data Handling:
data_to_messages(self.chat_history)
.Improved Error Handling:
run_agent
method.Simplified Logic:
agent_description
.build_agent
andcreate_agent_runnable
logic where applicable.Enhanced Readability:
Why These Changes?
Impact