How matthewzmd/emigo works
Project Type and Purpose
• Emigo is designed to integrate an AI-powered tool directly into Emacs. Its primary function is to let developers leverage large language models (LLMs) to interact with their project context, read/write files, execute commands, and ultimately assist with code development in an "agentic" fashion.
• It achieves this by using an agent (implemented in Python) that orchestrates LLM interactions and acts upon user commands relayed via Emacs.
Analyzing the File Structure
• Key Python Files: Files such as agents.py, config.py, llm.py, system_prompt.py, repomapper.py, and utils.py collectively comprise the core backend logic. They handle tasks like managing LLM interactions, executing and approving tool actions, and processing commands.
• Emacs Lisp Files: Files like emigo.el and emigo-epc.el are the front-end integration components that allow Emacs to communicate with the Python backend, start sessions, and manage the context.
• Queries Directory: The “queries” folder (including its tree-sitter-language-pack and tree-sitter-languages subdirectories) indicates that the project supports language-specific parsing or tagging — likely used to assist in accurate code reading or refactoring by the LLM.
• Additional Files: Standard files like requirements.txt and README.md support dependency management and documentation, while todo.md suggests ongoing feature development.
Architectural Components and Their Relationships
• Emacs Frontend (User Interface):
• Emigo.el & Emigo-epc.el: These files integrate with Emacs and provide the interface for end-users to invoke commands (M-x emigo), interact with prompts, and approve tool actions.
• Python Agent Backend:
• Core Modules: The Python files (agents.py, config.py, llm.py, system_prompt.py, repomapper.py, and utils.py) form the brain of the system. They handle session management, the iterative LLM tool-use cycle, and file system interactions.
• File Interaction: The agent monitors and manipulates files (e.g., reading, refactoring, executing commands). Mention in Emacs with an “@” symbol triggers addition of files to the context by the backend.
• Language Query Support:
• The queries directory holds language-specific tree-sitter configurations that likely assist in understanding or tagging code in various languages. This module informs the agent with extra context regarding the specific codebase language structure.
• External Services:
• LLM Providers: External LLM services (integrated via the LiteLLM library) are used for generating responses and decision making within the agent.
• Emacs and System Integration: The backend may use system commands or file system calls based on the agents’ actions.
Architectural Patterns and Design Principles
• Layered Architecture: The system clearly separates the presentation layer (Emacs Lisp integration) from the business logic layer (Python agent) and further abstracts external dependencies (LLM services, language parsing).
• Tool-Use Pattern: The agent decouples LLM-generated suggestions from actual tool execution. The iterative cycle is central: the LLM analyzes user requests, picks a tool (such as read, write, or execute commands), and the result is fed back as context.
• Extensibility & Configurability: From the tree-sitter queries to dynamic LLM support via LiteLLM, the system is designed to be flexible and accommodate various coding languages and LLM providers.