# Repository Briefing: shaxiu/XianyuAutoAgent
> Source: https://repoforai.com/repo/shaxiu/XianyuAutoAgent (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/shaxiu/XianyuAutoAgent
- **Category**: Agents & Frameworks (智能体与框架)
- **Primary Language**: Python
- **License**: GPL-3.0
- **Engineering Health**: B (53/100 · Maintenance 12/35 · Adoption 24/25 · Releases 6/20 · License 11/20)
- **Review Snapshot**: 2026-12-01
- **Deployment / Stack Signals**: Docker, Self-Hosted
- **Momentum**: 9,920 ★ total (+24 24h / +149 7d) · 1,729 forks
- **Topics**: `agent`, `chatbot`, `llm`
- **When to Use**: Best for: Xianyu sellers piloting supervised replies for common inquiries and routine bargaining who can manage account sessions and test reply behavior. Skip if: You need offline operation, verified multi-channel support, mature administrative controls, or guaranteed pricing-policy enforcement.

## Overview
```text
### Architecture & Core Mechanics
Xianyu AutoAgent is a Python application specialized for Xianyu seller chat, with `main.py` as its entrypoint. The tree separates agent logic (`XianyuAgent.py`), platform integration (`XianyuApis.py`), and conversation context (`context_manager.py`). The runtime pins `websockets==13.1` and `requests==2.32.3` for networking, `openai==1.65.5` for model access, `python-dotenv==1.0.1` for configuration, and `loguru==0.7.3` for logging.

The reply flow combines stored conversation history with LLM-based intent classification and routing rules, then selects a bargaining, technical-support, or default reply path. The four prompt roles in `prompts/` are customization points for classification and generation. Here, “multi-expert” is best understood as specialized routing; the available interface does not establish a general-purpose agent or plugin platform.

### Key Capabilities & Differentiators
The application combines context-aware automatic replies, stepwise price concessions, and web search for technical support. Sellers can toggle between automated handling and manual takeover with `TOGGLE_KEYWORDS`; `SIMULATE_HUMAN_TYPING` controls an optional reply delay. These controls make a supervised rollout possible without treating generated price responses as independently enforced business policy.

Qwen is the default model family. `MODEL_BASE_URL` and `MODEL_NAME` let operators change the endpoint and model, but a replacement should be tested against the OpenAI client and the classifier's expected behavior. Basic logging is implemented. Market-price comparison, RAG-backed knowledge, enhanced sentiment analysis, DingTalk integration, and web administration remain planned.

### Trade-offs & Limitations
Compared with building on a general-purpose agent framework, this app supplies Xianyu-specific session integration and bargaining out of the box, at the cost of portability. The cookie-based integration depends on a valid session and continued platform compatibility. Compared with a support suite, the operational surface is much narrower: basic logs and manual takeover are available, but a web console is still planned and no direct commercial Xianyu substitute is verified.

Sending stored history to the model preserves continuity, but longer threads can increase token usage and expose more conversation data to an external provider. Routing and replies also inherit the endpoint's latency and availability. Test multi-turn bargaining and manual takeover before leaving it unattended, and check account automation rules and data handling separately from GPL-3.0 obligations on redistribution.

### Hardware & Deployment Guide
The stated requirement is Python 3.8+. For a native installation, use an isolated environment, install `requirements.txt`, configure `.env` with `API_KEY`, `COOKIES_STR`, `MODEL_BASE_URL`, and `MODEL_NAME`, then launch `python main.py`. Prompt overrides can be supplied under `prompts/`; templates provide defaults. The agent host needs network access to Xianyu and the configured model endpoint. Self-hosting the application does not make it offline, nor does it require local GPU inference.

Compose runs `shaxiu/xianyuautoagent:latest` on a bridge network with `restart: always` and `TZ=Asia/Shanghai`. It mounts `./data`, `./prompts`, and `./.env` at `/app/data`, `/app/prompts`, and `/app/.env`, respectively. No GitHub release is listed, so the `latest` tag is not a reproducible version pin. Record the tested image digest or source revision, protect the mounted credentials and chat data, and verify session recovery before unattended use.
```

## Key Capabilities
```text
- Routing: Prompt-based intent classification and rules select bargaining, technical support, or default replies.
- Conversation state: Stored chat history is supplied as LLM context for follow-up turns.
- Seller control: A configurable keyword toggles between automated replies and manual handling.
- Model endpoint: `openai==1.65.5` with configurable `MODEL_BASE_URL` and `MODEL_NAME`; Qwen is the default.
- Deployment: Compose bind-mounts `./data`, `./prompts`, and `./.env` into `/app` with an `always` restart policy.
- Operations: Basic logging is implemented; the web console and DingTalk integration are planned.
```

## Quick Start / Clone
```bash
1. 克隆仓库
git clone https://github.com/shaxiu/XianyuAutoAgent.git
cd XianyuAutoAgent

2. 安装依赖
pip install -r requirements.txt

3. 配置环境变量
创建一个 `.env` 文件，包含以下内容，也可直接重命名 `.env.example` ：
#必配配置
API_KEY=apikey通过模型平台获取
COOKIES_STR=填写网页端获取的cookie
MODEL_BASE_URL=模型地址
MODEL_NAME=模型名称
#可选配置
TOGGLE_KEYWORDS=接管模式切换关键词，默认为句号（输入句号切换为人工接管，再次输入则切换AI接管）
SIMULATE_HUMAN_TYPING=True/False #模拟人工回复延迟

注意：默认使用的模型是通义千问，如需使用其他API，请自行修改.env文件中的模型地址和模型名称；
COOKIES_STR自行在闲鱼网页端获取cookies(网页端F12打开控制台，选择Network，点击Fetch/XHR,点击一个请求，查看cookies)

4. 创建提示词文件prompts/*_prompt.txt（也可以直接将模板名称中的_example去掉），否则默认读取四个提示词模板中的内容
```
