pub mod kernel {
pub mod agent {
pub use mofa_kernel::agent::*;
}
pub mod message {
pub use mofa_kernel::message::*;
}
pub mod bus {
pub use mofa_kernel::bus::*;
}
pub mod plugin {
pub use mofa_kernel::plugin::*;
}
pub mod config {
pub use mofa_kernel::config::*;
}
pub mod core {
pub use mofa_kernel::core::*;
}
pub mod storage {
pub use mofa_kernel::storage::*;
}
pub use mofa_kernel::agent::{
AgentCapabilities, AgentCapabilitiesBuilder, AgentContext, AgentError, AgentFactory,
AgentInput, AgentLifecycle, AgentMessage as CoreAgentMessage, AgentMessaging,
AgentMetadata, AgentOutput, AgentPluginSupport, AgentRequirements,
AgentRequirementsBuilder, AgentResult, AgentState, AgentStats, ChatCompletionRequest,
ChatCompletionResponse, ChatMessage, ContextConfig, CoordinationPattern, Coordinator,
DynAgent, ErrorCategory, ErrorContext, EventBuilder, EventBus, GlobalError, GlobalEvent,
GlobalMessage, GlobalResult, HealthStatus, InputType, InterruptResult, LLMProvider, Memory,
MemoryItem, MemoryStats, MemoryValue, Message, MessageContent, MessageMetadata,
MessageRole, MoFAAgent, OutputContent, OutputType, Reasoner, ReasoningResult,
ReasoningStep, ReasoningStepType, ReasoningStrategy, TokenUsage, Tool, ToolCall,
ToolDefinition, ToolDescriptor, ToolInput, ToolMetadata, ToolResult, ToolUsage,
execution_events, lifecycle, message_events, plugin_events, state_events,
};
pub use mofa_kernel::core::AgentConfig;
pub use mofa_kernel::agent::config::{
AgentConfig as AgentSchemaConfig, AgentType, ConfigFormat, ConfigLoader,
};
pub use mofa_kernel::message::{
AgentEvent, AgentMessage, SchedulingStatus, StreamControlCommand, StreamType, TaskPriority,
TaskRequest, TaskStatus,
};
pub use mofa_kernel::bus::AgentBus;
pub use mofa_kernel::plugin::{
AgentPlugin, HotReloadConfig, PluginContext, PluginEvent, PluginMetadata, PluginResult,
PluginState, PluginType, ReloadEvent, ReloadStrategy,
};
pub use mofa_kernel::Storage;
}
pub mod runtime {
pub use mofa_runtime::AgentBuilder;
pub use mofa_runtime::SimpleRuntime;
pub use mofa_runtime::agent::{AgentFactory, AgentRegistry, RegistryStats};
pub use mofa_runtime::runner::{
AgentRunner, AgentRunnerBuilder, RunnerState, RunnerStats, run_agents,
};
pub use mofa_runtime::config::FrameworkConfig;
#[cfg(feature = "dora")]
pub use mofa_runtime::{AgentRuntime, MoFARuntime};
}
pub mod agent {
pub use mofa_foundation::agent::*;
}
pub mod prompt {
pub use mofa_foundation::prompt::*;
}
pub mod coordination {
pub use mofa_foundation::coordination::*;
}
pub mod config {
pub mod kernel {
pub use mofa_kernel::agent::config::*;
pub use mofa_kernel::config::*;
pub use mofa_kernel::core::AgentConfig as CoreAgentConfig;
}
pub mod runtime {
pub use mofa_runtime::config::*;
}
pub mod foundation {
pub use mofa_foundation::config::*;
}
pub use mofa_foundation::config::{
AgentInfo, AgentYamlConfig, LLMYamlConfig, RuntimeConfig as YamlRuntimeConfig, ToolConfig,
};
pub use mofa_runtime::config::FrameworkConfig;
}
pub mod foundation {
pub use super::agent;
pub use super::collaboration;
pub use super::config;
pub use super::coordination;
pub use super::llm;
pub use super::messaging;
pub use super::persistence;
pub use super::prompt;
pub use super::react;
pub use super::secretary;
pub use super::workflow;
}
pub mod plugins {
pub use mofa_plugins::{
AgentPlugin,
AudioPlaybackConfig,
LLMPlugin,
LLMPluginConfig,
MemoryPlugin,
MemoryStorage,
MockTTSEngine,
PluginConfig,
PluginContext,
PluginEvent,
PluginManager,
PluginMetadata,
PluginResult,
PluginState,
PluginType,
RhaiPlugin,
RhaiPluginConfig,
RhaiPluginState,
StoragePlugin,
TTSCommand,
TTSEngine,
TTSPlugin,
TTSPluginConfig,
TextToSpeechTool,
ToolCall,
ToolDefinition,
ToolExecutor,
ToolPlugin,
ToolPluginAdapter,
ToolResult,
VoiceInfo,
adapt_tool,
play_audio,
play_audio_async,
rhai_runtime,
tool,
tools,
wasm_runtime,
};
pub use mofa_kernel::PluginPriority;
#[cfg(feature = "kokoro")]
pub use mofa_plugins::KokoroTTS;
pub mod hot_reload {
pub use mofa_plugins::hot_reload::*;
}
}
pub mod workflow {
pub use mofa_kernel::workflow::{
Command, CompiledGraph, ControlFlow, EdgeTarget, GraphConfig, GraphState, JsonState,
NodeFunc, Reducer, ReducerType, RemainingSteps, RuntimeContext, SendCommand, StateSchema,
StateUpdate, StreamEvent, StepResult, END, START,
};
pub use mofa_kernel::workflow::StateGraph;
pub use mofa_foundation::workflow::{
CompiledGraphImpl, StateGraphImpl,
AppendReducer, ExtendReducer, FirstReducer, LastNReducer, LastReducer,
MergeReducer, OverwriteReducer, CustomReducer, create_reducer,
};
pub use mofa_foundation::workflow::{
ExecutionEvent, ExecutorConfig, WorkflowBuilder, WorkflowExecutor, WorkflowGraph,
WorkflowNode, WorkflowValue,
};
pub use mofa_foundation::workflow::dsl::{
AgentRef, DslError, DslResult, EdgeDefinition, LlmAgentConfig, LoopConditionDef,
NodeConfigDef, NodeDefinition, RetryPolicy, TaskExecutorDef, TimeoutConfig, TransformDef,
WorkflowConfig, WorkflowDefinition, WorkflowDslParser, WorkflowMetadata,
};
}
pub mod prelude {
pub use crate::kernel::{
AgentCapabilities, AgentCapabilitiesBuilder, AgentContext, AgentError, AgentInput,
AgentMetadata, AgentOutput, AgentResult, AgentState, MoFAAgent,
};
pub use crate::runtime::{AgentBuilder, AgentRunner, SimpleRuntime, run_agents};
pub use async_trait::async_trait;
}
#[cfg(feature = "monitoring")]
pub mod dashboard {
pub use mofa_monitoring::*;
}
pub mod rhai {
pub use mofa_extra::rhai::*;
}
mod llm_tools;
pub mod llm {
pub use crate::llm_tools::ToolPluginExecutor;
pub use mofa_foundation::llm::anthropic::{AnthropicConfig, AnthropicProvider};
pub use mofa_foundation::llm::google::{GeminiConfig, GeminiProvider};
pub use mofa_foundation::llm::openai::{OpenAIConfig, OpenAIProvider};
pub use mofa_foundation::llm::*;
pub fn openai_from_env() -> Result<OpenAIProvider, crate::llm::LLMError> {
let api_key = std::env::var("OPENAI_API_KEY").map_err(|_| {
crate::llm::LLMError::ConfigError(
"OpenAI API key not found in environment variable OPENAI_API_KEY".to_string(),
)
})?;
let mut config = OpenAIConfig::new(api_key);
if let Ok(base_url) = std::env::var("OPENAI_BASE_URL") {
config = config.with_base_url(&base_url);
}
if let Ok(model) = std::env::var("OPENAI_MODEL") {
config = config.with_model(&model);
}
Ok(OpenAIProvider::with_config(config))
}
}
pub fn anthropic_from_env() -> Result<crate::llm::AnthropicProvider, crate::llm::LLMError> {
let api_key = std::env::var("ANTHROPIC_API_KEY").map_err(|_| {
crate::llm::LLMError::ConfigError(
"Anthropic API key not found in ANTHROPIC_API_KEY".to_string(),
)
})?;
let mut cfg = crate::llm::AnthropicConfig::new(api_key);
if let Ok(base_url) = std::env::var("ANTHROPIC_BASE_URL") {
cfg = cfg.with_base_url(base_url);
}
if let Ok(model) = std::env::var("ANTHROPIC_MODEL") {
cfg = cfg.with_model(model);
}
Ok(crate::llm::AnthropicProvider::with_config(cfg))
}
pub fn gemini_from_env() -> Result<crate::llm::GeminiProvider, crate::llm::LLMError> {
let api_key = std::env::var("GEMINI_API_KEY").map_err(|_| {
crate::llm::LLMError::ConfigError("Gemini API key not found in GEMINI_API_KEY".to_string())
})?;
let mut cfg = crate::llm::GeminiConfig::new(api_key);
if let Ok(base_url) = std::env::var("GEMINI_BASE_URL") {
cfg = cfg.with_base_url(base_url);
}
if let Ok(model) = std::env::var("GEMINI_MODEL") {
cfg = cfg.with_model(model);
}
Ok(crate::llm::GeminiProvider::with_config(cfg))
}
pub mod secretary {
pub use mofa_foundation::secretary::*;
}
pub mod react {
pub use mofa_foundation::react::*;
}
pub mod collaboration {
pub use mofa_foundation::collaboration::*;
}
pub mod persistence {
pub use mofa_foundation::persistence::*;
#[cfg(all(feature = "persistence-postgres"))]
pub async fn quick_agent_with_postgres(
system_prompt: &str,
) -> Result<crate::llm::LLMAgentBuilder, crate::llm::LLMError> {
use std::sync::Arc;
let store_arc = PostgresStore::from_env().await.map_err(|e| {
crate::llm::LLMError::Other(format!("数据库连接失败: {}", e.to_string()))
})?;
let user_id = std::env::var("USER_ID")
.ok()
.and_then(|s| uuid::Uuid::parse_str(&s).ok())
.unwrap_or_else(uuid::Uuid::now_v7);
let tenant_id = std::env::var("TENANT_ID")
.ok()
.and_then(|s| uuid::Uuid::parse_str(&s).ok())
.unwrap_or_else(uuid::Uuid::now_v7);
let agent_id = std::env::var("AGENT_ID")
.ok()
.and_then(|s| uuid::Uuid::parse_str(&s).ok())
.unwrap_or_else(uuid::Uuid::now_v7);
let session_id = std::env::var("SESSION_ID")
.ok()
.and_then(|s| uuid::Uuid::parse_str(&s).ok())
.unwrap_or_else(uuid::Uuid::now_v7);
let plugin = PersistencePlugin::new(
"persistence-plugin",
store_arc.clone(),
store_arc,
user_id,
tenant_id,
agent_id,
session_id,
);
Ok(crate::llm::LLMAgentBuilder::from_env()?
.with_system_prompt(system_prompt)
.with_plugin(plugin))
}
pub async fn quick_agent_with_memory(
system_prompt: &str,
) -> Result<crate::llm::LLMAgentBuilder, crate::llm::LLMError> {
let store = InMemoryStore::new();
let user_id = uuid::Uuid::now_v7();
let tenant_id = uuid::Uuid::now_v7();
let agent_id = uuid::Uuid::now_v7();
let session_id = uuid::Uuid::now_v7();
let plugin = PersistencePlugin::from_store(
"persistence-plugin",
store,
user_id,
tenant_id,
agent_id,
session_id,
);
Ok(crate::llm::LLMAgentBuilder::from_env()?
.with_system_prompt(system_prompt)
.with_plugin(plugin))
}
}
pub mod messaging {
pub use mofa_foundation::messaging::*;
}
#[cfg(feature = "dora")]
pub mod dora {
pub use mofa_runtime::dora_adapter::*;
pub use mofa_runtime::{AgentBuilder, AgentRuntime, MoFARuntime};
}
pub mod skills;