### Install dependencies (bash) Source: https://github.com/agibottech/agibot_agentsdk_sample_code/blob/main/README.md Commands to create a virtual environment, activate it, upgrade pip, install the AgentSDK wheel, and install project dependencies. Requires downloading the wheel or source package first. ```bash cd /path/to/sample_code python3 -m venv .venv source .venv/bin/activate python -m pip install --upgrade pip python -m pip install /path/to/agentsdk-package.whl python -m pip install -r requirements.txt ``` -------------------------------- ### Install dependencies (PowerShell) Source: https://github.com/agibottech/agibot_agentsdk_sample_code/blob/main/README.md Windows PowerShell commands to create a virtual environment, activate it, upgrade pip, install the AgentSDK wheel, and install project dependencies. ```powershell python -m venv .venv .\ .venv\Scripts\Activate.ps1 python -m pip install --upgrade pip python -m pip install C:\path\to\agentsdk-package.whl python -m pip install -r requirements.txt ``` -------------------------------- ### Install AgentSDK from source package Source: https://github.com/agibottech/agibot_agentsdk_sample_code/blob/main/README.md Replacement command for installing the AgentSDK when using a source package instead of a wheel. ```bash python -m pip install /path/to/agentsdk-source-package ``` -------------------------------- ### Example LLM configuration for business model Source: https://github.com/agibottech/agibot_agentsdk_sample_code/blob/main/README.md JSON configuration for an OpenAI-compatible LLM provider (e.g., Volcano Ark) for the business reply route. Uses api_key_env instead of a hardcoded key. ```json { "provider": "openai_compatible", "base_url": "https://ark.cn-beijing.volces.com/api/v3", "api_key_env": "BUSINESS_LLM_API_KEY", "model": "ep-your-endpoint-id", "temperature": 0.1, "max_tokens": 512, "timeout_seconds": 5, "business_timeout_seconds": 10, "stream": true } ``` -------------------------------- ### Project structure tree Source: https://github.com/agibottech/agibot_agentsdk_sample_code/blob/main/README.md Shows the file and directory layout of the sample_code project, including entry points, handlers, configuration files, and knowledge base files. ```text sample_code/ ├── main.py # 应用入口和 AgentSDK 回调 ├── app_config.py # 配置加载与校验 ├── scope_router.py # LLM 意图路由和结果解析 ├── route_dispatcher.py # 响应意图注册与分发 ├── handlers/ # 由分发器动态加载的响应处理器 │ ├── __init__.py │ ├── business_handler.py │ └── general_chat_handler.py ├── skill_handler.py # 技能白名单校验与执行 ├── skill_config.py # 技能配置解析 ├── conversation_manager.py # 单机器人内存会话 ├── knowledge_retriever.py # 远程知识库检索 ├── llm_client.py # OpenAI-compatible LLM 客户端 ├── config.json # 技术运行配置 ├── config/ │ ├── prompt_layout.json # 开发人员维护的提示词结构 │ └── locales/ │ ├── zh-CN.json # 简体中文提示词与话术 │ └── en-US.json # 英文提示词与话术 ├── knowledge_base/ # 用于导入灵心平台的知识库文件 │ ├── hospital_qa_curated_250_zh.xlsx │ └── hospital_qa_curated_250_en.xlsx ├── .env.example # 环境变量名称示例 ├── requirements.txt # 固定版本依赖 ├── pyproject.toml # Python 项目元数据 ├── README.md # 中文说明 └── README_EN.md # English documentation ``` -------------------------------- ### 导入环境变量并启动应用 Source: https://github.com/agibottech/agibot_agentsdk_sample_code/blob/main/README.md 在 Linux/macOS 上导出所需环境变量,验证配置文件 JSON 格式,然后启动 main.py。程序不会自动加载 .env,需在启动 main.py 的同一 shell 中执行 export 或通过容器/部署系统注入。按 Ctrl+C 可停止应用。 ```bash export AGIBOT_APP_ID="your_app_id" export AGIBOT_APP_KEY="your_app_key" export AGIBOT_APP_SECRET="your_app_secret" export AGIBOT_AGENT_CODE="your_agent_code" export SCOPE_ROUTER_LLM_API_KEY="your_scope_router_llm_api_key" export GENERAL_CHAT_LLM_API_KEY="your_general_chat_llm_api_key" export BUSINESS_LLM_API_KEY="your_business_llm_api_key" python -m json.tool config.json >/dev/null python -m json.tool config/prompt_layout.json >/dev/null python -m json.tool config/locales/zh-CN.json >/dev/null python -m json.tool config/locales/en-US.json >/dev/null python main.py ``` -------------------------------- ### 在 config.json 的 reply_routes 中注册技术配置 Source: https://github.com/agibottech/agibot_agentsdk_sample_code/blob/main/README.md 在 config.json 的 reply_routes 中添加同名配置,指定处理器路径、LLM 配置和知识库设置。LLM 使用 openai_compatible provider,api_key 从环境变量读取。 ```json "registration": { "handler": "handlers.registration_handler:RegistrationHandler", "llm": { "provider": "openai_compatible", "base_url": "https://ark.cn-beijing.volces.com/api/v3", "api_key_env": "REGISTRATION_LLM_API_KEY", "model": "ep-your-endpoint-id", "stream": false }, "knowledge_base": {"enabled": false} } ``` -------------------------------- ### 创建 RegistrationHandler 处理器文件 Source: https://github.com/agibottech/agibot_agentsdk_sample_code/blob/main/README.md 每个响应意图对应一个独立处理器文件,需继承 BaseHandler 并实现 handle 方法。处理器必须位于 handlers/ 目录,文件名以 _handler.py 结尾。BaseHandler 根据合并后的当前意图配置创建 self.llm,可直接调用。 ```python from base_handler import BaseHandler, HandlerContext class RegistrationHandler(BaseHandler): def handle(self, context: HandlerContext) -> str: reply_text = self.llm(context.user_text, history=context.history) context.response.on_vlm_item_delta( context.event_id, context.item_id, reply_text, ) context.response.on_vlm_item_done(context.event_id, context.item_id) context.response.on_vlm_done(context.event_id) return reply_text ``` -------------------------------- ### 在 config/locales/zh-CN.json 中添加语言文本 Source: https://github.com/agibottech/agibot_agentsdk_sample_code/blob/main/README.md 在 config/locales/zh-CN.json 的同名 reply_routes 中添加语言文本,包括 description、waiting_replies、system_prompt、user_prompt 和 timeout_reply_text。description 会自动加入路由模型的意图说明。 ```json "registration": { "description": "挂号流程相关咨询", "waiting_replies": [], "system_prompt": "...", "user_prompt": "...", "timeout_reply_text": "系统当前繁忙,请稍后再试。" } ``` -------------------------------- ### 配置知识库检索参数 Source: https://github.com/agibottech/agibot_agentsdk_sample_code/blob/main/README.md 在 config.json 的 reply_routes.business.knowledge_base 中配置检索参数,包括启用、API URL、top_k、rerank 等。注意此片段仅展示知识库配置路径,应与 business 中已有的 handler 和 llm 配置合并。 ```json { "reply_routes": { "business": { "knowledge_base": { "enabled": true, "api_url": "https://open.agibot.com/api/V1/open-portal/app/retriever/search/agent_kb", "top_k": 5, "rerank": true, "check_qa_first": true, "score_threshold": 0.1, "timeout_seconds": 5, "business_timeout_seconds": 5 } } } } ``` -------------------------------- ### 配置英文 locale_file Source: https://github.com/agibottech/agibot_agentsdk_sample_code/blob/main/README.md 在 config.json 顶层设置 locale_file 为英文路径。 ```json { "locale_file": "config/locales/en-US.json" } ``` -------------------------------- ### 配置中文 locale_file Source: https://github.com/agibottech/agibot_agentsdk_sample_code/blob/main/README.md 在 config.json 顶层设置 locale_file 为中文路径。 ```json { "locale_file": "config/locales/zh-CN.json" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.