AGENT SKILL

python-standards

Python coding standards for Amplifier including type hints, async patterns, error handling, and formatting. Use when writing Python code for Amplifier modules.

License 许可
MIT
最近更新
2026-10-03
Stars
★ 12
Forks
11

01 前言 Front Matter

name
python-standards
license
MIT
version
1.0.0
metadata
{ "category": "development", "complexity": "low" }
description
Python coding standards for Amplifier including type hints, async patterns, error handling, and formatting. Use when writing Python code for Amplifier modules.

03 SKILL.md 正文

Python Coding Standards

Type Hints

ALL functions must have complete type hints:

from typing import Any

async def process_data(items: list[str], config: dict[str, Any]) -> dict[str, Any]:
    """Process data items with configuration."""
    results = {}
    for item in items:
        results[item] = await transform(item, config)
    return results

Include type hints for self:

class MyClass:
    def __init__(self: "MyClass", name: str) -> None:
        self.name = name

    async def process(self: "MyClass") -> str:
        return f"Processing {self.name}"

Async Patterns

All I/O operations must be async:

# Good
async def read_file(path: Path) -> str:
    content = path.read_text()  # For now, sync is OK
    return content

# Better (when using async libraries)
async def read_file(path: Path) -> str:
    async with aiofiles.open(path) as f:
        return await f.read()

Use asyncio.gather for parallel operations:

async def process_files(files: list[Path]) -> list[dict]:
    tasks = [process_file(f) for f in files]
    return await asyncio.gather(*tasks)

Error Handling

Return errors, don't raise:

from amplifier_core import ToolResult

async def execute(self: "MyTool", input: dict[str, Any]) -> ToolResult:
    """Execute tool operation."""
    try:
        result = await self._process(input)
        return ToolResult(success=True, output=result)
    except ValueError as e:
        logger.error(f"Validation error: {e}")
        return ToolResult(success=False, error={"message": str(e)})

Provide clear error messages:

# Good
return ToolResult(
    success=False,
    error={"message": f"File not found: {path}"}
)

# Bad
return ToolResult(
    success=False,
    error={"message": "Error"}
)

Formatting

Line length: 120 characters

Import organization:

# Standard library
import asyncio
import logging
from pathlib import Path
from typing import Any

# Third-party
import yaml
from pydantic import BaseModel

# Local/Amplifier
from amplifier_core import ModuleCoordinator, ToolResult

Files must end with newline - Add blank line at EOF

Use ruff for formatting:

uv run ruff format .
uv run ruff check . --fix

Dependencies

Use uv for dependency management:

# Add dependency
cd amplifier-module-tool-mytool
uv add package-name

# Add dev dependency
uv add --dev pytest ruff pyright

Never manually edit pyproject.toml dependencies - Use uv add

Testing

Test behavior at protocol level:

import pytest
from amplifier_core.testing import TestCoordinator

@pytest.mark.asyncio
async def test_tool_basic():
    """Test basic tool functionality."""
    coordinator = TestCoordinator()

    # Mount module
    await mount(coordinator, {"timeout": 10})

    # Get and test
    tool = coordinator.get("tools", "my-tool")
    result = await tool.execute({"param": "value"})

    assert result.success
    assert "expected" in result.output

Test pyramid: 60% unit, 30% integration, 10% end-to-end

Common Pitfalls

Don't use blocking I/O

# Bad
content = requests.get(url).text

# Good
async with aiohttp.ClientSession() as session:
    async with session.get(url) as response:
        content = await response.text()

Don't modify module internals from outside

# Bad
tool._internal_state = new_value

# Good
await tool.execute({"operation": "update", "value": new_value})

Don't put logic in mount()

# Bad
async def mount(coordinator, config):
    tool = MyTool()
    await tool.initialize_database()  # Heavy logic
    await coordinator.mount("tools", tool)

# Good
async def mount(coordinator, config):
    tool = MyTool(config)  # Light initialization only
    await coordinator.mount("tools", tool)
    # Heavy logic happens in execute(), not mount()

Remember

  • Run make check before committing
  • Keep modules focused and simple
  • Document public interfaces
  • Test at the protocol level

04 同仓库更多 Skills

microsoft
microsoft/amplifier-bundle-skills

verification-discipline

Use when verifying that completed work actually works. Auto-surface during /verify mode, post-implementation review, or before claiming a task is done. Teaches testing outcomes vs implementation, the unit/integration/smoke gradient, and what "done" actually means.

★ 12
microsoft
microsoft/amplifier-bundle-skills

user-advocate

User-need reviewer that speaks for the person who isn't in the room — the one who will actually live with what gets built. Hunts the gap between "we can build this" and "they actually want this," in the patient, impatient voice of the absent user. Use at any checkpoint — brainstorm, design, plan, implement, debug, review — when a feature is being built because it's buildable rather than wanted, the recovery path is missing, or nobody can name the person this serves: "do they actually want this, and can they live with it?"

★ 12
microsoft
microsoft/amplifier-bundle-skills

tester-breaker

Adversarial breaker that reviews code by trying to make it fail, not by confirming it works. Hunts the unhappy paths — malformed input, the empty string, the reversed range, the race condition — as a gleeful adversary who assumes everything is broken until a concrete attempt to break it comes up empty. Use at any checkpoint — brainstorm, design, plan, implement, debug, review — when the happy path is celebrated while the edges sit unexamined, "looks fine" stands in for "I tried to break it and couldn't," or nobody has named the input that makes this fall over: "how does this fail, and where are the edges?"

开发工程师
★ 12
microsoft
microsoft/amplifier-bundle-skills

skills-assist

Authoritative consultant for all skills-related questions. Use when creating or modifying skills, understanding the Agent Skills spec, troubleshooting skill loading or invocation issues, leveraging enhanced format features (context fork, model_role, user-invocable), writing cross-harness portable skills, ensuring Claude Code Skills 2.0 compatibility, or deciding between skills vs agents.

★ 12
microsoft
microsoft/amplifier-bundle-skills

skillify

Capture a repeatable process from the current session into a reusable Amplifier SKILL.md skill file. Use when the user wants to create a skill, save a workflow as a skill, turn a process into a reusable skill, or mentions "skillify", "create skill", "make a skill", "save as skill", "capture workflow", "turn this into a skill", "new skill", or wants to automate a repeatable process they just performed.

Skill与智能体开发
★ 12
microsoft
microsoft/amplifier-bundle-skills

session-debug

Diagnose issues in the current Amplifier session — misconfigured tools, failing operations, unexpected behavior. Use when something isn't working right.

开发工程师
★ 12