$ show shaxiu/XianyuAutoAgent
XianyuAutoAgent is an AI-powered customer service bot for the Chinese second-hand marketplace platform Xianyu (闲鱼). It connects via WebSocket to Xianyu's messaging service, receives user messages, and generates intelligent replies using a Large Language Model (LLM) with multi-expert routing. The system features intent classification (price negotiation, technical support, general query), dynamic pricing negotiation with gradual concessions and adaptive LLM temperature, context-aware conversation management via SQLite, and a manual takeover mode. It handles authentication via cookies, token refresh, heartbeat, and captcha-triggered cookie re-entry. The bot operates as a long-running async process, suitable for deployment via Docker.
The LLM identified 3 files worth highlighting for reuse:
A pure Python implementation of a MessagePack decoder (class MessagePackDecoder). It handles all standard MessagePack formats (fixint, fixstr, arrays, maps, bin, float, integers, etc.) without external dependencies. The decrypt function attempts to decode data as MessagePack after base64 decoding, with fallback to text or hex representation. This component is self-contained and can be extracted and reused in any Python project requiring MessagePack decoding without installing the msgpack library.
The IntentRouter class implements a hybrid approach to user intent detection: first applies keyword/regex rules for technical and price-related queries, then falls back to an LLM-powered classifier for ambiguous cases. The routing logic is isolated (only imports re and logging) and can be repurposed for any chatbot system needing a combination of deterministic and ML-based intent routing. The rules and patterns are customizable via configuration.
ChatContextManager provides a full-featured, persistent chat history manager using SQLite. It stores messages with user-id, item-id, chat-id, role, and timestamp; tracks bargain counts per chat session; and caches item information. It supports automatic message trimming to a configurable max history, indexing for query performance, and schema migration for backward compatibility. This component is self-contained (only stdlib and loguru) and can be extracted for any chat application requiring local persistent context storage.