chore: Add Chinese README and refactor NPU backend to use Unix domain sockets

- Introduced a new Chinese version of the README (README_CN.md) to provide localized documentation for AgentOS.
- Refactored the NPU bridge to utilize Unix domain sockets instead of HTTP loopback, enhancing security and performance.
- Updated the NPU backend to include a server socket configuration, ensuring proper communication over Unix sockets.
- Modified the Ntex client to support both network and Unix socket transports, improving flexibility in backend communication.
- Adjusted validation logic to enforce the use of Unix sockets for local model endpoints, rejecting loopback HTTP addresses.
- Enhanced error messages and documentation throughout the codebase to clarify the new socket-based architecture.
This commit is contained in:
emmettlu
2026-08-02 15:48:09 +08:00
parent eee7fed161
commit f863f83960
8 changed files with 1157 additions and 65 deletions
+10 -5
View File
@@ -7,7 +7,10 @@ use agentos_inference::{
};
use agentos_kernel::{ProcessCredentials, enable_no_new_privileges, kernel_info};
use agentos_memory::MemoryStore;
use agentos_npu::{CandleNpuConfig, NpuBackend, NpuProbe, inspect_candle_npu, open_candle_npu};
use agentos_npu::{
CandleNpuConfig, DEFAULT_NPU_SERVER_SOCKET, NpuBackend, NpuProbe, inspect_candle_npu,
open_candle_npu,
};
use agentos_protocol::{BackendStatus, ChatBackend};
use agentos_tools::ToolRegistry;
use agentos_tools::linux::{LinuxToolConfig, build_linux_registry};
@@ -61,6 +64,7 @@ pub struct RuntimeConfig {
pub openai_compatible_api: OpenAiCompatibleApi,
pub openai_compatible_max_retries: usize,
pub npu_bridge_command: Vec<String>,
pub npu_server_socket: PathBuf,
pub npu_candle_calbin: Option<PathBuf>,
pub npu_candle_tokenizer: Option<PathBuf>,
pub npu_candle_device_index: u8,
@@ -112,6 +116,8 @@ impl RuntimeConfig {
openai_compatible_api,
openai_compatible_max_retries: env_usize("AGENTOS_OPENAI_COMPATIBLE_MAX_RETRIES", 2)?,
npu_bridge_command: command_env("AGENTOS_NPU_BRIDGE_COMMAND"),
npu_server_socket: std::env::var_os("AGENTOS_NPU_SERVER_SOCKET")
.map_or_else(|| PathBuf::from(DEFAULT_NPU_SERVER_SOCKET), PathBuf::from),
npu_candle_calbin: std::env::var_os("AGENTOS_NPU_CALBIN").map(PathBuf::from),
npu_candle_tokenizer: std::env::var_os("AGENTOS_NPU_TOKENIZER").map(PathBuf::from),
npu_candle_device_index: env_u8("AGENTOS_NPU_DEVICE_INDEX", 0)?,
@@ -266,6 +272,7 @@ pub fn doctor(config: &RuntimeConfig) -> Result<DoctorReport, RuntimeError> {
config.npu_bridge_command.clone(),
config.model_timeout,
probe.clone(),
config.npu_server_socket.clone(),
);
backends.push(npu_backend.status());
backends.push(candle_npu_status(config));
@@ -303,6 +310,7 @@ fn build_backend(config: &RuntimeConfig) -> Result<Arc<dyn ChatBackend>, Runtime
config.npu_bridge_command.clone(),
config.model_timeout,
npu_probe(config),
config.npu_server_socket.clone(),
));
let subprocess: Arc<dyn ChatBackend> = Arc::new(SubprocessBackend {
name: "subprocess".into(),
@@ -329,11 +337,8 @@ fn build_backend(config: &RuntimeConfig) -> Result<Arc<dyn ChatBackend>, Runtime
{
return Ok(Arc::new(openai_compatible));
}
if subprocess.status().ready {
return Ok(subprocess);
}
Err(RuntimeError::BackendUnavailable(
"no NPU, OpenAI-compatible, or subprocess backend is ready; use --fake-model only for tests".into(),
"no NPU or remote OpenAI-compatible backend is ready; local deployed models must use a Unix domain socket, and subprocess/fake backends are explicit test adapters".into(),
))
}
}