Skip to content

feat(python): add AgentOverlapAnalyzer — Python port of TypeScript analyzer#541

Open
nuthalapativarun wants to merge 1 commit into
2FastLabs:mainfrom
nuthalapativarun:feat/119-python-agent-overlap-analyzer
Open

feat(python): add AgentOverlapAnalyzer — Python port of TypeScript analyzer#541
nuthalapativarun wants to merge 1 commit into
2FastLabs:mainfrom
nuthalapativarun:feat/119-python-agent-overlap-analyzer

Conversation

@nuthalapativarun

Copy link
Copy Markdown

Issue Link (REQUIRED)

Fixes #119

Summary

Changes

Adds python/src/agent_squad/agent_overlap_analyzer.py — a pure-stdlib Python implementation of the existing TypeScript AgentOverlapAnalyzer.

Algorithm (matches the TypeScript reference):

  1. Tokenise and remove English stopwords from each agent description
  2. Build TF-IDF vectors (implemented without external dependencies)
  3. Compute pairwise cosine similarity
  4. Label pairs: High (>0.3), Medium (>0.1), Low (≤0.1)
  5. Derive a uniqueness score per agent (1 − mean similarity to others)

Public API mirrors the TypeScript class:

from agent_squad.agent_overlap_analyzer import AgentOverlapAnalyzer

analyzer = AgentOverlapAnalyzer({
    "flight_agent": {"name": "Flight Agent", "description": "..."},
    "hotel_agent":  {"name": "Hotel Agent",  "description": "..."},
})
result = analyzer.analyze_overlap()
# result.pairwise_overlap["flight_agent__hotel_agent"].potential_conflict
# → "Low" | "Medium" | "High"

Also adds python/src/tests/test_agent_overlap_analyzer.py (12 tests) covering: return type, pair count, key format, percentage bounds, conflict levels, uniqueness score count and bounds, high/low overlap cases, single-agent and empty-agent edge cases.

No new external dependencies — pure stdlib (math, re).

User experience

Before: Python users had no equivalent of the TypeScript overlap analyzer and had to write their own or use the TS version.

After: same analysis is available in Python with identical thresholds and output format.

Checklist

  • I have performed a self-review of this change
  • Changes have been tested
  • Changes are documented
  • I have linked this PR to an existing issue (required)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…alyzer

Adds python/src/agent_squad/agent_overlap_analyzer.py as a pure-stdlib
Python implementation of the TypeScript AgentOverlapAnalyzer. Uses the
same TF-IDF / cosine-similarity approach and identical conflict
thresholds (>0.3 → High, >0.1 → Medium, else Low). Includes 12 unit
tests covering pairwise overlap, uniqueness scores, conflict levels,
edge cases (0 or 1 agent), and identical / orthogonal descriptions.

Closes 2FastLabs#119
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.

Feature request: Agent overlap analysis script for Python

1 participant