Show HN: Pixelagent – 用200行代码构建你的状态化 Agent 框架
pixeltable / **pixelagent ** Public
Pixelagent — 构建你自己的状态化 agent 框架 pixeltable.com
License
Apache-2.0 license 111 stars 15 forks
pixeltable/pixelagent
main
Folders and files
Name| Name| Last commit message| Last commit date
---|---|---|---
blueprints| blueprints
examples| examples
pixelagent| pixelagent
scripts| scripts
tests| tests
.gitignore| .gitignore
LICENSE| LICENSE
README.md| README.md
poetry.lock| poetry.lock
poetry.toml| poetry.toml
pyproject.toml| pyproject.toml
Documentation | API Reference | Examples |
👆 Click to watch the demo video
Pixelagent: 一个 Agent 工程蓝图
我们认为 agent 是 LLM、存储和编排的交汇点。Pixeltable 将此接口统一到一个声明式框架中,使其成为工程师构建自定义 agent 应用的首选,并提供用于内存、工具调用等功能的构建功能。
构建你自己的 agent 框架:
- 数据编排和存储 : 构建在 Pixeltable 的数据基础设施之上
- 原生多模态 : 内置支持文本、图像、音频和视频
- 声明式模型 : 一个类型安全的 Python 框架
- 模型无关 : 可扩展到多个提供商
- 可观测性 : 完整的可追溯性,自动记录消息、工具调用和性能指标
- Agentic 扩展 : 添加推理、反思、记忆、知识和团队工作流程。
将蓝图连接到 Cursor, Windsurf, Cline:
即插即用的扩展
- Tools : 将自定义 Python 函数添加为工具
- Memory : 使用语义搜索功能实现长期记忆系统
- Reflection : 添加自我改进循环
- Reasoning : 添加计划循环
- Multimodal Agentic Rag : 多模态 Agentic 检索
用法
将你的 agent 蓝图转换为 PyPI 上的可分发包,将构建理念扩展到部署和共享。
安装
pip install pixelagent
# 安装特定于提供商的依赖项
pip install anthropic # For Claude models
pip install openai # For GPT models
快速开始
from pixelagent.anthropic import Agent # Or from pixelagent.openai import Agent
# 创建一个简单的 agent
agent = Agent(
name="my_assistant",
system_prompt="You are a helpful assistant."
)
# 与你的 agent 聊天
response = agent.chat("Hello, who are you?")
print(response)
添加工具
import pixeltable as pxt
from pixelagent.anthropic import Agent
import yfinance as yf
# 将工具定义为 UDF
@pxt.udf
def stock_price(ticker: str) -> dict:
"""Get stock information for a ticker symbol"""
stock = yf.Ticker(ticker)
return stock.info
# 使用工具创建 agent
agent = Agent(
name="financial_assistant",
system_prompt="You are a financial analyst assistant.",
tools=pxt.tools(stock_price)
)
# 使用工具调用
result = agent.tool_call("What's the current price of NVDA?")
print(result)
状态管理
import pixeltable as pxt
# Agent memory is automatically persisted in tables
memory = pxt.get_table("my_assistant.memory")
conversations = memory.collect()
# Access tool call history
tools_log = pxt.get_table("financial_assistant.tools")
tool_history = tools_log.collect()
# cusomatizable memory database
conversational_agent = Agent(
name="conversation_agent",
system_prompt="Focus on remebering the conversation",
n_latest_messages=14
)
自定义 Agentic 策略
# ReAct pattern for step-by-step reasoning and planning
import re
from datetime import datetime
from pixelagent.openai import Agent
import pixeltable as pxt
# Define a tool
@pxt.udf
def stock_info(ticker: str) -> dict:
"""Get stock information for analysis"""
import yfinance as yf
stock = yf.Ticker(ticker)
return stock.info
# ReAct system prompt with structured reasoning pattern
REACT_PROMPT = """
Today is {date}
IMPORTANT: You have {max_steps} maximum steps. You are on step {step}.
Follow this EXACT step-by-step reasoning and action pattern:
1. THOUGHT: Think about what information you need to answer the question.
2. ACTION: Either use a tool OR write "FINAL" if you're ready to give your final answer.
Available tools:
{tools}
Always structure your response with these exact headings:
THOUGHT: [your reasoning]
ACTION: [tool_name] OR simply write "FINAL"
"""
# Helper function to extract sections from responses
def extract_section(text, section_name):
pattern = rf'{section_name}:?\s*(.*?)(?=\n\s*(?:THOUGHT|ACTION):|$)'
match = re.search(pattern, text, re.DOTALL | re.IGNORECASE)
return match.group(1).strip() if match else ""
# Execute ReAct planning loop
def run_react_loop(question, max_steps=5):
step = 1
while step <= max_steps:
# Dynamic system prompt with current step
react_system_prompt = REACT_PROMPT.format(
date=datetime.now().strftime("%Y-%m-%d"),
tools=["stock_info"],
step=step,
max_steps=max_steps,
)
# Agent with updated system prompt
agent = Agent(
name="financial_planner",
system_prompt=react_system_prompt,
reset=False, # Maintain memory between steps
)
# Get agent's response for current step
response = agent.chat(question)
# Extract action to determine next step
action = extract_section(response, "ACTION")
# Check if agent is ready for final answer
if "FINAL" in action.upper():
break
# Call tool if needed
if "stock_info" in action.lower():
tool_agent = Agent(
name="financial_planner",
tools=pxt.tools(stock_info)
)
tool_agent.tool_call(question)
step += 1
# Generate final recommendation
return Agent(name="financial_planner").chat(question)
# Run the planning loop
recommendation = run_react_loop("Create an investment recommendation for AAPL")
查看我们的教程,了解更多示例,包括反思循环、规划模式和多提供商实现。
教程和示例
- Basics : 查看 Getting Started,获取核心概念的逐步介绍
- Advanced Patterns : 探索 Reflection 和 Planning,了解更复杂的 agent 架构
- Specialized Directories : 浏览我们的示例目录,了解特定技术的更深入的实现
准备好开始构建了吗? 深入研究蓝图,根据你的需求进行调整,让 Pixeltable 处理 AI 数据基础设施,而你专注于创新!
关于
Pixelagent — 构建你自己的状态化 agent 框架 pixeltable.com
Topics
python ai agents llms agent-engineering