mirror of
https://github.com/sanjeed5/awesome-cursor-rules-mdc.git
synced 2026-11-29 22:22:55 +08:00
- Refreshed all 241 library rules with current best practices - Updated Exa search results for all libraries with 2025 content - Fixed --regenerate-all flag logic to properly process all libraries - Removed duplicate astro entry in rules.json (merged tags) - Added missing docker.mdc and vim.mdc files - All rules now include modern patterns and anti-patterns - Updated with framework-specific recommendations for 2025 Technical improvements: - Fixed retry_failed_only logic in generate_mdc_files.py - Improved progress tracking for regeneration scenarios - Ensured proper handling of --refresh-exa flag
51 lines
1.5 KiB
Plaintext
51 lines
1.5 KiB
Plaintext
---
|
|
description: Definitive guidelines for building robust, performant, and maintainable AI agents using smolagents, focusing on practical patterns and avoiding common pitfalls.
|
|
globs: **/*.py
|
|
---
|
|
# smolagents Best Practices
|
|
|
|
This guide outlines the definitive best practices for developing `smolagents` applications. Adhering to these principles ensures your agents are reliable, efficient, and easy to maintain.
|
|
|
|
## 1. Code Organization and Structure
|
|
|
|
Organize your agent logic and tools into clear, distinct modules. This improves readability, reusability, and testability.
|
|
|
|
❌ BAD: Monolithic agent file
|
|
```python
|
|
# agent.py
|
|
from smolagents import CodeAgent, HfApiModel, tool
|
|
import requests # Direct import in agent file
|
|
|
|
@tool
|
|
def search_web(query: str) -> str:
|
|
# ... complex search logic ...
|
|
return "search result"
|
|
|
|
@tool
|
|
def calculate_math(expression: str) -> float:
|
|
# ... math logic ...
|
|
return eval(expression) # DANGER! Unsafe!
|
|
|
|
agent = CodeAgent(tools=[search_web, calculate_math], model=HfApiModel())
|
|
agent.run("What is 2+2 and also search for 'latest AI news'")
|
|
```
|
|
|
|
✅ GOOD: Modular structure
|
|
```python
|
|
# src/tools.py
|
|
from smolagents import tool
|
|
import requests
|
|
import json
|
|
|
|
@tool
|
|
def web_search(query: str) -> str:
|
|
"""
|
|
Performs a web search for the given query.
|
|
Args:
|
|
query: The search term.
|
|
Returns:
|
|
A summary of the search results or an error message.
|
|
"""
|
|
try:
|
|
# Replace with a real search API (e.g., DuckDuckGoSearchTool, custom API)
|
|
response = requests.get(f"https://api.example.com/search?q |