Tool family¶
Wrap any callable as a Tool for an Agent. The Tool.wrap()
classmethod is the canonical multi-input factory (callable / Agent
/ existing Tool); Tool(...) is the explicit constructor used when
you want to set every field by hand. ToolProvider is the protocol
for expandable tool catalogues (MCP servers etc.). NativeTool
enumerates provider-hosted server-side tools.
The module-level lazybridge.tool (lowercase) is a thin
backwards-compat alias for Tool.wrap — existing imports keep
working, new code should prefer the classmethod.
For narrative usage see Guides → Basic → Tool and Guides → Basic → Native tools.
lazybridge.Tool ¶
Tool(func: Callable, *, name: str | None = None, description: str | None = None, mode: Literal['signature', 'llm', 'hybrid'] = 'signature', schema_llm: Any | None = None, strict: bool = False, returns_envelope: bool = False, agent_memory: Any | None = None, agent_store: Any | None = None)
Wraps any Python callable as an LLM-accessible tool.
Pass raw functions directly; Tool auto-wraps them on the agent level. Use Tool(fn, ...) only when you need explicit configuration.
Source code in lazybridge/tools.py
from_schema
classmethod
¶
from_schema(name: str, description: str, parameters: dict[str, Any], func: Callable[..., Any], *, strict: bool = False, returns_envelope: bool = False) -> Tool
Create a Tool with a pre-built JSON Schema for parameters.
Use this when the schema is already known (from MCP, OpenAPI, a third-party tool registry, ...) and signature introspection would either be unavailable or produce the wrong shape.
parameters must be a JSON Schema object (the same shape that
ToolDefinition.parameters carries).
Source code in lazybridge/tools.py
run_sync ¶
Blocking tool invocation.
Handles three cases so that callers never see a stray coroutine:
- plain sync function → called directly.
- async function → executed inside the current event loop if one
is running (a worker thread hops out of it), otherwise on a
fresh
asyncio.runloop. Needed because :meth:Agent.as_toolwraps the agent's.run()coroutine intoTool.func—SupervisorEngine/ REPL callers were previously getting"<coroutine object _run at 0x...>"instead of the result.
Source code in lazybridge/tools.py
wrap
classmethod
¶
wrap(obj: Any, *, name: str | None = None, description: str | None = None, mode: Literal['signature', 'hybrid', 'llm'] = 'signature', schema_llm: Any | None = None, strict: bool = _UNSET_BOOL) -> Tool
Canonical multi-input factory — accepts a callable, an Agent, or an
existing :class:Tool, and returns a properly wrapped Tool.
For Python functions — name is required so Plan steps, tool
maps, and LLM calls all share the same stable identifier::
search = Tool.wrap(search_web, name="search", description="Search the web.")
researcher = Agent(name="research", engine=LLMEngine(...), tools=[search])
For Agents — the canonical path is tools=[agent] directly;
Tool.wrap is useful when you need a local alias::
Tool.wrap(researcher, name="deep_research")
For existing Tools — returns the object unchanged (no overrides) or clones it with the specified overrides (non-mutating)::
search_v2 = Tool.wrap(search, name="web_search")
Parameters¶
obj:
A callable, :class:Agent, or existing :class:Tool to wrap.
name:
Required for callables. Optional alias for agents and Tools.
description:
Human-readable description forwarded to the LLM.
mode:
Schema generation mode. "signature" (default) introspects the
function signature and docstring deterministically. Pass
"hybrid" (signature + LLM-enriched descriptions) or "llm"
(full LLM-inferred schema) explicitly when the signature alone
is insufficient — both require schema_llm= to be set.
schema_llm:
Engine used when mode="hybrid" or mode="llm".
strict:
Enable JSON Schema strict mode.
Notes¶
Module-level :func:tool is a thin alias for backwards compatibility
and is kept indefinitely; new code should prefer Tool.wrap.
Source code in lazybridge/tools.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
lazybridge.tool ¶
tool(obj: Any, *, name: str | None = None, description: str | None = None, mode: Literal['signature', 'hybrid', 'llm'] = 'signature', schema_llm: Any | None = None, strict: bool = _UNSET_BOOL) -> Tool
Backwards-compatibility alias for :meth:Tool.wrap.
New code should call Tool.wrap(obj, name=...) — it lives on the class
alongside the explicit constructor, mirroring Python stdlib factories
like :meth:dict.fromkeys and :meth:datetime.datetime.fromisoformat.
The lowercase :func:tool is kept indefinitely so existing imports
(from lazybridge import tool) continue to work; no deprecation
timer is set.
Source code in lazybridge/tools.py
lazybridge.ToolProvider ¶
Bases: Protocol
A tools=[...] entry that expands itself into one or more Tools.
Implementors set _is_lazy_tool_provider = True and define
as_tools() -> list[Tool]. MCPServer and
ExternalToolProvider both satisfy this protocol structurally;
custom providers (OpenAPI imports, internal tool registries, etc.)
can do the same — drop the instance into Agent(tools=[provider])
and build_tool_map will expand it on construction.
lazybridge.NativeTool ¶
Bases: StrEnum
Provider-native server-side tools (run on provider infrastructure).