SuperAPI AI 工具集

dym-harness-sdk-quickstart

智能体与模型

查看项目

更新于 10-18 01:21

技能介绍

用途

该技能面向需要“开箱即用”智能体的场景:希望用一行 create_harness() 获得带 shell、文件读写、网页抓取、子智能体、待办、记忆、会话与上下文卸载等能力的智能体,而无需自行编写 agent loop。也可在花钱调用模型之前,先查看 harness 会装配哪些工具与插件。生成结果是普通的 strands.Agent,而非额外包装类,因此搭建后仍可继续使用 SDK 的全部能力。

安装与环境

使用隔离虚拟环境,Python 需 ≥ 3.10(macOS 系统自带的 Python 3.9 无法安装):

python3.13 -m venv .venv-strands && .venv-strands/bin/pip install -q strands-harness

provider khác Bedrock: strands-harness[anthropic] | [openai] | [gemini] | [ollama] | [litellm]

主要能力与验证

可在不调用模型的情况下搭建智能体并查看工具列表:

from strands_harness import create_harness a = create_harness(session=False, memory=False) print(sorted(a.tool_names))

['edit','programmatic_tool_caller','read','retrieve_context','retrieve_offloaded_content',

'shell','strands_manage_background_task','subagent','todo_write','web_fetch','write']

真正运行会消耗费用,例如 a("Find the slowest test in this repo")。默认模型为 Bedrock Opus 5,需要 AWS 凭证;可通过 model="anthropic/claude-fable-5"(provider/name 字符串)切换。

create_harness 的主要参数(keyword-only):model · effort(auto|off|minimal..max)· instructions(拼接在 harness contract 之后)· tools · mcp_servers · builtin_tools · session(默认 ./.agent/sessions)· memory(默认 ./.agent/memory)· skills · builtin_plugins · interventions · **agent_kwargs(显式传入的 SDK 值总是优先于 harness 默认值)。

如需启用 trace,在搭建前设置 OTEL_TRACES_EXPORTER=otlp(或 console);未设置则关闭遥测。

使用注意与限制

  • 模型不支持原生 web search(如 Bedrock)时,harness 只打印警告并移除 web_search 工具,不会报错;需要搜索时设置 builtin_tools={'web_search': 'exa'}。
  • session/memory 默认开启并写入当前工作目录的 ./.agent/;试验时应设为 session=False, memory=False,以免污染仓库。
  • 五个来源(consumer · builtin · MCP · plugin · subagent)存在同名工具时,会在搭建阶段直接报错;MCP 工具只有在连接后才知道名称,因此可能绕过该检查。
  • Memory extract 在后台运行:短脚本必须调用 shutdown,否则可能丢失数据。
  • 生产使用需谨慎:harness 仍为 0.x,且默认启用 strands.experimental 的 ContextManager,不承诺 semver。