liveBook · Manning

Compositional tool use

As explained in Build an AI Agent (From Scratch)

Tool composition is the combination of multiple callable capabilities into a larger functionality or processing pipeline.

Compositional tool use combines small callable capabilities into a larger function or processing pipeline. Instead of asking an agent to call tools one at a time, code lets it connect tool outputs, transformations, and reporting in one executable flow. This reduces repeated model calls, context passing, and tool-selection overhead. section 8.1.2 section 8.6

A compositional workflow typically combines:

  • Tool calls that gather inputs, such as news, prices, files, or sales data. section 8.1.2
  • Intermediate variables that store, transform, and reuse results without repeatedly sending complete context to the model. section 8.1.2
  • Ordinary program logic that combines outputs, selects records, summarizes results, or creates a new callable capability. section 8.1.2 section 8.6
  • A sandbox that executes generated code with isolation, resource management, and recovery when failures occur. section 8.6

Company analysis as a composed tool

A generated function can search recent company news, retrieve thirty days of stock data, calculate a price change, select several headlines, analyze sentiment, and pass the combined summary to a report creator. The resulting function behaves like a new tool assembled from existing capabilities. section 8.1.2

Listing 8.4 Creating new tools through tool composition
def analyze_company(company_name):
    """Simple company analysis combining news and stock data"""

    news = search_news(company_name, limit=10)
    stock_data = get_stock_price(company_name, days=30)

    summary = {
        'price_change': stock_data['change_percent'],
        'recent_news': [n['title'] for n in news[:3]],
        'sentiment': analyze_sentiment(news)
    }

    report = create_report(data=summary)

    return report

Inspect a complete composition that gathers news and stock data, derives a summary, analyzes sentiment, and creates a report. section 8.1.2

How Build an AI Agent (From Scratch) covers it

How deep it goes
Explains composition through data flow and generated functions, then identifies source extraction and sandbox registration as an implementation approach.
Examples
Demonstrates company analysis by combining news search, stock retrieval, sentiment analysis, and report creation.
What it assumes
Assumes callable tools and code execution while teaching how to combine their inputs and outputs into larger functionality.
What you can do after
Build it from scratch by wiring existing tools, intermediate results, transformations, and reporting into an executable pipeline.
How it connects
Connects tool composition to code execution, control flow, data flow, sandboxes, workspaces, and hierarchical tool structures.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build an AI Agent (From Scratch). The section links point to the parts of the book it draws on.