Skip to main content

RootDriver

根源出发,驱动万物

一个轻量级的 Python AI Agent 开发框架。

解决痛点:

  • 想快速跑一个 Agent?一行代码,不需要编排、不需要懂设计模式
  • 市面框架太重、太复杂、学习成本高?RootDriver 核心代码几千行,不用记几百个 API
  • 需要扩展?按需添加,想加什么加什么,不被框架绑架

特性

  • 简洁易用:装饰器方式定义工具,快速构建 Agent
  • 模块化设计:LLM 适配器、工具系统、会话管理解耦
  • 工具调用:支持 function calling,自动执行工具并返回结果
  • 状态管理:支持内存和数据库持久化检查点
  • 异常体系:完整的异常类层次结构
  • 异步支持:全面异步支持,并发 Agent / 工具调用

安装

pip install rootdriver

快速开始

定义工具

from rootdriver import tool

@tool
def get_weather(city: str) -> str:
    """获取城市天气"""
    return f"{city} 晴天"

创建 Agent

from rootdriver import Agent, LLMConfig, OpenAIAdapter

llm_config = LLMConfig(
    model="gpt-4",
    adapter=OpenAIAdapter(
        api_key="YOUR_API_KEY",
        base_url="BASE_URL"
    )
)

agent = Agent.create(
    llm_config=llm_config,
    tools=[get_weather],
    system_prompt="你是一个有用的助手",
)

# 单次对话(无 tool)
response = agent.talk("北京天气怎么样?")
print(response)

使用工具

# 完整对话循环(包含工具调用)
response = agent.react("帮我查下上海天气")
print(response)

异步用法

import asyncio
from rootdriver import Agent, LLMConfig, OpenAIAdapter

async def main():

    # 单次异步对话
    response = await agent.atalk("你好")
    print(response)

    # 并发多个 Agent
    results = await asyncio.gather(
        agent.areact("问题1"),
        agent.areact("问题2"),
        agent.areact("问题3"),
    )

asyncio.run(main())

记忆持久化

Agent 支持对话历史持久化到 JSON 文件:

agent = Agent.create(
    llm_config=llm_config,
    system_prompt="你是一个有用的助手",
    db_path="conversations.json",
)

# 对话
response = agent.react("我们之前聊了什么?")

# 手动保存到数据库
agent.conversation_repo.db_opt.update(
    agent.engine.conversation.get_messages(),
    checkpoint_name="session_1"
)

# 从数据库恢复对话历史
messages = agent.conversation_repo.db_opt.get("session_1")
agent.engine.conversation.update_message(messages)

内存快照

# 保存到内存快照
agent.conversation_repo.buffer_opt.update(
    agent.engine.conversation.get_messages(),
    checkpoint_name="backup_point"
)

# 从内存快照恢复
messages = agent.conversation_repo.buffer_opt.get("backup_point")

核心组件

组件 说明
Agent 智能体入口,整合 LLM、工具、会话
Engine 核心引擎,处理对话循环和工具调用
Conversation 会话管理,维护消息历史
LLM LLM 调用封装
Tool 工具集合,管理所有可调用工具
State 状态管理,支持检查点和持久化
JsonDB JSON 文件数据库封装

项目结构

rootdriver/
├── __init__.py        # 包入口,导出核心组件和异常
├── agent.py           # Agent 智能体
├── engine.py          # 引擎核心(DBOpt/BufferOpt/ConversationRepo)
├── conversation.py    # 对话管理
├── conversation_repo.py # 会话持久化仓库
├── exceptions.py      # 异常定义
├── constants.py       # 常量定义
├── db/                # 数据库封装包
│   ├── __init__.py
│   ├── base_db.py     # 数据库抽象基类
│   └── json_db.py     # JsonDB 实现
├── llm/
│   ├── __init__.py
│   ├── llm.py         # LLM 封装
│   ├── base_adapter.py    # 适配器基类
│   └── adapter/
│       ├── __init__.py
│       ├── anthropic_adapter.py  # Anthropic 适配器
│       └── openai_adapter.py     # OpenAI 兼容适配器
├── tool/
│   ├── __init__.py
│   ├── base_tool.py   # 工具基类
│   └── tools.py       # 工具集
├── types/             # 类型定义
│   ├── __init__.py
│   ├── config.py      # LLMConfig 等配置类型
│   ├── message.py     # Message 消息类型
│   ├── llm.py         # LLMRequest/LLMResponse
│   └── tool.py        # ToolDefinition/ToolCall
└── utils/             # 工具函数
    ├── __init__.py
    ├── build_message.py   # 消息构建函数
    ├── file.py        # 文件操作
    ├── optional_dependence.py  # 可选依赖检测
    ├── strip_think.py # 去除思考过程标签
    └── time.py        # 时间工具

License

MIT

Metadata

Release files for rootdriver 0.9.3

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

Source distribution (sdist)

Source distribution for rootdriver 0.9.3
File Size Uploaded Provenance Actions
rootdriver-0.9.3.tar.gz 27.1 kB Without provenance Details for rootdriver-0.9.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rootdriver 0.9.3
File Interpreter ABI Platform Actions
rootdriver-0.9.3-py3-none-any.whl Python 3 none any Details for rootdriver-0.9.3-py3-none-any.whl

Total release size: 62.8 kB

Release files / rootdriver-0.9.3.tar.gz

Download URL rootdriver-0.9.3.tar.gz
Size 27.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2a6dd5f2f8d87f0150e8010fbdf208c952a533b57f7e3ff4aa45a48423559d01
BLAKE2b-256 checksum
How to use checksums
533e8e47bbd23ee4ee508cfb3669a3d12fce4215f30332603e3f63553f4c7d40
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.7

Release files / rootdriver-0.9.3-py3-none-any.whl

Download URL rootdriver-0.9.3-py3-none-any.whl
Size 35.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b2ea2cdddbf6e1d432d902c940542c6080837350a16534cc98bee94ea6c35397
BLAKE2b-256 checksum
How to use checksums
93aeebacd54b144480f228d43c983e26c0f92499d3b0b64166b98aca7a3b0b57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.7

Security for rootdriver 0.9.3

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