开源项目 GitHub Trending 2026-09-23T12:01 正文 ok 819 words

Strands Agents Harness SDK:端到端构建并控制 AI Agent

英文标题:🔥 strands-agents/harness-sdk

Strands Agents 是一个开源 SDK,支持使用 Python 和 TypeScript 构建、运行生产级 AI Agent,并且无需依赖托管控制平面。项目提供开箱即用的 Strands harness,以及可深度定制 Agent 循环、工具、模型提供商、记忆、会话与 Hooks 的底层 SDK。其支持 Amazon Bedrock、Anthropic、OpenAI、Gemini 等多种模型平台,并内置 MCP、流式输出、多 Agent 模式、结构化输出、护栏、追踪和评测能力。对开发者而言,该项目可在快速原型与自主掌控 Agent 基础设施之间提供渐进式路径,且支持在不同模型和云服务之间迁移而尽量不改动业务代码。
打开原文相关 5 · 机会 6
media2.0 KB media2.0 KB media1.3 KB media1.3 KB media1.3 KB media1.3 KB media1.3 KB media1.3 KB media1.2 KB media1.3 KB media1.3 KB media61.1 KB

中文

Strands Agents 是一个用于在 Python 和 TypeScript 中构建和运行 AI Agent 的开源 SDK。当你原本需要自行编写 Agent 循环时,可以选择 Strands:它在你的进程内运行,不依赖托管控制平面,并覆盖了手写循环逐渐会演变出的各类能力。在一个 SDK 中,你可以获得生命周期控制(轮次限制、Token 预算、取消、停止原因)、工具和结构化输出、MCP、多 Agent 模式、记忆和会话、模型可移植性、流式处理、护栏、追踪以及评测。

这个 monorepo 包含 Strands harness、Python 和 TypeScript SDK、文档站点及支持包:

目录 说明
harness-py/ Python Strands harness:通过 create_harness() 创建完整组装的 Agent(PyPI · 文档)
harness-ts/ TypeScript Strands harness:通过 createHarness() 创建完整组装的 Agent(npm · 文档)
strands-cli/ strands CLI:可在终端中对 harness Agent 进行原型开发和聊天(npm)
strands-py/ Python SDK:Agent 循环、模型提供商、工具(PyPI · 发行版本)
strands-ts/ TypeScript SDK:Agent 循环、模型提供商、工具(npm · 发行版本)
site/ strandsagents.com 文档站点的源代码(Astro/Starlight)
team/ 治理与跨 SDK 流程文档,包括原则、决策、PR 与兼容性指南,以及 designs/ 提案

构建 Agent harness,端到端掌控它。

  • 按你的方式构建。 支持任意模型、任意云。在写下一行配置之前,即可获得内置的上下文管理、执行限制和可观测性。随着规模增长可更换后端,代码保持不变。
  • 模型无关。 原生支持 Amazon Bedrock、Anthropic、OpenAI 和 Gemini,以及更多提供商和自定义提供商。
  • 始终保持控制。 Agent 循环默认追踪每一个决策。Hooks 让你能拦截任意步骤,进行记录、验证或重定向。
  • 交付可靠结果。 护栏会在错误实际执行前将其捕获。Steering handlers 让 Agent 可以自行纠正,而非静默失败。

MCP、流式处理、多 Agent 模式和结构化输出均已内置。

最简单的入门方式是使用 Strands harness,这是一个完整组装、技术先进的 Agent。只需一次 create_harness()(Python)或 createHarness()(TypeScript)调用,即可获得一个经过优化的 Agent,其中包含面向模型、工具、记忆、会话和上下文管理的基准化默认配置,可直接从创意推进至生产环境。请遵循 harness 快速入门,或查看 Python Strands harness 和 TypeScript Strands harness 软件包开始使用。

pip install strands-harness

python from strands_harness import create_harness

agent = create_harness() agent("Find the slowest test in this repo and explain why it's slow")

npm install @strands-agents/harness

typescript import { createHarness } from '@strands-agents/harness'

const agent = await createHarness() await agent.invoke("Find the slowest test in this repo and explain why it's slow")

从这里开始可获得一个开箱即用的 Agent;当你希望自己掌控 Agent 循环,并自行连接工具、模型提供商和记忆能力时,再深入使用下方的 SDK。harness 配置参考记录了每一项可覆盖的默认配置。

快速入门指南介绍了如何配置提供商,包括 Amazon Bedrock、Anthropic、OpenAI、Gemini、Ollama 等。

Strands Harness SDK 可让你进一步深入并控制 Agent 的每个部分:循环、工具、模型提供商、记忆、会话和 Hooks。你可以在使用 Strands harness 后再深入 SDK;或者,当组合式默认配置无法满足需求时,也可以从头开始构建自己的 harness。

要求 Python 3.10+:

pip install strands-agents strands-agents-tools

python from strands import Agent from strands_tools import calculator

agent = Agent(tools=[calculator]) agent("What is the square root of 1764")

Python SDK README 涵盖工具、模型提供商、MCP 和双向流式处理。

要求 Node.js 22+:

npm install @strands-agents/sdk

typescript import { Agent } from '@strands-agents/sdk'

const agent = new Agent() const result = await agent.invoke('What is the square root of 1764?') console.log(result)

更多内容请参阅 TypeScript SDK README,其中包括 Zod 类型化工具、结构化输出和多 Agent 模式。

如需详细指南与示例,请探索我们的文档:

文档本身位于此 monorepo 的 site/ 目录中,欢迎结合代码变更一并提交文档 PR。

