How geeeekexplorer/kkbot works
What this project is (type + purpose)
kkbot is a single-process “agent bot” that connects to Feishu (Lark) via a WebSocket channel, receives chat events, and—when triggered—runs an LLM-driven agent loop that can call tools (shell, file I/O, web search/fetch, memory) and then replies back into Feishu.
It’s not a typical multi-service web app; architecturally it’s closer to:
• a CLI-managed daemon (started via kkbot start)
• that hosts an event-driven bot runtime
• that orchestrates LLM calls + tool execution
• persisting state to a local workspace (not a DB service)
Read the file tree as architecture hints
From the tree + README:
• kkbot/main.py: CLI entrypoint (kkbot init, kkbot start)
• kkbot/config.py: config loading + paths (notably ~/.kkbot/config.json and workspace dirs)
• kkbot/feishu.py: Feishu WebSocket channel (ingress events + egress replies)
• kkbot/agent.py: core agent loop + tool execution + web tools
• kkbot/llm.py: OpenAI-compatible LLM provider (HTTP API calls)
• kkbot/session.py: session + memory management (chat context, MEMORY.md)
• kkbot/tools.py: tool definitions / dispatcher (shell, files, memory, web, restart)
• skills/*.md: “skill injection” into system prompt at startup
agent.py starts handling
• loads/uses system prompt (config)
• includes skills (skills/*.md)
• loads memory from session.py / MEMORY.md
• includes relevant chat history/session context
If tool call returned
• tools.py dispatch to tool:
• shell → OS shell
• read_file/write_file/patch_file → filesystem
• save_memory/recall_memory → MEMORY.md
• web_search → Brave API
• web_fetch → website HTTP fetch + extraction
• restart_self → process restart mechanism
• tool result → back to agent.py
• agent continues loop (bounded by max_tool_rounds)
Event-driven ingress
• kkbot is reactive: Feishu events drive computation.
• Only responds in group chat when @-mentioned, plus DMs.
Prompt assembly pipeline
Explicitly show prompt inputs:
• System prompt (config)
• Skills (markdown)
• Memory (long-term MEMORY.md)
• Session history (recent messages)
Tool execution loop
• LLM output can request tools
• Tools can mutate local state (files, memory) and retrieve external info (web)
• Agent repeats until final response or tool-round limit hit
Persistence is filesystem-based
• No database service; the “DB” is essentially MEMORY.md + workspace files.
“Don’t overthink”: how to split into “as many components as possible” without noise
A practical decomposition that stays accurate: