Skip to content

Instantly share code, notes, and snippets.

@mrmaheshrajput
Created November 17, 2025 04:28
Show Gist options
  • Select an option

  • Save mrmaheshrajput/758171e8b1f22c28df81826b572edea7 to your computer and use it in GitHub Desktop.

Select an option

Save mrmaheshrajput/758171e8b1f22c28df81826b572edea7 to your computer and use it in GitHub Desktop.
import asyncio
from typing import List, Dict
class AdvancedCodeAssistant(CodeAssistant):
"""Enhanced with parallel tool execution"""
async def search_codebase(self, query: str) -> List[Dict]:
"""Search entire codebase"""
return self.retrieve_context(query, k=5)
async def read_file(self, filepath: str) -> str:
"""Read file contents"""
try:
with open(filepath, 'r') as f:
return f.read()
except:
return f"Error reading {filepath}"
async def check_dependencies(self, filepath: str) -> List[str]:
"""Extract and check dependencies"""
content = await self.read_file(filepath)
# Simple import extraction (enhance this)
imports = []
for line in content.split('\n'):
if line.startswith('import ') or line.startswith('from '):
imports.append(line.strip())
return imports
async def parallel_context_gather(self, file_path: str, query: str):
"""Gather context from multiple sources in parallel"""
tasks = [
self.search_codebase(query),
self.read_file(file_path),
self.check_dependencies(file_path)
]
results = await asyncio.gather(*tasks)
return {
'relevant_chunks': results[0],
'current_file': results[1],
'dependencies': results[2]
}
async def main():
assistant = AdvancedCodeAssistant(
anthropic_key=os.getenv("ANTHROPIC_API_KEY"),
openai_key=os.getenv("OPENAI_API_KEY")
)
assistant.build_index("./project")
# Parallel context gathering
context = await assistant.parallel_context_gather(
file_path="./src/api.py",
query="authentication middleware"
)
print(f"Found {len(context['relevant_chunks'])} relevant chunks")
print(f"Dependencies: {len(context['dependencies'])}")
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment