-
Notifications
You must be signed in to change notification settings - Fork 92
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
Route directly to custom agents #227
Conversation
Caution Review failedThe pull request is closed. WalkthroughThe changes modify the Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
app/modules/conversations/conversation/conversation_service.py (1)
Line range hint
166-176
: Enhance error handling and configuration.Consider the following improvements:
- Make the confidence threshold configurable.
- Provide more informative error messages.
- Add logging for debugging purposes.
+ CONFIDENCE_THRESHOLD = 0.5 # Move to configuration try: agent_id, confidence = response.split("|") confidence = float(confidence) except (ValueError, TypeError): + logger.error(f"Failed to parse classification response: {response}") return Command( - update={"response": "Error in classification format"}, goto=END + update={"response": f"Error in classification format. Expected 'agent_id|confidence', got: {response}"}, goto=END ) - if confidence < 0.5 or agent_id not in self.agents: + if confidence < CONFIDENCE_THRESHOLD or agent_id not in self.agents: + logger.debug(f"Classification rejected: confidence={confidence}, agent_id={agent_id}")🧰 Tools
🪛 GitHub Actions: Pre-commit
[warning] Code formatting issues fixed by Black formatter
🧹 Nitpick comments (1)
app/modules/conversations/conversation/conversation_service.py (1)
81-87
: Add type hints for better code maintainability.Consider adding type hints to the
available_agents
attribute for better code maintainability and IDE support.- self.available_agents = [] + self.available_agents: List[Any] = [] # Replace Any with your agent type🧰 Tools
🪛 GitHub Actions: Pre-commit
[warning] Code formatting issues fixed by Black formatter
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
app/modules/conversations/conversation/conversation_service.py
(2 hunks)
🧰 Additional context used
🪛 GitHub Actions: Pre-commit
app/modules/conversations/conversation/conversation_service.py
[warning] Code formatting issues fixed by Black formatter
🔇 Additional comments (1)
app/modules/conversations/conversation/conversation_service.py (1)
Line range hint
154-176
: Add unit tests for the new routing logic.The new routing logic in the
classifier_node
method should be covered by unit tests to ensure it handles various scenarios correctly:
- Direct routing to custom agents
- System agent routing
- Invalid agent_id handling
- Classification response parsing
Would you like me to help create unit tests for these scenarios?
🧰 Tools
🪛 GitHub Actions: Pre-commit
[warning] Code formatting issues fixed by Black formatter
agent_list = {agent.id:agent.status for agent in self.available_agents} | ||
|
||
#Do not route for custom agents | ||
if state["agent_id"] in agent_list and agent_list[state["agent_id"]] != "SYSTEM": | ||
return Command(update={"agent_id": state["agent_id"]}, goto=state["agent_id"]) | ||
|
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.
Validate agent_id before using it.
The code should validate that agent_id
exists in agent_list
before accessing it to prevent potential KeyError. Also, consider improving the comment style.
- #Do not route for custom agents
- if state["agent_id"] in agent_list and agent_list[state["agent_id"]] != "SYSTEM":
+ # Do not route for custom agents
+ agent_id = state.get("agent_id")
+ if agent_id and agent_id in agent_list and agent_list[agent_id] != "SYSTEM":
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
agent_list = {agent.id:agent.status for agent in self.available_agents} | |
#Do not route for custom agents | |
if state["agent_id"] in agent_list and agent_list[state["agent_id"]] != "SYSTEM": | |
return Command(update={"agent_id": state["agent_id"]}, goto=state["agent_id"]) | |
agent_list = {agent.id:agent.status for agent in self.available_agents} | |
# Do not route for custom agents | |
agent_id = state.get("agent_id") | |
if agent_id and agent_id in agent_list and agent_list[agent_id] != "SYSTEM": | |
return Command(update={"agent_id": state["agent_id"]}, goto=state["agent_id"]) | |
🧰 Tools
🪛 GitHub Actions: Pre-commit
[warning] Code formatting issues fixed by Black formatter
…into custom_agent_routing
Quality Gate passedIssues Measures |
Summary by CodeRabbit
New Features
Bug Fixes