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()

# 初始化工具
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.1.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.1-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: smartagents_py-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 e14067c6f4b887ffc57ab1c006e6a9e0bc0991ffc16e02d848d349a611e043d9
MD5 312a47b285d1183fa0fb99ce0ceaf153
BLAKE2b-256 141a9d5f3e3ccd11097824b16535f0c8c337edfebc041d3ba90fa8c2e930a6fe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: smartagents_py-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0714a309ce4931dcfd0b87ebc7231b722719ec058a143dad3a5da8c3c853a960
MD5 b13929f57748e523a4f9c6da17282398
BLAKE2b-256 b63a121c816b564c97fed645b629e594491dbf0f3c502c945072928799572a15

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