Skip to main content

Lightweight AI agent infrastructure — harness orchestrates, backends execute

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_harness-0.3.2.tar.gz (15.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_harness-0.3.2-py3-none-any.whl (97.4 kB view details)

Uploaded Python 3

File details

Details for the file llm_harness-0.3.2.tar.gz.

File metadata

  • Download URL: llm_harness-0.3.2.tar.gz
  • Upload date:
  • Size: 15.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for llm_harness-0.3.2.tar.gz
Algorithm Hash digest
SHA256 fe6332f9b486ad9e2637a2cf24f6d749bdfb5827a3c9add3b88870c5fb0e8bb8
MD5 86979117b1d2fe93fa0a233bd3493644
BLAKE2b-256 34d084c7510e924a0f58da4ba284f5f2142bb42bec32315a7204107f3fadf150

See more details on using hashes here.

File details

Details for the file llm_harness-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: llm_harness-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 97.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for llm_harness-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3c19f3402486b06ec7b1b3e242b6e1cdb90102119194a91b2f43776fc487f2ca
MD5 ad155bd144350d8eecc07a93220c9360
BLAKE2b-256 252c8bf87cbc818f1f5648475cde3c083bd1946bd6d3750dbc7827382419d022

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page