Multi-Tool Integrationο
ostruct provides integration with multiple OpenAI tools and services, allowing you to combine different capabilities in a single workflow. This guide covers how to use Code Interpreter, File Search, Web Search, and MCP servers effectively.
Overviewο
ostruct supports four main tool categories:
Code Interpreter: Execute code, analyze data, generate visualizations
File Search: Semantic search across uploaded documents
Web Search: Access current information from the internet
MCP Servers: Connect to Model Context Protocol servers for custom tools
All tools can be used individually or combined in the same request for comprehensive analysis workflows.
Automatic File Routingο
ostruct can automatically route files to appropriate tools based on file type detection:
Auto-routing Target: Use --file auto:alias file.txt to let ostruct decide:
Text files β Template access (
prompt)Binary files β User-data for vision models (
ud)
File Type Detection:
Enhanced detection: Uses machine learning (Magika) for accurate file type identification
Extension fallback: Recognizes 30+ common file extensions (.txt, .md, .json, .py, .csv, etc.)
Installation:
pip install ostruct-cli[enhanced-detection]for enhanced detection
Example:
# Auto-route based on file type
ostruct run analysis.j2 schema.json \
--file auto:doc1 report.pdf \ # β user-data (binary)
--file auto:doc2 summary.txt \ # β prompt (text)
--file auto:doc3 data.json # β prompt (text)
Code Interpreterο
Code Interpreter allows the AI model to execute Python code, analyze data, create visualizations, and work with files programmatically.
How It Worksο
Files uploaded with
--file ci:are made available in the execution environmentThe model can write and execute Python code to analyze your data
Generated files (charts, reports, processed data) are automatically downloaded
Results and insights are included in the structured output
Note
π‘ Multi-Tool Tip: Use --file ci,fs:alias file.csv to make the same file available for both programmatic analysis and semantic search. This is especially useful for research data, financial reports, and technical documentation that benefit from multiple analysis approaches.
CLI Optionsο
File Upload:
# Upload single file for code execution
ostruct run analysis.j2 schema.json --file ci:data sales_data.csv
# Upload multiple files
ostruct run analysis.j2 schema.json \
--file ci:sales sales_data.csv \
--file ci:customers customer_data.csv
# Upload directory of files
ostruct run analysis.j2 schema.json --dir ci:project_data ./data/
Configuration Options:
--ci-cleanup: Clean up uploaded files after execution (default: True)--ci-download-dir DIR: Directory to save generated files (default: ./downloads/)--ci-duplicate-outputs {overwrite|rename|skip}: Handle duplicate file names
File Download Behaviorο
Automatic Workaround (v1.6+)
ostruct automatically handles the OpenAI API file download bug by enabling the two-pass sentinel strategy when:
Code Interpreter is enabled
File downloads are explicitly enabled (
--ci-downloadflag)
This ensures reliable file downloads when needed while optimizing performance when downloads are not required.
CLI Usage
Enable file downloads explicitly when needed:
# Enable downloads for generated files (charts, reports, data)
ostruct run analysis.j2 schema.json --file ci:data data.csv --ci-download
# Computation only - no downloads (faster execution)
ostruct run analysis.j2 schema.json --file ci:data data.csv
Configuration (Deprecated)
Deprecated since version 1.6.0: The auto_download configuration option is deprecated. Use --ci-download CLI flag instead.
# ostruct.yaml (legacy configuration)
tools:
code_interpreter:
download_strategy: "two_pass_sentinel" # Force enable
auto_download: false # New default (changed from true)
output_directory: "./downloads"
Performance Notes
Two-pass execution adds 2-3 seconds to requests
Single-pass mode is faster but files wonβt download with structured output
The workaround will be removed when OpenAI fixes the underlying API bug
Best Practicesο
Data Preparation: Upload clean, well-structured data files
Clear Instructions: Specify exactly what analysis or processing you need
File Organization: Use descriptive aliases for uploaded files
Output Management: Organize download directories for different projects
Example Templateο
---
system_prompt: You are a data analyst expert in Python and visualization.
---
Analyze the uploaded sales data and create visualizations showing:
1. Monthly sales trends
2. Top-performing products
3. Regional performance comparison
Please:
- Load and clean the uploaded CSV data
- Create meaningful visualizations using matplotlib/seaborn
- Generate a summary report with key insights
- Save charts as PNG files with descriptive names
- Provide download links for your sales analysis report
File Searchο
File Search enables semantic search across uploaded documents, allowing the model to find relevant information from large document collections.
Warning
Known Issue: The OpenAI Responses API file_search tool currently has a widespread issue where it returns empty results despite successful vector store creation. This affects all models and is an upstream OpenAI API bug. See known issue documentation for detailed information and community reports.
How It Worksο
Documents uploaded with
--file fs:are processed and indexedA vector store is created for semantic search capabilities
The model can search for relevant information during response generation
Search results are automatically included in the analysis context
Note
π‘ Multi-Tool Tip: Combine with Code Interpreter using --file ci,fs:docs report.pdf to both analyze document structure programmatically and search content semantically. Perfect for research papers, financial statements, and technical specifications.
CLI Optionsο
Document Upload:
# Upload single document
ostruct run research.j2 schema.json --file fs:manual user_manual.pdf
# Upload multiple documents
ostruct run research.j2 schema.json \
--file fs:docs documentation.pdf \
--file fs:specs technical_specs.docx
# Upload directory of documents
ostruct run research.j2 schema.json --dir fs:knowledge ./documentation/
Configuration Options:
--fs-cleanup: Clean up uploaded files and vector stores (default: True)--fs-store-name TEXT: Name for the vector store (useful for reuse)--fs-timeout FLOAT: Timeout for vector store indexing (default: 60.0)--fs-retries INT: Number of retry attempts (default: 3)
Best Practicesο
Document Quality: Upload well-formatted, text-rich documents
Relevant Content: Include only documents relevant to your query
Clear Questions: Ask specific questions that can be answered from the documents
Vector Store Management: Use meaningful store names for reusable collections
Example Templateο
---
system_prompt: You are a technical documentation expert.
---
Based on the uploaded technical documentation, please answer:
1. What are the system requirements for installation?
2. How do I configure the authentication settings?
3. What troubleshooting steps are recommended for common issues?
Search the documentation for relevant information and provide detailed answers with specific references to the source documents.
Web Searchο
Web Search provides access to current information from the internet, enabling analysis of up-to-date data and current events.
How It Worksο
Web search is enabled with
--enable-tool web-searchThe model can perform web searches during response generation
Search results are automatically incorporated into the analysis
Geographically tailored results based on specified location
CLI Optionsο
Basic Usage:
# Enable web search
ostruct run research.j2 schema.json --enable-tool web-search
# Disable web search (if enabled by default)
ostruct run analysis.j2 schema.json --disable-tool web-search
Geographic Customization:
# Specify location for tailored results
ostruct run research.j2 schema.json \
--enable-tool web-search \
--ws-country "United States" \
--ws-region "California" \
--ws-city "San Francisco"
Content Control:
--ws-context-size [low|medium|high]: Control amount of content retrieved--ws-country TEXT: Specify user country for geographically tailored results--ws-region TEXT: Specify user region/state for search results--ws-city TEXT: Specify user city for search results
Best Practicesο
Specific Queries: Include specific search terms in your template
Current Information: Use for time-sensitive or rapidly changing topics
Geographic Relevance: Set location parameters for location-specific queries
Content Filtering: Use appropriate context size for your needs
Example Templateο
---
system_prompt: You are a market research analyst.
---
Research the current state of artificial intelligence in healthcare:
1. What are the latest AI breakthroughs in medical diagnosis?
2. Which companies are leading AI healthcare innovation in 2024?
3. What regulatory challenges are affecting AI adoption in healthcare?
Please search for recent news, research papers, and industry reports to provide a comprehensive analysis with current information.
MCP Serversο
Model Context Protocol (MCP) servers allow you to connect to custom tools and services, extending ostructβs capabilities with specialized functionality.
How It Worksο
Connect to MCP servers using
--mcp-serverwith server URLsAvailable tools from connected servers are made accessible to the model
Tool usage can be controlled with approval settings and allowed tool lists
Custom headers can be provided for authentication
CLI Optionsο
Server Connection:
# Connect to MCP server
ostruct run analysis.j2 schema.json --mcp-server https://api.example.com/mcp
# Connect with custom label
ostruct run analysis.j2 schema.json --mcp-server mytools@https://api.example.com/mcp
# Connect to multiple servers
ostruct run analysis.j2 schema.json \
--mcp-server tools@https://api.example.com/mcp \
--mcp-server data@https://data.example.com/mcp
Authentication and Headers:
# Provide authentication headers
ostruct run analysis.j2 schema.json \
--mcp-server https://api.example.com/mcp \
--mcp-headers '{"Authorization": "Bearer token123", "X-API-Key": "key456"}'
Tool Control:
--mcp-require-approval [always|never]: Control tool usage approval--mcp-allowed-tools TEXT: Specify allowed tools per server
Note
π‘ Multi-Tool Tip: MCP servers work excellently with shared files. Use --file ci,fs:data report.pdf to make business documents available for both programmatic analysis and semantic search, while MCP tools access your CRM or analytics systems for additional context.
Best Practicesο
Secure Connections: Use HTTPS for MCP server connections
Authentication: Properly configure headers for authenticated servers
Tool Approval: Set appropriate approval levels for tool usage
Error Handling: Monitor for connection and tool execution errors
Example Templateο
---
system_prompt: You are a business analyst with access to custom tools.
---
Using the available MCP tools, please:
1. Retrieve the latest sales data from our CRM system
2. Generate a quarterly performance report
3. Create forecasts for the next quarter
Use the appropriate tools to gather data and perform analysis, then provide a comprehensive business summary.
Multi-Tool Workflowsο
Combining Tools for Comprehensive Analysisο
ostructβs multi-tool capabilities shine when you need comprehensive analysis that combines different approaches. The key is using shared files that serve multiple purposes simultaneously.
Research Analysis Workflow:
# Research paper analysis with shared files
ostruct run research_analysis.j2 schema.json \
--file ci,fs:paper research_paper.pdf \
--file ci,fs:data experiment_data.csv \
--enable-tool web-search \
--ws-country "United States"
This command makes the research paper and data available to both Code Interpreter (for statistical analysis and visualization) and File Search (for semantic queries about methodology and findings), while also enabling web search for current context.
Financial Analysis Workflow:
# Comprehensive financial analysis
ostruct run financial_analysis.j2 schema.json \
--file ci,fs:quarterly quarterly_report.pdf \
--file ci,fs:historical historical_data.csv \
--file fs:policies investment_policies.pdf \
--enable-tool web-search \
--ws-country "United States"
The quarterly report and historical data serve dual purposes: Code Interpreter performs numerical analysis and trend calculations, while File Search enables contextual queries about business strategy and policy compliance.
Technical Documentation Analysis:
# Code and documentation analysis
ostruct run tech_analysis.j2 schema.json \
--file ci,fs:specs technical_specification.pdf \
--file ci:codebase source_code.zip \
--file fs:docs user_manual.pdf \
--mcp-server dev@https://api.company.com/mcp
Technical specs benefit from both programmatic analysis (extracting requirements, parsing formats) and semantic search (finding related concepts and dependencies).
Example Multi-Tool Templateο
---
system_prompt: You are a senior analyst with access to multiple data sources and analysis tools.
---
# Comprehensive Analysis Report
## Quantitative Analysis
Using Code Interpreter, analyze the uploaded data files:
- Calculate key metrics and statistical summaries
- Identify trends and patterns in the numerical data
- Create visualizations showing important relationships
- Generate charts showing analysis results
## Contextual Research
Search the uploaded documents for:
- Background information and methodology
- Historical context and previous findings
- Policy implications and constraints
- Related research and citations
## Current Market Context
Research current developments related to our analysis topic:
- Recent industry trends and changes
- Competitive landscape updates
- Regulatory or policy changes
- Expert opinions and market sentiment
## Integrated Findings
Combine insights from all sources:
1. **Data-Driven Insights**: Key findings from quantitative analysis
2. **Contextual Understanding**: Background and historical perspective
3. **Current Relevance**: How findings relate to current market conditions
4. **Strategic Implications**: Actionable recommendations based on comprehensive analysis
## Supporting Evidence
Reference specific data points, document sections, and current sources that support each conclusion.
Shared File Benefits:
Consistency: Same source data across all analysis methods
Efficiency: Single upload serves multiple purposes
Completeness: Comprehensive analysis without data gaps
Cross-Validation: Findings can be verified across different approaches
Tool Combination Strategies:
Use Case |
Tool Combination |
Shared File Strategy |
|---|---|---|
Research Analysis |
CI + FS + Web Search |
|
Financial Reporting |
CI + FS + MCP |
|
Technical Documentation |
CI + FS + MCP |
|
Market Research |
FS + Web Search + MCP |
|
Compliance Analysis |
CI + FS + Web Search |
|
Tool Selection Guidelinesο
Choose tools based on your analysis needs:
Code Interpreter for: - Data processing and analysis - Statistical calculations - Visualization creation - File format conversions
File Search for: - Large document collections - Research and reference materials - Historical data analysis - Knowledge base queries
Web Search for: - Current events and trends - Market research - Competitive analysis - Real-time information
MCP Servers for: - Custom business tools - Proprietary data sources - Specialized APIs - Internal systems integration
Configuration Managementο
Environment Variablesο
Configure tool behavior using environment variables:
# MCP server configuration
export OSTRUCT_MCP_URL_crm="https://api.company.com/mcp"
export OSTRUCT_MCP_URL_analytics="https://analytics.company.com/mcp"
# Default tool settings
export OSTRUCT_DEFAULT_WS_COUNTRY="United States"
export OSTRUCT_DEFAULT_CI_DOWNLOAD_DIR="./analysis_outputs"
Configuration Fileο
Use ostruct.yaml for persistent configuration:
template:
max_file_size: null # unlimited (can also use size suffixes like "128KB", "1MB")
tools:
web_search:
enabled: true
country: "United States"
context_size: "medium"
code_interpreter:
cleanup: true
download_dir: "./downloads"
duplicate_outputs: "rename"
file_search:
cleanup: true
timeout: 60.0
retries: 3
mcp:
servers:
- label: "crm"
url: "https://api.company.com/mcp"
headers:
Authorization: "Bearer ${CRM_TOKEN}"
- label: "analytics"
url: "https://analytics.company.com/mcp"
require_approval: "never"
Troubleshootingο
Common Issuesο
Code Interpreter: - Large file upload timeouts: Reduce file sizes or use streaming - Memory errors: Process data in smaller chunks - Package availability: Check Python environment limitations
File Search: - Empty results: Known OpenAI API issue - see known issue documentation - Indexing failures: Ensure documents are text-readable - Search timeouts: Increase timeout values for large document sets - Poor search results: Use more specific queries and relevant documents
Web Search: - No results: Check internet connectivity and search terms - Geographic restrictions: Verify location settings - Rate limiting: Reduce search frequency in templates
MCP Servers: - Connection failures: Verify server URLs and network connectivity - Authentication errors: Check headers and credentials - Tool unavailability: Verify server status and tool permissions
Performance Optimizationο
Selective Tool Usage: Only enable tools needed for your specific task
File Size Management: Optimize file sizes for faster uploads and processing
Concurrent Requests: Use appropriate timeout values for your network
Caching: Reuse vector stores and downloaded files when appropriate
See Alsoο
CLI Reference - Complete CLI flag reference
Template Guide - Template authoring with tool integration
Advanced Template Patterns - Advanced multi-tool workflows
Security Overview - Security considerations for tool usage