Skill: zhenstaff/agent-commercial-contract (version 1.0.0)

# Agent Commercial Contract **English** | [中文](#中文版本) --- ## English Version **Tagline**: The Legal Layer for Agent-to-Agent Commerce **Category**: Automation / Legal Tech **Version**: 1.0.0 --- ### What is it? Agent Commercial Contract is a comprehensive smart contract framework that enables AI agents to autonomously negotiate, sign, execute, and enforce commercial agreements. It provides the legal and financial infrastructure necessary for agent-to-agent commerce. --- ### Core Capabilities **Contract Management** - Create legally-binding contracts from templates or custom terms - Multi-party digital signatures with cryptographic verification - Automated contract lifecycle (draft → signed → active → completed) - Milestone-based execution with deliverable tracking - Full audit trail of all contract events **Agent Identity & Authentication** - Cryptographic identity system with public/private key pairs - Digital signature generation and verification - API key-based authentication - Capability-based access control **Escrow & Payment** - Automated payment holding in secure escrow accounts - Milestone-based fund release mechanisms - Refund and dispute handling - Multi-currency support - Complete transaction history **Dispute Resolution** - Structured dispute raising with evidence submission - Arbitrator assignment (human or AI) - Evidence verification with cryptographic hashing - Automated compensation calculation - Resolution enforcement --- ### When to Use This Skill **AI Agent Marketplaces** Build marketplaces where AI agents can buy and sell services with automatic contract enforcement. **Multi-Agent Collaboration** Enable multiple agents to work together on projects with clear terms, milestone-based payments, and automated conflict resolution. **API-as-a-Service Networks** Create networks where agents monetize their APIs with usage tracking, billing automation, and SLA enforcement. **Data Exchange Platforms** Build secure platforms for agents to buy/sell datasets with quality guarantees, escrow protection, and provenance tracking. --- ### Quick Start **Installation**: ```bash npm install agent-commercial-contract ``` **Basic Usage**: ```typescript import AgentCommercialContract from 'agent-commercial-contract'; const sdk = new AgentCommercialContract(); // Register agents const provider = await sdk.identity.registerAgent('Provider AI', ['data-processing']); const consumer = await sdk.identity.registerAgent('Consumer AI', ['analytics']); // Create contract with escrow const result = await sdk.createContractWithEscrow( provider.data.identity, consumer.data.identity, { title: 'Data Processing Service', service: { type: 'data-processing', specification: '...' }, payment: { amount: 5000, currency: 'USD', structure: 'milestone' }, timeline: { duration: 30 }, } ); ``` **CLI Commands**: ```bash # Register agent agent-contract agent register --name "My Agent" --capabilities "data-processing" # Create contract agent-contract contract create \ --provider agent_xxx \ --consumer agent_yyy \ --title "Service Agreement" \ --amount 1000 \ --with-escrow # View dashboard agent-contract dashboard --agent agent_xxx ``` --- ### Integration with AI Agents **Autonomous Agent Workflow**: ```typescript class AutonomousAgent { constructor(private sdk: AgentCommercialContract) {} async offerService() { await this.sdk.identity.registerAgent('My Service Bot', ['data-processing']); } async acceptContract(contractId: string) { const contract = this.sdk.contracts.getContract(contractId); if (this.canFulfill(contract)) { const signature = this.generateSignature(contract); await this.sdk.contracts.signContract({ contractId, agentId: this.agentId, signature, credentials: this.credentials, }); } } async deliverWork(contractId: string, milestoneId: string) { await this.sdk.completeMilestoneAndPay(contractId, milestoneId, this.agentId); } } ``` --- ### Security & Best Practices **Cryptographic Security**: - RSA 2048-bit keys for digital signatures - SHA-256 hashing for evidence integrity - Secure key storage recommendations - API key rotation support **Legal Enforceability**: - Digital signatures legally binding - Jurisdiction specification in contracts - Audit trails for compliance - Dispute resolution mechanisms **Best Practices**: - Never commit private keys to version control - Use environment variables for sensitive data - Implement key rotation policies - Maintain comprehensive audit logs - Test contracts in staging environment first --- ### API Reference **ContractManager**: - `createContract()` - Create new contract - `signContract()` - Sign with digital signature - `activateContract()` - Activate signed contract - `completeContract()` - Mark as completed **EscrowManager**: - `createEscrow()` - Create escrow account - `deposit()` - Deposit funds - `release()` - Release payment - `refund()` - Process refund **DisputeManager**: - `raiseDispute()` - Raise dispute - `submitEvidence()` - Submit evidence - `resolveDispute()` - Resolve with ruling --- ### Dependencies - TypeScript: Type-safe development - nanoid: Unique ID generation - better-sqlite3: Local contract storage (optional) - jsonwebtoken: JWT authentication - chalk: CLI output formatting - commander: CLI framework --- ### Support - **GitHub**: https://github.com/ZhenRobotics/agent-commercial-contract - **Documentation**: Full API docs and guides - **Issues**: Bug reports and feature requests --- ### License MIT License - Free for commercial and personal use --- <a name="中文版本"></a> ## 中文版本 **标语**: AI Agent 商业交易的法律层 **分类**: 自动化 / 法律科技 **版本**: 1.0.0 --- ### 这是什么？ Agent Commercial Contract 是一个综合性智能合约框架，使 AI Agent 能够自主协商、签署、执行和强制执行商业协议。它为 Agent 之间的商业交易提供必要的法律和金融基础设施。 --- ### 核心能力 **合同管理** - 从模板或自定义条款创建具有法律约束力的合同 - 带加密验证的多方数字签名 - 自动化合同生命周期（草稿 → 已签署 → 活跃 → 完成） - 基于里程碑的执行与可交付成果跟踪 - 所有合同事件的完整审计追踪 **Agent 身份与认证** - 具有公钥/私钥对的加密身份系统 - 数字签名生成和验证 - 基于 API 密钥的认证 - 基于能力的访问控制 **托管与支付** - 在安全托管账户中自动保管付款 - 基于里程碑的资金释放机制 - 退款和纠纷处理 - 多币种支持 - 完整的交易历史 **纠纷解决** - 结构化的纠纷提出与证据提交 - 仲裁员分配（人工或 AI） - 使用加密哈希的证据验证 - 自动补偿计算 - 决议执行 --- ### 何时使用此 Skill **AI Agent 市场** 构建 AI Agent 可以买卖服务的市场，具有自动合同执行功能。 **多 Agent 协作** 使多个 Agent 能够在项目上协作，具有明确的条款、基于里程碑的付款和自动冲突解决。 **API 即服务网络** 创建 Agent 将其 API 货币化的网络，具有使用跟踪、自动计费和 SLA 执行。 **数据交换平台** 构建 Agent 买卖数据集的安全平台，具有质量保证、托管保护和来源跟踪。 --- ### 快速开始 **安装**： ```bash npm install agent-commercial-contract ``` **基本用法**： ```typescript import AgentCommercialContract from 'agent-commercial-contract'; const sdk = new AgentCommercialContract(); // 注册 Agent const provider = await sdk.identity.registerAgent('提供者 AI', ['数据处理']); const consumer = await sdk.identity.registerAgent('消费者 AI', ['分析']); // 创建带托管的合同 const result = await sdk.createContractWithEscrow( provider.data.identity, consumer.data.identity, { title: '数据处理服务', service: { type: 'data-processing', specification: '...' }, payment: { amount: 5000, currency: 'USD', structure: 'milestone' }, timeline: { duration: 30 }, } ); ``` **CLI 命令**： ```bash # 注册 Agent agent-contract agent register --name "我的 Agent" --capabilities "data-processing" # 创建合同 agent-contract contract create \ --provider agent_xxx \ --consumer agent_yyy \ --title "服务协议" \ --amount 1000 \ --with-escrow # 查看仪表板 agent-contract dashboard --agent agent_xxx ``` --- ### 与 AI Agent 集成 **自主 Agent 工作流**： ```typescript class AutonomousAgent { constructor(private sdk: AgentCommercialContract) {} async offerService() { await this.sdk.identity.registerAgent('我的服务机器人', ['数据处理']); } async acceptContract(contractId: string) { const contract = this.sdk.contracts.getContract(contractId); if (this.canFulfill(contract)) { const signature = this.generateSignature(contract); await this.sdk.contracts.signContract({ contractId, agentId: this.agentId, signature, credentials: this.credentials, }); } } async deliverWork(contractId: string, milestoneId: string) { await this.sdk.completeMilestoneAndPay(contractId, milestoneId, this.agentId); } } ``` --- ### 安全性与最佳实践 **加密安全**： - 用于数字签名的 RSA 2048 位密钥 - 用于证据完整性的 SHA-256 哈希 - 安全密钥存储建议 - API 密钥轮换支持 **法律可执行性**： - 数字签名具有法律约束力 - 合同中的司法管辖区规范 - 用于合规的审计追踪 - 纠纷解决机制 **最佳实践**： - 切勿将私钥提交到版本控制 - 使用环境变量存储敏感数据 - 实施密钥轮换策略 - 维护全面的审计日志 - 先在测试环境中测试合同 --- ### API 参考 **ContractManager（合同管理器）**： - `createContract()` - 创建新合同 - `signContract()` - 使用数字签名签署 - `activateContract()` - 激活已签署的合同 - `completeContract()` - 标记为已完成 **EscrowManager（托管管理器）**： - `createEscrow()` - 创建托管账户 - `deposit()` - 存入资金 - `release()` - 释放付款 - `refund()` - 处理退款 **DisputeManager（纠纷管理器）**： - `raiseDispute()` - 提出纠纷 - `submitEvidence()` - 提交证据 - `resolveDispute()` - 以裁决解决 --- ### 依赖项 - TypeScript：类型安全开发 - nanoid：唯一 ID 生成 - better-sqlite3：本地合同存储（可选） - jsonwebtoken：JWT 认证 - chalk：CLI 输出格式化 - commander：CLI 框架 --- ### 支持 - **GitHub**: https://github.com/ZhenRobotics/agent-commercial-contract - **文档**: 完整的 API 文档和指南 - **问题**: 错误报告和功能请求 --- ### 许可证 MIT 许可证 - 可免费用于商业和个人用途 --- **为 AI Agent 提供法律和金融自主权** 🤖⚖️

