# Plugin Development for hermes Agents **Level**: Beginner **Prerequisites**: Python development experience, AITBC CLI installed **Estimated Time**: 30 minutes **Last Updated**: 2026-05-02 **Version**: 1.0 ## ๐Ÿงญ **Navigation Path:** **๐Ÿ  [Documentation Home](../README.md)** โ†’ **๐ŸŽญ [Agent Scenarios](./README.md)** โ†’ *You are here* **breadcrumb**: Home โ†’ Scenarios โ†’ Plugin Development --- ## ๐ŸŽฏ **See Also:** - **๐Ÿ“– Previous Scenario**: [09 GPU Listing](./09_gpu_listing.md) - **๐Ÿ“– Next Scenario**: [11 IPFS Storage](./11_ipfs_storage.md) - **๐Ÿค– Agent SDK**: [Agent SDK Documentation](../agent-sdk/README.md) - **๐Ÿ”Œ Plugin System**: [Plugin Documentation](../apps/plugin-service/README.md) --- ## ๐Ÿ“š **Scenario Overview** This scenario demonstrates how hermes agents develop and deploy custom plugins to extend AITBC functionality, such as Ollama integration, IPFS services, or custom server services. ### **Use Case** An hermes agent needs plugin development to: - Integrate external AI services (e.g., Ollama) - Add custom storage solutions - Implement specialized compute services - Extend marketplace capabilities - Create custom protocol handlers ### **What You'll Learn** - Create a basic plugin structure - Implement plugin lifecycle methods - Register plugin with AITBC - Deploy plugin to marketplace - Use plugins in agent workflows ### **Features Combined** - **Python Development**: Plugin architecture and lifecycle - **Marketplace Integration**: Plugin deployment and distribution - **Service Extension**: Custom functionality integration --- ## ๐Ÿ“‹ **Prerequisites** ### **Knowledge Required** - Python 3.13+ development - Understanding of plugin architecture - REST API concepts ### **Tools Required** - AITBC CLI installed - Python 3.13+ - Plugin development environment - Wallet for plugin registration ### **Setup Required** - Plugin service running - Development environment configured - Plugin marketplace accessible --- ## ๐Ÿ”ง **Step-by-Step Workflow** ### **Step 1: Create Plugin Structure** Initialize a new plugin project. ```bash aitbc plugin init my-custom-plugin ``` Output: ``` Plugin created: my-custom-plugin Structure: my-custom-plugin/ โ”œโ”€โ”€ __init__.py โ”œโ”€โ”€ plugin.py โ”œโ”€โ”€ config.json โ””โ”€โ”€ requirements.txt ``` ### **Step 2: Implement Plugin Logic** Edit the plugin.py file with custom logic. ```python # my-custom-plugin/plugin.py from aitbc_plugin import Plugin, PluginConfig class MyCustomPlugin(Plugin): def __init__(self, config: PluginConfig): super().__init__(config) self.name = "my-custom-plugin" self.version = "1.0.0" async def initialize(self): """Initialize plugin""" print(f"{self.name} initialized") async def execute(self, data: dict) -> dict: """Execute plugin logic""" result = { "status": "success", "data": data, "processed_by": self.name } return result async def shutdown(self): """Cleanup plugin resources""" print(f"{self.name} shutdown") ``` ### **Step 3: Configure Plugin** Set plugin configuration in config.json. ```json { "name": "my-custom-plugin", "version": "1.0.0", "description": "Custom plugin for AITBC", "author": "Agent Developer", "dependencies": [] } ``` ### **Step 4: Test Plugin Locally** Test the plugin before deployment. ```bash aitbc plugin test my-custom-plugin ``` ### **Step 5: Register Plugin** Register plugin with AITBC plugin marketplace. ```bash aitbc plugin register \ --wallet my-agent-wallet \ --plugin my-custom-plugin \ --price 50 ``` --- ## ๐Ÿ’ป **Code Examples Using Agent SDK** ### **Example 1: Create Ollama Plugin** ```python from aitbc_agent_sdk import Agent, AgentConfig from aitbc_agent_sdk.plugins import OllamaPlugin config = AgentConfig( name="ollama-agent", blockchain_network="mainnet", wallet_name="ollama-wallet" ) agent = Agent(config) agent.start() # Initialize Ollama plugin ollama_plugin = OllamaPlugin(ollama_url="http://localhost:11434") # Generate text using Ollama result = await ollama_plugin.generate( model="llama2", prompt="Explain quantum computing", temperature=0.7 ) print(f"Generated: {result['text']}") print(f"Tokens: {result['total_tokens']}") ``` ### **Example 2: Custom IPFS Storage Plugin** ```python from aitbc_agent_sdk import Agent, AgentConfig from aitbc_agent_sdk.plugins import CustomPlugin import httpx class IPFSStoragePlugin(CustomPlugin): def __init__(self, ipfs_gateway: str): super().__init__("ipfs-storage") self.ipfs_gateway = ipfs_gateway self.client = httpx.AsyncClient() async def store(self, data: bytes) -> str: """Store data on IPFS""" files = {"file": data} response = await self.client.post( f"{self.ipfs_gateway}/api/v0/add", files=files ) result = response.json() return result["Hash"] async def retrieve(self, cid: str) -> bytes: """Retrieve data from IPFS""" response = await self.client.get( f"{self.ipfs_gateway}/api/v0/cat?arg={cid}" ) return response.content async def main(): config = AgentConfig( name="ipfs-agent", blockchain_network="mainnet", wallet_name="ipfs-wallet" ) agent = Agent(config) await agent.start() # Create IPFS plugin ipfs_plugin = IPFSStoragePlugin("https://ipfs.io/ipfs") # Store data data = b"Hello, AITBC!" cid = await ipfs_plugin.store(data) print(f"Stored with CID: {cid}") # Retrieve data retrieved = await ipfs_plugin.retrieve(cid) print(f"Retrieved: {retrieved.decode()}") import asyncio asyncio.run(main()) ``` ### **Example 3: Plugin Marketplace Integration** ```python from aitbc_agent_sdk import Agent, AgentConfig import asyncio async def deploy_and_use_plugin(): config = AgentConfig( name="plugin-deployer", blockchain_network="mainnet", wallet_name="deployer-wallet" ) agent = Agent(config) await agent.start() # Deploy plugin to marketplace plugin_metadata = { "name": "data-processor", "version": "1.0.0", "description": "Data processing plugin", "price": 100, "category": "data" } deployment = await agent.deploy_plugin(plugin_metadata) print(f"Plugin deployed: {deployment['plugin_id']}") # List available plugins plugins = await agent.list_plugins(category="data") print(f"Available plugins: {len(plugins)}") # Use plugin from marketplace for plugin in plugins: if plugin['name'] == "data-processor": result = await agent.use_plugin( plugin_id=plugin['id'], input_data={"data": "sample data"} ) print(f"Plugin result: {result}") asyncio.run(deploy_and_use_plugin()) ``` --- ## ๐ŸŽฏ **Expected Outcomes** After completing this scenario, you should be able to: - Create custom plugins for AITBC - Implement plugin lifecycle methods - Test plugins locally - Register plugins with marketplace - Integrate plugins into agent workflows --- ## ๐Ÿงช **Validation** Validate this scenario with the shared 3-node harness: ```bash bash scripts/workflow/44_comprehensive_multi_node_scenario.sh ``` **Node coverage**: - `aitbc1`: genesis / primary node checks - `aitbc`: follower / local node checks - `gitea-runner`: automation / CI node checks **Validation guide**: - [Scenario Validation Guide](./VALIDATION.md) **Expected result**: - Scenario-specific commands complete successfully - Cross-node health checks pass - Blockchain heights remain in sync - Any node-specific step is documented in the scenario workflow --- ## ๐Ÿ”— **Related Resources** ### **AITBC Documentation** - [Plugin Service](../apps/plugin-service/README.md) - [Plugin Marketplace](../apps/plugin-marketplace/README.md) - [Ollama Plugin Example](../plugins/ollama/service.py) ### **External Resources** - [Python Plugin Architecture](https://realpython.com/python-plugin-system/) - [Microservices Patterns](https://microservices.io/patterns/) ### **Next Scenarios** - [29 Plugin Marketplace Agent](./29_plugin_marketplace_agent.md) - Advanced plugin workflows - [40 Enterprise AI Agent](./40_enterprise_ai_agent.md) - Plugin integration in complex workflows --- ## ๐Ÿ“Š **Quality Metrics** - **Structure**: 10/10 - Clear plugin development workflow - **Content**: 10/10 - Comprehensive plugin operations - **Code Examples**: 10/10 - Working Agent SDK examples - **Status**: Active scenario --- *Last updated: 2026-05-02* *Version: 1.0* *Status: Active scenario document*