Skip to main content

tangyuanAI

一个轻量的多 LLM 协议 Agent 框架,把 provider 方言差异收拢到一处。

A lightweight multi-LLM-protocol Agent framework that puts provider dialect differences in one place.

PyPI Python License CI

文档站 / Docs · 学习路径 / Tutorial · CHANGELOG


1 分钟讲清楚 / 60-second pitch

每家 LLM 都有自己的协议方言(OpenAI Chat Completions / Anthropic Messages / OpenAI Responses / 你公司机房网关)。tangyuanAI 写一份 Agent 代码就能切任意 provider——切协议是改一行类字段,不是重写循环。

Every LLM has its own wire format. Write your Agent once; switch providers with a single class field instead of rewriting your loop.


30 秒 demo

# 推荐 uv(本仓库 CI / docs-site 都用 uv)
uv pip install tangyuanAI
# 或 pip install tangyuanAI

export API_KEY="sk-..."                    # OpenAI 协议
export ANTHROPIC_API_KEY="sk-ant-..."      # Anthropic 协议(可选)
import os, tangyuanAI
from tangyuanAI import template_agent
from tangyuanAI.Agent_list import activate_template

@tangyuanAI.tool_registry.register_tool(
    description="查询某城市天气",
    parameters={"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]},
)
def get_weather(city: str) -> str:
    return f"{city}今天晴,25°C"

@template_agent("weather", uuid="weather-1", description="天气助手")
class WeatherAgent(tangyuanAI.Agent):                # ← 协议无关工厂基类
    protocol     = "openai"                            # ← 一行切协议
    prompt       = "你是天气助手,用 get_weather 工具回答"
    api_provider = os.getenv("API_BASE", "https://api.openai.com/v1")
    model_name   = os.getenv("MODEL", "gpt-5")
    api_key      = os.getenv("API_KEY")

activate_template("weather")
print(tangyuanAI.agent_list["weather"].conversation("北京今天天气怎么样?"))

切协议只改一个字段:

class ReviewerAgent(tangyuanAI.Agent):
    protocol     = "anthropic"                          # ← 改这一行
    api_provider = "https://api.anthropic.com"
    model_name   = "claude-3-5-sonnet-latest"
    api_key      = os.getenv("ANTHROPIC_API_KEY")

怎么写好 Agent —— 4 件事 / How to write good Agents

  1. @template_agent 注册,activate_template 实例化。 装饰器只登记;激活才实例化——import 时不付成本,真用时再实例化。
  2. description= 是一句话不是段。 它是别的 Agent 决定"要不要调我"时读的。
  3. 工具描述决定工具选择。 schema / docstring 直接决定 LLM 调 get_user_orders(user_id=...) 还是 list_all_orders()。
  4. 自定义 out() 是接入点。 默认 print;覆写可推到 logger / queue / UI。别动 pack()。

完整内容去哪看 / Where to read more

想了解 看哪
从零开始 30 分钟跑通第一个 TUTORIAL.md
完整 API / 钩子 / ACL / MCP / 持久化 / Skill 文档站
协议背景 + A2A 对比 + 架构图 docs/concepts.md (本批未写,见 issues)
版本变更 CHANGELOG.md
协议简单性 demo examples/

开发与测试

git clone https://github.com/secret-tangyuan/tangyuanAI.git
cd tangyuanAI
uv sync --group dev
uv run pytest -v
uv run ruff check .

tests/_llm_mock.py 提供了完整 wire-format mock,跑测试不用 API key。

加新 transport?实现 LLMTransport 并在 __init__.py 调 register_protocol(name, cls)。


许可证 / License

Apache License 2.0 · Copyright 2025-2026 Secret Tangyuan

完整许可证见 LICENSE。

Release files for tangyuanAI 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tangyuanAI 1.3.0
File Size Uploaded
tangyuanai-1.3.0.tar.gz 274.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tangyuanAI 1.3.0
File Interpreter ABI Platform
tangyuanai-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 524.2 kB

Release files / tangyuanai-1.3.0.tar.gz

Download URL tangyuanai-1.3.0.tar.gz
Size 274.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0bad32dbd58d0e2404a9014f19ba44f25a25534b8d06fa3bdd2ddad7b84b7ecf
BLAKE2b-256 checksum
How to use checksums
c33adbc9f79dbc942aae9a8f07bedf8b6d589cb53917fd7496f11b60ea47ff83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release files / tangyuanai-1.3.0-py3-none-any.whl

Download URL tangyuanai-1.3.0-py3-none-any.whl
Size 250.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a741545fcd0841f061500db451d9facf26fe1ddd298c3a5a2d4594acc617ba7
BLAKE2b-256 checksum
How to use checksums
6b52e665d2c752b6c7cccd2fe205b23a5cb8671092dae45634f125526ec92e01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page