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
