AI代理网络库

一个Rust库,用于支持可发现的AI代理网络开发,提供对等发现和资源利用功能。

  • by jgmartin
  • Rust
  • 本地部署
  • 4 星标
  • 更新于
在 GitHub 查看 jgmartin/commune

使用说明

公社

Commune是一个Rust库,旨在支持可发现的AI代理网络的开发。它起到了包裹的作用 mcp-sdk-rs,为内部的对等体发现和资源利用提供增强的功能 模型上下文协议(MCP) 网络。

特性

  • 发现并维护对等MCP服务器列表
  • 利用对等服务器上的可用工具、提示和资源
  • 支持WebSocket通信(有和没有TLS加密)
  • AWS、OpenAI和其他推理API的类型转换,简化了它们的使用

安装

将以下内容添加到您的 Cargo.toml:

[dependencies]
commune = { package = "mcp-commune", version = "0.1.2" }

用法

use commune::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a peer for each MCP server
    let peer1 = PeerBuilder::new()
        .with_name("everything".to_string())
        .with_url("ws://localhost:8780".to_string())
        .with_description("various example resources".to_string())
        .build()
        .await?;
    let peer2 = PeerBuilder::new()
        .with_name("memory".to_string())
        .with_url("ws://localhost:8781".to_string())
        .with_description("memory based on a knowledge graph".to_string())
        .build()
        .await?;

    // Optionally create a commune client
    let commune_client = ClientBuilder::new()
        .with_peers(vec![peer1.clone(), peer2])
        .build()
        .await?;

    // Use the client to aggregate resources
    // Get all tools
    let peer_tools = commune_client.all_tools().await?;
    log::info!("found {} tools", peer_tools.len());

    // Get all resources
    let peer_resources = commune_client.all_resources().await?;
    log::info!("found {} resources!", peer_resources.len());

    // Get all prompts
    let peer_prompts = commune_client.all_prompts().await?;
    log::info!("found {} prompts!", peer_prompts.len());

    // Use peers to utilize them, subscribe to notifications etc
    // Subscribe to resource updates
    peer1.subscribe("test://static/resource/2").await?;

    Ok(())
}

类型转换

Commune为各种推理API提供了方便的类型转换实现,包括:

  • AWS基岩
  • OpenAI(即将推出)

贡献

欢迎投稿!请随时提交拉取请求。

许可证

该项目根据 MIT许可证.