ByteNoteByteNote

字节笔记本

2026年3月13日

nanoAgent:轻量级 AI Agent 框架

API中转
¥120

本文介绍 nanoAgent,一个轻量级的 AI Agent 框架。项目旨在提供简单、高效的方式来构建和部署 AI Agent,适合快速开发和原型验证,是构建智能助手的理想选择。

项目简介

nanoAgent 是一个开源的轻量级 AI Agent 框架,由 sanbuphy 开发维护。项目采用极简设计理念,提供了构建 AI Agent 所需的核心功能,同时保持代码简洁和易于理解,适合初学者和有经验的开发者使用。

核心特性

  • 轻量级:最小化依赖,快速启动
  • 简单易用:清晰的 API,易于上手
  • 可扩展:模块化设计,易于扩展
  • 高性能:优化的执行效率
  • 灵活配置:支持多种配置方式
  • 快速开发:快速原型和迭代

技术栈

  • Python 3.8+ - 核心开发语言
  • 异步支持 - 基于 asyncio
  • 插件系统 - 可扩展的插件架构
  • 配置管理 - 灵活的配置系统

安装指南

前置要求

  • Python 3.8 或更高版本
  • pip 包管理器

安装步骤

bash
# 克隆项目
git clone https://github.com/sanbuphy/nanoAgent.git

# 安装依赖
cd nanoAgent
pip install -r requirements.txt

快速开始

创建第一个 Agent

python
from nanoagent import Agent

# 创建 Agent
agent = Agent(
    name="MyAgent",
    instructions="You are a helpful assistant."
)

# 运行 Agent
response = agent.run("Hello, how are you?")
print(response)

基本配置

python
# 配置 Agent
agent = Agent(
    name="CustomAgent",
    model="gpt-4",
    temperature=0.7,
    max_tokens=1000,
    tools=[tool1, tool2]
)

主要功能

对话管理

  • 多轮对话支持
  • 上下文管理
  • 会话持久化

工具调用

  • 内置工具集
  • 自定义工具
  • 工具链组合

任务执行

  • 任务分解
  • 并行执行
  • 错误处理

插件系统

  • 插件加载
  • 插件管理
  • 插件开发

使用示例

场景 1:简单对话

python
agent = Agent(name="ChatBot")
response = agent.chat("Tell me a joke")

场景 2:工具使用

python
from nanoagent.tools import search

agent = Agent(tools=[search])
result = agent.run("Search for Python tutorials")

场景 3:自定义工具

python
@agent.tool
def my_tool(input: str) -> str:
    return f"Processed: {input}"

agent.run("Use my_tool with hello")

应用场景

  • 快速原型:快速验证想法
  • 学习研究:学习 Agent 开发
  • 小型项目:构建简单的 AI 应用
  • 教学演示:教学和展示
  • 集成开发:集成到现有系统

项目链接

分享: