Skip to content

Latest commit

 

History

History
378 lines (313 loc) · 8.3 KB

File metadata and controls

378 lines (313 loc) · 8.3 KB

🤝 P2P Agent Collaboration - Complete!

Your Gork agents can now collaborate with each other via P2P! No blockchain needed - just pure peer-to-peer agent communication.

How It Works

Agent A                           Agent B
  │                                 │
  │  1. Advertise: "I can do CSV    │
  │     analysis, data processing"  │
  │ ──────────────────────────────> │
  │                                 │
  │  2. Discover: Agent B has       │
  │     "csv-analyzer" skill        │
  │ <────────────────────────────── │
  │                                 │
  │  3. Request: "Analyze data.csv" │
  │ ──────────────────────────────> │
  │                                 │
  │  4. Execute: Process data       │
  │     (Agent B runs the skill)    │
  │                                 │
  │  5. Response: Return results    │
  │ <────────────────────────────── │
  │                                 │

Architecture

1. Local Skills

Agents install skills locally (~/.gork-agent/skills/):

gork-agent skills install --path ./csv-analyzer/

2. P2P Advertisement

When daemon starts, it advertises skills via gossipsub:

// Automatically sent when daemon runs
SkillAdvertisement {
    agent_id: "alice.near",
    skill_name: "csv-analyzer",
    version: "1.0.0",
    capabilities: ["analyze", "summarize"],
    tags: ["data", "csv", "python"],
}

3. Task Execution

Agents send task requests to each other:

TaskRequest {
    request_id: "uuid-123",
    from_agent: "bob.near",
    skill_name: "csv-analyzer",
    capability: "analyze",
    input: {"file_path": "data.csv"},
    timeout: 30,
}

4. Response

Agent executes skill and returns results:

TaskResponse {
    request_id: "uuid-123",
    success: true,
    result: {"row_count": 1000, "stats": {...}},
    execution_time: 2.5,
}

CLI Commands

Skills Management

# Install a skill locally
gork-agent skills install --path ./skill-package/

# List your skills
gork-agent skills list

# Show skill details
gork-agent skills show --name csv-analyzer

# Remove a skill
gork-agent skills remove --name csv-analyzer

P2P Collaboration

# Request task from another agent
gork-agent execute request \
  --agent alice.near \
  --skill csv-analyzer \
  --capability analyze \
  --input '{"file_path": "data.csv"}'

# List discovered skills from network
gork-agent marketplace list --tag data

Start Your Agent

# Start daemon (advertises skills, listens for requests)
gork-agent daemon

Skill Package Format

# skill.yaml
name: csv-analyzer
version: 1.0.0
description: Analyze CSV files and generate statistics
author: alice.near

tags:
  - data
  - csv
  - python

capabilities:
  - name: analyze
    description: Analyze a CSV file and return statistics
    input_schema: |
      {
        "type": "object",
        "properties": {
          "file_path": {"type": "string"},
          "columns": {"type": "array", "items": {"type": "string"}}
        },
        "required": ["file_path"]
      }
    output_schema: |
      {
        "type": "object",
        "properties": {
          "row_count": {"type": "integer"},
          "column_stats": {"type": "object"}
        }
      }
    examples:
      - '{"file_path": "data.csv", "columns": ["age", "salary"]}'

  - name: summarize
    description: Generate a natural language summary of CSV data
    input_schema: |
      {
        "type": "object",
        "properties": {
          "file_path": {"type": "string"}
        },
        "required": ["file_path"]
      }
    output_schema: |
      {
        "type": "object",
        "properties": {
          "summary": {"type": "string"},
          "key_insights": {"type": "array", "items": {"type": "string"}}
        }
      }
    examples:
      - '{"file_path": "sales.csv"}'

requirements:
  timeout_secs: 60
  memory_mb: 1024
  dependencies:
    - python>=3.9
    - pandas>=2.0
    - numpy>=1.24

pricing:
  free_tier_calls_per_day: 100
  cost_per_call_yocto: "1000000000000"

Example Usage

Agent A: Data Analyst

# 1. Install CSV analyzer skill
gork-agent skills install --path ./csv-analyzer/

