跳到主要内容Skip to main content
Agent 框架与编排Agent Frameworks & Orchestration生产可用Production

Instructor

567-labs / instructor

用 Pydantic 模型约束 LLM 输出:自动重试、流式部分对象、函数调用/JSON schema、多 provider 适配,让“返回一个结构体”变可靠。Constrain LLM output with Pydantic models: automatic retries, streaming partial objects, function calling / JSON schema and multi-provider adapters make “return a struct” reliable.

14.1k stars 1396 forks Python 语言Language MIT 许可License 最近推送Last push 2026-11-19

为什么选Why choose it

  • 把 schema、校验与重试放在一处,少写解析代码。Schema, validation and retries live in one place, cutting parser code.
  • 流式部分对象适合长表单与实时 UI。Streaming partial objects suit long forms and live UI.
  • 支持多家 provider,换模型不必重写 schema 层。Multi-provider support means changing models does not require rewriting the schema layer.

不适合Not for

不是 agent 框架;多步工具编排仍要 LangGraph 等。Not an agent framework; multi-step tool orchestration still needs LangGraph and similar.
模型不支持结构化输出时要降级,重试也有成本。Fallback is needed when a model lacks structured output, and retries cost tokens.
不负责 prompt 版本管理与评测。No prompt versioning or evaluation.

最小上手Minimum setup

  1. pip install instructor,用 Pydantic 定义一个小 schema。pip install instructor and define a small Pydantic schema.
  2. 让模型返回该对象,故意给一个坏例子看重试。Ask the model for that object, then feed a bad example to see retries.
  3. 再接流式与多 provider,记录失败率与 token 成本。Add streaming and a second provider; record failure rate and token cost.

依赖与成本Dependencies and cost

Python;至少一个模型 provider 的 API key 或本地 OpenAI 兼容端点;生产要重试预算与日志。Python; an API key for at least one provider or a local OpenAI-compatible endpoint; production needs retry budgets and logs.

许可与使用边界License and usage boundaries

MIT;接入的模型 provider 与 SDK 各自条款。MIT; connected model providers and SDKs have their own terms.

开源不等于可商用:GPL / AGPL 有传染性;代码许可、模型许可、生成内容许可要分开看。上线前读仓库 LICENSE 与模型卡,必要时让法务确认。Open source is not automatically commercial-use friendly: GPL / AGPL are copyleft; code, model and output licenses are separate. Read the LICENSE and model card before launch, and involve legal when needed.

替代与相邻Alternatives and neighbors

  • Pydantic AI — 轻量Lightweight,用 Pydantic 的类型系统写 agent:输入、输出、工具参数都强类型校验。Write agents with Pydantic’s type system: inputs, outputs and tool arguments are strongly validated.
  • DSPy — 生产可用Production,把提示词、检索和工具调用写成可组合的模块,再用优化器按指标自动改提示与示例;不是手写链式调用的封装。Write prompts, retrieval and tool calls as composable modules, then optimise prompts and examples against a metric instead of hand-tuning chains.
  • Outlines — 生产可用Production,结构化生成库:用正则、JSON schema 或 CFG 约束 token 采样,保证输出可解析;支持 Transformers、vLLM、llama.cpp 等后端。Structured generation: constrain token sampling with regex, JSON schema or a CFG so output is parseable; supports Transformers, vLLM, llama.cpp and other backends.

下一步Next steps

  • 打开 GitHub,先读 README、LICENSE、最近 release 与 issue。Open GitHub and read the README, LICENSE, latest release and issues first.
  • 按“部署依赖 / 显存 / 数据 / 网络 / 权限”列一张上手清单。Make an onboarding checklist for deployment dependencies, VRAM, data, network and permissions.
  • 用一个小样本跑通,再决定是否进生产;不要直接上生产数据。Run a small sample first, then decide on production; never start with production data.

GitHub 仓库 ↗GitHub repository ↗ 文档 ↗Docs ↗ 加入对比Add to compare

快照口径:stars / forks / language / license / pushed_at 来自 GitHub API 2026-11-20 快照;之后的变化没有回写。标签与“适合 / 不适合”是编辑判断,不是 GitHub 元数据。Snapshot: stars / forks / language / license / pushed_at come from the GitHub API snapshot on 2026-11-20; later changes are not written back. Tags and “fit / not fit” are editorial judgments, not GitHub metadata.
不背书:本站只做索引与风险提示,不审计代码、不保证安全、不替你做许可判断。仓库脚本与模型权重请自行审查。No endorsement: this site only indexes and flags risks; it does not audit code, guarantee security or make license decisions for you. Review repository scripts and model weights yourself.