Python

From elophanto/EloPhanto · View interactive version

Python is an AI agent skill from the GitHub repository elophanto/EloPhanto. Python coding guide for EloPhanto — covers plugin development, async patterns, error handling, testing with pytest, and the BaseTool interface.

How to use this skill

Skill file

Python Development

Description

Python coding guide for EloPhanto — covers plugin development, async patterns, error handling, testing with pytest, and the BaseTool interface.

Triggers

Instructions

1. Before Writing Code

  1. Read existing code in the target area (self_read_source or file_read).
  2. Match the patterns already in use — naming, error handling, imports.
  3. Check if something similar exists (self_list_capabilities for tools,

file_list with *.py pattern for general code).

  1. Identify edge cases upfront: empty input, missing params, file not found,

permission denied, timeouts.

2. Style

3. EloPhanto Plugin Interface

Every tool must implement the BaseTool abstract class:

from __future__ import annotations
from typing import Any
from tools.base import BaseTool, PermissionLevel, ToolResult

class MyTool(BaseTool):
    @property
    def name(self) -> str:
        return "my_tool"  # snake_case, unique across all tools

    @property
    def description(self) -> str:
        return "Clear, actionable description the LLM reads to decide when to use this tool."

    @property
    def input_schema(self) -> dict[str, Any]:
        return {
            "type": "object",
            "properties": {
                "param": {"type": "string", "description": "What this does"},
            },
            "required": ["param"],
        }

    @property
    def permission_level(self) -> PermissionLevel:
        return PermissionLevel.MODERATE  # SAFE | MODERATE | DESTRUCTIVE | CRITICAL

    async def execute(self, params: dict[str, Any]) -> ToolResult:
        try:
            result = await do_something(params["param"])
            return ToolResult(success=True, data={"output": result})
        except Exception as e:
            return ToolResult(success=False, error=f"Failed: {e}")

Critical rules:

4. Error Handling

# Specific exceptions with informative messages
try:
    data = json.loads(response)
except json.JSONDecodeError as e:
    return ToolResult(success=False, error=f"Invalid JSON: {e}")

# Early returns for validation (guard clauses)
async def execute(self, params):
    path = Path(params["path"])
    if not path.exists():
        return ToolResult(success=False, error=f"Not found: {path}")
    if not path.is_file():
        return ToolResult(success=False, error=f"Not a file: {path}")
    # main logic after guards pass

Anti-patterns:

5. Async Patterns

import asyncio

# Subprocess with timeout
proc = await asyncio.create_subprocess_exec(
    "command", "arg1",
    stdout=asyncio.subprocess.PIPE,
    stderr=asyncio.subprocess.PIPE,
)
try:
    stdout, stderr = await asyncio.wait_for(proc.communicate(), timeout=30)
except asyncio.TimeoutError:
    proc.kill()
    await proc.communicate()
    return ToolResult(success=False, error="Command timed out")

# Parallel operations
results = await asyncio.gather(task_a(), task_b(), return_exceptions=True)

# File I/O (sync is fine for small files in asyncio context)
content = Path("file.txt").read_text(encoding="utf-8")

6. Testing

import pytest
from plugins.my_tool.plugin import MyTool

@pytest.mark.asyncio
async def test_execute_success():
    tool = MyTool()
    result = await tool.execute({"param": "valid_input"})
    assert result.success
    assert "output" in result.data

@pytest.mark.asyncio
async def test_execute_missing_param():
    tool = MyTool()
    result = await tool.execute({})
    assert not result.success

7. Code Review Checklist

8. Tooling

Verify

Notes

EloPhanto plugins live in plugins/<name>/plugin.py. They are registered in

core/registry.py and their dependencies injected in core/agent.py. Use

self_read_source to study existing tools before creating new ones.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.