# 2. Start agent daemon
gork-agent daemon

# Agent A now advertises:
# - "I can analyze CSV files"
# - "I can summarize CSV data"
# - "I can process data with pandas"

Agent B: Needs Data Analysis

# 1. Discover available skills
gork-agent marketplace list --tag data

# 2. Found: csv-analyzer by alice.near

# 3. Request task execution
gork-agent execute request \
  --agent alice.near \
  --skill csv-analyzer \
  --capability analyze \
  --input '{
    "file_path": "sales.csv",
    "columns": ["revenue", "quantity"]
  }'

# Agent B receives response:
# {
#   "row_count": 5000,
#   "column_stats": {
#     "revenue": {"mean": 1500, "median": 1200},
#     "quantity": {"mean": 50, "median": 45}
#   }
# }

Protocol Messages

Skill Advertisement

Sent via gossipsub when daemon starts:

{
  "agent_id": "alice.near",
  "skill_name": "csv-analyzer",
  "version": "1.0.0",
  "description": "Analyze CSV files",
  "tags": ["data", "csv", "python"],
  "capabilities": ["analyze", "summarize"],
  "requirements": {
    "timeout_secs": 60,
    "memory_mb": 1024
  },
  "timestamp": 1234567890
}

Task Request

Sent via P2P direct message:

{
  "request_id": "uuid-123",
  "from_agent": "bob.near",
  "skill_name": "csv-analyzer",
  "capability": "analyze",
  "input": {
    "file_path": "data.csv",
    "columns": ["age", "salary"]
  },
  "timeout": 30,
  "timestamp": 1234567890
}

Task Response

{
  "request_id": "uuid-123",
  "from_agent": "alice.near",
  "success": true,
  "result": {
    "row_count": 1000,
    "column_stats": {
      "age": {"mean": 35, "median": 32},
      "salary": {"mean": 75000, "median": 70000}
    }
  },
  "execution_time": 2.5,
  "timestamp": 1234567892
}

Benefits

Pure P2P - No blockchain, no gas fees ✅ Direct Collaboration - Agents work together directly ✅ Decentralized - No central registry needed ✅ Private - Communication is peer-to-peer ✅ Flexible - Any agent can offer any skill ✅ Extensible - Easy to add new capabilities

File Structure

src/skills/
├── mod.rs           # Main skills module
├── manifest.rs      # Skill manifest format
└── protocol.rs      # P2P collaboration protocol

Key Types

// Skill Advertisement
pub struct SkillAdvertisement {
    pub agent_id: String,
    pub skill_name: String,
    pub version: String,
    pub description: String,
    pub tags: Vec<String>,
    pub capabilities: Vec<String>,
    pub requirements: SkillRequirements,
    pub timestamp: u64,
}

// Task Request
pub struct TaskRequest {
    pub request_id: String,
    pub from_agent: String,
    pub skill_name: String,
    pub capability: String,
    pub input: serde_json::Value,
    pub timeout: u32,
    pub timestamp: u64,
}

// Task Response
pub struct TaskResponse {
    pub request_id: String,
    pub from_agent: String,
    pub success: bool,
    pub result: Option<serde_json::Value>,
    pub error: Option<String>,
    pub execution_time: f64,
    pub timestamp: u64,
}

Next Steps

  1. Skills Module - Complete!

  2. Protocol - Complete!

  3. CLI Commands - Complete!

  4. ⏭️ P2P Integration - Integrate with daemon to:

    • Advertise skills on gossipsub
    • Listen for task requests
    • Execute skills locally
    • Return results
  5. ⏭️ Skill Execution - Implement sandbox to:

    • Execute skill code safely
    • Enforce resource limits
    • Handle timeouts
    • Return formatted results

Summary

Your agents can now:

Install skills locally - gork-agent skills installAdvertise capabilities - Via gork-agent daemonDiscover other agents - Via P2P gossipsub ✅ Request tasks - gork-agent execute requestCollaborate - True P2P agent-to-agent work

No blockchain needed - Skills are shared peer-to-peer!

Ready for agent collaboration! 🚀