strands-agents / harness-sdk
strands-agents / harness-sdk
Strands Agents: A model-driven approach to building AI agents in just a few lines of code. Strands Agents:一种只需几行代码即可构建 AI 智能体的模型驱动方法。
Documentation ◆ Samples ◆ MCP Server ◆ Discord 文档 ◆ 示例 ◆ MCP 服务器 ◆ Discord
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. Strands Agents 是一个用于在 Python 和 TypeScript 中构建及运行 AI 智能体的开源 SDK。当你需要编写自己的智能体循环(agent loop)时,请选择 Strands:它直接在你的进程中运行,无需托管控制平面,并且涵盖了手写循环随着功能扩展所需要处理的所有任务。在一个 SDK 中,你即可获得生命周期控制(轮次限制、Token 配额、取消机制、停止原因)、工具与结构化输出、MCP、多智能体模式、记忆与会话、模型可移植性、流式传输、护栏(guardrails)、追踪和评估功能。
This monorepo contains Strands harness, the Python and TypeScript SDKs, the documentation site, and supporting packages: 此代码仓库(monorepo)包含 Strands harness、Python 和 TypeScript SDK、文档网站以及相关支持包:
| 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) |
| 目录 | 描述 |
|---|---|
| harness-py/ | Python Strands harness:通过 create_harness() 创建的全功能智能体 (PyPI · 文档) |
| harness-ts/ | TypeScript Strands harness:通过 createHarness() 创建的全功能智能体 (npm · 文档) |
| strands-cli/ | strands CLI:在终端中原型设计并与 harness 智能体对话 (npm) |
| strands-py/ | Python SDK:智能体循环、模型提供商、工具 (PyPI · 发布) |
| strands-ts/ | TypeScript SDK:智能体循环、模型提供商、工具 (npm · 发布) |
| site/ | strandsagents.com 文档网站源码 (Astro/Starlight) |
| team/ | 治理与跨 SDK 流程文档(原则、决策、PR 与兼容性指南、设计/提案) |
Why Strands
为什么选择 Strands
- 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. 模型无关。 对 Amazon Bedrock、Anthropic、OpenAI 和 Gemini 以及更多提供商和自定义模型提供一流支持。
- 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. 保持掌控。 智能体循环默认追踪每一个决策。钩子(Hooks)允许你拦截任何步骤以进行记录、验证或重定向。
- 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. 交付可靠成果。 护栏(Guardrails)在错误发生前将其捕获。引导处理程序(Steering handlers)让智能体能够自我纠正,而不是静默失败。MCP、流式传输、多智能体模式和结构化输出均为内置功能。
Quick Start
快速开始
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.
开始的最简单方法是使用 Strands harness,这是一个全功能、最先进的智能体。只需调用一次 create_harness() (Python) 或 createHarness() (TypeScript),即可获得一个经过优化的智能体,它具备模型、工具、记忆、会话和上下文管理的基准默认配置,可直接从构思投入生产。
Follow the harness quickstart, or see the Python Strands harness and TypeScript Strands harness packages to get started. 请参考 harness 快速入门,或查看 Python Strands harness 和 TypeScript Strands harness 包以开始使用。
Python
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")
TypeScript
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). 从这里开始获取一个“开箱即用”的智能体,当你想要掌控智能体循环并自行连接工具、模型提供商和记忆时,再深入使用下方的 SDK。Harness 配置参考文档记录了你可以覆盖的每一个默认设置。快速入门指南涵盖了如何配置提供商(Amazon Bedrock、Anthropic、OpenAI、Gemini、Ollama 等)。
Working with the SDK
使用 SDK
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. Strands Harness SDK 允许你深入控制智能体的每一个部分:循环、工具、模型提供商、记忆、会话和钩子。在体验过 Strands harness 后,或者当默认配置无法满足需求、你希望从零开始构建自己的框架时,可以深入研究 SDK。
Python Requires Python 3.10+: 需要 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. Python SDK 的 README 涵盖了工具、模型提供商、MCP 和双向流式传输。
TypeScript Requires Node.js 22+: 需要 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. 更多信息请参阅 TypeScript SDK 的 README,包括 Zod 类型工具、结构化输出和多智能体模式。
Documentation
文档
For detailed guidance & examples, explore our documentation: 如需详细指南和示例,请浏览我们的文档:
- User Guide 用户指南
- Strands Harness Guide (quickstart · configuration reference) Strands Harness 指南 (快速入门 · 配置参考)
- Quick Start Guide 快速入门指南
- Agent Loop Examples 智能体循环示例
- API Reference: Python · TypeScript API 参考:Python · TypeScript
- Production & Deployment Guide 生产与部署指南
The docs themselves live in this monorepo under site/, and doc PRs are welcome alongside code changes.
文档本身位于此代码仓库的 site/ 目录下,欢迎提交文档 PR 以及代码变更。
Development
开发
Git operations (commits, branches, PRs) are done from the repo root. Each package has its own toolchain: 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 - Documentation site (site/):
cd site npm install npm run dev # local dev server at http://localhost:4321/
Contributing ❤️
贡献 ❤️
We welcome contributions! See our Contributing Guide for details on: 我们欢迎贡献!有关以下内容的详细信息,请参阅我们的贡献指南:
- Reporting bugs & features 报告 Bug 和功能建议
- Development setup 开发环境设置
- Contributing via Pull Requests 通过 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. 欢迎在 Discord 上与 Strands 团队及其他用户交流。
License
许可证
This project is licensed under the Apache License 2.0 - see the LICENSE.APACHE file for details. 本项目采用 Apache License 2.0 许可证 - 详情请参阅 LICENSE.APACHE 文件。
Security
安全
See CONTRIBUTING for more information. 更多信息请参阅 CONTRIBUTING。