SmolSharpAgent is a C# implementation inspired by Hugging Face's SmollAgents, which generates and executes Python code. This project brings the same powerful concept to the .NET ecosystem, allowing real-time code generation and execution using C#. It combines AI-powered code generation with Roslyn scripting to create a versatile automation tool.
SmolSharpAgent is built on the concept of Hugging Face's SmollAgents but specifically designed for C# developers. While SmollAgents focuses on Python code generation and execution, SmolSharpAgent brings this capability to C# with additional features:
- Support for multiple AI providers (HuggingFace and OpenAI)
- Real-time code execution using Roslyn scripting
- Robust error handling with automatic correction
- Built-in security validations
- Extensive .NET library support
- AI-Powered Code Generation: Utilizes multiple AI providers (HuggingFace, OpenAI) for intelligent code generation
- Real-Time Code Execution: Executes generated code immediately using Roslyn scripting
- Multiple AI Providers: Supports multiple AI providers with easy switching
- Robust Error Handling: Includes automatic error correction and retry mechanisms
- Security Features: Built-in code validation and security checks
- Resource Management: Proper handling of disposable resources
- Extensive Library Support: Pre-configured with popular .NET libraries
-
Prerequisites
- .NET 8.0 SDK
- Windows/Linux/macOS
- AI Provider API Keys (HuggingFace or OpenAI)
-
Clone and Setup
# Clone the repository
git clone https://github.com/yourusername/SmolSharpAgent.git
# Navigate to project directory
cd SmolSharpAgent
# Restore dependencies
dotnet restore
- Configure AI Providers
Rename
appsettings.example.json
toappsettings.json
and add your configurations:
{
"AIProviders": {
"HuggingFace": {
"Endpoint": "YOUR_HUGGINGFACE_ENDPOINT",
"ApiKey": "YOUR_HUGGINGFACE_API_KEY",
"Model": "YOUR_MODEL_NAME"
},
"OpenAI": {
"Endpoint": "YOUR_OPENAI_ENDPOINT",
"ApiKey": "YOUR_OPENAI_API_KEY",
"Model": "YOUR_MODEL_NAME"
}
}
}
- Build and Run
dotnet run
SmolSharpAgent operates through a sophisticated pipeline:
-
User Input
- User provides a natural language query describing the desired code operation
- User selects the AI provider (HuggingFace or OpenAI)
- User sets retry attempts for error correction
-
AI Code Generation
- Selected AI provider processes the query
- Generates C# code based on the prompt and requirements
- Ensures code follows Roslyn script execution format
-
Code Execution
- RoslynExecutor validates the generated code for security
- Prepares execution environment with required dependencies
- Executes code using Roslyn scripting engine
- Handles errors and performs automatic correction if needed
-
Error Handling
- Detects compilation or runtime errors
- Sends errors back to AI for correction
- Implements retry mechanism with specified attempts
- Provides detailed error feedback
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
Anas Nafees
- Inspired by Hugging Face's SmollAgents
- Implemented C# version with extended capabilities
- Added multi-provider support and enhanced error handling
- Hugging Face - For the original SmollAgents concept and API
- OpenAI - For their powerful language models and API
- Microsoft - For .NET, Roslyn, and Playwright
- .NET Community - For the amazing libraries and tools
- Open Source Community - For inspiration and contributions
Made with ❤️ by Anas Nafees