agentleFS
lauren-frameworklauren-framework/lauren-ai/skills/building-tools/SKILL.md

building-tools

Skill0 starsChanged 6 months agoMITView on GitHub

Creates tools for lauren-ai agents using @tool() on async functions or classes. Use when implementing a @tool() function or class, working with ToolContext for DI injection, adding caching, HITL approval, or using built-in skills like WebSearchTool, HttpFetchTool, or CodeExecutionTool.

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • celigo/aitheir own version, first seen Nov 5, 2026

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use a class when the tool needs injected dependencies.

    line 60
  2. Very specific:

    Read the authenticated user identity from ctx.execution_context.request.state

    line 100

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Use codemap find "SymbolName" to locate any symbol before reading — it gives exact file + line range and is faster than grep across the whole repo.

Building Tools with lauren-ai

Critical rule — tool annotations must resolve

from __future__ import annotations is supported, but every type used by @tool() must resolve when schema generation runs.

@tool() resolves annotations when it builds the JSON schema. Future annotations are supported, but unresolved forward references and circular imports in function-form tool files still break schema generation.

A safe reminder comment is:


# @tool() resolves parameter annotations when this module is imported.
# Keep tool signature types importable and avoid unresolved forward refs.

Quick start — function-form tool


from lauren_ai import tool

@tool()
async def get_price(item: str) -> dict:
    """Look up an item's current price.

    Args:
        item: Product name to look up.
    """
    return {"item": item, "price": 9.99}

Attach it to an agent:

from lauren_ai import agent, use_tools

@agent(model="claude-opus-4-6", system="You are a helpful shop assistant.")
@use_tools(get_price)
class ShopAgent: ...

Quick start — class-form tool

Use a class when the tool needs injected dependencies. The method must be named run() — not __call__(). The @tool() decorator looks for run; a __call__ is silently ignored and the decorator will raise ValueError.


from lauren_ai import tool, ToolContext

@tool()
class SendEmailTool:
    """Send an email to a recipient.

    Args:
        to: Recipient email address.
        subject: Email subject line.
        body: Email body text (plain text).
    """

    def __init__(self, smtp_client: SmtpClient) -> None:
        self._smtp = smtp_client

    async def run(
        self,
        to: str,
        subject: str,
        body: str,
        ctx: ToolContext | None = None,
    ) -> dict:
        await self._smtp.send(to=to, subject=subject, body=body)
        return {"sent": True, "to": to}

ToolContext — DI injection, not LLM input

ToolContext is never included in the JSON schema sent to the LLM. ToolExecutor injects it automatically at call time. Use it to:

  • Access the agent's AgentContext via ctx.agent_context
  • Read the authenticated user identity from ctx.execution_context.request.state
  • Identify the current turn number via ctx.turn
@tool()
async def whoami(ctx: ToolContext | None = None) -> dict:
    """Return the authenticated user's ID.

    (No additional parameters — all identity comes from context.)
    """
    if ctx is None or ctx.execution_context is None:
        return {"user_id": None}
    state = getattr(ctx.execution_context.request, "state", None)
    user_id = state.get("user_id") if state else None
    return {"user_id": user_id}

The generated schema contains zero parameters:

{
  "name": "whoami",
  "input_schema": {"type": "object", "properties": {}, "required": []}
}

Schema generation rules

Python annotationJSON Schema typeRequired?
str"string"yes (unless Optional)
int / float"number"yes (unless Optional)
bool"boolean"yes (unless Optional)
dict"object"yes (unless Optional)
list"array"yes (unless Optional)
Optional[T] / T | Nonetype Tno
ctx: ToolContext / ctx: ToolContext | None = None—excluded entirely
parameter with default valuetype Tno

Parameter descriptions come from the Args: section of the Google-style docstring. Always document every parameter.


Safety invariants

RuleWhy
run() not __call__()@tool() looks for run; a __call__ method is silently ignored
Resolvable tool annotationsFuture annotations are supported, but @tool() still needs every referenced type to resolve when it builds the schema
Decorate with @tool() (parentheses required)Bare @tool raises DecoratorUsageError
Never use LLM-supplied identityRead from ctx.execution_context.request.state — see security.md
Always return a dictLLM receives the JSON-serialised return value as the tool result

Reference files

FileContents
tools.mdFull reference: schema rules, HITL approval, caching, on_tool_result hook, built-in skills
../securing-agents/security.mdSecure tool patterns using ToolContext.execution_context
../building-agents/agents.md@agent, lifecycle hooks, attaching tools via @use_tools

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.