Skip to content

A data-driven registry and operator-based specification for normalizing AI models. Decouple providers from your code with a unified, versioned manifest.

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

hiddenpath/ai-protocol

AI-Protocol: Data-State Rulebook

AI-Protocol is a provider-agnostic specification for all AI models, standardizing how we interact with intelligence, regardless of modality (text, vision, audio, video). We decouple the "data-state rulebook" from the "language-state runtime" to provide unified infrastructure for the AI ecosystem.

We complement standards like MCP by providing a declarative runtime for raw API normalization. While MCP focuses on high-level protocols for tool calling and context management, AI-Protocol focuses on standardizing and normalizing low-level API calls, enabling runtimes to uniformly handle APIs from different providers.

🎯 Project Vision

  • Data-State Rulebook: Focuses on defining standardized interfaces and behavioral norms for AI models
  • Language-State Runtime: Focuses on implementing efficient, scalable AI model runtimes (like ai-lib)
  • Ecosystem Decoupling: Protocol specifications are separated from implementations, supporting unified ecosystems across multiple languages and frameworks
  • Provider-Agnostic: Unifies APIs from different AI providers, enabling true cross-provider interoperability
  • Cross-Modality Support: Standardizes interactions across text, vision, audio, video, and other modalities

πŸ“ Project Structure

ai-protocol/
β”œβ”€β”€ schemas/                    # JSON Schema validation specifications
β”‚   └── v1.json                # v1.x stable version Schema
β”œβ”€β”€ v1/                        # v1.x stable version specification
β”‚   β”œβ”€β”€ spec.yaml              # Basic specifications: standard parameters, event enumeration
β”‚   β”œβ”€β”€ providers/             # Provider configurations (split by vendor for easy PR)
β”‚   β”‚   β”œβ”€β”€ openai.yaml        # OpenAI compatible interface
β”‚   β”‚   β”œβ”€β”€ anthropic.yaml     # Anthropic Claude interface
β”‚   β”‚   β”œβ”€β”€ gemini.yaml        # Google Gemini interface
β”‚   β”‚   β”œβ”€β”€ groq.yaml          # Groq compatible interface
β”‚   β”‚   β”œβ”€β”€ deepseek.yaml      # DeepSeek compatible interface
β”‚   β”‚   β”œβ”€β”€ qwen.yaml          # Qwen (DashScope) compatible interface
β”‚   β”‚   └── ...                # More providers
β”‚   └── models/                # Model instance registry
β”‚       β”œβ”€β”€ gpt.yaml           # GPT series models
β”‚       β”œβ”€β”€ claude.yaml        # Claude series models
β”‚       └── ...                # More models
β”œβ”€β”€ v2-alpha/                  # v2-alpha experimental version: multimodal and real-time features
β”‚   β”œβ”€β”€ spec.yaml              # Experimental operator definitions
β”‚   └── providers/             # Experimental provider configurations
β”œβ”€β”€ examples/                  # Configuration examples
β”‚   └── tool_accumulation.yaml # Tool accumulation pattern example
β”œβ”€β”€ research/                  # Research documents (official API excerpts and verification)
β”‚   └── providers/             # Provider-specific official documentation research
β”‚       β”œβ”€β”€ openai.md          # OpenAI official API rules (VERIFIED)
β”‚       β”œβ”€β”€ anthropic.md       # Anthropic official API rules (VERIFIED)
β”‚       β”œβ”€β”€ gemini.md          # Gemini official API rules (VERIFIED)
β”‚       └── ...                # More provider research
└── scripts/                   # Maintenance scripts

πŸ“¦ Release Packaging Policy (What gets published)

To avoid publishing work/discussion/internal documents by default, release archives SHOULD exclude:

  • research/
  • scripts/
  • v2-alpha/

The normative, publish-ready artifacts are:

  • schemas/
  • v1/ (spec + providers + models)
  • examples/
  • README.md, LICENSE-*, CHANGELOG.md

πŸ”§ Core Concepts

1. Operator-based Design

AI-Protocol standardizes AI model behavior through the concept of operators:

  • Parameter Operators: Standardized parameter mapping (temperature, max_tokens, stream, etc.)
  • Event Operators: Standardized streaming events (PartialContentDelta, ToolCallStarted, StreamError, etc.)
  • Capability Operators: Standardized capability declarations (chat, vision, tools, streaming, multimodal, etc.)
  • Error Handling Operators: Standardized error classification, rate limiting, and retry strategies (error_classification, retry_policy, rate_limit_headers)

2. Version Isolation

  • v1.x: Production environment stable version, supporting current mainstream AI models
  • v2-alpha: Experimental version, exploring multimodal streams, real-time instructions, and other cutting-edge features
  • Schema Constraints: Every configuration file is strictly validated through JSON Schema