Git 操作(提交、分支、PR)均从仓库根目录执行。每个软件包都有各自的工具链:

Python SDK(strands-py/):

cd strands-py pip install hatch hatch test # run unit tests hatch fmt # format & lint

TypeScript SDK(strands-ts/):

npm ci # install from repo root npm run build # build npm test # run unit tests

文档站点(site/):

cd site npm install npm run dev # local dev server at http://localhost:4321/

我们欢迎贡献!有关以下事项的详细信息,请参阅我们的贡献指南:

  • 报告 Bug 与功能需求
  • 开发环境设置
  • 通过 Pull Request 贡献
  • 行为准则
  • 报告安全问题

与团队保持联系

欢迎在 Discord 上与 Strands 团队及其他用户交流。

本项目采用 Apache License 2.0 许可协议,详情请见 LICENSE.APACHE 文件。

有关更多信息,请参阅 CONTRIBUTING。

English / 原文

Strands Agents is an open-source SDK for building and running AI agents in Python and TypeScript. Choose Strands when you would otherwise write your own agent loop: it runs in your process with no hosted control plane, and it covers the jobs a hand-rolled loop grows into. In one SDK you get lifecycle controls (turn limits, token budgets, cancellation, stop reasons), tools and structured output, MCP, multi-agent patterns, memory and sessions, model portability, streaming, guardrails, tracing, and evals.

This monorepo contains Strands harness, the Python and TypeScript SDKs, the documentation site, and supporting packages:

Directory Description
harness-py/ Python Strands harness: fully assembled agent via create_harness() (PyPI · docs)
harness-ts/ TypeScript Strands harness: fully assembled agent via createHarness() (npm · docs)
strands-cli/ strands CLI: prototype and chat with a harness agent from the terminal (npm)
strands-py/ Python SDK: agent loop, model providers, tools (PyPI · releases)
strands-ts/ TypeScript SDK: agent loop, model providers, tools (npm · releases)
site/ Source for the strandsagents.com documentation site (Astro/Starlight)
team/ Governance and cross-SDK process docs (tenets, decisions, PR & compatibility guidelines, and designs/ proposals)

Build an agent harness. Control it end-to-end.

  • Build your way. Any model, any cloud. Context management, execution limits, and observability built in before you write a line of config. Swap backends when you scale; your code stays the same.
  • Model agnostic. First-class support for Amazon Bedrock, Anthropic, OpenAI, and Gemini, plus many more providers and custom ones.
  • Stay in control. The agent loop traces every decision by default. Hooks let you intercept any step to log it, validate it, or redirect it.
  • Deliver outcomes that work. Guardrails catch mistakes before they run. Steering handlers let agents correct themselves instead of failing silently.

MCP, streaming, multi-agent patterns, and structured output are all built in.

The easiest way to get started is with Strands harness , a fully assembled, state-of-the-art agent. A single create_harness() (Python) or createHarness() (TypeScript) call gives you an optimized agent with benchmarked defaults for the model, tools, memory, sessions, and context management — ready to take from idea to production. Follow the harness quickstart, or see the Python Strands harness and TypeScript Strands harness packages to get started.

pip install strands-harness


from strands_harness import create_harness

agent = create_harness()
agent("Find the slowest test in this repo and explain why it's slow")


npm install @strands-agents/harness


import { createHarness } from '@strands-agents/harness'

const agent = await createHarness()
await agent.invoke("Find the slowest test in this repo and explain why it's slow")

Start here to get a batteries-included agent, then drop down to the SDKs below when you want to own the agent loop and wire up tools, model providers, and memory yourself. The harness configuration reference documents every default you can override.

The Quickstart Guide covers configuring providers (Amazon Bedrock, Anthropic, OpenAI, Gemini, Ollama, and more).

The Strands Harness SDK lets you go deeper and control every part of the agent: the loop, tools, model providers, memory, sessions, and hooks. You can dive into the SDK after working with Strands harness or if you prefer building your own harness from the ground up when the assembled defaults aren't enough.

Requires Python 3.10+:

pip install strands-agents strands-agents-tools


from strands import Agent
from strands_tools import calculator

agent = Agent(tools=[calculator])
agent("What is the square root of 1764")

The Python SDK README covers tools, model providers, MCP, and bidirectional streaming.

Requires Node.js 22+:

npm install @strands-agents/sdk


import { Agent } from '@strands-agents/sdk'

const agent = new Agent()
const result = await agent.invoke('What is the square root of 1764?')
console.log(result)

More in the TypeScript SDK README, including Zod-typed tools, structured output, and multi-agent patterns.

For detailed guidance & examples, explore our documentation:

The docs themselves live in this monorepo under site/, and doc PRs are welcome alongside code changes.

Git operations (commits, branches, PRs) are done from the repo root. Each package has its own toolchain:

Python SDK (strands-py/):

cd strands-py
pip install hatch
hatch test        # run unit tests
hatch fmt         # format & lint

TypeScript SDK (strands-ts/):

npm ci            # install from repo root
npm run build     # build
npm test          # run unit tests

Documentation site (site/):

cd site
npm install
npm run dev       # local dev server at http://localhost:4321/

We welcome contributions! See our Contributing Guide for details on:

  • Reporting bugs & features
  • Development setup
  • Contributing via Pull Requests
  • Code of Conduct
  • Reporting of security issues

Stay in touch with the team

Come meet the Strands team and other users on Discord

This project is licensed under the Apache License 2.0 - see the LICENSE.APACHE file for details.

See CONTRIBUTING for more information.