- Updated .env.example to provide clearer configuration instructions and API key setup. - Removed debug_env.py as it was no longer needed. - Refactored main.py to streamline application initialization and workspace setup. - Introduced a new HistoryManager for managing task execution history. - Enhanced UI components in chat_view.py and task_guide_view.py to improve user interaction and code preview functionality. - Added loading indicators and improved task history display in the UI. - Implemented unit tests for history management and intent classification.
LocalAgent - Windows Local AI Execution Assistant
A Windows-based local AI assistant that can understand natural language commands and execute file processing tasks safely in a sandboxed environment.
Features
- Intent Recognition: Automatically distinguishes between chat conversations and execution tasks
- Code Generation: Generates Python code based on user requirements
- Safety Checks: Multi-layer security with static analysis and LLM review
- Sandbox Execution: Runs generated code in an isolated environment
- Task History: Records all executed tasks for review
- Streaming Responses: Real-time display of LLM responses
Project Structure
LocalAgent/
├── app/ # Main application
│ └── agent.py # Core application class
├── llm/ # LLM integration
│ ├── client.py # API client with retry support
│ └── prompts.py # Prompt templates
├── intent/ # Intent classification
│ ├── classifier.py # Intent classifier
│ └── labels.py # Intent labels
├── safety/ # Security checks
│ ├── rule_checker.py # Static rule checker
│ └── llm_reviewer.py # LLM-based code review
├── executor/ # Code execution
│ └── sandbox_runner.py # Sandbox executor
├── history/ # Task history
│ └── manager.py # History manager
├── ui/ # User interface
│ ├── chat_view.py # Chat interface
│ ├── task_guide_view.py # Task confirmation view
│ └── history_view.py # History view
├── tests/ # Unit tests
├── workspace/ # Working directory (auto-created)
│ ├── input/ # Input files
│ ├── output/ # Output files
│ ├── codes/ # Generated code
│ └── logs/ # Execution logs
├── main.py # Entry point
├── requirements.txt # Dependencies
└── .env.example # Configuration template
Installation
Prerequisites
- Python 3.10+
- Windows OS
- SiliconFlow API Key (Get one here)
Setup
-
Clone the repository
git clone <repository-url> cd LocalAgent -
Create virtual environment (recommended using Anaconda)
conda create -n localagent python=3.10 conda activate localagent -
Install dependencies
pip install -r requirements.txt -
Configure environment
cp .env.example .env # Edit .env and add your API key -
Run the application
python main.py
Configuration
Edit .env file with your settings:
# SiliconFlow API Configuration
LLM_API_URL=https://api.siliconflow.cn/v1/chat/completions
LLM_API_KEY=your_api_key_here
# Model Configuration
INTENT_MODEL_NAME=Qwen/Qwen2.5-7B-Instruct
GENERATION_MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
Usage
Chat Mode
Simply type questions or have conversations:
- "What is Python?"
- "Explain machine learning"
Execution Mode
Describe file processing tasks:
- "Copy all files from input to output"
- "Convert all PNG images to JPG format"
- "Rename files with today's date prefix"
Workflow
- Place input files in
workspace/input/ - Describe your task in the chat
- Review the execution plan and generated code
- Click "Execute" to run
- Find results in
workspace/output/
Security
LocalAgent implements multiple security layers:
-
Hard Rules - Blocks dangerous operations:
- Network modules (socket, subprocess)
- Code execution (eval, exec)
- System commands (os.system, os.popen)
-
Soft Rules - Warns about sensitive operations:
- File deletion
- Network requests (requests, urllib)
-
LLM Review - Semantic analysis of generated code
-
Sandbox Execution - Isolated subprocess with limited permissions
Testing
Run unit tests:
python -m pytest tests/ -v
Supported File Operations
The generated code can use these libraries:
Standard Library:
- os, sys, pathlib - Path operations
- shutil - File copy/move
- json, csv - Data formats
- zipfile, tarfile - Compression
- And more...
Third-party Libraries:
- Pillow - Image processing
- openpyxl - Excel files
- python-docx - Word documents
- PyPDF2 - PDF files
- chardet - Encoding detection
License
MIT License
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.