-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Fix performance issue: cache agent knowledge to avoid reloading on every kickoff #3077
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
- Add caching mechanism in Agent.set_knowledge to track loaded state - Skip knowledge reloading when sources and embedder haven't changed - Add reset_knowledge_cache method for explicit cache clearing - Add comprehensive tests for caching behavior and edge cases - Fixes issue #3076 performance overhead on repeated kickoffs Co-Authored-By: João <joao@crewai.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Disclaimer: This review was made by a crew of AI Agents. Code Review Comments on Knowledge Caching ImplementationOverviewThis pull request effectively implements a caching strategy for knowledge in the File:
|
- Add proper PrivateAttr declarations for cache attributes to fix mypy errors - Simplify tests to focus on set_knowledge method directly instead of full kickoff - Remove network calls and invalid method mocking from tests - All knowledge caching functionality verified working locally Co-Authored-By: João <joao@crewai.com>
- Remove hasattr/getattr calls that caused mypy type-checker errors - Fix test mocking to use 'crewai.agent.Knowledge' for proper isolation - Prevent network calls in tests by mocking Knowledge class constructor - All knowledge-related tests now pass locally without API dependencies Co-Authored-By: João <joao@crewai.com>
- Update VCR cassettes for knowledge-related tests - Ensures CI has consistent test recordings Co-Authored-By: João <joao@crewai.com>
Fix: Cache agent knowledge to prevent unnecessary reloading on repeated kickoffs
Summary
This PR implements a caching mechanism in the
Agent.set_knowledge()
method to resolve a significant performance issue where agent knowledge was being reloaded on every crew kickoff operation. The issue was occurring increw.py
line 645 where knowledge sources were being processed (chunked, embedded, stored) unnecessarily on each kickoff, causing substantial performance overhead.Key Changes:
_knowledge_loaded
,_last_embedder
,_last_knowledge_sources
set_knowledge()
to skip reloading when knowledge hasn't changedreset_knowledge_cache()
method for explicit cache clearing when neededThe caching mechanism intelligently detects when knowledge needs to be reloaded (when sources or embedder changes) while preventing redundant processing when the same agent is used across multiple kickoffs.
Review & Testing Checklist for Human
reset_knowledge_cache()
methodRecommended Test Plan:
Diagram
Notes