Skip to main content

llm-harness

纯异步、依赖注入的 AI Agent 开发框架。一个 ~7,000 行的引擎内核,做一件事:运行 ReAct Agent 循环,所有组件可插拔。

PyPI Python 文档

定位

  • 不是 LangChain 套壳
  • 不是 Dify 替代品
  • 是 纯异步、无状态、依赖注入的 Agent 引擎内核

快速开始

pip install llm-harness[openai]
import os, asyncio
from pathlib import Path
from llm_harness.adapters.providers.openai_compat_provider import OpenAICompatProvider
from llm_harness.adapters.sandbox.srt import SRTSandboxBackend
from llm_harness.core.harness import Harness
from llm_harness.core.session.session import Session
from llm_harness.core.bus.events import InboundMessage
from llm_harness.core.tools.base import ToolRegistry
from llm_harness.core.tools.factory import ToolFactory

async def main():
    provider = OpenAICompatProvider(
        api_key=os.environ["LLM_HARNESS_API_KEY"],
        api_base="https://api.deepseek.com",
    )
    sandbox = SRTSandboxBackend(Path("./workspace"))
    factory = ToolFactory(sandbox=sandbox)
    tools = ToolRegistry()
    for name in ["read_file", "write_file", "web_search"]:
        tool = factory.build(name)
        if tool:
            tools.register(tool)

    harness = Harness(provider=provider, model="deepseek-chat", tools=tools, sandbox=sandbox)
    agent = harness.create_agent()

    session = Session(key="user:chat1")
    msg = InboundMessage("cli", "user", "c1", "What is 2+2?")
    result = await agent.process(msg, session=session, cwd=Path("./workspace"))
    print(result.final_content)

asyncio.run(main())

三层架构

InboundMessage → Agent → AgentLoop → Harness
                   │          │           │
              纯引擎     ReAct 骨架    组装器
              零状态     回调注入      全部依赖显式传入

核心特性

  • Protocol 驱动:SandboxBackend / MemoryBackend / AgentBackend / SessionBackend 全部 Protocol,无需继承
  • 15 个内置工具:文件 I/O、搜索、执行、子代理、MCP 集成
  • 20+ LLM 服务商:OpenAI / Anthropic / DeepSeek / DashScope / Gemini / 等
  • 权限检查:9 步检查链,内置敏感路径拒绝列表
  • 记忆系统:TencentDB Gateway 管道模式(capture → 自动提取 → recall)
  • 可观测性:11 种结构化事件类型
  • WebSocket 通道:支持多前端接入
  • Hook 系统:Command / HTTP / Prompt / Agent 四种钩子类型
  • Skills 渐进披露:系统提示词只列名称,LLM 按需加载完整内容

测试

pytest tests/ -q
# 293 passed, 4 skipped

文档

完整中文文档:h-mr.github.io/llm-harness

License

MIT

Metadata

Release files for llm-harness 0.3.2

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

Source distribution (sdist)

Source distribution for llm-harness 0.3.2
File Size Uploaded Provenance Actions
llm_harness-0.3.2.tar.gz 15.7 MB Without provenance Details for llm_harness-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llm-harness 0.3.2
File Interpreter ABI Platform Actions
llm_harness-0.3.2-py3-none-any.whl Python 3 none any Details for llm_harness-0.3.2-py3-none-any.whl

Total release size: 15.8 MB

Release files / llm_harness-0.3.2.tar.gz

Download URL llm_harness-0.3.2.tar.gz
Size 15.7 MB
Tags Source
SHA-256 checksum
How to use checksums
fe6332f9b486ad9e2637a2cf24f6d749bdfb5827a3c9add3b88870c5fb0e8bb8
BLAKE2b-256 checksum
How to use checksums
34d084c7510e924a0f58da4ba284f5f2142bb42bec32315a7204107f3fadf150
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / llm_harness-0.3.2-py3-none-any.whl

Download URL llm_harness-0.3.2-py3-none-any.whl
Size 97.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3c19f3402486b06ec7b1b3e242b6e1cdb90102119194a91b2f43776fc487f2ca
BLAKE2b-256 checksum
How to use checksums
252c8bf87cbc818f1f5648475cde3c083bd1946bd6d3750dbc7827382419d022
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Security for llm-harness 0.3.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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