How lsdefine/genericagent works
1. Overall shape
GenericAgent is a local, Python-based agent runtime. The architecture centers on one autonomous loop that talks to an LLM, chooses from a small toolset, executes actions on the local machine or browser, and then writes results back into layered memory for reuse.
2. Runtime entry points
The main launch surfaces are launch.pyw, agentmain.py, hub.pyw, and agent_loop.py. Those entry points wire together model access, UI/frontends, tool execution, and memory persistence. The .pyw files suggest the project is meant to run as a desktop app on systems where a GUI is available.
3. Core reasoning loop
agent_loop.py is the central orchestration layer described in the README as a ~100-line loop. It performs the repeated cycle: observe state, ask the LLM what to do next, call a tool, inspect the result, and continue until the task is complete. llmcore.py is the model-facing boundary for Claude/Gemini/Kimi/MiniMax-style backends.
4. Tool layer
The agent’s capabilities are intentionally narrow and atomic: code execution, file read/write/patch, web scan, browser JavaScript execution, user confirmation, plus memory checkpoint/update operations. The tool definitions live in assets/tools_schema*.json and the usable-tool history in assets/tool_usable_history.json, which means the loop can stay generic while the available actions are externally described.
5. Browser control subsystem
TMWebDriver.py and assets/tmwd_cdp_bridge/ form a browser-injection boundary. Instead of using a headless sandbox, the agent controls a real browser session and preserves login state. The Chrome extension bridge (manifest.json, background.js, content.js, etc.) is the glue between the Python agent and browser-side events/CDP-style control.
6. Memory and skill architecture
The memory/ tree is the main long-term knowledge subsystem. The README’s L0–L4 model maps to behavior rules, insight index, global facts, reusable SOPs/skills, and archived sessions. This repo stores those as markdown templates, SOP docs, and archived session artifacts, with memory/skill_search/ providing skill indexing/lookup and memory/L4_raw_sessions/ handling session compression.
7. Self-evolution boundary
The key architectural loop is not just “act” but “distill.” New task solutions are expected to be crystallized into reusable skills, written into the memory layers, and then recalled later via skill search. That is the main mechanism by which the agent becomes more capable without growing the core codebase.
8. Reflection and scheduling
reflect/autonomous.py and reflect/scheduler.py indicate a second control plane for background or periodic work. Combined with the cron-oriented memory SOPs and the README’s scheduler note, the agent can move from one-off task execution into scheduled autonomous routines.
9. Frontends and message ingress
The frontends/ directory is a set of adapters that normalize different user entry channels into the same agent core. There is a Streamlit UI, a Qt desktop UI, and bot frontends for Telegram, WeChat, WeCom, DingTalk, QQ, and Feishu. frontends/chatapp_common.py appears to hold shared chat orchestration so those channels all feed the same agent pipeline.
10. Vision, OCR, and device automation
The memory/ utilities such as ocr_utils.py, ui_detect.py, adb_ui.py, and related controller/scanner helpers show that the agent can operate beyond the browser, including mobile/Android workflows and screen-based interaction. This is the perception layer that supports tasks requiring screenshots, OCR, UI element detection, or ADB-driven phone control.
11. Dynamic code execution and extensibility
code_run is a structural escape hatch: the agent can install packages, write scripts, call APIs, or create temporary automation code at runtime. That means the repo is not just a fixed-agent system; it is a bootstrap environment for generating new capabilities and then folding them back into persistent skills.
12. Configuration and trust boundaries
Secrets and provider configuration are intentionally separated into mykey_template.py / mykey.py. The repo also includes setup docs and platform-specific install helpers in assets/, showing that external dependencies are mostly runtime integrations rather than built-in service infrastructure.
13. Tests and model integration
tests/test_minimax.py and tests/test_minimax_integration.py show that at least some of the external-model behavior is validated with automated tests. That reinforces that the critical boundary is the LLM provider interface, not a web backend or database service.
14. How to draw the diagram
A good architecture diagram would place the LLM-driven agent_loop in the center, with arrows out to: frontends/bot adapters, browser control, file/code tools, vision/ADB tools, and memory/skill storage. Then show a feedback arrow from execution results back into the layered memory and skill search system, because that persistence loop is the project’s defining architectural feature.
Main entry points: agent_loop.py Agent loop · chatapp_common.py Chat common · memory Memory tree · engine.py Skill search
Components 20
Core runtime
Agent loop, model boundary, and launch surfaces.
- Launch · Desktop launch surface that starts the agent runtime.
launch.pyw - Agent main · Main application bootstrap and wiring.
agentmain.py - Hub · Alternate entry surface for coordinating the agent.
hub.pyw - Agent loop · Central observe-decide-act loop that selects tools and advances tasks.
agent_loop.py - LLM core · Provider boundary for Claude, Gemini, Kimi, MiniMax, and similar backends.
llmcore.py - GA · Supporting runtime module used by the agent system.
ga.py
Frontends
User and bot ingress adapters into the same agent core.
- Streamlit UI · Web-style user interface adapter.
frontends/stapp.py - Qt UI · Desktop GUI adapter.
frontends/qtapp.py - Chat common · Shared chat orchestration used by bot frontends.
frontends/chatapp_common.py - Bot adapters · Telegram, WeChat, WeCom, DingTalk, and QQ ingress adapters.
frontends/tgapp.py
Memory
Long-term knowledge, skills, and operational SOPs.
- Memory tree · Layered long-term memory and reusable skill archive.
memory - Skill search · Skill indexing and lookup subsystem.
memory/skill_search/skill_search/engine.py - Raw sessions · Compressed and archived interaction sessions for later distillation.
memory/L4_raw_sessions/compress_session.py
Browser control
Real-browser automation and extension bridge.
- WebDriver · Python-side browser control boundary.
TMWebDriver.py - CDP bridge · Chrome extension bridge for injecting control and relaying browser events.
assets/tmwd_cdp_bridge/manifest.json
Automation
Background scheduling and reflection flows.
- Reflection · Background autonomous routines and scheduling.
reflect/autonomous.py - Scheduler · Periodic task scheduling and execution.
reflect/scheduler.py
Assets
External tool schemas, prompts, and support resources.
- Tool schema · Externally described tool set for execution, file ops, web, and confirmation.
assets/tools_schema.json - Tool history · History of usable tools used to keep the loop generic.
assets/tool_usable_history.json
Other components
- Secrets · Local provider credentials and environment-specific configuration.
mykey_template.py
Connections 21
- Launch → Agent loop: starts · Launches the main agent loop.
- Agent main → Agent loop: boots · Initializes the runtime and enters the loop.
- Hub → Agent loop: routes · Hands off control to the shared agent core.
- Agent loop → LLM core: queries · Requests the next action or response from the model.
- Agent loop → Tool schema: selects · Uses the external tool contract to choose actions.
- Agent loop → WebDriver: drives · Controls local browser sessions when needed.
- WebDriver → CDP bridge: injects · Uses the browser extension bridge for CDP-style coordination.
- Agent loop → Memory tree: writes · Stores outcomes and distilled knowledge into layered memory.
- Agent loop → Skill search: recalls · Retrieves reusable skills and prior solutions.
- Memory tree → Raw sessions: archives · Compresses and stores raw session artifacts.
- Memory tree → Skill search: indexes · Promotes reusable knowledge into skill search.
- Skill search → Agent loop: feeds · Returns relevant skills to guide the next step.
- Reflection → Scheduler: coordinates · Background autonomous work is scheduled and executed.
- Scheduler → Agent loop: triggers · Can invoke the agent loop for periodic jobs.
- Streamlit UI → Chat common: uses · Shares common chat orchestration.
- Qt UI → Chat common: uses · Shares common chat orchestration.
- Bot adapters → Chat common: uses · Bot frontends normalize into the shared chat path.
- Chat common → Agent loop: hands off · Forwards user intents into the core agent loop.
- Tool schema → Agent loop: constrains · Defines the actions available to the agent.
- Tool history → Agent loop: guides · Narrows tool selection based on prior usability.
- Secrets → LLM core: configures · Provides local secrets and provider credentials.