|
| 1 | +# ClawSharp Architecture |
| 2 | + |
| 3 | +## High-Level Overview |
| 4 | + |
| 5 | +``` |
| 6 | +┌─────────────────────────────────────────────────────┐ |
| 7 | +│ Channels │ |
| 8 | +│ ┌──────────┐ ┌─────────┐ ┌───────┐ ┌────────┐ │ |
| 9 | +│ │ Telegram │ │ Discord │ │ Slack │ │ CLI │ │ |
| 10 | +│ └────┬─────┘ └────┬────┘ └───┬───┘ └───┬────┘ │ |
| 11 | +│ └──────────────┴──────────┴───────────┘ │ |
| 12 | +│ │ IChannel / IMessageBus │ |
| 13 | +├──────────────────────┼──────────────────────────────┤ |
| 14 | +│ Agent Loop │ |
| 15 | +│ ┌───────────────────┴───────────────────────┐ │ |
| 16 | +│ │ Receive → Think → Act → Respond → Store │ │ |
| 17 | +│ └───┬──────────┬────────────────┬───────────┘ │ |
| 18 | +│ │ │ │ │ |
| 19 | +│ ┌───┴───┐ ┌──┴──────┐ ┌─────┴────┐ │ |
| 20 | +│ │ Tools │ │ Provider│ │ Memory │ │ |
| 21 | +│ │(ITool)│ │(ILlm- │ │(ISession │ │ |
| 22 | +│ │ │ │Provider) │ │ Manager) │ │ |
| 23 | +│ └───────┘ └─────────┘ └──────────┘ │ |
| 24 | +├─────────────────────────────────────────────────────┤ |
| 25 | +│ Gateway (HTTP API + UI) │ |
| 26 | +└─────────────────────────────────────────────────────┘ |
| 27 | +``` |
| 28 | + |
| 29 | +## Key Interfaces |
| 30 | + |
| 31 | +| Interface | Location | Purpose | |
| 32 | +|-----------|----------|---------| |
| 33 | +| `ILlmProvider` | `Core/Providers/` | Abstraction over LLM APIs (OpenAI, Anthropic, etc.) | |
| 34 | +| `ITool` | `Core/Tools/` | A capability the agent can invoke | |
| 35 | +| `IToolRegistry` | `Core/Tools/` | Registry for discovering and invoking tools | |
| 36 | +| `IChannel` | `Core/Channels/` | Inbound/outbound messaging for a platform | |
| 37 | +| `IMessageBus` | `Core/Channels/` | Routes messages between channels and the agent | |
| 38 | +| `ISessionManager` | `Core/Sessions/` | Manages conversation sessions and context | |
| 39 | + |
| 40 | +## Project Responsibilities |
| 41 | + |
| 42 | +- **ClawSharp.Core** — Interfaces, models, configuration. Zero external dependencies. Everything depends on Core. |
| 43 | +- **ClawSharp.Agent** — The agent loop: receives messages, calls the LLM, executes tools, returns responses. |
| 44 | +- **ClawSharp.Providers** — Concrete LLM provider implementations (OpenAI, Anthropic, Ollama, OpenRouter). |
| 45 | +- **ClawSharp.Tools** — Built-in tools (file I/O, shell exec, web search, etc.). |
| 46 | +- **ClawSharp.Memory** — Persistent storage, embeddings, and semantic search. |
| 47 | +- **ClawSharp.Infrastructure** — Dependency injection, logging, service registration. |
| 48 | +- **ClawSharp.Gateway** — ASP.NET Core HTTP API for external access and the web UI. |
| 49 | +- **ClawSharp.Cli** — Command-line interface and entry point. |
| 50 | +- **ClawSharp.UI** — Blazor-based web frontend. |
| 51 | + |
| 52 | +## Data Flow |
| 53 | + |
| 54 | +1. **Message arrives** via a channel (Telegram, CLI, etc.) |
| 55 | +2. **IMessageBus** routes it to the agent |
| 56 | +3. **Agent loop** builds an `LlmRequest` with conversation history + available tools |
| 57 | +4. **ILlmProvider** sends the request to the LLM and returns an `LlmResponse` |
| 58 | +5. If the response contains **tool calls**, the agent executes them via `IToolRegistry` and loops back to step 3 |
| 59 | +6. Final response is sent back through the **channel** |
| 60 | +7. Conversation is persisted via **ISessionManager** |
| 61 | + |
| 62 | +## Configuration |
| 63 | + |
| 64 | +All configuration flows through `ClawSharpConfig` (loaded from TOML). Sub-configs: |
| 65 | + |
| 66 | +- `ProvidersConfig` — API keys, endpoints, default models |
| 67 | +- `GatewayConfig` — HTTP bind address, port, API key |
| 68 | +- `ChannelsConfig` — Per-channel settings (tokens, allowed users) |
| 69 | +- `MemoryConfig` — Database path, embedding settings |
| 70 | +- `SecurityConfig` — Sandbox rules, allowed commands |
| 71 | +- `HeartbeatConfig` — Periodic polling settings |
| 72 | +- `TunnelConfig` — External tunnel (cloudflared, etc.) |
0 commit comments