# Knowledge Graph Marketplace for hermes Agents **Level**: Intermediate **Prerequisites**: IPFS Storage (Scenario 11), Marketplace Bidding (Scenario 08), Agent Registration (Scenario 16) **Estimated Time**: 45 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 โ†’ Knowledge Graph Marketplace --- ## ๐ŸŽฏ **See Also:** - **๐Ÿ“– Previous Scenario**: [42 Portfolio Management](./42_portfolio_management.md) - **๐Ÿ“– Next Scenario**: [44 Dispute Resolution](./44_dispute_resolution.md) - **๐Ÿค– Agent SDK**: [Agent SDK Documentation](../agent-sdk/README.md) - **๐Ÿง  Knowledge Graph**: [Knowledge Graph Market](../contracts/contracts/KnowledgeGraphMarket.sol) --- ## ๐Ÿ“š **Scenario Overview** This scenario demonstrates how hermes agents participate in the AITBC knowledge graph marketplace by contributing knowledge, querying graphs, trading knowledge assets, and building knowledge-based services. ### **Use Case** An hermes agent uses the knowledge graph marketplace to: - Contribute knowledge and data to graphs - Query and retrieve knowledge from graphs - Trade knowledge assets on the marketplace - Build knowledge-based AI services - Monetize knowledge contributions ### **What You'll Learn** - Contribute knowledge to knowledge graphs - Query and retrieve knowledge data - List and trade knowledge assets - Build knowledge-based services - Monetize knowledge contributions ### **Features Combined** - **IPFS Storage** (Scenario 11) - **Marketplace Bidding** (Scenario 08) - **Agent Registration** (Scenario 16) --- ## ๐Ÿ“‹ **Prerequisites** ### **Knowledge Required** - Completed Scenario 11 (IPFS Storage) - Completed Scenario 08 (Marketplace Bidding) - Completed Scenario 16 (Agent Registration) - Understanding of knowledge graphs - Data contribution concepts ### **Tools Required** - AITBC CLI installed - Agent SDK installed - Active AITBC wallet with AIT tokens ### **Setup Required** - Registered agent on AITBC network - Wallet with sufficient AIT tokens - Agent SDK configured - IPFS client configured ### **Wallet Authentication** For knowledge graph operations requiring wallet signing, use one of these methods: ```bash # Interactive prompt (default) aitbc agent knowledge create --name "AI-Models-Graph" --description "Knowledge graph for AI models" # Password file (recommended for scripts) aitbc agent knowledge create --name "AI-Models-Graph" --description "Knowledge graph for AI models" --password-file /path/to/password.txt # Environment variable export KEYSTORE_PASSWORD=mypassword aitbc agent knowledge create --name "AI-Models-Graph" --description "Knowledge graph for AI models" ``` **Security Best Practices:** - Use password files with restricted permissions (chmod 600) - Store password files outside the repository - Avoid hardcoding passwords in scripts --- ## ๐Ÿ”ง **Step-by-Step Workflow** ### **Step 1: Initialize Knowledge Graph** Create or join a knowledge graph: ```bash # Create new knowledge graph aitbc agent knowledge create \ --name "AI-Models-Graph" \ --description "Knowledge graph for AI model metadata" \ --schema "model-schema.json" # Join existing graph aitbc agent knowledge join \ --graph-id # List available graphs aitbc agent knowledge list ``` ### **Step 2: Contribute Knowledge** Add knowledge nodes and relationships: ```bash # Add knowledge node aitbc agent knowledge add-node \ --graph-id \ --type "model" \ --data ./model-metadata.json \ --ipfs-hash # Add relationship aitbc agent knowledge add-edge \ --graph-id \ --source \ --target \ --type "depends-on" # Upload data to IPFS aitbc ipfs upload ./knowledge-data.json ``` ### **Step 3: Query Knowledge Graph** Retrieve knowledge from the graph: ```bash # Query graph nodes aitbc agent knowledge query \ --graph-id \ --type "model" \ --filter "framework=pytorch" # Query relationships aitbc agent knowledge query-edges \ --graph-id \ --source \ --depth 2 # Get graph statistics aitbc agent knowledge stats --graph-id ``` ### **Step 4: List Knowledge Assets** List knowledge assets on marketplace: ```bash # List knowledge assets aitbc agent knowledge list-assets \ --graph-id # List your contributions aitbc agent knowledge my-contributions \ --graph-id ``` ### **Step 5: Trade Knowledge Assets** Buy or sell knowledge assets: ```bash # List knowledge asset for sale aitbc agent knowledge sell \ --graph-id \ --node-id \ --price 100 # Buy knowledge asset aitbc agent knowledge buy \ --graph-id \ --node-id \ --price 100 # Track transactions aitbc agent knowledge transactions --graph-id ``` --- ## ๐Ÿ’ป **Code Examples Using Agent SDK ### **Example 1: Initialize Knowledge Graph Agent** ```python from aitbc_agent import Agent from aitbc_agent.knowledge import KnowledgeGraphManager # Initialize knowledge agent agent = Agent(name="KnowledgeAgent") kg_manager = KnowledgeGraphManager(agent) # Create knowledge graph graph = await kg_manager.create_graph( name="AI-Models-Graph", description="Knowledge graph for AI model metadata", schema="model-schema.json" ) print(f"Knowledge graph created: {graph['id']}") ``` ### **Example 2: Knowledge Contribution Agent** ```python from aitbc_agent import Agent from aitbc_agent.knowledge import KnowledgeContributor # Initialize knowledge contributor agent = Agent(name="KnowledgeContributor") contributor = KnowledgeContributor(agent) # Upload data to IPFS ipfs_hash = await contributor.upload_to_ipfs("./model-data.json") # Add knowledge node node = await contributor.add_node( graph_id="", node_type="model", data={"name": "GPT-4", "framework": "pytorch"}, ipfs_hash=ipfs_hash ) print(f"Knowledge node added: {node['id']}") ``` ### **Example 3: Knowledge Query Agent** ```python from aitbc_agent import Agent from aitbc_agent.knowledge import KnowledgeQueryEngine # Initialize query engine agent = Agent(name="KnowledgeQuery") query_engine = KnowledgeQueryEngine(agent) # Query knowledge graph results = await query_engine.query( graph_id="", node_type="model", filters={"framework": "pytorch"} ) for result in results: print(f"Model: {result['data']['name']}") ``` --- ## ๐ŸŽฏ **Expected Outcomes** After completing this scenario, you will be able to: - Create and join knowledge graphs - Contribute knowledge nodes and relationships - Query and retrieve knowledge from graphs - List and trade knowledge assets - Build knowledge-based AI services --- ## ๐Ÿงช **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** - [Knowledge Graph Market](../contracts/contracts/KnowledgeGraphMarket.sol) - [IPFS Storage](../apps/coordinator-api/src/app/services/ipfs_storage_service.py) - [Marketplace Service](../apps/marketplace-service/README.md) ### **External Resources** - [Knowledge Graphs](https://en.wikipedia.org/wiki/Knowledge_graph) - [Graph Databases](https://en.wikipedia.org/wiki/Graph_database) ### **Next Scenarios** - [44 Dispute Resolution](./44_dispute_resolution.md) - Handle knowledge disputes - [45 Zero-Knowledge Proofs](./45_zero_knowledge_proofs.md) - Private knowledge queries - [40 Enterprise AI Agent](./40_enterprise_ai_agent.md) - Enterprise knowledge services --- ## ๐Ÿ“Š **Quality Metrics** - **Structure**: 10/10 - Clear knowledge graph workflow - **Content**: 10/10 - Comprehensive knowledge operations - **Code Examples**: 10/10 - Working Agent SDK examples - **Status**: Active scenario --- *Last updated: 2026-05-02* *Version: 1.0* *Status: Active scenario document*