How eplayed/cowagent works
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 App · bridge Bridge · agent Agent · channel Channels
Components 21
Inbound
User-facing entry channels and message adapters
- Channels · Protocol-specific front doors that adapt external traffic into a common message flow
channel - Web Console · Browser-based console and web chat interface
channel/web/web_channel.py - WeChat Family · Weixin, WeCom bot/app, and WeChat MP integrations
channel/weixin - Enterprise Chat · Feishu, DingTalk, and QQ messaging integrations
channel/feishu - Terminal · Local terminal interaction adapter
channel/terminal/terminal_channel.py
Core
App wiring, bridge, agent runtime, and shared utilities
- App · Main runtime entrypoint that wires config, channels, bridge, models, and agent loop
app.py - Config · Repository-wide configuration loading and constants
config.py - Common · Cross-cutting helpers for logging, time, caching, temp paths, processes, and compatibility
common - Bridge · Normalizes inbound messages, builds context, and routes replies between channels and the agent
bridge - Agent · Agent chat/session orchestration, prompt building, protocol models, and reasoning loop
agent
Capabilities
Tools, memory, knowledge, skills, and scheduling
- Memory · Chunking, embedding, summarization, storage, and conversation memory management
agent/memory - Knowledge · Knowledge-base ingestion and retrieval subsystem
agent/knowledge - Skills · Installed skill loading, formatting, metadata, and management
agent/skills - Tool Manager · Validates and dispatches tool calls from the agent loop
agent/tools/tool_manager.py - Tools · File, shell, browser, search, memory, send, vision, and scheduler tools
agent/tools - Scheduler · Persistent scheduled jobs and task storage for out-of-band execution
agent/tools/scheduler
Providers
Model, voice, and translation adapters
Connections 32
- 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