3. Modular Maintenance

  • Provider Independence: Each AI provider's configuration is maintained independently, facilitating community contributions
  • Model Registration: Model instances are registered as configuration files referencing provider definitions
  • PR Friendly: Modifying a single provider won't affect other configurations

πŸš€ Quick Start

1. Provider Configuration Example

# v1/providers/anthropic.yaml
$schema: "https://github.com/hiddenpath/ai-protocol/tree/main/schemas/v1.json"

id: anthropic
protocol_version: "1.1"

streaming:
  decoder:
    format: "sse"
    strategy: "anthropic_event_stream"

  event_map:
    - match: { "path": "$.type", "op": "eq", "value": "content_block_delta" }
      emit: "PartialContentDelta"
      extract:
        content: "$.delta.text"

2. Error Handling and Rate Limiting Example

# v1/providers/openai.yaml (excerpt)
error_classification:
  by_http_status:
    "400": "invalid_request"
    "401": "authentication"
    "429": "rate_limited"  # Could be rate limit or quota exhausted
    "500": "server_error"

rate_limit_headers:
  requests_limit: "x-ratelimit-limit-requests"
  requests_remaining: "x-ratelimit-remaining-requests"
  retry_after: null  # OpenAI doesn't use standard Retry-After

retry_policy:
  strategy: "exponential_backoff"
  min_delay_ms: 1000
  jitter: "full"
  retry_on_http_status: [429, 500]
  notes:
    - "429 may be rate limit or quota exhausted; runtimes should inspect error messages"

3. Model Registration Example

# v1/models/claude.yaml
$schema: "https://github.com/hiddenpath/ai-protocol/tree/main/schemas/v1.json"

models:
  claude-3-5-sonnet:
    provider: anthropic
    model_id: "claude-3-5-sonnet-20241022"
    context_window: 200000
    capabilities: [chat, vision, tools, streaming, agentic, reasoning]
    pricing:
      input_per_token: 0.000003
      output_per_token: 0.000015

4. Runtime Integration

// Dynamic loading example in ai-lib
use ai_protocol::{ProtocolRegistry, ProviderConfig};

let registry = ProtocolRegistry::new();
let provider = registry.load_provider("anthropic").await?;
let model = registry.get_model("claude-3-5-sonnet").await?;

πŸ“‹ Validation and Testing

# Run JSON Schema validation
npm install -g ajv-cli
ajv validate -s schemas/v1.json -d "v1/providers/*.yaml"

# Run compatibility tests
cargo test --package ai-protocol-validation

Validation scripts are also available in scripts/validate-configs.sh.

πŸ›£οΈ Roadmap

v1.x (Current Stable)

  • βœ… Mainstream AI provider support (OpenAI, Anthropic, Gemini, Groq, DeepSeek, Qwen)
  • βœ… Standardized parameters and event normalization
  • βœ… Tool calling and streaming response support
  • βœ… JSON Schema constraints
  • βœ… Error handling and classification standardization (error_classification, 13 standard error classes)
  • βœ… Rate limiting and retry policy standardization (rate_limit_headers, retry_policy)
  • βœ… API family declarations (api_families, endpoints) to avoid request/response model confusion
  • βœ… Termination reason normalization (termination_reasons) unified across providers

v2-alpha (Experimental In Progress)

  • πŸ”„ Multimodal stream interleaving (FrameInterleave operator)
  • πŸ”„ Real-time instructions (StateSync operator)
  • πŸ”„ Schema-less mapping (Schema-less Mapping)
  • πŸ”„ Advanced tool accumulation patterns

v2.x (Future Plans)

  • πŸ“… Audio/video streaming processing
  • πŸ“… Real-time collaborative sessions
  • πŸ“… Model switching and migration
  • πŸ“… Performance monitoring and QoS

🀝 Contribution Guide

Adding New Providers

  1. Create a new file under v1/providers/ (e.g., new-provider.yaml)
  2. Follow JSON Schema specifications (schemas/v1.json)
  3. Add official documentation research under research/providers/ (new-provider.md) with VERIFIED evidence
  4. Add corresponding model configurations under v1/models/
  5. Submit PR with test cases and validation results

All configurations are hosted in this repository, where community contributions follow the same version control and validation process as official configurations.

Adding New Operators

  1. Define new operators in the corresponding version's spec.yaml
  2. Update JSON Schema
  3. Implement operator logic in runtime
  4. Add example configurations

πŸ“„ License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.

πŸ”— Related Projects

Note: AI-Protocol itself already includes configuration registry functionality. Community contributions for new provider configurations and model registrations can be submitted directly via PRs to this repository's v1/providers/ and v1/models/ directories, without needing a separate configuration repository.


AI-Protocol abstracts the complexity of AI models into standardized protocols, allowing developers to focus on business logic rather than provider adaptation.

About

A data-driven registry and operator-based specification for normalizing AI models. Decouple providers from your code with a unified, versioned manifest.

Topics

Resources

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published