feat: initial query engine for agents md - #756
Conversation
|
Connected to Huly®: UNOPL-893 |
|
Claude finished @JayGhiya's task —— View job Code Review for PR #756: Initial Query Engine for AgentsConducted a comprehensive review of this large PR (86 files, 9926+ additions). Review Progress
Review Findings✅ StrengthsArchitecture & Design
Configuration & Environment
Development Tooling
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||||||||||
|
we do not have tests yet so it fails as it cannot find the test directory which is fine as of now |
feat: initial query engine for agents md
PR Type
Enhancement
Description
• Implements comprehensive agent-based codebase analysis system with streaming SSE support
• Creates unified agent execution service with concurrent processing across multiple codebases
• Adds five specialized agents (directory, framework, workflow, business logic, context7) with factory pattern
• Implements multi-provider AI model configuration system with hot-reload capabilities
• Provides ripgrep-based codebase search and structural analysis tools
• Creates post-processing pipeline for enriching agent outputs with database information
• Adds comprehensive REST API endpoints for configuration management and streaming analysis
• Implements MCP (Model Context Protocol) server management for tool integration
• Establishes encrypted credentials management and feature flag system
• Provides complete Docker containerization and development workflow automation
Diagram Walkthrough
File Walkthrough
45 files
agent_execution_service.py
Unified agent execution service with streaming supportunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/agent_execution_service.py
• Implements unified agent execution service consolidating duplicated
logic for streaming and non-streaming execution
• Provides concurrent
execution of agents across multiple codebases with standardized SSE
event streaming
• Includes comprehensive error handling, timeout
management, and optional post-processing capabilities
• Features
producer-consumer pattern for event streaming with proper completion
signaling
codebase_agent_rules.py
SSE endpoint for streaming codebase agent analysisunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/api/v1/endpoints/codebase_agent_rules.py
• Implements SSE endpoint for streaming codebase agent rules with
real-time progress updates
• Orchestrates sequential execution of four
agents (directory, framework, workflow, business logic) with
aggregation
• Includes connection monitoring, timeout handling, and
baseline framework merging functionality
• Provides comprehensive
logging and debugging for SSE connection lifecycle management
search_across_codebase.py
Ripgrep-based codebase search tool implementationunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/tools/search_across_codebase.py
• Implements ripgrep-based codebase search tool with regex/literal
pattern matching support
• Provides file filtering, case sensitivity
options, and contextual preview capabilities
• Includes comprehensive
error handling, timeout management, and JSON output parsing
• Features
security validation to ensure search paths remain within codebase
boundaries
code_confluence_agents.py
Code confluence agents factory with specialized agent definitionsunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/agents/code_confluence_agents.py
• Creates factory function for instantiating code confluence agents
with provided model and settings
• Defines five specialized agents:
directory, framework explorer, context7, development workflow, and
business logic domain
• Each agent includes specific system prompts,
tool configurations, and output type specifications
• Integrates MCP
server manager for tool integration and supports model settings
configuration
model_factory.py
Pydantic AI model factory with multi-provider supportunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/model_factory.py
• Implements factory pattern for creating Pydantic AI models from
configuration
• Supports multiple providers including OpenAI,
Anthropic, Google, Groq, Mistral, Cohere, HuggingFace
• Handles both
native providers and OpenAI-compatible providers with credential
management
• Includes comprehensive provider configuration with API
key handling and custom settings
config_hot_reload.py
AI model configuration hot-reload service implementationunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/config_hot_reload.py
• Implements ORM events service for hot-reload functionality of AI
model configuration
• Provides lazy rebuilding of models when
configuration changes are detected
• Includes SQLAlchemy event
handlers for tracking configuration changes and invalidation
•
Features application agent updating mechanism for configuration
refresh
provider_catalog.py
AI model provider catalog with configuration schemasunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/provider_catalog.py
• Defines catalog of available AI model providers with configuration
schemas
• Includes provider field definitions for UI form generation
with validation rules
• Supports both native providers and
OpenAI-compatible providers with specific configurations
• Provides
utility methods for provider lookup and schema retrieval
ai_model_config_service.py
AI model configuration service with database operationsunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/ai_model_config_service.py
• Implements service for AI model configuration database operations
with single-record approach
• Provides CRUD operations for model
configuration with credential management integration
• Includes
provider validation using catalog and automatic provider kind
inference
• Features comprehensive error handling and logging for
database operations
agent_prompt_registry.py
Centralized agent prompt registry with XML formattingunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/agent_prompt_registry.py
• Implements centralized registry for agent-specific prompt templates
• Provides XML-formatted context injection using
pydantic_ai.format_as_xmlfor better model compliance• Includes
specialized prompts for framework, directory, workflow, and business
logic agents
• Features flexible context formatting for BaseModel,
list, and string inputs
agent_md_output.py
Pydantic models for codebase analysis output schemaunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/models/agent_md_output.py
• Defines comprehensive Pydantic models for codebase analysis output
•
Includes models for project structure, framework usage, development
workflow, and business logic
• Features extended enums and supporting
models with strict validation rules
• Provides complete schema for
agent markdown output with proper field descriptions
mcp_server_manager.py
MCP Server Manager Service Implementationunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/mcp/mcp_server_manager.py
• Implements MCP server lifecycle management using PydanticAI's
MCPServerStdio and MCPServerSSE
• Supports both local (stdio) and
remote (SSE) MCP server configurations
• Provides methods for loading
config, starting/stopping servers, and retrieving active servers
ai_model_config.py
AI Model Configuration API Endpointsunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/api/v1/endpoints/ai_model_config.py
• Adds REST API endpoints for AI model configuration management (GET,
PUT, DELETE)
• Includes provider catalog endpoints for listing
available AI providers
• Implements automatic agent refresh when
configuration is updated
framework_baseline_service.py
Framework Baseline Service Implementationunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/framework_baseline_service.py
• Fetches baseline framework data from Neo4j and maps to output models
• Enriches framework metadata from PostgreSQL with descriptions and
documentation URLs
• Filters frameworks to include only those with
actual usage locations
get_framework_lib_feature_overview.py
Framework Library Feature Overview Toolunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/tools/get_framework_lib_feature_overview.py
• Provides tool for retrieving comprehensive framework/library feature
overview from Neo4j
• Returns detailed feature usage information
including file locations
• Transforms raw Neo4j data into structured
FrameworkSummarymodelscredentials_service.py
Encrypted Credentials Management Serviceunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/credentials_service.py
• Manages encrypted credentials via shared credentials table
•
Provides CRUD operations with encryption/decryption using Fernet
•
Supports both standalone and session-based database operations
repository_metadata_service.py
Repository Metadata Service Implementationunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/db/repository_metadata_service.py
• Fetches repository and codebase configuration data from PostgreSQL
•
Resolves absolute paths from Neo4j using qualified repository names
•
Enriches metadata with programming language information
agent_md_aggregate.py
Agent Metadata Aggregator Builder Classunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/models/agent_md_aggregate.py
• Builder class for accumulating agent results into final
AgentMdOutput• Provides methods to update from different agent types
(directory, framework, workflow, business logic)
• Creates complete
output with defaults for missing fields
flag_service.py
Feature Flag Management Serviceunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/flag_service.py
• Service for managing feature flags using the existing commons Flag
model
• Provides CRUD operations for flags with proper error handling
• Supports flag status checking and existence validation
flags.py
Feature Flags API Endpointsunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/api/v1/endpoints/flags.py
• REST API endpoints for feature flag management (GET, PUT, DELETE)
•
Follows upsert pattern for flag creation/updates
• Provides both
individual flag and bulk flag operations
codebase_path_resolver.py
Codebase Path Resolution Serviceunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/codebase_path_resolver.py
• Resolves absolute codebase paths from Neo4j graph database
• Maps
relative paths from PostgreSQL to absolute paths from Neo4j
•
Implements flexible path matching logic for different naming
conventions
library_documentation_service.py
Library Documentation Service Implementationunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/library_documentation_service.py
• Service for retrieving library/framework documentation using
Context7 agent
• Supports both general library overviews and specific
feature documentation
• Handles developer tools with command and
configuration information
framework_explorer_post_processor.py
Framework Explorer Post-Processor Implementationunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/post_processors/framework_explorer_post_processor.py
• Post-processor for framework explorer agent output
• Merges database
frameworks with novel agent-discovered frameworks
• Filters frameworks
based on location data and database coverage
get_structural_signature.py
Structural Signature Retrieval Toolunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/tools/get_structural_signature.py
• Tool for retrieving structural signature and imports from Neo4j
knowledge graph
• Returns complete file structural information
including functions, classes, and variables
• Validates file paths and
handles parsing errors gracefully
framework_overview_repository.py
Framework Overview Neo4j Repositoryunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/db/neo4j/framework_overview_repository.py
• Neo4j repository for framework/library overview queries
•
Centralizes graph reads for tools and services reuse
• Provides
transaction functions for codebase existence checks and framework
feature queries
get_directory_tree.py
Directory Tree Generation Toolunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/tools/get_directory_tree.py
• Tool for generating text-based directory trees using the
ezautility• Supports depth limiting and custom path specification
• Provides
comprehensive error handling for missing dependencies and permissions
package_manager_metadata_service.py
Package Manager Metadata Serviceunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/package_manager_metadata_service.py
• Service for fetching package manager metadata from Neo4j graph
•
Converts Neo4j records to
ProgrammingLanguageMetadataOutputmodels•
Handles missing or incomplete metadata gracefully
get_content_file.py
File Content Reading Toolunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/tools/get_content_file.py
• Tool for reading file content with optional line range filtering
•
Supports both full file reading and specific line range extraction
•
Includes comprehensive validation and error handling for file
operations
mcp_config.py
MCP Server Configuration Modelsunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/models/mcp_config.py
• Pydantic models for MCP server configuration
• Supports both local
(stdio) and remote (SSE) server types using discriminated unions
•
Includes validation for commands, URLs, and configuration parameters
agent_logs.py
Agent Logging Utilitiesunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/utils/agent_logs.py
• Utilities for agent logging paths and node serialization
• Provides
project root detection and logs directory resolution
• Handles async
JSON serialization of agent execution nodes
db.py
PostgreSQL Database Connection Managerunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/db/postgres/db.py
• Async PostgreSQL database connection management using SQLAlchemy
•
Implements scoped sessions for concurrent agent operations
• Provides
connection initialization and disposal with proper cleanup
business_logic_repository.py
Business Logic Neo4j Repositoryunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/db/neo4j/business_logic_repository.py
• Neo4j repository for querying data model files
• Uses both direct
detection (
has_data_model=true) and feature-based detection• Follows
async session pattern for consistent database access
business_logic_domain_post_processor.py
Business Logic Domain Post-Processorunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/post_processors/business_logic_domain_post_processor.py
• Post-processor for business logic domain agent output
• Enriches
agent description with core files from database
• Creates
CoreFileobjects from data model file paths
agent_execution_request.py
Agent Execution Request Models and Protocolsunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/models/agent_execution_request.py
• Core types and protocols for unified agent execution service
•
Defines
AgentExecutionRequestdataclass and protocol interfaces•
Provides abstractions for prompt providers and tool message policies
connection_manager.py
Neo4j Connection Manager for Query Engineunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/db/neo4j/connection_manager.py
• Async Neo4j connection manager using neomodel for query operations
•
Provides managed transaction support for read operations
• Focuses on
query operations without schema creation responsibilities
post_processing_service.py
Post-Processing Orchestrator Serviceunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/post_processing_service.py
• Post-processing orchestrator service with registry pattern
•
Registers built-in processors for framework explorer and business
logic domain
• Adapts processor interfaces and manages execution
dependencies
get_lib_data.py
Library Documentation Retrieval Toolunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/tools/get_lib_data.py
• Tool for retrieving library/framework documentation using
LibraryDocumentationService• Provides simplified interface to
Context7-powered documentation lookup
• Supports both general library
overviews and specific feature descriptions
tool_message_policy.py
Tool Message Policy Implementationunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/tool_message_policy.py
• Tool message policies for consistent messaging across agents
•
Provides default messages with tool-specific and agent-specific
overrides
• Implements
ToolMessagePolicyProtocolfor standardized toolcommunication
get_data_model_files.py
Data Model Files Retrieval Toolunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/tools/get_data_model_files.py
• Tool for fetching data model file paths from Neo4j
• Returns files
marked as data models or using data model framework features
•
Provides guidance for agents on how to process the returned file paths
get_core_files.py
Core Files with Context Retrieval Toolunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/tools/get_core_files.py
• Tool for fetching core files (data models) with additional context
•
Returns enriched file information including package, features,
signature, and imports
• Supports domain filtering for focused
analysis
ai_model_config.py
AI Model Configuration Database Modelunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/db/postgres/ai_model_config.py
• SQLModel for AI model provider configuration storage
• Single record
approach with comprehensive configuration fields
• Includes provider
metadata, model settings, and timestamps
ai_model_config.py
AI Model Configuration Pydantic Modelsunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/models/ai_model_config.py
• Pydantic models for AI model configuration API
• Defines
input/output models with validation constraints
• Includes provider
kind enumeration and configuration fields
post_processor_base.py
Create base protocol and dependencies for post-processorsunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/post_processors/post_processor_base.py
• Defines
ProcessorDependenciesclass with codebase path, Neo4jconnection, and programming language
• Creates
PostProcessorProtocolgeneric protocol for agent output transformation
• Establishes base
structure for post-processing agent outputs with type safety
agent_dependencies.py
Add agent dependencies dataclass for PydanticAI agentsunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/models/agent_dependencies.py
• Defines
AgentDependenciesdataclass for PydanticAI agentdependencies
• Includes repository metadata, Neo4j connection,
context7 agent, and library documentation service
• Follows best
practices for dependency injection in agent execution
registry.py
Create registry for managing agent post-processorsunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/post_processors/registry.py
• Implements
PostProcessingRegistryclass for managing post-processorsby agent name
• Provides
registermethod to associate processors withspecific agents
• Includes
getmethod to retrieve processors forspecific agents
repository_ruleset_metadata.py
Add repository and codebase metadata modelsunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/models/repository_ruleset_metadata.py
• Defines
CodebaseMetadatamodel with name, path, and programminglanguage fields
• Creates
RepositoryRulesetMetadatamodel containingrepository name and codebase metadata list
• Uses Pydantic models with
descriptive field documentation
4 files
__init__.py
MCP services package initializationunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/mcp/init.py
• Creates package initialization file for MCP (Model Context Protocol)
services
__init__.py
Tools package initializationunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/tools/init.py
• Creates empty package initialization file for tools module
__init__.py
Initialize utils packageunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/utils/init.py
• Creates package initialization file for utility modules
__init__.py
Initialize post-processors packageunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/services/post_processors/init.py
• Creates package initialization file for post-processor services
23 files
settings.py
Application Environment Settings Configurationunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/config/settings.py
• Environment settings configuration using Pydantic Settings
•
Includes PostgreSQL, Neo4j, MCP, encryption, and logging
configurations
• Provides computed fields for connection URLs
logging_config.py
Logging Configuration Setupunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/config/logging_config.py
• Configures Loguru logging for console and file output
• Sets up log
rotation, retention, and async-safe logging for FastAPI
• Provides
structured logging format with colorization for development
.python-version
Python Version Specificationunoplat-code-confluence-query-engine/.python-version
• Sets Python version requirement to 3.13
local-dependencies-docker-compose.yml
Add Docker Compose configuration for local dependenciesunoplat-code-confluence-query-engine/local-dependencies-docker-compose.yml
• Defines complete Docker Compose setup with Elasticsearch,
PostgreSQL, Temporal, Neo4j services
• Includes
code-confluence-flow-bridge service with environment configuration
•
Sets up networking, volumes, and health checks for all services
Taskfile.yml
Add Taskfile for development workflow automationunoplat-code-confluence-query-engine/Taskfile.yml
• Defines development tasks for dependency management, testing, and
code quality
• Includes tasks for starting/stopping services, running
tests with coverage, and linting
• Provides development workflow
automation with uv package manager
Dockerfile
Add multi-stage Dockerfile for application containerizationunoplat-code-confluence-query-engine/Dockerfile
• Creates multi-stage Docker build with Bun and Python stages
•
Includes security best practices with non-root user and minimal
runtime dependencies
• Configures FastAPI application with proper
environment variables
pyproject.toml
Add Python project configuration with dependenciesunoplat-code-confluence-query-engine/pyproject.toml
• Defines Python project configuration with FastAPI, PydanticAI, and
database dependencies
• Includes development and test dependency
groups with type checking tools
• Configures pytest settings and
custom markers for integration tests
yaak.rq_zcJSFbvhRK.yaml
Add HTTP request for model configurationyak/yaak.rq_zcJSFbvhRK.yaml
• Creates HTTP request configuration for setting model configuration
•
Configures Hugging Face provider with Kimi model and API key header
ruff.toml
Add Ruff linter configurationunoplat-code-confluence-query-engine/ruff.toml
• Configures Ruff linter with Python 3.13 target and import/error
checking rules
• Sets up code formatting standards with 88 character
line length
• Defines per-file ignores for
init.pyfiles.dockerignore
Add Docker ignore configurationunoplat-code-confluence-query-engine/.dockerignore
• Excludes development artifacts, tests, and temporary files from
Docker builds
• Preserves essential configuration files for container
builds
mypy.ini
Add MyPy type checker configurationunoplat-code-confluence-query-engine/mypy.ini
• Configures MyPy type checker with strict typing rules and error
reporting
• Relaxes strictness for test modules while maintaining type
safety
yaak.rq_TmmhvnQtTM.yaml
Add HTTP request for providers endpointyak/yaak.rq_TmmhvnQtTM.yaml
• Creates HTTP GET request configuration for retrieving providers
yaak.rq_v59Nw6A6i7.yaml
Update repository refresh request URLyak/yaak.rq_v59Nw6A6i7.yaml
• Updates URL from localhost to 127.0.0.1 for refresh-repository
endpoint
yaak.rq_Jp2qmok4Xs.yaml
Update repository deletion request URLyak/yaak.rq_Jp2qmok4Xs.yaml
• Updates URL from localhost to 127.0.0.1 for delete-repository
endpoint
yaak.rq_DwTkeJP8FJ.yaml
Update token ingestion request URLyak/yaak.rq_DwTkeJP8FJ.yaml
• Updates URL from localhost to 127.0.0.1 for ingest-token endpoint
yaak.rq_EECnrR2aEe.yaml
Update ingested repositories request URLyak/yaak.rq_EECnrR2aEe.yaml
• Updates URL from localhost to 127.0.0.1 for ingested repositories
endpoint
yaak.rq_ET5prEchnU.yaml
Add HTTP request for configuration endpointyak/yaak.rq_ET5prEchnU.yaml
• Creates HTTP GET request configuration for retrieving configuration
yaak.rq_bytnZBU5hq.yaml
Add HTTP request for OpenAI provider schemayak/yaak.rq_bytnZBU5hq.yaml
• Creates HTTP GET request configuration for OpenAI provider UI schema
yaak.rq_yMsbRmdhHJ.yaml
Update ingestion start request URLyak/yaak.rq_yMsbRmdhHJ.yaml
• Updates URL from localhost to 127.0.0.1 for start-ingestion endpoint
yaak.fl_Pgb37JQfSX.yaml
Update folder sort priorityyak/yaak.fl_Pgb37JQfSX.yaml
• Updates sort priority for code-confluence-query-engine folder
yaak.fl_a9CJGFoCVq.yaml
Update folder sort priorityyak/yaak.fl_a9CJGFoCVq.yaml
• Updates sort priority for code-confluence-flow-bridge folder
yaak.fl_jtBaK7a5pU.yaml
Add agent configuration folderyak/yaak.fl_jtBaK7a5pU.yaml
• Creates new folder configuration for agent_configuration
mcp-servers.json
Add MCP servers configurationunoplat-code-confluence-query-engine/mcp-servers.json
• Configures MCP servers for context7 and mcp-tasks with Bun execution
• Defines server types, commands, and timeout settings
1 files
agent_error_logger.py
Add agent error logging utility for PydanticAI exceptionsunoplat-code-confluence-query-engine/src/unoplat_code_confluence_query_engine/utils/agent_error_logger.py
• Creates a utility function
log_agent_errorfor consistent agenterror logging
• Logs PydanticAI
UnexpectedModelBehaviorexceptionswith timestamp and context
• Includes optional context information and
message history for debugging
• Uses loguru logger with structured
error information
11 files