loading…
Search for a command to run...
loading…
Enables natural language file operations and intelligent file analysis via MCP, supporting CRUD actions and multi-step reasoning for directory management.
Enables natural language file operations and intelligent file analysis via MCP, supporting CRUD actions and multi-step reasoning for directory management.
An intelligent agent for CRUD file operations with CLI interface and MCP (Model Context Protocol) integration.
This project implements an autonomous agent capable of:
The system offers two operational modes:
The project implements two architectural approaches to meet different needs:
From-scratch implementation of the entire ReAct architecture (Reasoning + Acting) with manual tool orchestration and dual-model system. Uses GPT-4o for planning and LLaMA 3 for query validation. This approach ensures maximum control and transparency over the decision cycle, with a lightweight structure optimized for local execution, low latency, and custom MCP integration.
Technical advantages:
Modern implementation using the Pydantic-AI framework for declarative tool orchestration, automatic structured output validation, and dependency injection. Demonstrates integration with modern agentic frameworks while maintaining the same user interface and functionality.
Technical advantages:
ALL agents strictly respect assignment requirements:
Example of compliant behavior:
User: "list files"
❌ Direct response: "I can help you list files..."
✅ Correct response: Uses list_files() tool + provides results
User: "read config.json"
❌ Direct response: "I'll read that file for you..."
✅ Correct response: Uses read_file("config.json") tool + shows content
# Clone repository
git clone <repository-url>
cd assignment
# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate # Linux/Mac
# or
.venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
Create a .env file in the project root:
OPENAI_API_KEY=your_openai_api_key_here
GROQ_API_KEY=your_groq_api_key_here
The project offers 2 distinct agents for different operational needs:
Features:
Prerequisites:
OPENAI_API_KEY=your_openai_api_key_here
GROQ_API_KEY=your_groq_api_key_here # Optional but recommended
Launch:
python chat_interface/llm_cli.py --directory /path/to/working/directory
For testing, sample files are created in the test_files folder:
python chat_interface/llm_cli.py --directory ./test_files
Advanced usage examples:
# Natural language queries
> "Show me all Python files and summarize what they do"
> "Find the most recently modified file and read its content"
> "Create a backup of all important files with timestamp"
> "Analyze the file types and tell me about the project structure"
Features:
Prerequisites:
OPENAI_API_KEY=your_openai_api_key_here # REQUIRED
GROQ_API_KEY=your_groq_api_key_here # OPTIONAL
Launch:
python chat_interface/pydantic_cli.py --directory /path/to/working/directory
Usage examples:
# Same commands as other agents but with structured output
> "List all files and analyze their types"
> "Create a summary report of all JSON files"
> "Read the largest Python file and explain its structure"
The project provides MCP (Model Context Protocol) server integration for seamless use with Claude Desktop and other MCP-compatible clients.
Configure API Keys: Update the mcp_config.json file with your API keys:
{
"mcpServers": {
"llm-file-operations-agent": {
"env": {
"OPENAI_API_KEY": "your_openai_api_key_here",
"GROQ_API_KEY": "your_groq_api_key_here"
}
}
}
}
Install Configuration: Copy the configuration to Claude Desktop:
# Create Claude Desktop config directory if it doesn't exist
mkdir -p ~/Library/Application\ Support/Claude/
# Copy configuration file
cp mcp_config.json ~/Library/Application\ Support/Claude/claude_desktop_config.json
Restart Claude Desktop: Close and reopen Claude Desktop to load the new configuration
Verify Connection: Check the MCP settings in Claude Desktop to ensure the server shows as connected
Once connected to Claude Desktop, you can use natural language commands:
"Show me all Python files and their purposes"
"Create a summary of all JSON configuration files"
"Find the largest file and analyze its content"
"Delete all temporary files that end with .tmp"
The agent implements a 3-level fallback system:
The agent can execute tool sequences in a single request:
Query: "read the file that was modified most recently"
Execution:
1. list_files() -> gets file metadata
2. Identifies the most recent file
3. read_file(filename) -> reads the content
4. Returns the result
The project includes a comprehensive and optimized test suite with 40 tests (39 passing, 1 skipped) verifying all CRUD components, agent functionality, error scenarios, security and integration. The test suite has been streamlined for efficiency while maintaining complete coverage.
Core Test Files:
test_tools.py (27 tests): Complete testing of all five CRUD tools (list, read, write, delete, answer_question). Includes functionality tests, error handling, security validation, and integration tests. Covers path traversal protection, binary file detection, Unicode support, and concurrent operations.
test_agents.py (13 tests): Comprehensive testing of Custom ReAct agent functionality and query validation system. Tests the fix for file analysis queries, validator behavior, tool usage decisions, and error handling scenarios for both Custom ReAct and Pydantic-AI agents.
conftest.py: Test configuration and shared fixtures. Provides temporary test directories with sample files, ensuring consistent test environments across all test modules.
Test Documentation:
TESTING_GUIDE.md: Comprehensive guide for running tests, understanding test scenarios, and extending the test suite. Updated with current test structure and coverage metrics.# Run all tests (verified working)
python -m pytest tests/ -v
# Run specific test files
python -m pytest tests/test_tools.py -v # CRUD operations (27 tests)
python -m pytest tests/test_agents.py -v # Both agents (13 tests)
# Run specific test classes
python -m pytest tests/test_tools.py::TestListFiles -v
python -m pytest tests/test_agents.py::TestCustomReActAgent -v
# Tests with coverage
python -m pytest tests/ --cov=. --cov-report=html
# Quick verification
python -m pytest tests/ -q
tests/test_agents.py::TestLLMValidator::test_file_analysis_queries_approved PASSED [ 2%]
tests/test_agents.py::TestLLMValidator::test_inappropriate_queries_rejected PASSED [ 5%]
tests/test_agents.py::TestCustomReActAgent::test_should_use_tools_file_queries PASSED [ 7%]
tests/test_agents.py::TestCustomReActAgent::test_should_not_use_tools_general_queries PASSED [ 10%]
tests/test_agents.py::TestPydanticAgent::test_pydantic_agent_initialization PASSED [ 12%]
tests/test_agents.py::TestPydanticAgent::test_pydantic_list_files_tool PASSED [ 15%]
tests/test_agents.py::TestPydanticAgent::test_pydantic_read_file_tool PASSED [ 17%]
tests/test_agents.py::TestPydanticAgent::test_pydantic_write_file_tool PASSED [ 20%]
tests/test_agents.py::TestPydanticAgent::test_pydantic_delete_file_tool PASSED [ 22%]
tests/test_agents.py::TestPydanticAgent::test_pydantic_answer_question_tool SKIPPED [ 25%]
tests/test_agents.py::TestErrorHandling::test_binary_file_error_messages PASSED [ 27%]
tests/test_agents.py::TestErrorHandling::test_nonexistent_file_error_messages PASSED [ 30%]
tests/test_agents.py::TestErrorHandling::test_path_traversal_protection PASSED [ 32%]
...
======================== 39 passed, 1 skipped in 3.70s ========================
assignment/
├── agent/ # Main agent logic
│ ├── llm_agent.py # Custom ReAct agent
│ ├── tool_registry.py # Tool registry
│ └── llm_validator.py # LLM validation
├── Pydantic-AI_Agent/ # Pydantic-AI implementation
│ ├── pydantic_agent.py # Agent with Pydantic-AI framework
│ ├── models.py # Pydantic models
│ ├── dependencies.py # Dependency injection
│ └── README_Pydantic.md # Specific documentation
├── tools/ # Tool implementations
│ ├── list_files.py
│ ├── read_file.py
│ ├── write_file.py
│ ├── delete_file.py
│ └── answer_question_about_files.py
├── chat_interface/ # User interfaces
│ ├── llm_cli.py # LLM CLI
│ └── pydantic_cli.py # Pydantic-AI CLI
├── server/ # MCP servers
│ └── llm_mcp_server.py # Enhanced MCP server with Custom ReAct Agent
├── tests/ # Optimized test suite (40 tests)
│ ├── test_tools.py # CRUD tools testing (27 tests)
│ ├── test_agents.py # Agent functionality testing (13 tests)
│ ├── conftest.py # Test configuration and fixtures
│ └── TESTING_GUIDE.md # Comprehensive test documentation
├── Guide_Documents/ # Extended documentation
├── test_files/ # Sample files for testing
├── mcp_config.json # MCP configuration
├── requirements.txt # Python dependencies
└── README.md # This file
This project meets and exceeds all assignment requirements:
Guide_Documents/To test MCP server functionality:
# Test server startup
export OPENAI_API_KEY="your_key_here"
export GROQ_API_KEY="your_key_here"
python server/llm_mcp_server.py --directory ./test_files --name llm-file-operations-agent
# Test with sample request
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}' | python server/llm_mcp_server.py --directory ./test_files --name llm-file-operations-agent
MCP server generates logs in:
/tmp/llm_mcp_server.log - Complete server activity and error logsTo contribute to the project:
This project is released under MIT license.
For questions or support, contact the developer: Andrea Belli Contarini - [email protected]
Выполни в терминале:
claude mcp add llm-file-operations-agent -- npx Безопасность
Низкий рискАвтоматическая эвристика по публичным данным — не гарантия безопасности.