8000 Lorenze/console printer nice by lorenzejay · Pull Request #3004 · crewAIInc/crewAI · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Lorenze/console printer nice #3004

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

lorenzejay
Copy link
Collaborator
@lorenzejay lorenzejay commented Jun 12, 2025

before
Screenshot 2025-06-12 at 9 51 56 AM

after
Screenshot 2025-06-12 at 10 06 57 AM

pythonbyte and others added 4 commits June 11, 2025 13:58
- Introduced AgentLogsStartedEvent and AgentLogsExecutionEvent to enhance logging capabilities during agent execution.
- Updated CrewAgentExecutor to emit these events at the start and during execution, respectively.
- Modified EventListener to handle the new logging events and format output accordingly in the console.
- Enhanced ConsoleFormatter to display agent logs in a structured format, improving visibility of agent actions and outputs.
@joaomdmoura
Copy link
8000 Collaborator

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

Code Review Comment for PR #3004

Overview

This PR introduces essential enhancements for the crewAI application, focusing on improved event handling and structured logging for agent execution. These improvements enhance functionalities around LLM calls and event tracking.

Event Listener Changes (event_listener.py)

Improvements Made:

  • Effective handling of the "thinking" state for LLM calls.
  • Addition of new event handlers to bolster agent logging and tracking.

Potential Issues:

  • Memory Management: There’s a potential for memory leaks if the management of thinking branches isn't adequately executed. Adjustments suggest adding cleanup mechanisms to ensure proper resource management.

Suggestions:

Consider implementing a cleanup method:

def cleanup_thinking_branches(self):
    """Cleanup method to ensure all thinking branches are properly removed"""
    if self.formatter.current_tool_branch is not None:
        if "Thinking" in str(self.formatter.current_tool_branch.label):
            self.formatter.current_tool_branch = None

This method will help prevent over-accumulation of unused references.

Console Formatter Changes (console_formatter.py)

Improvements Made:

  • Refined output management for LLM calls.
  • Enhanced accuracy in visual representation for agent logs.

Issues:

  • Code Duplication: The logic for branch handling is repeated across methods, making it harder to maintain.
  • Complex Conditionals: The nested if statements can complicate the logic flow.

Suggestions:

Refactor repeated branch handling logic to a utility method:

def find_thinking_branch(self, parents: List[Tree]) -> Optional[Tree]:
    """Utility method to find thinking branch in tree hierarchy"""
    for parent in parents:
        if isinstance(parent, Tree):
            for child in parent.children:
                if "Thinking" in str(child.label):
                    return child
    return None

# Streamline thinking state management
def handle_thinking_state(self, branch: Tree, action: Literal["start", "complete", "fail"]) -> None:
    # Logic here...

Recommendations for Type Hints:

Completing type hints throughout your codebase ensures better readability and aids in preventing runtime errors.

Crew Agent Executor Changes (crew_agent_executor.py)

Improvements Made:

  • Transitioned to event-based logging instead of direct logging, fostering a better separation of logging functionality.

Issues:

  • Error Handling Gaps: Some error scenarios may not be adequately logged, which could lead to a lack of insight into failures.

Suggestions:

Add validation for required parameters upon event emission:

def _emit_agent_logs(self, event_type: Type[BaseEvent], **kwargs: Any) -> None:
    required_fields = {...}
    if not all(kwargs.get(field) for field in required_fields[event_type]):
        raise ValueError(f"Missing required fields for {event_type.__name__}")
    # Emit event

General Recommendations:

  • Testing Requirements:

    • Implement unit tests specific to the new event handlers.
    • Include integration tests that cover the management of thinking states.
    • Ensure edge cases around branch cleanup are tested thoroughly.
  • Documentation:

    • Add detailed docstrings for all new methods, alongside usage examples.
    • Clearly document new event types and their handling logic to facilitate future maintenance.
  • Performance Monitoring:

    • Pay attention to memory usage, particularly with large tree structures that are affected by branch management.
    • Integrate performance metrics that track event handling efficiency.

These changes will significantly enrich the codebase, ensuring robust performance while addressing prior deficiencies. Continued monitoring and testing will ensure stability as these features are deployed into production.

…Formatter

- Refactored imports in lite_agent.py for better readability.
- Enhanced guardrail property initialization in LiteAgent.
- Updated logging functionality to emit AgentLogsExecutionEvent for better tracking.
- Modified ConsoleFormatter to include tool arguments and final output in status updates.
- Improved output formatting for long text in ConsoleFormatter.
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