Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

功能标志

MoFA 使用功能标志来控制构建中包含哪些功能。

核心功能

功能默认描述
default基本智能体功能
openaiOpenAI 提供商支持
anthropicAnthropic 提供商支持
uniffi跨语言绑定
python原生 Python 绑定 (PyO3)

持久化功能

功能描述
persistence启用持久化层
persistence-postgresPostgreSQL 后端
persistence-mysqlMySQL 后端
persistence-sqliteSQLite 后端

运行时功能

功能描述
doraDora-rs 分布式运行时
rhaiRhai 脚本引擎
wasmWASM 插件支持

使用功能标志

在 Cargo.toml 中

[dependencies]
# 默认功能
mofa-sdk = "0.1"

# 仅特定功能
mofa-sdk = { version = "0.1", default-features = false, features = ["openai"] }

# 多个功能
mofa-sdk = { version = "0.1", features = ["openai", "anthropic", "persistence-postgres"] }

# 所有功能
mofa-sdk = { version = "0.1", features = ["full"] }

功能组合

# 最小设置(无 LLM)
mofa-sdk = { version = "0.1", default-features = false }

# 带 OpenAI 和 SQLite 持久化
mofa-sdk = { version = "0.1", features = ["openai", "persistence-sqlite"] }

# 带 PostgreSQL 的生产设置
mofa-sdk = { version = "0.1", features = [
    "openai",
    "anthropic",
    "persistence-postgres",
    "rhai",
] }

Crate 特定功能

mofa-kernel

没有可选功能 - 始终是最小化核心。

mofa-foundation

功能描述
openaiOpenAI LLM 提供商
anthropicAnthropic LLM 提供商
persistence持久化抽象

mofa-runtime

功能描述
doraDora-rs 集成
monitoring内置监控

mofa-ffi

功能描述
uniffi通过 UniFFI 生成绑定
python通过 PyO3 的原生 Python 绑定

构建大小影响

配置二进制大小编译时间
最小(无 LLM)~5 MB
默认~10 MB中等
完整功能~20 MB

条件编译

#![allow(unused)]
fn main() {
#[cfg(feature = "openai")]
pub fn openai_from_env() -> Result<OpenAIProvider, LLMError> {
    // OpenAI 实现
}

#[cfg(feature = "persistence-postgres")]
pub async fn connect_postgres(url: &str) -> Result<PostgresStore, Error> {
    // PostgreSQL 实现
}

#[cfg(not(feature = "openai"))]
compile_error!("必须启用 OpenAI 功能才能使用 openai_from_env");
}

另见