-
Notifications
You must be signed in to change notification settings - Fork 167
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.
LightAgent registers several built-in tools:
execute_python_codeexecute_python_fileexecute_python_code_streamupload_file_to_oss
These are powerful tools. In production, review whether they should be exposed to every agent, especially when user input can influence code, files, network calls, or uploads.
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.
- Home
- 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