This guide helps developers extend and customize LinX (灵枢).
- Development Setup
- Project Structure
- Creating Custom Agents
- Adding New Skills
- Extending the API
- Testing
- Contributing
- Python 3.11+
- Node.js 20+
- Docker and Docker Compose
- Git
# Clone repository
git clone https://github.com/your-org/linx.git
cd linx
# Backend setup
cd backend
python3.11 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install -r requirements-dev.txt
# Frontend setup
cd ../frontend
npm install
# Start infrastructure
cd ..
docker-compose up -d# Backend (with hot reload)
cd backend
source venv/bin/activate
uvicorn api_gateway.main:app --reload --host 0.0.0.0 --port 8000
# Frontend (with hot reload)
cd frontend
npm run devlinx/
├── backend/ # Python backend
│ ├── api_gateway/ # REST API
│ ├── agent_framework/ # Agent system
│ ├── task_manager/ # Task orchestration
│ ├── memory_system/ # Memory management
│ ├── knowledge_base/ # Document processing
│ └── ...
├── frontend/ # React frontend
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── pages/ # Page components
│ │ ├── api/ # API client
│ │ └── stores/ # State management
│ └── ...
└── infrastructure/ # Deployment configs
Create a new template in backend/agent_framework/default_templates.py:
CUSTOM_AGENT_TEMPLATE = {
"name": "Custom Agent",
"description": "My custom agent",
"skills": ["custom_skill_1", "custom_skill_2"],
"system_prompt": "You are a custom agent that...",
"config": {
"temperature": 0.7,
"max_tokens": 2000
}
}from agent_framework.agent_template import AgentTemplateManager
manager = AgentTemplateManager()
manager.register_template("custom_agent", CUSTOM_AGENT_TEMPLATE)from agent_framework.base_agent import BaseAgent
agent = BaseAgent.from_template(
template_id="custom_agent",
name="My Custom Agent",
user_id="user-123"
)Create backend/skill_library/custom_skill.py:
from skill_library.skill_model import Skill, SkillParameter
class CustomSkill(Skill):
def __init__(self):
super().__init__(
name="custom_skill",
description="Performs custom operation",
version="1.0.0",
parameters=[
SkillParameter(
name="input_data",
type="string",
required=True,
description="Input data to process"
)
]
)
def execute(self, input_data: str, **kwargs) -> dict:
"""Execute the skill."""
# Your custom logic here
result = self.process_data(input_data)
return {
"success": True,
"result": result
}
def process_data(self, data: str) -> str:
"""Custom processing logic."""
return data.upper()from skill_library.skill_registry import SkillRegistry
from skill_library.custom_skill import CustomSkill
registry = SkillRegistry()
registry.register_skill(CustomSkill())agent.add_skill("custom_skill")
result = agent.execute_skill("custom_skill", input_data="hello")Create backend/api_gateway/routers/custom.py:
from fastapi import APIRouter, Depends
from access_control.jwt_auth import get_current_user
router = APIRouter(prefix="/custom", tags=["custom"])
@router.get("/")
async def get_custom_data(current_user = Depends(get_current_user)):
"""Get custom data."""
return {"message": "Custom endpoint"}
@router.post("/")
async def create_custom_data(
data: dict,
current_user = Depends(get_current_user)
):
"""Create custom data."""
return {"created": True, "data": data}In backend/api_gateway/main.py:
from api_gateway.routers import custom
app.include_router(custom.router, prefix="/api/v1")# backend/tests/test_custom_skill.py
import pytest
from skill_library.custom_skill import CustomSkill
def test_custom_skill():
skill = CustomSkill()
result = skill.execute(input_data="hello")
assert result["success"] is True
assert result["result"] == "HELLO"cd backend
pytest tests/
pytest tests/test_custom_skill.py -v
pytest --cov=. --cov-report=html# backend/tests/integration/test_api.py
import pytest
from fastapi.testclient import TestClient
from api_gateway.main import app
client = TestClient(app)
def test_create_agent():
response = client.post(
"/api/v1/agents",
json={"name": "Test Agent", "type": "data_analyst"},
headers={"Authorization": f"Bearer {token}"}
)
assert response.status_code == 201# Format code
black .
isort .
# Lint
flake8 .
# Type check
mypy .# Format code
npm run format
# Lint
npm run lint
# Type check
npm run type-checkgit clone https://github.com/your-username/linx.git
cd linx
git remote add upstream https://github.com/your-org/linx.gitgit checkout -b feature/my-feature- Write code
- Add tests
- Update documentation
git add .
git commit -m "feat: add my feature"git push origin feature/my-featureThen create a Pull Request on GitHub.
- Keep functions small and focused
- Use type hints
- Write docstrings
- Follow SOLID principles
from api_gateway.errors import APIError
try:
result = risky_operation()
except ValueError as e:
raise APIError(
code="INVALID_INPUT",
message=str(e),
status_code=400
)from shared.logging import get_logger
logger = get_logger(__name__)
logger.info("Operation started", extra={"user_id": user_id})
logger.error("Operation failed", extra={"error": str(e)})from shared.config import get_config
config = get_config()
api_key = config.get("external_api.key")For development questions:
- GitHub Discussions
- Discord: https://discord.gg/linx
- Email: dev-support@example.com