# eplayed/cowagent architecture

> Architecture diagram of the GitHub repository eplayed/cowagent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/eplayed/cowagent
- Repository: https://github.com/eplayed/cowagent

## Overview

1. **Overall shape**
   CowAgent is a Python-based agent platform, not just a chat bot. The runtime is centered around a single app entrypoint (`app.py`) that wires together configuration, inbound channels, the model backend, and the agent execution loop. Most features are built as pluggable subsystems rather than hard-coded into one path.

2. **Inbound message layer**
   The `channel/` package is the outer boundary for user traffic. It adapts many front doors into a common message format: web console, terminal, Weixin/WeChat, Feishu, DingTalk, QQ, WeCom bot, WeCom app, and WeChat MP. Each channel implementation handles its own protocol, authentication, and delivery semantics, then passes normalized messages into the core bridge.

3. **Bridge and dispatch**
   The `bridge/` layer is the routing core between channels and the agent. It owns message normalization, reply handling, context assembly, and agent initialization. This is where an inbound channel event becomes an internal conversation/task request, and where model/tool output is transformed back into a channel-specific reply.

4. **Agent runtime**
   The `agent/` package is the main orchestration layer for “agent mode.” It contains chat/session services, prompt construction, protocol models, and the planning/execution loop. In practice, this layer decides whether to answer directly or to continue multi-step reasoning with tools, memory, skills, and external services.

5. **Model abstraction**
   The `models/` directory is a provider adapter layer. It supports multiple vendors and protocols, including OpenAI-compatible APIs as well as native integrations for OpenAI, Claude, Gemini, DeepSeek, MiniMax, Qwen/DashScope, Moonshot/Kimi, Doubao, Baidu Wenxin, ZhipuAI/GLM, Xunfei, ModelScope, and LinkAI. The `models/session_manager.py` and per-vendor session objects indicate persistent conversational state and provider-specific streaming/session handling.

6. **Tool execution boundary**
   The `agent/tools/` tree is the execution surface the model can call. It includes file and system operations (`read`, `write`, `edit`, `ls`, `bash`), browser automation, web search/fetch, environment inspection, messaging/send, vision, memory access, and scheduling. `tool_manager.py` is the likely dispatcher that validates tool calls and runs them in a controlled way, keeping the agent loop separate from side effects.

7. **Long-term memory subsystem**
   `agent/memory/` implements persistent agent memory rather than ephemeral chat history. It has chunking, embedding, summarization, storage, conversation store, and memory manager components, which together support indexing, retrieval, compression, and “dream” style distillation. The README’s mention of core memory, day-level memory, vector search, and context compression maps directly to this subsystem.

8. **Knowledge and skills**
   The repo distinguishes between **knowledge** and **skills**. `agent/knowledge/` appears to manage knowledge-base style ingestion and retrieval, while `agent/skills/` handles installed skills, metadata/frontmatter, loading, formatting, and management. The `skills/` folder contains reusable skill packages and creator tooling, while `plugins/` is a separate plugin framework for event-driven behavior and legacy/extension modules.

9. **Scheduled and asynchronous work**
   The scheduler tool and its service/store live under `agent/tools/scheduler/`, showing that the agent can create deferred tasks that persist beyond a single message turn. This is an important architectural boundary: normal chat/tool execution is synchronous per request, while scheduled tasks are stored, resumed, and later delivered back through the same channel infrastructure.

10. **Multi-modal and voice support**
   The `voice/` package provides STT/TTS integrations across multiple vendors, and `translate/` handles text translation adapters. Together with the README’s support for image, file, and voice messages, this means the system can ingest and emit more than plain text, but these capabilities remain auxiliary services wired into the same conversation pipeline.

11. **CLI and operations**
   `cli/` exposes operational commands for starting, stopping, updating, installing browser dependencies, managing skills, knowledge, and process state. This is the main local-admin boundary around the runtime, complementing the web console. The CLI is what makes the project manageable as a long-running service on a laptop or server.

12. **Configuration and deployment**
   Configuration is file-driven via `config.json` derived from `config-template.json`, with `config.py` and `common/const.py` centralizing supported options and model names. Deployment supports direct Python execution, a Docker image, and repository-provided scripts. The web console runs on port `9899` by default, while some messaging channels use their own webhook/WebSocket ports.

