liveBook · Manning

Function_tool decorator

As explained in AI Agents in Action, Second Edition

A decorator or helper that exposes a programming-language function as an agent-callable tool and generates its structured tool description.

The function_tool decorator turns an ordinary internal function into an agent-callable tool. It handles the integration plumbing and generates the structured JSON description an agent uses when deciding whether and how to call it. section 2.4.1

Unlike a normal function call, a decorated function becomes part of the agent’s tool interface: its description is supplied to the language model on every call, whether the agent uses the tool or not. section 2.4.1

Expose a research-source function

@function_tool def get_research_sources() -> list[str]: """Provides a list of available research sources.""" return ["internal reports", "public datasets", "technical papers"] Registering this function lets an agent retrieve sources before creating a research plan. A more practical implementation could query available resources dynamically. section 2.4.1

Design decorated tools with these constraints in mind:

  • Keep tools distinct and clearly described so the agent can choose among them reliably. section 2.4.1
  • Account for token and prompt overhead because every registered JSON description travels with every language-model call. section 2.4.1
  • Handle failures explicitly because each additional tool creates another possible failure point. section 2.4.1 section 9.5

How AI Agents in Action, Second Edition covers it

How deep it goes
Explains automatic plumbing and JSON descriptions, but does not detail their schema-generation internals.
Examples
Uses a research-source function, typed research plans, local search facts, and deliberately failing tools with retries.
What you can do after
Build it from scratch by decorating typed functions and applying them within agentic research or task loops.
How it connects
Connects function tools to agents, language-model calls, prompts, JSON descriptions, and MCP-based tool connections.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents in Action, Second Edition. The section links point to the parts of the book it draws on.