# nanoclaw-java **Repository Path**: xiaoyaaimeili/nanoclaw-java ## Basic Information - **Project Name**: nanoclaw-java - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-12 - **Last Updated**: 2026-03-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # NanoClaw Java A lightweight AI assistant with container isolation - Java implementation. ## Features - **Container Isolation**: Agents run in Docker containers with filesystem isolation - **Multi-Model Support**: Support for multiple LLM providers (Anthropic, OpenAI, Alibaba Qwen, etc.) - **Multi-Channel Support**: Extensible channel system (WhatsApp, Telegram, Slack, etc.) - **Persistent Memory**: Per-group CLAUDE.md files for context - **Scheduled Tasks**: Cron, interval, and one-time task scheduling - **IPC Communication**: File-based inter-process communication ## Architecture ``` ┌──────────────────────────────────────────────────────────────────────┐ │ HOST (Java Process) │ ├──────────────────────────────────────────────────────────────────────┤ │ ┌──────────────────┐ ┌────────────────────┐ │ │ │ Channels │─────────────────▶│ SQLite Database │ │ │ │ (Self-register) │◀────────────────│ (messages.db) │ │ │ └──────────────────┘ └─────────┬──────────┘ │ │ │ │ │ ┌──────────────────┐ ┌──────────────────┐ │ │ │ │ Message Loop │ │ Scheduler Loop │ │ │ │ └────────┬─────────┘ └────────┬─────────┘ │ │ │ │ │ │ │ │ └───────────┬───────────┘ │ │ │ ▼ spawns container │ │ ├──────────────────────────────────────────────────────────────────────┤ │ CONTAINER (Docker) │ │ ┌──────────────────────────────────────────────────────────────┐ │ │ │ AGENT RUNNER (Java) │ │ │ │ - Tools: Bash, Read, Write, Edit, WebSearch, etc. │ │ │ │ - Memory: CLAUDE.md files │ │ │ └──────────────────────────────────────────────────────────────┘ │ └───────────────────────────────────────────────────────────────────────┘ ``` ## Quick Start ### 1. Build ```bash cd nanoclaw-java mvn clean package ``` ### 2. Configure Edit `application.yml`: ```yaml nanoclaw: assistant-name: Andy # 大模型配置 default-model: qwen models: - name: qwen model: qwen-plus api-key: your-dashscope-api-key base-url: https://dashscope.aliyuncs.com/compatible-mode/v1 provider: openai-compatible is-default: true ``` ### 3. Run ```bash java -jar target/nanoclaw-java-1.0.0-SNAPSHOT.jar ``` ## Model Configuration NanoClaw Java supports multiple LLM providers through a unified configuration format. ### Configuration Format ```yaml nanoclaw: default-model: # 默认使用的模型配置 models: - name: # 配置名称(自定义标识) model: # 模型标识 api-key: # API 密钥 base-url: # API 基础 URL provider: # 供应商类型 is-default: true/false # 是否为默认配置 ``` ### Supported Providers | Provider | 说明 | Base URL | |----------|------|----------| | `anthropic` | Anthropic Claude API | `https://api.anthropic.com` | | `openai` | OpenAI API | `https://api.openai.com/v1` | | `openai-compatible` | OpenAI 兼容 API(默认) | 根据供应商不同 | | `alibaba` / `qwen` / `dashscope` | 阿里云百练 | `https://dashscope.aliyuncs.com/compatible-mode/v1` | ### Example Configurations #### 阿里云百练(通义千问) ```yaml models: - name: qwen model: qwen-plus api-key: sk-xxx base-url: https://dashscope.aliyuncs.com/compatible-mode/v1 provider: openai-compatible is-default: true ``` #### Anthropic Claude ```yaml models: - name: claude model: claude-3-5-sonnet-20241022 api-key: sk-ant-xxx base-url: https://api.anthropic.com provider: anthropic is-default: true ``` #### OpenAI ```yaml models: - name: openai model: gpt-4o api-key: sk-xxx base-url: https://api.openai.com/v1 provider: openai is-default: true ``` #### DeepSeek ```yaml models: - name: deepseek model: deepseek-chat api-key: sk-xxx base-url: https://api.deepseek.com/v1 provider: openai-compatible is-default: true ``` ### Multi-Model Configuration You can configure multiple models and switch between them: ```yaml nanoclaw: default-model: qwen models: - name: qwen model: qwen-plus api-key: sk-xxx base-url: https://dashscope.aliyuncs.com/compatible-mode/v1 provider: openai-compatible is-default: true - name: claude model: claude-3-5-sonnet-20241022 api-key: sk-ant-xxx base-url: https://api.anthropic.com provider: anthropic is-default: false ``` ### Environment Variables You can use environment variables in the configuration: ```yaml models: - name: qwen api-key: ${DASHSCOPE_API_KEY:} ``` ## Container Environment Variables When a container is spawned, the following environment variables are injected: | Variable | Description | |----------|-------------| | `LLM_MODEL_NAME` | Model identifier (e.g., `qwen-plus`) | | `LLM_BASE_URL` | API endpoint (proxied through CredentialProxy) | | `LLM_API_KEY` | Placeholder (actual key managed by CredentialProxy) | | `LLM_PROVIDER` | Provider type (e.g., `openai-compatible`) | | `LLM_MODEL_CONFIG_NAME` | Configuration name (e.g., `qwen`) | For backward compatibility with Anthropic: | Variable | Description | |----------|-------------| | `ANTHROPIC_BASE_URL` | Same as `LLM_BASE_URL` (when provider is `anthropic`) | | `ANTHROPIC_API_KEY` | Same as `LLM_API_KEY` | ## Project Structure ``` nanoclaw-java/ ├── src/main/java/ai/nanoclaw/ │ ├── NanoClawApplication.java # Main entry │ ├── config/ │ │ └── NanoClawConfig.java # Configuration │ ├── model/ │ │ ├── Message.java # Message model │ │ ├── RegisteredGroup.java # Group model │ │ ├── ScheduledTask.java # Task model │ │ ├── ContainerInput.java # Container input │ │ └── ContainerOutput.java # Container output │ ├── channel/ │ │ ├── Channel.java # Channel interface │ │ ├── ChannelFactory.java # Factory interface │ │ ├── ChannelRegistry.java # Registry │ │ └── impl/ │ │ ├── ConsoleChannel.java # Console implementation │ │ └── TelegramChannelFactory.java │ ├── db/ │ │ └── Database.java # SQLite operations │ ├── container/ │ │ └── ContainerRunner.java # Docker execution │ ├── ipc/ │ │ └── IpcWatcher.java # IPC communication │ ├── scheduler/ │ │ └── TaskScheduler.java # Task scheduling │ ├── router/ │ │ └── MessageRouter.java # Message routing │ ├── queue/ │ │ └── GroupQueue.java # Message queue │ └── core/ │ └── Orchestrator.java # Main controller └── src/main/resources/ └── application.yml ``` ## Adding a New Channel 1. Implement `Channel` interface: ```java public class MyChannel implements Channel { @Override public String getName() { return "mychannel"; } @Override public void connect() { /* ... */ } @Override public void sendMessage(String jid, String text) { /* ... */ } // ... other methods } ``` 2. Create factory and register: ```java @Component public class MyChannelFactory implements ChannelFactory { @PostConstruct public void register() { registry.registerChannel("mychannel", this); } @Override public Channel create(ChannelOpts opts) { if (!hasCredentials()) return null; return new MyChannel(opts); } } ``` ## License MIT