8000 docs: Document Knowledge Events by tonykipkemboi · Pull Request #2872 · crewAIInc/crewAI · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

docs: Document Knowledge Events #2872

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 3 commits into from
May 21, 2025

Conversation

tonykipkemboi
Copy link
Contributor

This PR addresses the issue of undocumented knowledge events by:

  1. Adding a "Knowledge Events" section to the event-listener.mdx file that lists all knowledge-related events with descriptions
  2. Creating a comprehensive "Knowledge Events" section in knowledge.mdx that:
    - Explains what knowledge events are and their purpose
    - Lists all available knowledge events with descriptions
    - Provides a practical example of how to monitor knowledge retrieval
    - Links back to the event listener documentation
  3. Updating event_types.py to include knowledge events in the EventTypes union for code completeness and consistency.

These changes ensure that users can discover and utilize knowledge events for monitoring, debugging, and analyzing how knowledge is being retrieved and used by agents.

@tonykipkemboi tonykipkemboi requested a review from lorenzejay May 21, 2025 06:20
@joaomdmoura
Copy link
Collaborator

Disclaimer: This review was made by a crew of AI Agents.

Code Review Comment for PR #2872

Overview

This pull request introduces significant updates to the documentation and event handling through knowledge-related events in the CrewAI system. The efforts aim to enhance the clarity and usability of the Knowledge Events, which is commendable.

File-by-File Analysis

1. docs/concepts/event-listener.mdx

Improvements:

  • The addition of the Knowledge Events section is well executed, contributing positively to users' understanding.
  • The documentation structure is clear and consistent.

Suggestions:

  1. Add Practical Examples: Consider including an example for the Knowledge Event similar to those provided for other event types. This will help users implement and understand its usage.
    ### Example: Knowledge Event Usage
    @crew.on(KnowledgeRetrievalStartedEvent)
    def handle_knowledge_retrieval(event):
        print(f"Knowledge retrieval started for: {event.query}")

2. docs/concepts/knowledge.mdx

Improvements:

  • The implementation of ParamField components enhances the overall structure.
  • Comprehensive documentation regarding knowledge events strengthens the resource.

Issues:

  1. Inconsistent Heading Hierarchy: The document shows a jump from ## to ###, leading to potential confusion.
  2. Lack of Type Annotations: Certain code examples lack type hints, reducing their efficacy and clarity.

Suggestions:

  1. Restructure Headings: A consistent heading structure will improve readability:
    ## Knowledge System
    ### Understanding Knowledge
    ### Knowledge Types
  2. Add Type Hints: This will clarify parameter expectations for readers:
    from typing import List
    from crewai.types import KnowledgeChunk
    
    def on_knowledge_retrieval_completed(source: str, event: KnowledgeRetrievalCompletedEvent) -> None:
        print(f"Agent '{event.agent.role}' completed knowledge retrieval")
        print(f"Query: {event.query}")
        print(f"Retrieved {len(event.retrieved_knowledge)} knowledge chunks")

3. src/crewai/utilities/events/event_types.py

Improvements:

  • Implementation of new event types is clean and effective.
  • Updates to type unions have been properly addressed.

Suggestions:

  1. Group Related Events: Organizing events in Union definitions can enhance clarity:
    EventTypes = Union[
        # Crew Events
        CrewKickoffStartedEvent,
        CrewKickoffCompletedEvent,
        
        # Agent Events
        AgentReasoningStartedEvent,
        AgentReasoningCompletedEvent,
        AgentReasoningFailedEvent,
        
        # Knowledge Events
        KnowledgeRetrievalStartedEvent,
        KnowledgeRetrievalCompletedEvent,
        KnowledgeQueryStartedEvent,
        KnowledgeQueryCompletedEvent,
        KnowledgeQueryFailedEvent,
        KnowledgeSearchQueryFailedEvent,
    ]
  2. Add Docstrings: This will provide context and descriptions for the new knowledge events:
    """
    Knowledge-related event types for CrewAI.
    
    Contains event classes for tracking knowledge retrieval and query operations:
    - KnowledgeRetrievalStartedEvent: Emitted when knowledge retrieval begins
    - KnowledgeRetrievalCompletedEvent: Emitted when retrieval completes
    ...
    """

General Recommendations

  1. Documentation Consistency

    • Ensure a consistent heading hierarchy across all documentation files.
    • Enrich documentation with more practical examples relevant to new features.
  2. Code Quality

    • Implement type hints in all code examples to enhance clarity.
    • Consider validation mechanisms for knowledge event parameters to ensure robustness.
  3. Testing

    • Introduce unit tests specific to the new knowledge events.
    • Include integration tests for the event system in conjunction with knowledge operations.

Security Considerations

  • Implement robust error handling for scenarios where knowledge queries fail.
  • Consider establishing rate-limiting mechanisms for knowledge retrieval operations to enhance system stability.

Performance Impact

  • Monitor memory usage when conducting knowledge retrieval operations.
  • Investigate caching mechanisms for frequently accessed knowledge to improve efficiency.

The changes presented in this PR are well-structured and represent valuable enhancements to the CrewAI system. By implementing the provided suggestions, we can further improve code quality and overall user experience. Thank you for your diligent work on this!

@tonykipkemboi tonykipkemboi merged commit b3484c1 into crewAIInc:main May 21, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0