The fetchai.mdc file is a comprehensive set of development rules and best practices specifically designed for building Fetch.ai agents using Cursor IDE. It serves as an intelligent coding assistant that helps developers write correct, efficient, and production-ready uAgent code.
This rule file ensures:
- Consistent Code Quality: Standardized patterns across all Fetch.ai projects
- Compatibility: Exact package versions that work together seamlessly
- Best Practices: Official patterns from Fetch.ai Innovation Lab documentation
- Error Prevention: Common pitfalls and how to avoid them
- Production Readiness: Deployment patterns and monitoring guidelines
- Place the Rule File: The
fetchai.mdcfile should be in your.cursor/rules/directory - Activate Rules: Cursor automatically detects and applies rules in this directory
- Verify: Check that Cursor recognizes the rules in your project
The rules specify exact versions for compatibility:
# Basic uAgent development
pip install uagents==0.22.5
# Full framework integration
pip install uagents==0.22.5 uagents-adapter==0.4.0 langchain==0.3.23 langgraph==0.3.20 crewai==0.126.0 langchain-openai==0.2.14When you create Python files in your project, Cursor will automatically:
- Suggest proper imports
- Generate compatible code patterns
- Warn about common mistakes
- Reference official documentation
- Direct links to Fetch.ai Innovation Lab documentation
- Agent creation, communication, and deployment guides
- Examples for LangGraph, CrewAI, ASI:One integration
- MCP integration patterns
- uAgent Creation: Proper agent initialization with descriptive names and seeds
- Message Models: Pydantic-compatible model definitions
- Protocol Implementation: Versioned protocols with error handling
- REST API Integration: GET/POST endpoint patterns
- LangGraph: Simple function wrapper pattern (official approach)
- LangChain: Agent executor integration
- CrewAI: Multi-agent collaboration
- MCP Servers: Model Context Protocol integration
- Pydantic Compatibility: Avoiding problematic validators and decorators
- Error Handling: Comprehensive exception management
- Security: Input validation and rate limiting
- Performance: Async patterns and memory management
- Local Agents: Development and testing
- Mailbox Agents: Hybrid local/Agentverse deployment
- Hosted Agents: Full Agentverse deployment
- Production Monitoring: Analytics and health checks
When you ask Cursor to create agent code, it will:
# ✅ Generate this (correct pattern)
from uagents import Agent, Context, Model, Protocol
from pydantic import Field
from datetime import datetime, UTC
agent = Agent(
name="descriptive_service_name",
seed="unique_deterministic_seed_phrase",
port=8000,
endpoint=["http://localhost:8000/submit"],
mailbox=True
)
class ServiceRequest(Model):
request_id: str = Field(..., description="Unique identifier")
timestamp: str = Field(default="", description="Request timestamp")
def __init__(self, **data):
if 'timestamp' not in data or not data['timestamp']:
data['timestamp'] = datetime.now(UTC).isoformat()
super().__init__(**data)Instead of problematic patterns that cause errors.
Cursor will avoid generating code with:
- Deprecated
@field_validatordecorators that cause pickle errors - Incorrect REST endpoint parameter patterns
- Deprecated
datetime.utcnow()usage - Wrong Pydantic base classes
When you ask about Fetch.ai features, Cursor will reference:
- Official Innovation Lab documentation links
- Specific examples and tutorials
- Best practice patterns
- Compatibility requirements
The rules emphasize the correct workflow for agent communication:
# Step 1: Start Bob first
python bob.py
# Copy Bob's address from output
# Step 2: Update Alice's code with Bob's address
BOB_ADDRESS = "agent1qwj8cuywyt548afedw3mvw4jsklsl4343uhvagwpu0wux3rz2t8a2qtu0ul"
# Step 3: Start Alice
python alice.pyKey Rules:
- Always run agents in separate terminals (unless using Bureau)
- Start listener first, then initiator
- Copy real addresses, don't use hardcoded ones
For REST endpoints, the rules specify:
# GET endpoints: only response model
@agent.on_rest_get("/data", ResponseModel)
async def get_handler(ctx: Context) -> ResponseModel:
return ResponseModel(...)
# POST endpoints: both request and response models
@agent.on_rest_post("/process", RequestModel, ResponseModel)
async def post_handler(ctx: Context, request: RequestModel) -> ResponseModel:
return ResponseModel(...)# ✅ DO: Simple function wrapper
from langgraph.prebuilt import chat_agent_executor
from langchain_openai import ChatOpenAI
from langchain_community.tools.tavily_search import TavilySearchResults
tools = [TavilySearchResults(max_results=3)]
model = ChatOpenAI(temperature=0)
app = chat_agent_executor.create_tool_calling_executor(model, tools)
def langgraph_agent_func(query):
if isinstance(query, dict) and 'input' in query:
query = query['input']
messages = {"messages": [HumanMessage(content=query)]}
final = None
for output in app.stream(messages):
final = list(output.values())[0]
return final["messages"][-1].content if final else "No response"# ❌ DON'T: Complex StateGraph for simple tasks
class ComplexMathAgent:
def build_graph(self):
graph = StateGraph(ComplexState)
graph.add_node("ROUTER", router)
graph.add_node("PARSE_MATH", parse_math)
# ... 10+ nodes for simple math operationsThe rules guide you toward the official Fetch.ai pattern that's simpler and more maintainable.
Ask Cursor: "Create a basic uAgent with startup and shutdown handlers"
Ask Cursor: "Create two agents that communicate with each other"
- Cursor will generate proper Alice/Bob pattern with correct terminal workflow
Ask Cursor: "Create an agent with REST endpoints for health check and data processing"
- Cursor will use proper GET/POST patterns and uagents.Model inheritance
Ask Cursor: "Create a LangGraph agent with web search capabilities"
- Cursor will use the official simple function wrapper pattern
Ask Cursor: "Help me deploy this agent to Agentverse with monitoring"
- Cursor will include proper error handling, logging, and deployment patterns
- Check File Location: Ensure
fetchai.mdcis in.cursor/rules/ - Restart Cursor: Sometimes rules need to be reloaded
- Check Syntax: Ensure the rule file is properly formatted
- Verify Project Type: Rules apply to Python files (*.py)
The rules specify exact versions that are tested together:
- Use virtual environments to avoid conflicts
- Follow the exact version specifications
- Check the compatibility notes in the rules
- The rules are designed to prevent common errors
- If you see Pydantic errors, ensure you're using the patterns from the rules
- Check that you're using
uagents.Modelinstead ofpydantic.BaseModel
The rules include direct links to official documentation:
- Introduction: Start here for Fetch.ai basics
- Agent Creation: Core agent development
- LangGraph Example: Official integration pattern
- Agent Communication: Multi-agent patterns
To improve these rules:
- Test patterns with real Fetch.ai projects
- Identify common developer issues
- Reference official documentation updates
- Submit improvements based on community feedback
These rules follow Fetch.ai's open-source guidelines and are designed to help developers build better agent applications using official patterns and best practices.
Happy Coding with Fetch.ai and Cursor! 🚀