Skip to content

V1 Tools and Integrations en

weego edited this page Nov 15, 2026 · 1 revision

Tools and Integrations

简体中文 | English

Applies to v1.0.0. The host authorizes tools; the model cannot grant itself permission. Validate schema and business constraints, and expose only capabilities allowed for the current user and workspace.

Python tools and diagnostics

This example validates a tool schema and connector without credentials. The tool returns a fixed local string:

from LightAgent import ConnectorManifest, ToolRegistry, validate_connector

def lookup(term: str) -> str:
    return {"lightagent": "轻量 Agent 框架"}.get(term.lower(), "无匹配")

lookup.tool_info = {
    "tool_name": "lookup",
    "tool_description": "查询本地术语表",
    "tool_params": [
        {"name": "term", "description": "术语", "type": "string", "required": True}
    ],
}

registry = ToolRegistry()
assert registry.register_tool(lookup)
assert not registry.validate_tools()

connector = ConnectorManifest(name="glossary", version="1.0.0", tools=[lookup])
report = validate_connector(connector)
assert report.valid, report.to_dict()
print(lookup("LightAgent"))

Register lookup with LightAgent(..., tools=[lookup]) for repeated use, pass it to a single agent.run("查询 LightAgent", tools=[lookup]), or use load_tools() for named tools from a reviewed local directory. Check agent.validate_tools() for duplicate names and schema diagnostics. In a test, assert that the expected tool was actually called, rather than judging from the reply alone. OpenAI-compatible models do not necessarily handle every schema or tool stream. See the Tools Reference for tool composition, concurrent dispatch, and session-level toolset restrictions.

Built-in and generated tools

  • Use the default safe_expression tool or the local function below for simple arithmetic. It is not a general Python interpreter. Apply business-specific input limits as well.
  • Legacy arbitrary-Python tools are not registered by default, and model/tool dispatch blocks them. Do not use the legacy executor for untrusted code. To execute real workspace tasks, choose an explicit backend with independently enforced isolation.
  • create_tool() and the tool generation example produce drafts. Do not automatically register unreviewed code. Check dependencies, filesystem/network effects, arguments, and failure behavior before putting it into your tool directory.
from LightAgent import evaluate_safe_expression

assert evaluate_safe_expression("2 * (3 + 4)") == 14

MCP: connect to reviewed tool servers

python -m pip install 'lightagent[mcp] @ git+https://github.com/wanxingai/LightAgent.git@v1.0.0'

In an async function, run the following with an agent that already has a model configured. Start a trusted local server and substitute its actual URL. This example server does not require credentials; resolve production credentials from the environment or a secret manager, not committed configuration.

mcp_settings = {
    "mcpServers": {
        "catalog": {
            "url": "http://127.0.0.1:8000/mcp",
            "transport": "streamable-http",
            "namespace": "catalog",
            "namespace_tools": True,
        },
    },
}

await agent.setup_mcp(mcp_setting=mcp_settings)
result = await agent.arun("用已授权的目录工具列出可见条目。", result_format="object")
print(result.content)

For stdio, set command and args to start a trusted local program. For SSE, use an SSE endpoint. For Streamable HTTP, explicitly set transport. Existing mcpServers configuration and the MCPClientManager import remain available; the MCP SDK is required when actually connecting. For reconnection, tool refresh, namespaces, and credential resolution, see MCP, the tagged MCP example, and the runtime documentation. A successful connection does not authorize every advertised tool.

Skills: reuse domain instructions

PyYAML is a base dependency, so Skills work with a base install. Example skills/glossary/SKILL.md:

---
name: glossary
description: 解释当前项目中的术语。
---

遇到项目术语问题时,先查询已注册的术语表工具。
查不到时说明未知,不虚构定义。

Pass LightAgent(..., skills_directories=["./skills"]) to specify trusted directories. Conventional paths are discovered by default; disable that with auto_discover_skills=False. Use SkillManager.list_conflicts() to diagnose conflicts. A Skill packages instructions and resources; it does not grant scripts execution permission. Do not treat arbitrary downloaded directories, scripts, or AGENTS.md files as trusted instructions. See Skills and Agent Backends.

Connectors, browsers, and object storage

  • ConnectorManifest groups tools, Skills, MCP settings, Hooks, memory adapters, extras, and documentation. validate_connector() works offline: it neither installs dependencies nor activates the connector, and it is not a security proof. The local research connector and enterprise API example show how the host selects components.
  • Browser automation is an external integration; the base install supplies neither a browser nor a remote browsing account. See the browser-use integration and browser example. Start with an authorized page that contains no sensitive data and retain approvals for external actions.
  • OSS/NOS tools use boto3 from the oss or nos extra. Configure scoped credentials and bucket policies that allow only the required objects. Require authorization, audit uploads, and define a retry policy. Keep credentials, private files, and private URLs out of traces.

Clone this wiki locally