Upsonic的5个实际用法,让你学会用AI代理解决真实任务

2025年6月6日

Upsonic 是一个强大的 AI 代理平台,专注于构建可靠、任务导向的 AI 工作流。

基于其功能和实际应用场景,以下是 Upsonic 最实用的 5 个用法,简明扼要并结合实际案例,方便你快速理解和应用:

1. 自动化数据提取与分析

用途:从文档、网页或数据库中提取结构化数据,并进行分析,适合发票处理、市场研究等场景。
为什么实用:Upsonic 的检索增强生成(RAG)和模型上下文协议(MCP)支持从多种来源提取数据,准确率高(官方宣称可达 100%)。
示例:

from upsonic import Agent, Task, KnowledgeBase
from upsonic.client.tools import FetchMCP

# 定义输出格式
class InvoiceData:
    invoice_number: str
    total_amount: float

# 创建知识库(例如发票 PDF)
kb = KnowledgeBase(sources=["invoices.pdf"])

# 定义任务
task = Task(
    description="Extract invoice number and total amount from invoices",
    context=[kb],
    tools=[FetchMCP],
    response_format=InvoiceData
)

# 创建代理
agent = Agent("Invoice Processor", model="openai/gpt-4o")

# 执行任务
result = agent.print_do(task)
print(result.invoice_number, result.total_amount)

场景:财务团队用它批量处理发票,提取关键信息,节省人工时间。

2. 自动化客户服务

用途:创建能自主处理客户咨询的 AI 代理,支持文本或语音交互,适用于客服自动化。
为什么实用:通过可靠性层(防幻觉机制)和多轮验证,代理能提供准确、专业的回复,减少人工干预。
示例:

from upsonic import Agent, Task

# 定义任务
task = Task(description="Answer customer query about product pricing")

# 创建代理
agent = Agent(
    "Customer Support",
    model="openai/gpt-4o",
    company_url="https://upsonic.ai",
    reliability_layer=True  # 启用可靠性层
)

# 执行任务
result = agent.print_do(task)
print(result)

场景:电商平台用它处理常见问题(如价格、退货政策),提升响应速度。

3. 市场研究与竞争分析

用途:利用搜索工具和浏览器功能,收集行业趋势、竞争对手信息或新闻动态。
为什么实用:内置的 Search 和 BrowserUse 工具支持实时数据抓取,结合结构化输出,确保结果清晰且可操作。
示例:

from upsonic import Agent, Task, ObjectResponse
from upsonic.client.tools import Search

# 定义输出格式
class MarketTrend(ObjectResponse):
    trend: str
    source: str

# 创建任务
task = Task(
    description="Research latest AI trends in 2025",
    tools=[Search],
    response_format=list[MarketTrend]
)

# 创建代理
agent = Agent("Market Analyst", model="openai/gpt-4o")

# 执行任务
result = agent.print_do(task)
for trend in result:
    print(trend.trend, trend.source)

场景:市场团队用它快速汇总行业动态,为战略决策提供依据。

4. 内容生成与优化

用途:生成高质量的文本内容(如邮件、报告、博客),并通过 Canvas 功能进行精准编辑。
为什么实用:Canvas 确保代理只对指定文本区域操作,避免不必要的修改;可靠性层提高内容质量。
示例:

from upsonic import Agent, Task, Canvas

# 创建 Canvas
email_canvas = Canvas("Welcome Email")

# 定义任务
task = Task(
    description="Draft a welcome email for new Upsonic users",
    tools=[email_canvas]
)

# 创建代理
agent = Agent("Content Writer", model="openai/gpt-4o")

# 执行任务
result = agent.print_do(task)
print(email_canvas.get_current_state_of_canvas())

场景:营销团队用它生成个性化邮件或社交媒体内容,提升效率。

5. 浏览器自动化与无 API 系统交互

用途:模拟人类操作(如点击、输入、滚动),处理没有 API 的网站或应用。
为什么实用:支持复杂任务(如电商数据抓取、表单填写),无需依赖 API,扩展了自动化范围。
示例:

from upsonic import Agent, Task, ObjectResponse
from upsonic.client.tools import BrowserUse

# 定义输出格式
class Product(ObjectResponse):
    name: str
    price: float

# 创建任务
task = Task(
    description="Get the top 3 laptops from amazon.com",
    tools=[BrowserUse],
    response_format=list[Product]
)

# 创建代理
agent = Agent("Web Scraper", model="openai/gpt-4o")

# 执行任务
result = agent.print_do(task)
for product in result:
    print(product.name, product.price)

场景:电商运营用它抓取竞品价格,或自动填写在线表单。