Repository navigation
FAQ zh CN
LightAgent 是一个轻量级 Python Agent 框架,用于构建支持工具调用、记忆、MCP、Skills、思维树、结构化结果、Tracing、确定性 LightFlow 工作流和简单多智能体协作的 Agent 应用。
LightFlow 是 v0.8.0 新增的工作流层,用于确定性的多步骤 Agent 执行。它支持命名步骤、依赖关系、步骤级重试、输出传递和工作流级 trace 事件。
from LightAgent import LightFlow
flow = (
LightFlow()
.step("research", agent=research_agent)
.step("write", agent=writer_agent, depends_on=["research"])
)
result = flow.run("Analyze this company", trace=True)更多内容见 LightFlow。
兼容。默认仍然返回字符串。
response = agent.run("hello")
print(response)如果需要结构化结果,可以显式开启:
result = agent.run("hello", result_format="object")
print(result.content)
print(result.tool_calls)
print(result.trace_id)兼容。默认仍然返回旧版流式 generator。
for chunk in agent.run(query, stream=True, user_id=user_id):
print(chunk, end="")如果需要结构化流式事件:
for event in agent.run(query, stream=True, user_id=user_id, result_format="event"):
print(event.type, event.data)LightAgent 使用 OpenAI-compatible Chat Completions API。只要模型服务兼容该接口,就可以通过 model、api_key、base_url 接入。常见场景包括 OpenAI、OpenRouter、DeepSeek/Qwen 兼容接口、vLLM、llama.cpp server mode 和 Ollama OpenAI-compatible API。
如果使用工具调用、MCP 或 Skills,需要确认所选模型支持 OpenAI-compatible function calling。
定义一个 Python 函数,并给函数添加 tool_info 元数据:
def get_weather(city_name: str) -> str:
return f"{city_name} is sunny."
get_weather.tool_info = {
"tool_name": "get_weather",
"tool_description": "Get current weather information for a city.",
"tool_params": [
{
"name": "city_name",
"description": "The city name to query",
"type": "string",
"required": True,
}
],
}然后在初始化 Agent 或调用 run() 时传入:
agent = LightAgent(
model="gpt-4.1",
api_key="your_api_key",
base_url="https://api.openai.com/v1",
tools=[get_weather],
)更多内容见 Tools。
传入一个实现 store(data, user_id) 和 retrieve(query, user_id) 的对象即可。
agent = LightAgent(
model="gpt-4.1",
api_key="your_api_key",
base_url="https://api.openai.com/v1",
memory=memory_backend,
)共享记忆后端建议配置 MemoryPolicy 或 memory_namespace,避免不同用户、租户或环境之间的记忆混用。更多内容见 Memory 和 Security。
配置 mcp_settings 后调用异步方法 setup_mcp():
import asyncio
asyncio.run(agent.setup_mcp(mcp_setting=mcp_settings))v1.0.0 安装 mcp extra 后支持 stdio、SSE 和 Streamable HTTP;详情见 工具和集成。
Tools 负责执行动作,例如查天气、调用数据库、执行代码或访问外部 API。
Skills 负责提供可复用的任务说明、流程、参考资料、脚本和资产。LightAgent 会发现 SKILL.md 元数据,并在任务匹配时通过 Skill 工具激活完整说明。
推荐使用结构化结果和 trace:
result = agent.run("hello", result_format="object", trace=True)
print(result.content)
print(result.trace)也可以开启本地 debug 日志:
agent = LightAgent(
model="gpt-4.1",
api_key="your_api_key",
base_url="https://api.openai.com/v1",
debug=True,
log_level="DEBUG",
)-
LA-401: 鉴权失败。 -
LA-404: 模型、endpoint 或资源不存在。 -
LA-413: 请求过大。 -
LA-429: 触发限流。 -
LA-JSON: JSON 或工具参数解析失败。 -
LA-TOOL: 工具执行失败。
更多内容见 Tracing and Debugging。
请先阅读:
LightAgent Wiki - see the repository, releases, and issues.
- Installation and Your First Agent
- Tools and Integrations
- Memory, Sessions, and RAG
- Workflows and Multiple Agents
- Agent Backends and Codex
- Durable Execution, Jobs, and Subagents
- Safety, Observability, and Evaluation
- Usage, Cost Estimates, and Budgets
- Deployment, Migration, and Verification
- 安装与第一个 Agent
- 工具和集成
- 记忆、会话与 RAG
- 工作流与多 Agent
- 执行后端与 Codex
- 持久执行、Jobs 与 Subagents
- 安全、观测与评测
- 用量统计、费用估算与预算
- 部署、升级与验收
- Quick Start
- Core Concepts
- API Reference
- Examples Cookbook
- Migration Guide
- Tools
- Tool Generator
- Memory
- MCP
- Skills
- LightFlow
- Tree of Thought
- Self-Learning
- Multi-Agent
- Tracing and Debugging
- Langfuse Observability
- Model Providers
- browser-use Integration
- Testing and CI
- Deployment Guide
- Architecture
- Security
- Known Limitations
- FAQ
- FAQ 中文
- Roadmap
- Release Process
- Contributing