# Job-Searching-Agent **Repository Path**: PlonGuo/Job-Searching-Agent ## Basic Information - **Project Name**: Job-Searching-Agent - **Description**: Current local code snapshot - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-11-10 - **Last Updated**: 2026-11-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Job Searching Agent AI Engineer 校招岗位自动采集 Agent — 基于 PydanticAI 的多源智能求职助手。 输入自然语言 query(如 `"AI Engineer 校招"`),自动规划搜索策略、多站点抓取、LLM 分类筛选、去重入库,输出结构化岗位列表 + HTML 运行报告。 ## Architecture ``` run.py (CLI) │ ▼ src/core.py ── run_search() async generator ──▶ yields RunEvent stream │ ├── src/agent/orchestrator.py PydanticAI Agent (run_stream) │ ├── query_expander.py LLM: user query → keyword pool │ ├── classifier.py LLM: is_ai_engineer + tech_tags + SkillPortrait │ ├── self_review.py LLM: final quality audit │ └── tools.py 4 tools (search / fetch_and_classify / progress / expand) │ ├── src/adapters/ Site-specific parsers │ ├── base.py SiteAdapter Protocol + BaseAdapter (fixtures routing) │ ├── fiveone_job.py 51job │ ├── shixiseng.py 实习僧 │ ├── nowcoder.py 牛客 │ ├── lagou.py 拉勾 (Crawl4AI) │ └── bigtech.py 字节/阿里/腾讯 careers API │ ├── src/crawlers/ │ ├── stack.py httpx → Crawl4AI → Firecrawl 3-tier fallback │ └── politeness.py Global semaphore + per-domain delay + UA rotation │ ├── src/agent/guardrails.py Budget cap + empty-state abort + dry-run ├── src/agent/pricing.py Local token counter (model → USD/token) │ ├── src/storage.py SQLite WAL — dedupe + run_id + JSON/CSV export └── src/observability.py EventBus + 4 sinks (JSONL / Rich / SQLite / Langfuse) ``` **Key design decisions:** - **Two-layer streaming**: `Agent.run_stream()` is consumed internally by the orchestrator; `run_search()` yields semantic `RunEvent` objects only — decouples LLM internals from consumers. - **EventBus pub/sub**: Tools emit events → `subscribe_as_queue()` bridges to the async generator → CLI/future FastAPI consume uniformly. - **Fixtures + mock-LLM modes**: Fully offline testing without network or API keys. ## 快速开始(4 步启动) ### 环境要求 - Python 3.11+(推荐 3.12) - [uv](https://docs.astral.sh/uv/) 包管理器 - 国内网络环境(需要访问 51job / 实习僧 / 牛客 / 拉勾 / 大厂官网) > **安装 uv**(如果还没有):`pip install uv` 或 `curl -LsSf https://astral.sh/uv/install.sh | sh` ### 启动步骤 ```bash # 1. 解压并进入项目目录 unzip job-searching-agent.zip && cd job-searching-agent # 2. 安装 Python 依赖 uv sync # 3. 安装浏览器引擎(Crawl4AI 依赖 Playwright Chromium,首次约 5-10 分钟) uv run crawl4ai-setup # 4. 配置 API Key cp .env.example .env # 编辑 .env,填入 DEEPSEEK_API_KEY=sk-xxx(注册即送免费额度) # 5. 一键启动 uv run python run.py ``` > **如果第 3 步 `crawl4ai-setup` 失败**(网络问题或系统不支持),可以跳过此步,改用 httpx-only 模式: > ```bash > uv run python run.py --no-render > ``` > 此模式不使用浏览器引擎,通过纯 HTTP 请求抓取,功能完整但部分 JS 渲染页面可能抓不到。 运行完成后自动打开 HTML 报告,结果输出到: - `output/jobs.json` — 结构化岗位列表 - `output/jobs.csv` — 表格格式 - `output/report_.html` — 可视化运行报告 ### API Key 配置 **至少需要一个 LLM provider key:** | Provider | Env Var | 说明 | |----------|---------|------| | **DeepSeek(推荐)** | `DEEPSEEK_API_KEY` | 默认模型,最便宜,注册即送额度 | | OpenAI | `OPENAI_API_KEY` | 备选,需注意 TPM 限制 | | 通义千问 | `DASHSCOPE_API_KEY` | | | 智谱 GLM | `GLM_API_KEY` | | | Kimi | `KIMI_API_KEY` | | > DeepSeek 注册地址:https://platform.deepseek.com — 新用户赠送免费额度,足够跑多次。 **可选 key(不影响核心功能):** - `FIRECRAWL_API_KEY` — Firecrawl 兜底爬虫(仅当 Crawl4AI 失败时才需要) - `LANGFUSE_PUBLIC_KEY` / `LANGFUSE_SECRET_KEY` — 云端 trace(默认关闭) **安全策略:** - `config.yaml` 已 commit — 只含配置项,**不含任何密钥** - `.env` 在 `.gitignore` 中 — **绝不会被 commit** ### 运行模式 ```bash # 默认模式:搜索 "AI Engineer 校招"(需要 API key + 网络) uv run python run.py # 自定义搜索词 uv run python run.py --query "算法工程师 实习" # Dry-run:只展示关键词扩展,不抓取 uv run python run.py --dry-run # 完全离线(无需 API key,无需网络,用于快速验证安装) uv run python run.py --fixtures --mock-llm ``` ### Output 运行完成后自动生成: - `output/jobs.json` — 结构化岗位列表(JSON 数组) - `output/jobs.csv` — 表格格式(tech_tags 用 `|` 分隔) - `output/report_.html` — 可视化运行报告(自动在浏览器打开) - `logs/events.jsonl` — 完整事件日志(可用 `jq` 解析) ## Run Modes | Mode | Flags | Network | LLM | Use Case | |------|-------|---------|-----|----------| | **Full** | *(none)* | Yes | Yes | Production run | | **Dry-run** | `--dry-run` | No | Yes | Preview keyword expansion | | **Fixtures** | `--fixtures` | No | Yes | Test with real LLM, offline crawling | | **Offline** | `--fixtures --mock-llm` | No | No | CI / quick smoke test | | **No-render** | `--no-render` | Yes | Yes | Skip Crawl4AI/Playwright, httpx only | ## Switching LLM Providers The default model is set in `config.yaml`: ```yaml model: "deepseek:deepseek-chat" ``` To switch providers, change the model string. Supported prefixes: - `deepseek:deepseek-chat` (default, recommended) - `openai:gpt-4o-mini` (good fallback if DeepSeek tool-use is unreliable) - `anthropic:claude-sonnet-4-20250514` - `qwen:qwen-plus` - `glm:glm-4` - `kimi:moonshot-v1-8k` > **DeepSeek tool-use note**: DeepSeek's tool-use support can be inconsistent. If you experience issues (malformed tool calls, infinite loops), switch to `openai:gpt-4o-mini` as a fallback -- it has robust tool-use and is similarly priced. ## Refreshing Fixtures The `tests/fixtures/` directory contains offline HTML/JSON snapshots from each job site. These are used for `--fixtures` mode and unit tests. To refresh them: 1. Ensure you have network access and the target sites are reachable. 2. Delete the stale fixtures: `rm -rf tests/fixtures//*` 3. Run the adapter's fixture capture script or manually save new snapshots. 4. Run tests to verify: `uv run pytest tests/test_adapter_.py -v` > **Note**: Fixture snapshots may become stale as sites update their HTML structure. If adapter tests start failing, refreshing fixtures is the first thing to try. ## Crash Recovery If a run is interrupted (Ctrl+C, crash, timeout), the next run automatically detects and marks orphaned runs as `failed` in SQLite. **Runs are not resumable** -- a new `run_id` is generated each time. Simply re-run the command. ## FAQ **Q: How does the agent decide which jobs are relevant?** The `classifier.py` sub-agent uses the LLM to evaluate each job posting against the query. It checks: (1) is this an AI/ML engineering role, (2) is it new-grad or intern level, (3) extracts tech tags and builds a `SkillPortrait` (core skills, nice-to-have, domain, years hint). Jobs that don't match are filtered out. **Q: How does deduplication work?** Each job gets a `unique_hash` based on company + title + location. SQLite enforces uniqueness per `run_id`. The orchestrator also tracks seen URLs in-memory to avoid re-fetching. **Q: Why five different job sites?** Multi-source strategy reduces the risk of any single site being down or blocking requests. Each adapter handles site-specific parsing (HTML scraping or JSON API), while the base adapter provides unified fixtures routing and circuit-breaker logic. **Q: How is cost controlled?** `pricing.py` maintains a local token-cost table for each model. After every LLM call, `guardrails.py` accumulates the cost from PydanticAI's `usage()`. If the total exceeds `config.limits.max_llm_usd` (default $2.00), the agent emits a `budget_warning` event and gracefully exits. An empty-state abort also triggers if the classified rate falls below 10% after round 2. **Q: Can I add a new job site?** Yes. Create `src/adapters/.py` implementing the `SiteAdapter` protocol (see `base.py`). Add the site name to `config.yaml`'s `sources` list. Capture fixtures to `tests/fixtures//` for offline testing. ## Development ```bash # Run all unit tests (mock LLM, no network) uv run pytest tests/ -v -m "not eval" # Run real-LLM evaluation tests (requires API key) uv run pytest tests/eval/ -m eval -v # Lint uv run ruff check src/ tests/ ``` ## License MIT