Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ WORKSPACE_BASE_PATH=./data
# Configuration (For Seed — dev only, used by `prisma db seed`)
DEFAULT_PASSWORD=password1234

# DEFAULT_PROVIDER options: anthropic, openai, zai-coding, or any custom provider id.
# DEFAULT_PROVIDER options: anthropic, openai, zai-coding, deepseek, or any custom provider id.
DEFAULT_PROVIDER=openai
DEFAULT_LLM_MODEL=gpt-4o

Expand All @@ -97,6 +97,7 @@ DEFAULT_LLM_MODEL=gpt-4o
# ANTHROPIC_API_KEY=
# OPENAI_API_KEY=
# ZAI_CODING_API_KEY=
# DEEPSEEK_API_KEY=

# Custom provider (optional — any OpenAI-compatible Chat Completions endpoint).
# Set ALL of NAME / BASE_URL / API_KEY to enable. NAME is used as the DB key
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Most AI agent frameworks are either **toys** (single-process, no isolation, no a
Clawix sits in between: **production-grade orchestration you own entirely.**

- **Every agent runs in its own Docker container** -- no agent can read another's files, exhaust your host's memory, or escape its sandbox.
- **Plug in any LLM** -- Claude and GPT-4 today, with Azure, DeepSeek, Gemini, and OpenRouter coming soon. Any OpenAI-compatible endpoint (Ollama, vLLM, etc.) works now via the custom provider.
- **Plug in any LLM** -- Claude, GPT, DeepSeek, and Gemini today, with Azure and OpenRouter coming soon. Any OpenAI-compatible endpoint (Ollama, vLLM, etc.) works now via the custom provider.
- **Built for teams** -- RBAC, token budgets, audit logs, and scoped memory mean you can hand agents to your whole org without losing sleep.
- **Reach users where they are** -- Telegram, WhatsApp, Slack, and a built-in web dashboard. One agent, many channels.

Expand Down Expand Up @@ -55,7 +55,7 @@ Break complex tasks into sub-agent DAGs. The coordinator delegates, aggregates r

### Multi-Provider AI

Anthropic and OpenAI out of the box, with Azure, DeepSeek, Gemini, and OpenRouter planned. Any OpenAI-compatible endpoint already works via the custom provider. Add new providers with a single config entry.
Anthropic, OpenAI, DeepSeek, and Gemini out of the box, with Azure and OpenRouter planned. Any OpenAI-compatible endpoint already works via the custom provider. Add new providers with a single config entry.

### Scoped Memory System

Expand Down Expand Up @@ -167,6 +167,7 @@ PROVIDER_ENCRYPTION_KEY=$(openssl rand -hex 32)
# AI providers (used by db:seed; also env fallback at runtime)
ANTHROPIC_API_KEY=sk-ant-xxx # Claude
OPENAI_API_KEY=sk-xxx # GPT (optional)
DEEPSEEK_API_KEY=sk-xxx # DeepSeek (optional)

# Channels (optional -- used by db:seed to populate channel config)
TELEGRAM_BOT_TOKEN=123456789:ABCdef... # Telegram (from @BotFather)
Expand Down Expand Up @@ -204,7 +205,7 @@ pnpm run install:clawix
The installer will:

1. Check prerequisites (Node 20+, pnpm, Docker, Docker Compose)
2. Ask for deployment mode (production / development), provider (OpenAI or Zai-Coding) + API key, admin email/password (production only), and optional Telegram bot token
2. Ask for deployment mode (production / development), provider selection (Anthropic, OpenAI, Z.AI Coding, Kimi, Gemini, DeepSeek, or a custom OpenAI-compatible endpoint) + API key, admin email/password (production only), and optional Telegram bot token
3. Generate `.env` with cryptographically random `JWT_SECRET`, `PROVIDER_ENCRYPTION_KEY`, `POSTGRES_PASSWORD` (file permissions set to `600`)
4. Build `clawix-agent:latest` (agent image used for isolated per-task containers)
5. Run `docker compose … up -d --build`
Expand Down Expand Up @@ -299,9 +300,9 @@ Built-in providers plus extensible registry -- add new ones with a single `Provi
| **OpenAI** | model starts with `gpt-`/`o1-`/`o3-`/`o4-` | General purpose | Available |
| **Z.AI Coding** | model starts with `glm-` | GLM models | Available |
| **Azure** | config key `azure_openai` | Enterprise compliance | Planned |
| **DeepSeek** | model starts with `deepseek-` | Cost-effective | Planned |
| **Gemini** | model starts with `gemini-` | Google ecosystem | Planned |
| **Kimi** | model starts with `moonshot-` | Long-context tasks | Planned |
| **DeepSeek** | model starts with `deepseek-` | Cost-effective | Available |
| **Gemini** | model starts with `gemini-` | Google ecosystem | Available |
| **Kimi** | provider id `kimi-code` | Long-context tasks | Available |
| **OpenRouter** | API key starts with `sk-or-` | Provider gateway | Planned |
| **Custom** | any OpenAI-compatible endpoint | Ollama, vLLM, etc. | Available |

Expand Down Expand Up @@ -400,7 +401,7 @@ pnpm run db:studio # Open Prisma Studio (GUI)

- [x] Container-isolated agent execution
- [x] Multi-provider AI support (Claude, GPT, OpenAI-compatible endpoints)
- [ ] First-class Azure, DeepSeek, Gemini, Kimi, OpenRouter providers
- [ ] First-class Azure, OpenRouter providers
- [x] Warm container pool (~50ms cold start)
- [x] Swarm orchestration with DAG dependencies
- [x] Telegram channel integration
Expand Down
6 changes: 6 additions & 0 deletions packages/api/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ async function main(): Promise<void> {
envKey: 'ZAI_CODING_API_KEY',
baseUrl: 'https://api.z.ai/api/coding/paas/v4',
},
{
provider: 'deepseek',
displayName: 'DeepSeek',
envKey: 'DEEPSEEK_API_KEY',
baseUrl: 'https://api.deepseek.com',
},
];
const customName = process.env['CUSTOM_PROVIDER_NAME'];
const customBase = process.env['CUSTOM_PROVIDER_BASE_URL'];
Expand Down
127 changes: 127 additions & 0 deletions packages/api/src/channels/__tests__/message-router.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ describe('MessageRouterService', () => {
text: 'Hello human',
metadata: {
messageId: 'msg-abc',
replyToMessageId: 'msg-1',
sessionId: 'session-1',
},
});
Expand Down Expand Up @@ -189,6 +190,7 @@ describe('MessageRouterService', () => {
text: 'Response',
metadata: {
messageId: 'run-xyz',
replyToMessageId: 'msg-1',
sessionId: 'session-1',
},
});
Expand Down Expand Up @@ -288,6 +290,7 @@ describe('MessageRouterService', () => {
expect(channel.sendMessage).toHaveBeenCalledWith(
expect.objectContaining({
text: expect.stringContaining('went wrong'),
metadata: expect.objectContaining({ replyToMessageId: 'msg-1' }),
}),
);
});
Expand Down Expand Up @@ -687,6 +690,130 @@ describe('MessageRouterService', () => {
expect(calls[0][0]).toMatchObject({ recipientId: '123456', text: 'Thinking…' });
expect(calls[1][0]).toMatchObject({ recipientId: '123456', text: 'Dogs are loyal.' });
});

describe('edit-status-in-place', () => {
// A streaming run: one prose chunk, then three consecutive tool calls,
// then the final answer. Drives the status-consolidation path.
function streamThreeTools(): void {
mockAgentDefRepo.findById.mockResolvedValue({ id: 'agent-1', streamingEnabled: true });
mockChannelRepo.findById.mockResolvedValue({ id: 'channel-1', toolProgressMode: null });
mockAgentRunner.run.mockImplementation(
async (opts: { onEvent?: (e: unknown) => Promise<void> }) => {
if (opts.onEvent) {
await opts.onEvent({ type: 'assistant_chunk', content: 'Working.', isFinal: false });
await opts.onEvent({
type: 'tool_started',
name: 'web_search',
args: { query: 'a' },
});
await opts.onEvent({ type: 'tool_started', name: 'read_file', args: { path: 'b' } });
await opts.onEvent({ type: 'tool_started', name: 'shell_exec', args: { cmd: 'c' } });
await opts.onEvent({ type: 'assistant_chunk', content: 'Done.', isFinal: true });
}
return {
streamingUsed: true,
output: 'Done.',
agentRunId: 'run-1',
sessionId: 'session-1',
status: 'completed',
tokenUsage: { input: 10, output: 5 },
};
},
);
}

it('edits one status message in place across consecutive tool bubbles', async () => {
streamThreeTools();
const channel = mockChannel();
// First bubble send returns the status anchor id.
(channel.sendMessage as ReturnType<typeof vi.fn>).mockResolvedValue('status-1');
channel.editMessage = vi.fn().mockResolvedValue(undefined);

const router = createRouter();
await router.handleInbound(mockInbound(), channel);

// sendMessage: prose 'Working.', first tool bubble, final 'Done.' = 3.
const sends = (channel.sendMessage as ReturnType<typeof vi.fn>).mock.calls;
expect(sends).toHaveLength(3);
expect(sends[0][0].text).toBe('Working.');
expect(sends[1][0].text).toMatch(/^🔍 web_search:/);
expect(sends[2][0].text).toBe('Done.');

// The 2nd and 3rd tools edit the same status anchor instead of appending.
const edits = (channel.editMessage as ReturnType<typeof vi.fn>).mock.calls;
expect(edits).toHaveLength(2);
expect(edits[0]).toEqual(['123456', 'status-1', expect.stringMatching(/^📖 read_file:/)]);
expect(edits[1]).toEqual(['123456', 'status-1', expect.stringMatching(/^💻 shell_exec:/)]);
});

it('appends a new message per tool when the adapter has no editMessage', async () => {
streamThreeTools();
const channel = mockChannel(); // no editMessage
const router = createRouter();
await router.handleInbound(mockInbound(), channel);

// prose + 3 tool bubbles + final = 5 sends, no edits possible.
expect(channel.sendMessage).toHaveBeenCalledTimes(5);
});

it('opens a fresh status message after an interleaved assistant_chunk', async () => {
mockAgentDefRepo.findById.mockResolvedValue({ id: 'agent-1', streamingEnabled: true });
mockChannelRepo.findById.mockResolvedValue({ id: 'channel-1', toolProgressMode: null });
mockAgentRunner.run.mockImplementation(
async (opts: { onEvent?: (e: unknown) => Promise<void> }) => {
if (opts.onEvent) {
// Group 1: two tools.
await opts.onEvent({
type: 'tool_started',
name: 'web_search',
args: { query: 'a' },
});
await opts.onEvent({ type: 'tool_started', name: 'read_file', args: { path: 'b' } });
// Prose closes the group.
await opts.onEvent({ type: 'assistant_chunk', content: 'Midway.', isFinal: false });
// Group 2: one tool — must NOT edit group 1's anchor.
await opts.onEvent({ type: 'tool_started', name: 'shell_exec', args: { cmd: 'c' } });
await opts.onEvent({ type: 'assistant_chunk', content: 'Done.', isFinal: true });
}
return {
streamingUsed: true,
output: 'Done.',
agentRunId: 'run-1',
sessionId: 'session-1',
status: 'completed',
tokenUsage: { input: 10, output: 5 },
};
},
);

const channel = mockChannel();
(channel.sendMessage as ReturnType<typeof vi.fn>).mockResolvedValue('status-1');
channel.editMessage = vi.fn().mockResolvedValue(undefined);

const router = createRouter();
await router.handleInbound(mockInbound(), channel);

// Sends: group-1 first tool, 'Midway.', group-2 first tool (fresh), 'Done.' = 4.
expect(channel.sendMessage).toHaveBeenCalledTimes(4);
// Only the 2nd tool of group 1 was an edit; group 2's tool opened fresh.
expect(channel.editMessage).toHaveBeenCalledTimes(1);
});

it('falls back to a fresh send when editMessage rejects', async () => {
streamThreeTools();
const channel = mockChannel();
(channel.sendMessage as ReturnType<typeof vi.fn>).mockResolvedValue('status-1');
channel.editMessage = vi.fn().mockRejectedValue(new Error('edit failed'));

const router = createRouter();
await router.handleInbound(mockInbound(), channel);

// prose + tool-1 send, then tool-2 edit fails → fresh send, tool-3 edit
// fails → fresh send, + final = 5 sends. Both edits were attempted.
expect(channel.sendMessage).toHaveBeenCalledTimes(5);
expect(channel.editMessage).toHaveBeenCalledTimes(2);
});
});
});

describe('MessageRouterService.lookupUser (whatsapp)', () => {
Expand Down
Loading
Loading