-
Notifications
You must be signed in to change notification settings - Fork 0
fix: using langchain tool calling! #42
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
Conversation
WalkthroughThis update refactors the RAG (Retrieval-Augmented Generation) pipeline by replacing a class-based tool and multi-agent Crew setup with a streamlined LangChain function-based tool and agent executor. It also modifies error handling in agent logic and updates dependencies to include newer versions of Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant AgenticHivemindFlow
participant LangChainAgent
participant RAGTool
participant QueryDataSources
User->>AgenticHivemindFlow: Initiate RAG query
AgenticHivemindFlow->>LangChainAgent: Run agent executor
LangChainAgent->>RAGTool: Call get_rag_answer(query)
RAGTool->>QueryDataSources: query_data_sources(query)
QueryDataSources-->>RAGTool: Return answer or "NONE"
RAGTool-->>LangChainAgent: Return answer
LangChainAgent-->>AgenticHivemindFlow: Return agent output
AgenticHivemindFlow-->>User: Return answer
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (2)
tasks/agent.py (1)
181-184: Simplify the return logic using theinoperator.The return logic can be simplified by using the
inoperator and removing the unnecessaryelseblock.- if final_answer == "NONE" or final_answer == error_fallback_answer: - return None - else: - return final_answer + if final_answer in ("NONE", error_fallback_answer): + return None + return final_answertasks/hivemind/agent.py (1)
208-219: Enhance system instructions to maintain feature parity.The current system instructions are too minimal compared to the removed Crew agent's detailed goal and backstory. Consider adding more context about the agent's capabilities and constraints.
SYSTEM_INSTRUCTIONS = """\ - You are a helpful assistant. + You are an intelligent Q&A assistant capable of giving concise answers to questions. + You decide when to rely on your internal knowledge and when to retrieve real-time data using the available tools. + For queries that are not specific to community data, answer using your own knowledge. + Your responses should be clear, well-structured, and not exceed 250 words. """
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
requirements.txt(1 hunks)tasks/agent.py(2 hunks)tasks/hivemind/agent.py(2 hunks)tasks/hivemind/query_data_sources.py(3 hunks)
🧰 Additional context used
🧠 Learnings (3)
tasks/agent.py (1)
Learnt from: amindadgar
PR: TogetherCrew/agents-workflow#18
File: tasks/hivemind/agent.py:107-119
Timestamp: 2025-03-26T07:55:18.832Z
Learning: The team has decided to defer error handling for `AnswerValidator` calls in the `check_answer_validity` method, as they consider this error case unlikely to occur in practice. They plan to address it later if needed.
tasks/hivemind/agent.py (2)
Learnt from: amindadgar
PR: TogetherCrew/agents-workflow#2
File: tasks/hivemind/query_data_sources.py:27-31
Timestamp: 2025-02-26T15:41:54.631Z
Learning: In the agents-workflow project, "HivemindWorkflow" and "AgenticHivemindTemporalWorkflow" are two distinct workflows. The QueryDataSources class in tasks/hivemind/query_data_sources.py is designed to interact with "HivemindWorkflow", which is separate from "AgenticHivemindTemporalWorkflow" defined in tasks/agent.py.
Learnt from: amindadgar
PR: TogetherCrew/agents-workflow#12
File: tasks/hivemind/query_data_sources.py:68-73
Timestamp: 2025-03-15T13:24:31.131Z
Learning: The RAGPipelineTool class in tasks/hivemind/query_data_sources.py has a design with class-level attributes (community_id and enable_answer_skipping) set in the setup_tools classmethod, which could cause concurrency issues if multiple instances run in parallel with different parameters. This has been acknowledged as a future improvement point to be addressed later.
tasks/hivemind/query_data_sources.py (4)
Learnt from: amindadgar
PR: TogetherCrew/agents-workflow#12
File: tasks/hivemind/query_data_sources.py:68-73
Timestamp: 2025-03-15T13:24:31.131Z
Learning: The RAGPipelineTool class in tasks/hivemind/query_data_sources.py has a design with class-level attributes (community_id and enable_answer_skipping) set in the setup_tools classmethod, which could cause concurrency issues if multiple instances run in parallel with different parameters. This has been acknowledged as a future improvement point to be addressed later.
Learnt from: amindadgar
PR: TogetherCrew/agents-workflow#6
File: tasks/hivemind/query_data_sources.py:73-79
Timestamp: 2025-03-04T09:11:26.359Z
Learning: In the TogetherCrew/agents-workflow project, the `QueryDataSourcesTool` class uses a class method `setup_tools` that returns the class itself rather than an instance, as it's designed to be instantiated later in the code after configuration is set. This pattern is common in LangChain and similar frameworks.
Learnt from: amindadgar
PR: TogetherCrew/agents-workflow#6
File: tasks/hivemind/query_data_sources.py:73-79
Timestamp: 2025-03-04T09:11:26.359Z
Learning: In the TogetherCrew/agents-workflow project, the `QueryDataSourcesTool` class uses a class method `setup_tools` that returns the class itself rather than an instance, as it's designed to be instantiated later in the code after configuration is set.
Learnt from: amindadgar
PR: TogetherCrew/agents-workflow#2
File: tasks/hivemind/query_data_sources.py:27-31
Timestamp: 2025-02-26T15:41:54.631Z
Learning: In the agents-workflow project, "HivemindWorkflow" and "AgenticHivemindTemporalWorkflow" are two distinct workflows. The QueryDataSources class in tasks/hivemind/query_data_sources.py is designed to interact with "HivemindWorkflow", which is separate from "AgenticHivemindTemporalWorkflow" defined in tasks/agent.py.
🧬 Code Graph Analysis (2)
tasks/agent.py (1)
tasks/mongo_persistence.py (1)
update_workflow_step(91-138)
tasks/hivemind/agent.py (2)
tasks/hivemind/query_data_sources.py (1)
make_rag_tool(65-103)tasks/mongo_persistence.py (1)
MongoPersistence(10-200)
🪛 Pylint (3.3.7)
tasks/agent.py
[refactor] 181-184: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it
(R1705)
[refactor] 181-181: Consider merging these comparisons with 'in' by using 'final_answer in ('NONE', error_fallback_answer)'. Use a set instead if elements are hashable.
(R1714)
🪛 Ruff (0.11.9)
tasks/hivemind/agent.py
208-210: f-string without any placeholders
Remove extraneous f prefix
(F541)
🪛 Flake8 (7.2.0)
tasks/hivemind/agent.py
[error] 208-208: f-string is missing placeholders
(F541)
tasks/hivemind/query_data_sources.py
[error] 12-12: module level import not at top of file
(E402)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: ci / lint / Lint
- GitHub Check: ci / test / Test
🔇 Additional comments (3)
requirements.txt (1)
8-11: Dependencies Verified: No Known Security Issues
- Checked PyPI summaries for openai 1.93.0, langchain 0.3.26, and langchain-openai 0.3.27 – all official packages.
- Queried GitHub Security Advisories for openai; no vulnerabilities found in the specified range.
These upgrades align with the LangChain refactoring and carry no known security risks. Proceed with merging, ensuring your integration tests pass against these versions.
tasks/agent.py (1)
137-151: Good improvement to centralize the error fallback message.Extracting the error message to a variable improves maintainability and consistency.
tasks/hivemind/query_data_sources.py (1)
65-103: Excellent refactoring that resolves the concurrency issue!This function-based approach using closures effectively addresses the concurrency concerns with the previous class-level attributes design. Each tool instance now has its own captured parameters, eliminating potential race conditions when multiple instances run in parallel.
…n query_data_sources.py
langchain tool calling is more stable.
Summary by CodeRabbit
New Features
langchainandlangchain-openai.Refactor
Bug Fixes
Chores
openaipackage to the latest version.