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, AgentLLM, OpenAIAdapter

agent_llm = AgentLLM(
    adapter=OpenAIAdapter(
        api_key="YOUR_API_KEY",
        base_url="BASE_URL"
    ),
    model= "gpt-4",
    temperature=0.7
    )


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

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

使用工具

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

异步用法

import asyncio
from rootdriver import Agent, AgentLLM, 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(
    agent_llm=agent_llm,
    system_prompt="你是一个有用的助手",
    db_path="conversations.json",     # 记忆数据库路径
    auto_save=True,            # 开启自动保存(默认开启)
)

# 对话自动增量保存到 memory.json
response = agent.react("我们之前聊了什么?")

# 新建 Agent 时可从数据库恢复对话历史
agent2 = Agent(agent_llm=agent_llm, id="same_user", db_path="memory.json")
agent2.state.load_from_db("auto_saved")  # 恢复对话

手动检查点

# 内存快照
agent.state.checkpoint("backup_point")

# 保存到数据库
agent.state.save_from_checkpoints(name="my_backup", checkpoint_name="backup_point")

# 从数据库加载
agent.state.load_from_db("my_backup")

核心组件

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

项目结构

rootdriver/
├── agent.py           # Agent 智能体
├── engine.py          # 引擎核心
├── conversation.py    # 对话管理
├── state/             # 状态管理包
│   └── state.py       # State 实现
├── db/                # 数据库封装包
│   └── json_db.py     # JsonDB 实现
├── exceptions.py      # 异常定义
├── llm/
│   ├── llm.py         # LLM 封装
│   ├── base_adapter.py    # 适配器基类
│   └── adapter/
│       └── openai_adapter.py  # OpenAI 适配器
├── tool/
│   ├── base_tool.py   # 工具基类
│   └── tools.py       # 工具集
├── types/             # 类型定义
└── utils/             # 工具函数

License

MIT

Download files

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

Source Distribution

rootdriver-0.5.0.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

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

rootdriver-0.5.0-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file rootdriver-0.5.0.tar.gz.

File metadata

  • Download URL: rootdriver-0.5.0.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for rootdriver-0.5.0.tar.gz
Algorithm Hash digest
SHA256 c6c4bdc0ffd0c19fd5adf08edb350fe357405d469781dea37999cadc45c25195
MD5 880914b241a216d9e20485d5e89c2777
BLAKE2b-256 531925f067b1efdc79b8107573c0078db25e081a4217c4d8907e8e488b428860

See more details on using hashes here.

File details

Details for the file rootdriver-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: rootdriver-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 27.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for rootdriver-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d48a1c3d7cea9417eaddcfa2e54590fb42817782ca980492db6320b7111af644
MD5 dafab179687f7587c43a88da3335b6c2
BLAKE2b-256 1c20f76ba3e8ca2ed88e5959c01da90e224d83c68599dee5cc1c2fa6d652494c

See more details on using hashes here.

Release history Release notifications | RSS feed

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.1

2 files

0.7.0

2 files

0.6.1

2 files

0.6.0

2 files

This release

0.5.0 This release

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 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