feat: LLM Provider 管理、Token 用量追踪与 Python 代码执行工具#8
Merged
Conversation
## 核心变更
### LLM Provider 管理系统
- 新增 `agentpal/providers/` 模块:ProviderConfig、ProviderManager、OpenAIProvider、RetryModel
- 新增 `/api/v1/providers` REST API(CRUD + 连通性测试 + 模型发现)
- 支持多 Provider 配置、api_key 打码展示、自定义 Provider 管理
### Token 用量追踪
- 新增 `LLMCallLog` ORM 模型(`llm_call_logs` 表),按 session + call_round 记录用量
- `PersonalAssistant` 流式/非流式对话均自动写 token 日志
- 新增 `GET /api/v1/sessions/{id}/usage` 用量明细 API
- Dashboard 新增 `input_tokens` / `output_tokens` / `llm_calls` 精确统计
### execute_python_code 工具(#10)
- 在隔离子进程中执行 Python 代码,支持动态 `pip install` 依赖
- stdout / stderr 完整捕获,输出超 8000 字自动截断
- ChatPage 新增 Python 代码输出渲染组件(行号 + 退出码 + 输出块)
### 其他
- 内置 skills_data(find-skills / frontend-design / notion-api)开箱即用
- 新增 `init.sh` 开发环境一键初始化脚本
- 新增 Provider 单元测试 & cron_cli 工具测试
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
providers/模块(ProviderManager、OpenAIProvider、RetryModel)及/api/v1/providersREST API,支持多 Provider 配置、api_key 打码、连通性测试、动态模型发现LLMCallLog模型逐轮记录 token 消耗,PersonalAssistant 自动写日志;新增GET /sessions/{id}/usage用量明细 API;Dashboard 统计升级(input_tokens / output_tokens / llm_calls)变更文件
agentpal/providers/(5 files)api/v1/endpoints/providers.pymodels/llm_usage.pyLLMCallLogORM 模型agents/personal_assistant.pyapi/v1/endpoints/session.py/usage用量明细api/v1/endpoints/dashboard.pytools/builtin.pyexecute_python_code工具frontend/src/pages/ChatPage.tsxtests/unit/test_providers/tests/unit/test_cron/test_cron_cli.pyskills_data/init.shTest plan
cd backend && .venv/bin/pytest tests/unit/ tests/integration/ -v --tb=short全部通过llm_call_logs表有数据写入GET /api/v1/sessions/{id}/usage返回正确 token 数input_tokens/output_tokens/llm_calls有统计值GET /api/v1/providers返回 Provider 列表(api_key 打码)POST /api/v1/providers/{id}/test测试 Provider 连通性execute_python_code工具,让 Agent 执行简单 Python 脚本,ChatPage 正确渲染输出🤖 Generated with Claude Code