Skip to content

[#119] Add agent overlap analysis script for Python#327

Closed
pierrehanne wants to merge 1 commit into
2FastLabs:mainfrom
pierrehanne:feat/agent-overlap-analyzer-python
Closed

[#119] Add agent overlap analysis script for Python#327
pierrehanne wants to merge 1 commit into
2FastLabs:mainfrom
pierrehanne:feat/agent-overlap-analyzer-python

Conversation

@pierrehanne

Copy link
Copy Markdown

Implement AgentOverlapAnalyzer in Python [Issue #119] @cornelcroi

Adding Unit tests to verify:

  • Correct behavior when no agents are provided.
  • Correct behavior when only one agent is provided.
  • Correct handling of identical descriptions across agents.
  • Correct calculation of overlap percentages and uniqueness scores.

@pierrehanne pierrehanne changed the title [Feat][#119] Add agent overlap analysis script for Python [#119] Add agent overlap analysis script for Python May 8, 2025

@brnaba-aws brnaba-aws left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also add in the documentation the python version. Thanks

import pytest
from agent_squad.agent_overlap_analyzer import AgentOverlapAnalyzer, OverlapResult, UniquenessScore
from agent_squad.utils.logger import Logger

@brnaba-aws brnaba-aws May 28, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from unittest.mock import patch

analyzer = AgentOverlapAnalyzer(single_agent)
with pytest.raises(ValueError, match="Agent Overlap Analysis requires at least two agents."):
analyzer.analyze_overlap()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add another test to have 100% coverage and also checking on the log:

def test_analyze_overlap_logging_with_mock(sample_agents):
    """Test that analyze_overlap calls Logger.info with expected messages"""
    with patch.object(Logger, 'info') as mock_logger:
        analyzer = AgentOverlapAnalyzer(sample_agents)
        analyzer.analyze_overlap()

        # Verify Logger.info was called
        assert mock_logger.call_count > 0

        # Get all the logged messages
        logged_messages = [call.args[0] for call in mock_logger.call_args_list]

        # Verify specific log messages are present
        assert "Pairwise Overlap Results:" in logged_messages
        assert "_________________________\n" in logged_messages
        assert "Uniqueness Scores:" in logged_messages
        assert "_________________\n" in logged_messages

        # Verify agent pair combinations are logged
        agent_pairs_found = []
        for message in logged_messages:
            if " - " in message and "Overlap Percentage" in message:
                agent_pairs_found.append(message)

        # Should have 3 pairs: AgentA-AgentB, AgentA-AgentC, AgentB-AgentC
        assert len(agent_pairs_found) == 3

        # Verify uniqueness scores are logged for each agent
        uniqueness_messages = [msg for msg in logged_messages if "Agent:" in msg and "Uniqueness Score:" in msg]
        assert len(uniqueness_messages) == 3

@pierrehanne pierrehanne closed this by deleting the head repository Nov 16, 2025
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.

2 participants