Repository navigation
Tools
LightAgent tools are ordinary Python callables with a tool_info attribute. The framework converts that metadata into an OpenAI-compatible function schema and dispatches the callable when the model selects it.
from LightAgent import LightAgent
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 = LightAgent(
model="gpt-4.1",
api_key="your_api_key",
base_url="https://api.openai.com/v1",
tools=[get_weather],
)
print(agent.run("What is the weather in Shanghai?"))Pass stable tools when creating the agent:
agent = LightAgent(
model="gpt-4.1",
api_key="your_api_key",
base_url="https://api.openai.com/v1",
tools=[get_weather],
)Pass tools only for a specific run:
result = agent.run(
"Use the calculator for 42 * 19.",
tools=[calculator],
)Runtime tools are registered before the model request and can be called during that run.
tool_info should include:
-
tool_name: stable Python identifier, for exampleget_weather. -
tool_description: short model-facing description. -
tool_params: list of parameter definitions.
Supported parameter metadata follows a JSON-schema-like shape:
{
"name": "city_name",
"description": "The city name to query",
"type": "string",
"required": True,
}Common types: string, integer, number, boolean, array, and object.
ToolLoader can load a string-named tool from a tools directory. The tool file and function name must match the tool name:
tools/get_weather.py
def get_weather(city_name: str) -> str:
return f"{city_name} is sunny."
get_weather.tool_info = {...}Then pass the name:
agent = LightAgent(
model="gpt-4.1",
api_key="your_api_key",
base_url="https://api.openai.com/v1",
tools=["get_weather"],
)Tool names are validated as Python identifiers to avoid path traversal.
v1.0.0 uses the bounded safe_expression tool for simple data-only calculations. Legacy arbitrary-Python utilities are not registered by default and are blocked in model/tool dispatch. They must not be used for untrusted source. The storage integration requires an explicit oss or nos extra and appropriate storage authorization. See Tools and Integrations for examples and diagnostics.
agent.create_tool(user_input, tools_directory="tools") can ask the model to generate a tool file. Treat generated tools as code review candidates:
- keep generated tools outside automatic production paths until reviewed
- reject unsafe file names
- inspect imports and side effects
- add tests before relying on generated tools
- If the model never calls a tool, make the
tool_descriptionmore specific. - If a required argument is missing, check the
tool_paramslist. - If you see
[LA-TOOL], inspect the callable, parameter names, and exceptions raised inside the tool. - If local string tools do not load, confirm the file path, function name, and
tool_infomatch.
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