Skip to content

Tool Generator

weego edited this page May 28, 2026 · 1 revision

Tool Generator

agent.create_tool() can generate Python tool code from a natural-language tool specification.

Basic Flow

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.

Review Checklist

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

Loading Generated Tools

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.

Security Notes

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.

Clone this wiki locally