Hermes 不仅仅是一个 CLI 工具。你可以直接导入 AIAgent,在自己的 Python 脚本、Web 应用或自动化流水线中以编程方式使用它。pip install git+https://github.com/NousResearch/hermes-agent.git
MODEL_PROVIDER=customMODEL_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1MODEL_API_KEY=sk-yourkey
from run_agent import AIAgent# 仅保留 model、quiet_mode,不再传 provider_configagent = AIAgent( model="qwen3.6-plus", quiet_mode=True)response = agent.chat("你是谁?")print(response)
我是 **Hermes Agent**,由 Nous Research 创建的智能 AI 助手。简单来说,我是一个能帮你做很多事情的 AI Agent——比如:- 💻 **编程**:写代码、调试、运行脚本- 🔍 **信息检索**:搜索网页、阅读文章、分析数据- 🎨 **创意工作**:生成图像、制作视频、写文案- 🤖 **自动化**:控制浏览器、操作桌面、运行脚本- 📝 **文档**:处理文件、笔记、演示文稿等我运行在 Linux 环境中,有各种工具可以使用,还能在多轮对话中记住你的偏好和习惯。有什么我可以帮你的吗?
参考:https://hermes-agent.nousresearch.com/docs/zh-Hans/guides/python-libraryimport asynciofrom nanobot import Nanobotdef main(): # 手动创建事件循环执行异步任务 loop = asyncio.get_event_loop() async def task_logic(): bot = Nanobot.from_config() res = await bot.run("你是谁?", session_key="sdk:first-run") print(res.content) loop.run_until_complete(task_logic()) loop.close()if __name__ == "__main__": main()
2026-06-28 19:10:49.674 | INFO | nanobot.agent.loop:_register_default_tools:497 - Registered 16 tools: ['apply_patch', 'run_cli_app', 'complete_goal', 'edit_file', 'exec', 'find_files', 'grep', 'list_dir', 'list_exec_sessions', 'long_task', 'message', 'read_file', 'spawn', 'write_file', 'write_stdin', 'my']2026-06-28 19:10:50.027 | WARNING | nanobot.agent.tools.mcp:connect_single_server:519 - MCP server 'DeviceControl-MCP': http://192.168.31.110:8002/sse unreachable, skipping2026-06-28 19:10:50.027 | WARNING | nanobot.agent.tools.mcp:connect_missing_servers:754 - No MCP servers connected successfully (will retry next message)2026-06-28 19:10:50.028 | INFO | nanobot.agent.loop:_state_restore:1299 - Processing message from cli:user: 你是谁?2026-06-28 19:10:50.028 | DEBUG | nanobot.agent.loop:_process_message:1233 - [turn sdk:first-run:1782645050028057186] State RESTORE took 0.4ms -> event ok2026-06-28 19:10:50.028 | DEBUG | nanobot.agent.loop:_process_message:1233 - [turn sdk:first-run:1782645050028057186] State COMPACT took 0.0ms -> event ok2026-06-28 19:10:50.028 | DEBUG | nanobot.agent.loop:_process_message:1233 - [turn sdk:first-run:1782645050028057186] State COMMAND took 0.0ms -> event dispatch2026-06-28 19:10:50.327 | DEBUG | nanobot.agent.memory:maybe_consolidate_by_tokens:711 - Token consolidation idle sdk:first-run: 9257/65536 via tiktoken, msgs=82026-06-28 19:10:50.359 | DEBUG | nanobot.agent.loop:_process_message:1233 - [turn sdk:first-run:1782645050028057186] State BUILD took 330.6ms -> event ok2026-06-28 19:10:50.368 | DEBUG | nanobot.agent.progress_hook:before_iteration:104 - Starting agent loop iteration 0 for session sdk:first-run2026-06-28 19:10:52.470 | DEBUG | nanobot.agent.progress_hook:after_iteration:170 - LLM usage: prompt=9453 completion=40 cached=02026-06-28 19:10:52.470 | DEBUG | nanobot.agent.loop:_process_message:1233 - [turn sdk:first-run:1782645050028057186] State RUN took 2110.9ms -> event ok2026-06-28 19:10:52.471 | DEBUG | nanobot.agent.loop:_process_message:1233 - [turn sdk:first-run:1782645050028057186] State SAVE took 0.6ms -> event ok2026-06-28 19:10:52.471 | INFO | nanobot.agent.loop:_assemble_outbound:1274 - Response to cli:user: 我是 nanobot 🐈,你的个人AI助手。我来帮你处理任务、查找信息、管理提醒,或者只是聊聊天。有什么需要我帮忙的吗? 😊2026-06-28 19:10:52.471 | DEBUG | nanobot.agent.loop:_process_message:1233 - [turn sdk:first-run:1782645050028057186] State RESPOND took 0.1ms -> event ok2026-06-28 19:10:52.471 | DEBUG | nanobot.agent.loop:_process_message:1249 - [turn sdk:first-run:1782645050028057186] Turn completed after 7 states我是 nanobot 🐈,你的个人AI助手。我来帮你处理任务、查找信息、管理提醒,或者只是聊聊天。有什么需要我帮忙的吗? 😊2026-06-28 19:10:52.509 | DEBUG | nanobot.agent.memory:maybe_consolidate_by_tokens:711 - Token consolidation idle sdk:first-run: 9355/65536 via tiktoken, msgs=10
https://nanobot.wiki/cn/docs/0.2.2/advanced/python-sdk
使用OpenAI兼容API:
先运行:
🐈 Starting OpenAI-compatible API server Endpoint : http://127.0.0.1:8900/v1/chat/completions Model : qwen-flash Session : api:default Timeout : 120.0s
测试程序:
from openai import OpenAIclient = OpenAI( base_url="http://127.0.0.1:8900/v1", api_key="dummy",)resp = client.chat.completions.create( model="qwen-flash", messages=[{"role": "user", "content": "你是谁?"}], extra_body={"session_id": "my-session"},)print(resp.choices[0].message.content)
运行:
I'm nanobot 🐈, your personal AI assistant. I'm here to help you with tasks, answer questions, and make your day easier! 😊
OpenClaw
openclaw有点差异,两种方式
参考:
https://docs.openclaw.ai/zh-CN/gateway/protocol
https://github.com/masteryodaa/openclaw-sdk
