Plugin Development
Overview
Section titled “Overview”Plugins extend Clawdbot’s capabilities beyond basic chat functionality.
Plugin Structure
Section titled “Plugin Structure”my_plugin/├── __init__.py├── plugin.yaml└── handlers.pyplugin.yaml
Section titled “plugin.yaml”name: my_pluginversion: 1.0.0description: My custom pluginauthor: Your Name
# Dependenciesrequires: - requests>=2.28.0
# Configuration schemaconfig: api_key: type: string required: true description: API key for the servicehandlers.py
Section titled “handlers.py”from clawdbot import Plugin, command, tool
class MyPlugin(Plugin): @command("weather") async def weather_command(self, message, location: str): """Get weather for a location""" data = await self.fetch_weather(location) return f"Weather in {location}: {data['temp']}°C"
@tool("get_weather") async def weather_tool(self, location: str) -> dict: """Tool for Claude to get weather data""" return await self.fetch_weather(location)Creating a Plugin
Section titled “Creating a Plugin”-
Create plugin directory
Terminal window mkdir -p plugins/my_plugincd plugins/my_plugin -
Create plugin.yaml
-
Implement handlers
-
Register plugin
Terminal window # In .envPLUGINS=my_plugin
Available Hooks
Section titled “Available Hooks”| Hook | Purpose |
|---|---|
on_load | Plugin initialization |
on_unload | Cleanup |
pre_message | Before processing |
post_response | After response |
Example: Weather Plugin
Section titled “Example: Weather Plugin”import aiohttpfrom clawdbot import Plugin, tool
class WeatherPlugin(Plugin): async def on_load(self): self.api_key = self.config.get("api_key")
@tool("get_current_weather") async def get_weather(self, city: str) -> dict: """Get current weather for a city.
Args: city: City name (e.g., "London")
Returns: Weather data including temperature and conditions """ async with aiohttp.ClientSession() as session: url = f"https://api.weather.com/..." async with session.get(url) as resp: return await resp.json()Best Practices
Section titled “Best Practices”- Handle errors gracefully
- Use async/await properly
- Document your tools
- Validate configuration
- Clean up resources in on_unload