欣淇
发布于 2026-05-18 / 0 阅读
0
0

🤖 Upsonic:7.8k Stars 的 Python 自主 Agent 框架,20 行代码搭一个「OpenClaw 同款」AI 智能体

🤖 Upsonic:7.8k Stars 的 Python 自主 Agent 框架,20 行代码搭一个「OpenClaw 同款」AI 智能体

老实说现在市面上 Agent 框架多到挑花眼,但大部分都要你写一堆胶水代码才能跑起来。Upsonic 不太一样——它主打"Build Autonomous AI Agents in Python",目标是让你用最少的代码量,搭出能自己干活的那种 Agent(对,就是 OpenClaw/Claude Cowork 那类)。

项目信息:Upsonic · 7,850 Stars · Python · MIT License · 2024年5月开源 · GitHub: github.com/Upsonic/Upsonic

🔥 两种 Agent 模式,随你用

Upsonic 把 Agent 分成两类:Autonomous Agent(自主型)和 Traditional Agent(传统型)。自主型有文件系统权限和 shell 执行能力,适合跑自动化任务;传统型就是常规的 tool-calling Agent,可以接自定义工具和 MCP Server。

自主型 Agent:5 行代码

from upsonic import AutonomousAgent, Task

agent = AutonomousAgent(
    model="anthropic/claude-sonnet-4-5",
    workspace="/path/to/logs"
)

task = Task("Analyze server logs and detect anomaly patterns")
agent.print_do(task)

workspace 是沙箱路径,所有文件操作和 shell 命令都被限制在里面。你不用担心 Agent 乱跑——路径穿越和危险命令都被拦截了。

🛠 传统型 Agent + 自定义工具

from upsonic import Agent, Task
from upsonic.tools import tool

@tool
def sum_tool(a: float, b: float) -> float:
    """Add two numbers together."""
    return a + b

agent = Agent(model="anthropic/claude-sonnet-4-5", name="Calculator Agent")
task = Task(description="Calculate 15 + 27", tools=[sum_tool])
agent.print_do(task)

装饰器 @tool 一标,你的函数自动变成 Agent 可调用的工具。MCP 集成也是开箱即用,连上就能用社区那几千个 MCP Server。

📄 OCR 管线也打包了

Upsonic 还有个惊喜——自带了多层 OCR 管线。文档预处理、OCR 引擎(EasyOCR/RapidOCR/PaddleOCR/DeepSeek OCR)全封装了,一条命令就能从 PDF 抽文字:

uv pip install "upsonic[ocr]"
from upsonic.ocr import OCR
from upsonic.ocr.layer_1.engines import EasyOCREngine

engine = EasyOCREngine(languages=["en"])
ocr = OCR(layer_1_ocr_engine=engine)
text = ocr.get_text("invoice.pdf")

安装即用

uv pip install upsonic
# 或者
pip install upsonic

IDE 集成也很贴心——直接把 Docs 加到 Cursor/Windsurf 的 Docs 源里:https://docs.upsonic.ai/llms-full.txt,你的 Coding Agent 写代码时就能随时查 API。

要点总结:
- Autonomous Agent vs Traditional Agent 两种模式,自主型有沙箱文件 + shell 权限,传统型走 tool-calling
- @tool 装饰器一键把你的函数变 Agent 工具,MCP 集成开箱即用
- 内置多层 OCR 管线,一条命令跑文档识别
- pip install 即用,Coding Agent 能直接索引官方文档辅助开发
- workspace 沙箱隔离,路径遍历和危险命令默认拦截

Upsonic: 7.8k Stars — Build Autonomous AI Agents in Python, 20 Lines of Code

Let's be honest — most agent frameworks make you write tons of boilerplate before anything works. Upsonic is different. It's a Python framework built for creating autonomous agents (the OpenClaw / Claude Cowork type) with minimal code.

Project: Upsonic · 7,850 Stars · Python · MIT License · GitHub: github.com/Upsonic/Upsonic

🔥 Two Agent Modes

Upsonic splits agents into Autonomous (with filesystem + shell access in a sandboxed workspace) and Traditional (tool-calling agents with custom tools + MCP).

Autonomous Agent in 5 Lines:

from upsonic import AutonomousAgent, Task

agent = AutonomousAgent(
    model="anthropic/claude-sonnet-4-5",
    workspace="/path/to/logs"
)
task = Task("Analyze server logs and detect anomaly patterns")
agent.print_do(task)

All file operations and shell commands are scoped to the workspace. Path traversal and dangerous commands are blocked by default.

🛠 Traditional Agent with Custom Tools:

from upsonic import Agent, Task
from upsonic.tools import tool

@tool
def sum_tool(a: float, b: float) -> float:
    """Add two numbers together."""
    return a + b

agent = Agent(model="anthropic/claude-sonnet-4-5", name="Calculator Agent")
task = Task(description="Calculate 15 + 27", tools=[sum_tool])
agent.print_do(task)

The @tool decorator turns any Python function into an agent tool. MCP integration is built-in — connect to thousands of community MCP servers.

📄 Built-in OCR Pipeline

uv pip install "upsonic[ocr]"
from upsonic.ocr import OCR
from upsonic.ocr.layer_1.engines import EasyOCREngine

engine = EasyOCREngine(languages=["en"])
ocr = OCR(layer_1_ocr_engine=engine)
text = ocr.get_text("invoice.pdf")

Install & Go:

uv pip install upsonic

Add https://docs.upsonic.ai/llms-full.txt to your Cursor/Windsurf Docs source for inline API reference while coding.

Key takeaways:
- Autonomous mode has sandboxed filesystem + shell; Traditional mode is tool-calling only
- @tool decorator turns functions into agent tools; MCP works out of the box
- Built-in multi-layer OCR pipeline (EasyOCR, RapidOCR, PaddleOCR, DeepSeek OCR)
- pip install; official docs indexable by your coding agent
- Workspace sandboxing prevents path traversal and dangerous commands by default


评论