Skip to main content

A lightweight agent framework based on LLM

Project description

🤖 SmartAgents

从零实现LLM Agent框架 - 教学级实现与工程化实践

Python License Code style: black

🚀 快速开始📖 文档🎯 示例🤝 贡献指南


✨ 项目亮点

  • 🎓 低耦合架构: 清晰的模块组织和渐进式实现,适合学习Agent内部机制
  • 🏗️ 工程化实践: 模块化架构、完整测试、CI/CD流程
  • 🔧 生产可用: 支持DeepSeek/OpenAI等多Provider,自动检测服务商
  • 📚 功能完整: 内置多种工具调用、工具链、工具异步调用

🎬 快速演示

from smart_agents import SimpleAgent
from smart_agents.core import SmartAgentLLM
from smart_agents.tools import ToolRegistry
from smart_agents.tools.builtin import SearchTool
# 初始化LLM
llm = SmartAgentLLM()

# 初始化工具
tool_registry = ToolRegistry()
searchTool = SearchTool()
tool_registry.register_tool(searchTool)

# 初始化Agent
agent = SimpleAgent(
    name="工具增强助手",
    llm=llm,
    system_prompt="你是一个智能助手,可以使用工具来帮助用户。",
    tool_registry=tool_registry,
    enable_tool_calling=True
)

response = agent.run("2026年小米手机最新款是什么,有什么卖点")
print(f"工具增强助手响应: {response}")
# 2026年小米手机的最新款型有几个比较主要的系列:

# 1. Redmi Note系列:主打千元长续航、耐用抗造,适合长辈、户外、备用机。
# 2. Redmi K系列:主打电竞性能、性价比旗舰,适合学生、游戏玩家。...

📊 架构设计

┌─────────────────────────────────────────┐
│          User Interface (API)          │
└──────────────┬──────────────────────────┘
               │
┌──────────────▼──────────────────────────┐
│         Agent Core (ReAct)             │
│  ┌────────┐ ┌────────┐ ┌──────────┐   │
│  │Planning│ │Executor│ │Reflexion │   │
│  └────────┘ └────────┘ └──────────┘   │
└──────────────┬──────────────────────────┘
               │
    ┌──────────┼──────────┐
    │          │          │
┌───▼───┐  ┌──▼───┐  ┌──▼─────┐
│Memory │  │Tools │  │LLM Prov│
│System │  │      │  │        │
└───────┘  └──────┘  └────────┘

🚀 快速开始

安装

# 使用pip安装
pip install smart_agents-py

# 或从源码安装
git clone https://github.com/edgetalker/smart_agents.git
cd hello-agents

配置

cp .env.example .env
# 编辑.env文件,填入API密钥

📖 核心功能

1️⃣ ReAct执行循环

# Agent自动进行推理-行动循环
agent.run("帮我查询AAPL股票价格并分析走势")

# 内部执行过程:
# Thought: 需要先获取股票价格
# Action: get_stock_price("AAPL")
# Observation: $178.32
# Thought: 需要分析历史数据
# Action: analyze_trend("AAPL", days=30)
# Observation: 上涨趋势...
# Final Answer: ...

2️⃣ 向量记忆系统

# 长期记忆存储与检索
agent.memory.store("用户偏好Python开发")
relevant = agent.memory.retrieve("编程语言")
# 自动召回相关上下文

3️⃣ 自定义工具

from smart_agents-py.tools import Tool

@Tool(
    name="database_query",
    description="查询MySQL数据库"
)
async def query_db(sql: str) -> str:
    # 你的实现
    return results

🗺️ 开发路线图

  • 基础Agent框架 (v0.1.0)
  • ReAct执行循环 (v0.2.0)
  • 向量记忆系统 (v0.3.0)
  • Reflexion自我反思 (v0.4.0)
  • 多Agent协作 (v0.5.0)
  • 生产优化与部署 (v1.0.0)

🤝 贡献

欢迎提交Issue和Pull Request!

📄 许可证

MIT License © edgetalker

🙏 致谢

  • DataWhale HelloAgents项目启发
  • MIT 6.5940课程的优化技术
  • LangChain社区的最佳实践

📧 联系方式


如果这个项目对你有帮助,请给个⭐️支持一下!

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

smartagents_py-0.1.2.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

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

smartagents_py-0.1.2-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

Details for the file smartagents_py-0.1.2.tar.gz.

File metadata

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

File hashes

Hashes for smartagents_py-0.1.2.tar.gz
Algorithm Hash digest
SHA256 49a527cd92c323414d00f2beba60d483035bb412e9db6a78ad6df20fb69c459f
MD5 923b6a457945cf64e6c952cdeb897756
BLAKE2b-256 9ba139df78eddeb609fddead95e64b7a6a6eefbd1754a5c7766dfeffbcb3e68f

See more details on using hashes here.

File details

Details for the file smartagents_py-0.1.2-py3-none-any.whl.

File metadata

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

File hashes

Hashes for smartagents_py-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ecb4ecb2e8c84b2a8cc8b2eb160f08e15844a6a1597b903eea37052b4be0a0f1
MD5 c65b6f6fc32a971bd9353bd0810fedce
BLAKE2b-256 fb32454a8d0dda6df1dfb60d23668c79e4d839a4e801805e30efc9af49a96db9

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