13. **State, caching, and utilities**
   Shared cross-cutting helpers live in `common/`. This includes logging, temporary directories, caches, token buckets, time checks, singleton helpers, package/process utilities, and websocket compatibility. These are supporting boundaries that keep the higher-level agent/channel/model code focused on business logic.

14. **Main end-to-end data flow**
   The canonical flow is: external message arrives on a channel → bridge normalizes it → agent builds context from recent chat, memory, knowledge, and skills → model is called, possibly streaming and/or repeatedly invoking tools → tool results feed back into the agent loop → final response is adapted by the channel and sent back. Scheduled jobs and persistent memory are the two main paths that can outlive a single request/response cycle.

15. **Repository intent**
   Architecturally, this repo is a configurable “agent platform” with three big extension surfaces: channels, models, and capabilities (tools/skills/memory). That makes it suitable for drawing a diagram with a central orchestration core surrounded by inbound connectors, provider adapters, and persistence/automation subsystems rather than a simple controller-service-model stack.

Main entry points: [`app.py`](https://github.com/eplayed/cowagent/blob/master/app.py) (App), [`bridge`](https://github.com/eplayed/cowagent/tree/master/bridge) (Bridge), [`agent`](https://github.com/eplayed/cowagent/tree/master/agent) (Agent), [`channel`](https://github.com/eplayed/cowagent/tree/master/channel) (Channels)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_inbound["Inbound"]
  node_channel_layer["Channels<br/>inbound adapters"]
  node_web_channel["Web Console<br/>channel<br/>[web_channel.py]"]
  node_wechat_channels["WeChat Family<br/>channel set"]
  node_enterprise_channels["Enterprise Chat<br/>channel set"]
  node_terminal_channel["Terminal<br/>channel"]
end

subgraph group_group_core["Core"]
  node_app["App<br/>entrypoint<br/>[app.py]"]
  node_config["Config<br/>settings<br/>[config.py]"]
  node_common["Common<br/>shared utils"]
  node_bridge["Bridge<br/>routing core"]
  node_agent_runtime["Agent<br/>orchestration"]
end

subgraph group_group_capabilities["Capabilities"]
  node_memory["Memory<br/>persistence"]
  node_knowledge["Knowledge<br/>retrieval"]
  node_skills["Skills<br/>skill system"]
  node_tool_manager["Tool Manager<br/>dispatcher<br/>[tool_manager.py]"]
  node_tools["Tools<br/>execution surface"]
  node_scheduler["Scheduler<br/>deferred tasks"]
end

subgraph group_group_providers["Providers"]
  node_models["Models<br/>provider adapters"]
  node_voice["Voice<br/>stt/tts"]
  node_translate["Translate<br/>adapter"]
end

subgraph group_group_ops["Ops"]
  node_plugins["Plugins<br/>extension framework"]
  node_cli["CLI<br/>ops interface"]
end

node_app -->|"loads"| node_config
node_app -->|"starts"| node_channel_layer
node_app -->|"wires"| node_bridge
node_app -->|"selects"| node_models
node_app -->|"runs"| node_agent_runtime
node_app -.->|"managed by"| node_cli
node_channel_layer -->|"includes"| node_web_channel
node_channel_layer -->|"includes"| node_wechat_channels
node_channel_layer -->|"includes"| node_enterprise_channels
node_channel_layer -->|"includes"| node_terminal_channel
node_web_channel -->|"sends"| node_bridge
node_wechat_channels -->|"sends"| node_bridge
node_enterprise_channels -->|"sends"| node_bridge
node_terminal_channel -->|"sends"| node_bridge
node_bridge -->|"invokes"| node_agent_runtime
node_bridge -->|"queries"| node_models
node_bridge -->|"replies via"| node_channel_layer
node_agent_runtime -->|"calls"| node_tool_manager
node_tool_manager -->|"dispatches"| node_tools
node_tools -.->|"uses"| node_scheduler
node_agent_runtime -->|"reads/writes"| node_memory
node_agent_runtime -->|"consults"| node_knowledge
node_agent_runtime -->|"loads"| node_skills
node_agent_runtime -.->|"extends with"| node_plugins
node_app -.->|"enables"| node_voice
node_app -.->|"enables"| node_translate
node_cli -->|"manages"| node_skills
node_cli -->|"manages"| node_knowledge
node_cli -->|"manages"| node_plugins
node_common -.->|"supports"| node_bridge
node_common -.->|"supports"| node_agent_runtime
node_models -.->|"uses"| node_common

click node_app "https://github.com/eplayed/cowagent/blob/master/app.py"
click node_config "https://github.com/eplayed/cowagent/blob/master/config.py"
click node_common "https://github.com/eplayed/cowagent/tree/master/common"
click node_bridge "https://github.com/eplayed/cowagent/tree/master/bridge"
click node_agent_runtime "https://github.com/eplayed/cowagent/tree/master/agent"
click node_channel_layer "https://github.com/eplayed/cowagent/tree/master/channel"
click node_web_channel "https://github.com/eplayed/cowagent/blob/master/channel/web/web_channel.py"
click node_wechat_channels "https://github.com/eplayed/cowagent/tree/master/channel/weixin"
click node_enterprise_channels "https://github.com/eplayed/cowagent/tree/master/channel/feishu"
click node_terminal_channel "https://github.com/eplayed/cowagent/blob/master/channel/terminal/terminal_channel.py"
click node_models "https://github.com/eplayed/cowagent/tree/master/models"
click node_memory "https://github.com/eplayed/cowagent/tree/master/agent/memory"
click node_knowledge "https://github.com/eplayed/cowagent/tree/master/agent/knowledge"
click node_skills "https://github.com/eplayed/cowagent/tree/master/agent/skills"
click node_tool_manager "https://github.com/eplayed/cowagent/blob/master/agent/tools/tool_manager.py"
click node_tools "https://github.com/eplayed/cowagent/tree/master/agent/tools"
click node_scheduler "https://github.com/eplayed/cowagent/tree/master/agent/tools/scheduler"
click node_plugins "https://github.com/eplayed/cowagent/tree/master/plugins"
click node_cli "https://github.com/eplayed/cowagent/tree/master/cli"
click node_voice "https://github.com/eplayed/cowagent/tree/master/voice"
click node_translate "https://github.com/eplayed/cowagent/tree/master/translate"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_channel_layer,node_web_channel,node_wechat_channels,node_enterprise_channels,node_terminal_channel toneBlue
class node_app,node_config,node_common,node_bridge,node_agent_runtime toneAmber
class node_memory,node_knowledge,node_skills,node_tool_manager,node_tools,node_scheduler toneMint
class node_models,node_voice,node_translate toneRose
class node_plugins,node_cli toneIndigo
```

## Components

### Inbound

User-facing entry channels and message adapters

- [Channels](https://github.com/eplayed/cowagent/tree/master/channel): inbound adapters · Protocol-specific front doors that adapt external traffic into a common message flow · `channel`
- [Web Console](https://github.com/eplayed/cowagent/blob/master/channel/web/web_channel.py): channel · Browser-based console and web chat interface · `channel/web/web_channel.py`
- [WeChat Family](https://github.com/eplayed/cowagent/tree/master/channel/weixin): channel set · Weixin, WeCom bot/app, and WeChat MP integrations · `channel/weixin`
- [Enterprise Chat](https://github.com/eplayed/cowagent/tree/master/channel/feishu): channel set · Feishu, DingTalk, and QQ messaging integrations · `channel/feishu`
- [Terminal](https://github.com/eplayed/cowagent/blob/master/channel/terminal/terminal_channel.py): channel · Local terminal interaction adapter · `channel/terminal/terminal_channel.py`

### Core

App wiring, bridge, agent runtime, and shared utilities

- [App](https://github.com/eplayed/cowagent/blob/master/app.py): entrypoint · Main runtime entrypoint that wires config, channels, bridge, models, and agent loop · `app.py`
- [Config](https://github.com/eplayed/cowagent/blob/master/config.py): settings · Repository-wide configuration loading and constants · `config.py`
- [Common](https://github.com/eplayed/cowagent/tree/master/common): shared utils · Cross-cutting helpers for logging, time, caching, temp paths, processes, and compatibility · `common`
- [Bridge](https://github.com/eplayed/cowagent/tree/master/bridge): routing core · Normalizes inbound messages, builds context, and routes replies between channels and the agent · `bridge`
- [Agent](https://github.com/eplayed/cowagent/tree/master/agent): orchestration · Agent chat/session orchestration, prompt building, protocol models, and reasoning loop · `agent`

### Capabilities

Tools, memory, knowledge, skills, and scheduling

- [Memory](https://github.com/eplayed/cowagent/tree/master/agent/memory): persistence · Chunking, embedding, summarization, storage, and conversation memory management · `agent/memory`
- [Knowledge](https://github.com/eplayed/cowagent/tree/master/agent/knowledge): retrieval · Knowledge-base ingestion and retrieval subsystem · `agent/knowledge`
- [Skills](https://github.com/eplayed/cowagent/tree/master/agent/skills): skill system · Installed skill loading, formatting, metadata, and management · `agent/skills`
- [Tool Manager](https://github.com/eplayed/cowagent/blob/master/agent/tools/tool_manager.py): dispatcher · Validates and dispatches tool calls from the agent loop · `agent/tools/tool_manager.py`
- [Tools](https://github.com/eplayed/cowagent/tree/master/agent/tools): execution surface · File, shell, browser, search, memory, send, vision, and scheduler tools · `agent/tools`
- [Scheduler](https://github.com/eplayed/cowagent/tree/master/agent/tools/scheduler): deferred tasks · Persistent scheduled jobs and task storage for out-of-band execution · `agent/tools/scheduler`

### Providers

Model, voice, and translation adapters

- [Models](https://github.com/eplayed/cowagent/tree/master/models): provider adapters · LLM provider abstraction layer with vendor-specific bots and sessions · `models`
- [Voice](https://github.com/eplayed/cowagent/tree/master/voice): stt/tts · Speech recognition and synthesis adapters across vendors · `voice`
- [Translate](https://github.com/eplayed/cowagent/tree/master/translate): adapter · Text translation adapters · `translate`

### Ops

CLI, plugins, and deployment surfaces

- [Plugins](https://github.com/eplayed/cowagent/tree/master/plugins): extension framework · Event-driven plugin system and legacy extension modules · `plugins`
- [CLI](https://github.com/eplayed/cowagent/tree/master/cli): ops interface · Command-line management for install, process, skills, knowledge, and context operations · `cli`

## Connections

- App → Config: loads · Reads runtime configuration and constants
- App → Channels: starts · Initializes inbound channel front doors
- App → Bridge: wires · Connects channels to the routing core
- App → Models: selects · Configures provider backend(s)
- App → Agent: runs · Starts the main agent loop
- App → CLI: managed by · Can be operated through command-line commands
- Channels → Web Console: includes · Web console adapter
- Channels → WeChat Family: includes · WeChat-family adapters
- Channels → Enterprise Chat: includes · Enterprise chat adapters
- Channels → Terminal: includes · Terminal adapter
- Web Console → Bridge: sends · Normalizes user input into the bridge
- WeChat Family → Bridge: sends · Passes normalized events into the bridge
- Enterprise Chat → Bridge: sends · Passes normalized events into the bridge
- Terminal → Bridge: sends · Passes terminal messages into the bridge
- Bridge → Agent: invokes · Creates agent requests and handles responses
- Bridge → Models: queries · Routes model calls and streaming output
- Bridge → Channels: replies via · Adapts agent output back to channel-specific replies
- Agent → Tool Manager: calls · Requests tool execution through a guarded dispatcher
- Tool Manager → Tools: dispatches · Runs concrete tool implementations
- Tools → Scheduler: uses · Creates and resumes deferred tasks
- Agent → Memory: reads/writes · Uses persistent memory for context and retrieval
- Agent → Knowledge: consults · Pulls knowledge-base context when needed
- Agent → Skills: loads · Loads installed skills and metadata
- Agent → Plugins: extends with · Allows event-driven behavior and legacy extensions
- App → Voice: enables · Optional speech input/output integration
- App → Translate: enables · Optional translation integration
- CLI → Skills: manages · Installs and maintains skills
- CLI → Knowledge: manages · Maintains knowledge assets
- CLI → Plugins: manages · Supports plugin and process operations
- Common → Bridge: supports · Shared logging, utilities, and runtime helpers
- Common → Agent: supports · Shared state and utility helpers
- Models → Common: uses · Shares helpers and runtime utilities