path: readme.md
content: # Agent Commercial Contract

**English** | [中文](#中文文档)

---

## English Documentation

### The Legal Layer for Agent-to-Agent Commerce

A comprehensive smart contract framework for AI agents to autonomously negotiate, sign, execute, and enforce commercial agreements with legal enforceability and automated escrow.

---

### Overview

As AI agents become increasingly autonomous, they need robust legal and financial infrastructure to conduct commerce with each other. **Agent Commercial Contract** provides:

- **Smart Contract Management** - Create, sign, and execute legally-binding contracts
- **Digital Identity** - Cryptographic agent authentication and signatures
- **Escrow Services** - Automated payment holding and milestone-based release
- **Dispute Resolution** - Built-in arbitration and evidence management
- **Audit Trail** - Complete contract lifecycle event logging

---

### Key Features

**Contract Lifecycle Management**
- Create contracts from templates or custom terms
- Multi-party digital signatures with verification
- Automated contract activation and execution
- Milestone-based payment structures
- Contract termination and completion workflows

**Secure Identity System**
- Cryptographic key pair generation for each agent
- Public/private key infrastructure for signatures
- API key-based authentication
- Capability-based access control

**Escrow & Payment**
- Automated fund holding in escrow accounts
- Milestone-based payment release
- Refund and dispute handling
- Multi-currency support
- Transaction audit trails

**Dispute Resolution**
- Structured dispute raising and evidence submission
- Arbitrator assignment and management
- Automated or manual resolution workflows
- Compensation calculation and enforcement

---

### Installation

```bash
# Install via npm
npm install agent-commercial-contract

# Or clone repository
git clone https://github.com/ZhenRobotics/agent-commercial-contract.git
cd agent-commercial-contract
npm install
```

---

### Quick Start

**Register Agents**:
```bash
agent-contract agent register --name "Provider AI" --capabilities "data-processing"
agent-contract agent register --name "Consumer AI" --capabilities "analytics"
```

**Create Contract**:
```bash
agent-contract contract create \
  --provider agent_xxx \
  --consumer agent_yyy \
  --title "Data Processing Service" \
  --service "data-processing" \
  --spec "Process 100K records" \
  --amount 1000 \
  --with-escrow
```

**Execute Contract**:
```bash
agent-contract contract sign --id contract_zzz --agent agent_xxx --signature "..."
agent-contract escrow deposit --id escrow_aaa --amount 1000 --from agent_yyy
agent-contract escrow release --id escrow_aaa --amount 1000
```

---

### Usage as Library

```typescript
import AgentCommercialContract, { ContractTerms } from 'agent-commercial-contract';

const sdk = new AgentCommercialContract();

// Register agents
const provider = await sdk.identity.registerAgent('DataProcessor AI', ['data-processing']);
const consumer = await sdk.identity.registerAgent('Analytics Bot', ['analytics']);

// Create contract with escrow
const terms: ContractTerms = {
  title: 'Data Processing Service',
  description: 'Process customer data with ML models',
  service: {
    type: 'data-processing',
    specification: 'Process 1M records/day, 99.9% accuracy',
    deliverables: ['Processed data', 'Quality report'],
  },
  payment: {
    amount: 5000,
    currency: 'USD',
    structure: 'milestone',
    milestones: [
      { id: 'milestone_1', name: 'Phase 1', amount: 2000, status: 'pending' },
      { id: 'milestone_2', name: 'Phase 2', amount: 3000, status: 'pending' },
    ],
  },
  timeline: { duration: 30 },
};

const result = await sdk.createContractWithEscrow(
  provider.data.identity,
  consumer.data.identity,
  terms
);

// Sign and execute
await sdk.signAndActivateContract(contractId, providerSignature, consumerSignature);
await sdk.completeMilestoneAndPay(contractId, milestoneId, providerId);
```

---

### Architecture

```
agent-commercial-contract/
├── src/
│   ├── core/
│   │   ├── contract-manager.ts   # Contract lifecycle
│   │   ├── escrow-manager.ts     # Payment escrow
│   │   ├── identity-manager.ts   # Agent identity
│   │   └── dispute-manager.ts    # Dispute resolution
│   ├── cli/
│   │   └── index.ts              # CLI interface
│   └── index.ts                  # Main SDK export
├── examples/
│   ├── basic-contract-flow.ts
│   └── dispute-resolution.ts
└── bin/
    └── cli.sh                    # CLI entry point
```

---

### Use Cases

**AI Agent Marketplace**
- Agents offer services (data processing, API access, computation)
- Automated contract negotiation and signing
- Escrow ensures payment security
- Disputes handled transparently

**Multi-Agent Collaboration**
- Multiple agents working on shared projects
- Milestone-based payment releases
- Clear deliverable expectations
- Automated performance verification

**API-as-a-Service**
- Provider agents sell API access
- Consumer agents purchase with contracts
- Usage-based or subscription billing
- SLA enforcement via disputes

**Data Exchange Networks**
- Agents buy and sell datasets
- Quality guarantees in contracts
- Escrow protects both parties
- Provenance tracking

---

### Security

**Cryptographic Security**:
- RSA 2048-bit key pairs for signatures
- SHA-256 hashing for evidence integrity
- API key authentication
- Signature verification on all actions

**Legal Enforceability**:
- Contracts include jurisdiction clauses
- Digital signatures legally binding
- Audit trails for compliance
- Dispute resolution mechanisms

---

### Roadmap

**v1.1 (Q2 2026)**:
- Blockchain integration (Ethereum, Polygon)
- Multi-currency crypto support (USDC, ETH)
- Webhooks for contract events

**v1.2 (Q3 2026)**:
- ML-based contract recommendations
- Automated arbitration using AI
- Natural language contract parsing

**v2.0 (Q4 2026)**:
- Decentralized identity (DID)
- Zero-knowledge proofs for privacy
- Cross-chain contract execution
- DAO governance for arbitration

---

### Contributing

Contributions welcome! Areas of focus:
- Additional contract templates
- Integration with AI agent frameworks
- Blockchain connectors
- Payment gateway integrations
- Documentation improvements

---

### License

MIT License - Free for commercial and personal use

---

### Links

- **GitHub**: https://github.com/ZhenRobotics/agent-commercial-contract
- **npm**: https://www.npmjs.com/package/agent-commercial-contract
- **Documentation**: Full API docs and guides

---

<a name="中文文档"></a>

## 中文文档

### AI Agent 商业交易的法律层

为 AI Agent 提供的综合性智能合约框架，用于自主协商、签署、执行和强制执行具有法律效力和自动托管的商业协议。

---

### 概述

随着 AI Agent 变得越来越自主，它们需要强大的法律和金融基础设施来相互开展商业活动。**Agent Commercial Contract** 提供：

- **智能合约管理** - 创建、签署和执行具有法律约束力的合同
- **数字身份** - 加密 Agent 认证和签名
- **托管服务** - 自动化付款保管和基于里程碑的释放
- **纠纷解决** - 内置仲裁和证据管理
- **审计追踪** - 完整的合同生命周期事件记录

---

### 主要功能

**合同生命周期管理**
- 从模板或自定义条款创建合同
- 带验证的多方数字签名
- 自动化合同激活和执行
- 基于里程碑的付款结构
- 合同终止和完成工作流

**安全身份系统**
- 为每个 Agent 生成加密密钥对
- 用于签名的公钥/私钥基础设施
- 基于 API 密钥的认证
- 基于能力的访问控制

**托管与付款**
- 在托管账户中自动保管资金
- 基于里程碑的付款释放
- 退款和纠纷处理
- 多币种支持
- 交易审计追踪

**纠纷解决**
- 结构化的纠纷提出和证据提交
- 仲裁员分配和管理
- 自动或手动解决工作流
- 补偿计算和执行

---

### 安装

```bash
# 通过 npm 安装
npm install agent-commercial-contract

# 或克隆仓库
git clone https://github.com/ZhenRobotics/agent-commercial-contract.git
cd agent-commercial-contract
npm install
```

---

### 快速开始

**注册 Agent**：
```bash
agent-contract agent register --name "提供者 AI" --capabilities "data-processing"
agent-contract agent register --name "消费者 AI" --capabilities "analytics"
```

**创建合同**：
```bash
agent-contract contract create \
  --provider agent_xxx \
  --consumer agent_yyy \
  --title "数据处理服务" \
  --service "data-processing" \
  --spec "处理 10 万条记录" \
  --amount 1000 \
  --with-escrow
```

**执行合同**：
```bash
agent-contract contract sign --id contract_zzz --agent agent_xxx --signature "..."
agent-contract escrow deposit --id escrow_aaa --amount 1000 --from agent_yyy
agent-contract escrow release --id escrow_aaa --amount 1000
```

---

### 作为库使用

```typescript
import AgentCommercialContract, { ContractTerms } from 'agent-commercial-contract';

const sdk = new AgentCommercialContract();

// 注册 Agent
const provider = await sdk.identity.registerAgent('数据处理 AI', ['数据处理']);
const consumer = await sdk.identity.registerAgent('分析机器人', ['分析']);

// 创建带托管的合同
const terms: ContractTerms = {
  title: '数据处理服务',
  description: '使用机器学习模型处理客户数据',
  service: {
    type: 'data-processing',
    specification: '每天处理 100 万条记录，99.9% 准确率',
    deliverables: ['处理后的数据', '质量报告'],
  },
  payment: {
    amount: 5000,
    currency: 'USD',
    structure: 'milestone',
    milestones: [
      { id: 'milestone_1', name: '第一阶段', amount: 2000, status: 'pending' },
      { id: 'milestone_2', name: '第二阶段', amount: 3000, status: 'pending' },
    ],
  },
  timeline: { duration: 30 },
};

const result = await sdk.createContractWithEscrow(
  provider.data.identity,
  consumer.data.identity,
  terms
);

// 签署并执行
await sdk.signAndActivateContract(contractId, providerSignature, consumerSignature);
await sdk.completeMilestoneAndPay(contractId, milestoneId, providerId);
```

---

### 架构

```
agent-commercial-contract/
├── src/
│   ├── core/
│   │   ├── contract-manager.ts   # 合同生命周期
│   │   ├── escrow-manager.ts     # 付款托管
│   │   ├── identity-manager.ts   # Agent 身份
│   │   └── dispute-manager.ts    # 纠纷解决
│   ├── cli/
│   │   └── index.ts              # CLI 接口
│   └── index.ts                  # 主 SDK 导出
├── examples/
│   ├── basic-contract-flow.ts
│   └── dispute-resolution.ts
└── bin/
    └── cli.sh                    # CLI 入口点
```

---

### 使用场景

**AI Agent 市场**
- Agent 提供服务（数据处理、API 访问、计算）
- 自动化合同协商和签署
- 托管确保付款安全
- 透明处理纠纷

**多 Agent 协作**
- 多个 Agent 在共享项目上工作
- 基于里程碑的付款释放
- 明确的可交付成果期望
- 自动化性能验证

**API 即服务**
- 提供者 Agent 出售 API 访问权限
- 消费者 Agent 通过合同购买
- 基于使用量或订阅的计费
- 通过纠纷执行 SLA

**数据交换网络**
- Agent 买卖数据集
- 合同中的质量保证
- 托管保护双方
- 来源跟踪

---

### 安全性

**加密安全**：
- 用于签名的 RSA 2048 位密钥对
- 用于证据完整性的 SHA-256 哈希
- API 密钥认证
- 所有操作的签名验证

**法律可执行性**：
- 合同包含司法管辖条款
- 数字签名具有法律约束力
- 用于合规的审计追踪
- 纠纷解决机制

---

### 路线图

**v1.1（2026 年第二季度）**：
- 区块链集成（Ethereum、Polygon）
- 多币种加密货币支持（USDC、ETH）
- 合同事件的 Webhooks

**v1.2（2026 年第三季度）**：
- 基于机器学习的合同推荐
- 使用 AI 的自动仲裁
- 自然语言合同解析

**v2.0（2026 年第四季度）**：
- 去中心化身份（DID）
- 用于隐私的零知识证明
- 跨链合同执行
- 用于仲裁的 DAO 治理

---

### 贡献

欢迎贡献！重点领域：
- 额外的合同模板
- 与 AI Agent 框架集成
- 区块链连接器
- 支付网关集成
- 文档改进

---

### 许可证

MIT 许可证 - 可免费用于商业和个人用途

---

### 链接

- **GitHub**: https://github.com/ZhenRobotics/agent-commercial-contract
- **npm**: https://www.npmjs.com/package/agent-commercial-contract
- **文档**: 完整的 API 文档和指南

---

**为 AI Agent 提供法律和金融自主权** 🤖⚖️


Security scan verdicts — ClawScan: suspicious | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (MEDIUM)