# bff-agent **Repository Path**: hivedark/bff-agent ## Basic Information - **Project Name**: bff-agent - **Description**: 好友 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-08-07 - **Last Updated**: 2026-08-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # BFF Agent Backend-For-Frontend AI Agent 服务,基于 FastAPI 构建,支持 SSE 流式响应、Tool/Skill 调用、Sub Agent 和定时任务。 ## 特性 - **HTTP API** - FastAPI REST API,支持 SSE 流式响应 - **TUI 界面** - 交互式终端界面,实时显示思考过程 - **CLI 模式** - 命令行交互模式 - **Tool 系统** - 内置文件操作、Shell 命令、Web 搜索等工具 - **Skill 系统** - 组合多个工具实现复杂工作流 - **Sub Agent** - 主 Agent 管理多个子 Agent - **定时任务** - Cron 表达式任务调度 - **多模型支持** - 支持 OpenAI、Anthropic、MiniMax 等模型,动态切换 ## 项目结构 ``` bff_agent/ ├── api/routes/ # API 路由 ├── cli/ # CLI 入口 ├── cli_textual.py # TUI 界面 ├── llm/ # LLM 客户端 ├── scheduler/ # 任务调度器 ├── session/ # 会话存储 ├── skills/ # Skill 系统 ├── subagent/ # Sub Agent 系统 └── tools/ # 工具实现 .bff/ ├── agents/ # Agent MD 配置文件 └── skills/ # Skill MD 配置文件 ``` ## 快速开始 ### 安装 ```bash pip install -e . ``` ### TUI 模式(推荐) 交互式终端界面,支持动画显示思考过程: ```bash bff-agent tui ``` ### CLI 模式 ```bash # 交互模式 bff-agent chat # 单次执行 bff-agent chat "Hello, world!" # 指定 Agent bff-agent chat --agent-id default "Hello!" ``` ### 启动服务 ```bash bff-agent serve # 或 python -m bff_agent.main ``` ## API 使用 ```bash # 健康检查 curl http://localhost:8080/health # 创建会话 curl -X POST http://localhost:8080/api/sessions \ -H "Content-Type: application/json" \ -d '{"agent_id": "default"}' # 发送消息(SSE 流式) curl -X POST http://localhost:8080/api/chat \ -H "Content-Type: application/json" \ -d '{"session_id": "xxx", "message": "Hello", "stream": true}' # 列出工具 curl http://localhost:8080/api/tools # 列出 Skills curl http://localhost:8080/api/skills # 列出可用模型 curl http://localhost:8080/api/models ``` ## 配置 编辑 `config.yaml` 或设置环境变量: ```yaml # config.yaml models: default_model: MiniMax-M2.7 providers: minimax: api_key: your_api_key base_url: https://api.minimax.chat/v1 ``` 或使用环境变量: ```bash export OPENCODE_URL=http://localhost:4096 export PORT=8080 export LOG_LEVEL=INFO ``` ## Agent 配置 在 `.bff/agents/` 目录下创建 MD 配置文件: ```markdown --- name: my-agent description: 我的 Agent skills: - my-skill enabled: true model_id: MiniMax-M2.7 --- ## 角色定义 你是一个专业的... ## 规则 1. 始终... 2. 不要... ``` ## Skill 配置 在 `.bff/skills/` 目录下创建 MD 配置文件: ```markdown --- name: my-skill description: 我的技能 tools: - file_read - shell enabled: true --- ## 指令 这个技能用于... ``` ## 内置工具 | 工具 | 说明 | |------|------| | `file_read` | 读取文件内容 | | `file_write` | 写入文件 | | `file_list` | 列出目录文件 | | `shell` | 执行 Shell 命令 | | `web_search` | Web 搜索 | | `web_fetch` | 获取网页内容 | | `weather` | 查询天气(支持1-3天预报)| ## 开发 ```bash # 安装开发依赖 pip install -e ".[dev]" # 运行测试 pytest # 代码检查 ruff check . # 代码格式化 ruff format . ``` ## 技术栈 - FastAPI + Uvicorn - Textual(TUI) - aiosqlite(会话存储) - APScheduler(定时任务) - httpx / httpcore(HTTP 客户端) - Pydantic(数据验证) ## License MIT