A comprehensive Python-based search system for discovering, indexing, and searching agents with multiple backend engines.
- Register and manage agent metadata
- Search agents by name, description, or tags
- Filter by capability
- Track performance and reliability metrics
- Usage tracking and statistics
- TF-IDF vectorization for semantic understanding
- Cosine similarity matching
- Keyword extraction
- Document clustering
- Context-aware search results
- DuckDuckGo search (privacy-friendly)
- Google Custom Search (with API key)
- GitHub repository search
- Stack Overflow question search
- Web page content fetching and parsing
- Index local documents (txt, md, pdf, json, code files)
- Full-text search across documents
- Document metadata extraction
- Batch indexing with recursion support
- Index statistics and management
- Composite search across all backends
- Task-based agent recommendations
- Multi-format export (JSON, CSV)
- Search statistics and insights
pip install -r requirements.txt- Python 3.8+
- requests
- numpy
- scikit-learn
- beautifulsoup4
- lxml
from search_engine import AgentSearchSystem
# Initialize
search_system = AgentSearchSystem()
# Register an agent
agent = {
'id': 'agent_001',
'name': 'Data Analyzer',
'description': 'Analyzes data and generates insights',
'capabilities': ['data_processing', 'analysis'],
'tags': ['analytics', 'data'],
'version': '1.0.0',
'author': 'DataTeam'
}
search_system.register_and_index_agent(agent)
# Search agents
results = search_system.search_agents("data analysis")
# Get recommendations for a task
recommendations = search_system.get_agent_recommendations(
"I need to process and analyze customer data"
)
# Composite search (all sources)
results = search_system.composite_search(
query="machine learning",
include_agents=True,
include_web=True,
include_documents=True,
document_dir="./docs"
)registry = AgentRegistry("agents.db")
# Register agent
registry.register_agent(agent_data)
# Search agents
results = registry.search_agents("query")
# Find by capability
agents = registry.get_agent_by_capability("data_processing")
# Update metrics
registry.update_agent_metrics(agent_id, performance=0.95, reliability=0.99)
# Get all agents
all_agents = registry.get_all_agents()semantic = SemanticSearchEngine()
# Index documents
semantic.index_documents(documents)
# Search with relevance scores
results = semantic.search(query, top_k=5)
# Get detailed results
detailed = semantic.search_with_details(query)
# Calculate similarity
score = semantic.similarity_score(text1, text2)
# Extract keywords
keywords = semantic.get_keywords(text, top_n=10)
# Cluster documents
clusters = semantic.cluster_documents(n_clusters=3)web = WebSearchEngine()
# DuckDuckGo search
results = web.search_duckduckgo("query")
# GitHub search
repos = web.search_github("machine learning", language="python")
# Stack Overflow search
questions = web.search_stackoverflow("python error handling")
# Fetch page content
content = web.fetch_page_content("https://example.com")indexer = DocumentIndexer("documents.db")
# Index directory
count = indexer.index_directory("./docs", recursive=True)
# Index single document
indexer.index_document("file.txt", tags=["important"])
# Search documents
results = indexer.search_documents("query", file_types=['.md', '.txt'])
# Get full document
doc = indexer.get_document(doc_id)
# Get statistics
stats = indexer.get_index_stats()search = AgentSearchSystem()
# Search agents (registry, semantic, or capability)
results = search.search_agents("query", search_type="all")
# Web search
web_results = search.search_web("query", service="duckduckgo")
# Document search
doc_results = search.search_documents("query", directory="./docs")
# Get recommendations
recommendations = search.get_agent_recommendations(task_description)
# Composite search
results = search.composite_search(
query="query",
include_agents=True,
include_web=True,
include_documents=True
)
# Export results
json_export = search.export_search_results(results, format="json")
csv_export = search.export_search_results(results, format="csv")Run the example script to see all features in action:
python example_usage.pyThis demonstrates:
- Agent registration
- Registry-based search
- Semantic search
- Capability search
- Task-based recommendations
- Composite search
- System statistics
- Keyword extraction
- Web search
- Result export
id: Unique agent identifiername: Agent namedescription: Agent descriptioncapabilities: JSON array of capabilitiestags: JSON array of tagsversion: Agent versionauthor: Creator/maintainercreated_at: Registration timestampupdated_at: Last update timestamp
id: Unique document identifierpath: File pathtitle: Document titlecontent: Full text contentfile_type: File extensionindexed_at: Index timestampmodified_at: File modification timefile_size: File size in bytestags: JSON array of tags
- TF-IDF vectorization with configurable parameters
- Cosine similarity for fast distance calculation
- Indexed document search with SQL queries
- Batch indexing for multiple documents
- Pluggable search backends
- Customizable document parsing
- Configurable semantic parameters
- Support for multiple file formats
- Keyword extraction from documents
- Document clustering for categorization
- Relevance scoring with threshold
- Capability-based agent discovery
Create a config.json file for custom settings:
{
"semantic_search": {
"max_features": 500,
"min_df": 1,
"max_df": 0.95,
"ngram_range": [1, 2]
},
"web_search": {
"timeout": 10,
"max_retries": 3
},
"indexing": {
"batch_size": 100,
"supported_formats": [".txt", ".md", ".pdf", ".json"]
}
}- Semantic Search: O(n) with pre-indexed documents
- Registry Search: O(n) full-text search via SQL
- Web Search: API-dependent (typically 0.5-2 seconds)
- Document Indexing: O(n) where n = number of documents
- Capability Matching: O(n) with fuzzy matching
- Web search uses privacy-respecting backends (DuckDuckGo)
- Document indexing respects file permissions
- Database queries use parameterized statements (SQL injection safe)
- No API keys stored in code (use environment variables)
- ML-based relevance ranking
- Distributed agent network discovery
- Real-time agent health monitoring
- Advanced NLP with transformers
- Caching layer for frequently searched items
- API endpoints (Flask/FastAPI)
- Web UI dashboard
- Rate limiting and throttling
MIT License
For issues or feature requests, please create an issue in the repository.