Repository navigation
Tool Generator
weego edited this page May 28, 2026
·
1 revision
agent.create_tool() can generate Python tool code from a natural-language tool specification.
from LightAgent import LightAgent
agent = LightAgent(
name="ToolGenerator",
instructions="You generate LightAgent tool code from specifications.",
role="Generate accurate and reviewable Python tools.",
model="gpt-4.1",
api_key="your_api_key",
base_url="https://api.openai.com/v1",
)
tool_spec = """
Create a tool named get_weather that accepts city_name as a string and returns
current weather text from a public API.
"""
agent.create_tool(tool_spec, tools_directory="tools")Generated files are saved under tools_directory.
Before using generated tools:
- inspect imports
- inspect network requests
- inspect file writes
- check parameter names against
tool_info - add tests
- run the tool manually with safe inputs
- remove hardcoded secrets
- review exception handling
If the generated file is tools/get_weather.py and it defines get_weather, load it by name:
agent = LightAgent(
model="gpt-4.1",
api_key="your_api_key",
base_url="https://api.openai.com/v1",
tools=["get_weather"],
)Tool file name, function name, and tool_info["tool_name"] should match.
Generated tools should be treated like unreviewed code. Do not automatically deploy generated tools into production. Keep generation, review, testing, and release as separate steps.
Reference example: example/09.create_tools.py.
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