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.llm import SimpleAgentLLM
from smart_agents.tools import ToolRegistry
from smart_agents.tools.bulitin import SearchTool
# 初始化LLM
llm = SmartAgentLLM()

# 初始化工具
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

# 或从源码安装
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.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.0.tar.gz (22.2 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.0-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: smartagents_py-0.1.0.tar.gz
  • Upload date:
  • Size: 22.2 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.0.tar.gz
Algorithm Hash digest
SHA256 10dfaa8b8659d4b94c99f5849cc39f1443acc0a2a0aa9e544b95cd1f7c999024
MD5 28e10a81adc35e1c83ce601bd0418559
BLAKE2b-256 ac479127b1a468bb6e4cf6f6f37410be9aa7416aa94dfff0a993d61e43792787

See more details on using hashes here.

File details

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

File metadata

  • Download URL: smartagents_py-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.2 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 434fb5d62ad9c6497d2a6ca68bf75bcb79e321349df86acefd3e9b1f97483971
MD5 565182bdca92bb98e9bbf1ddb14bc782
BLAKE2b-256 c2f18517ddcfe5d8cd130804591a24a1c12a37973bd691c520a2730af00b24f3

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