{{variableName}}). At runtime, you provide actual values to dynamically customize agent instructions, tool resource configurations, and response parameters—without creating separate agent versions for each configuration.
In this article, you learn how to:
- Define structured inputs in an agent definition
- Use handlebar templates in agent instructions
- Dynamically configure tool resources such as Code Interpreter and File Search
- Pass structured input values at runtime through the Responses API
Prerequisites
- A basic or standard agent environment.
- The latest SDK package for your language. See the quickstart for installation steps.
- Azure credentials configured for authentication (such as
DefaultAzureCredential). - Your Foundry project endpoint URL and model deployment name.
What are structured inputs?
Structured inputs use handlebar template syntax ({{variableName}}) to create parameterized agent definitions. You define input schemas in the agent definition under structured_inputs, where each input has a name, description, type, and optional default value. At runtime, supply actual values that replace the template placeholders before the agent processes the request.
Structured inputs support two categories of overrides:
- Instruction overrides: Parameterize agent instructions, response-level instructions, and system or developer messages.
- Tool resource overrides: Dynamically configure tool properties at runtime, including:
- File search vector store IDs
- Code interpreter file IDs and containers
- Model Context Protocol (MCP) server URLs and headers
file_ids and vector_store_ids, the system automatically removes empty string values at runtime. This feature enables flexible input counts – define more template slots than needed and leave unused ones empty.
Supported structured input properties
The following table lists the agent definition properties that support handlebar templates:| Category | Property | Description |
|---|---|---|
| Instructions | Agent instructions | Agent-level instruction text |
| Instructions | Response instructions | Instructions passed in the Responses API request |
| Instructions | System/developer message content | Message content in the input array |
| File Search | vector_store_ids | Array of vector store IDs (empty values stripped) |
| Code Interpreter | container (string) | Container ID for a preconfigured container |
| Code Interpreter | container.file_ids (array) | File IDs in an auto container (empty values stripped) |
| MCP | server_label | Label for the MCP server |
| MCP | server_url | URL for the MCP server endpoint |
| MCP | headers (values) | HTTP header values as key-value pairs |
| Azure AI Search | filter | OData filter expression applied to a search index |
Use structured inputs with agent instructions
The simplest use of structured inputs is to parameterize agent instructions. Define handlebar templates in theinstructions field and supply values at runtime. This approach lets you personalize agent behavior for different users or contexts without creating multiple agent versions.
The following examples create an agent whose instructions include user-specific details and then supply those values when creating a response.
Use structured inputs with Code Interpreter
By using structured inputs, you can dynamically configure which files and containers the Code Interpreter tool uses at runtime. Define handlebar templates in the tool’sfile_ids or container properties, and then supply actual IDs when creating a response.
Use structured inputs with File Search
By using structured inputs, you can dynamically configure which vector stores the File Search tool queries at runtime. Define template placeholders in thevector_store_ids array, and then supply actual vector store IDs when creating a response.
Use structured inputs with Azure AI Search
By using structured inputs, you can dynamically configure the Azure AI Search tool’s indexfilter at runtime. Define a handlebar template inside the OData filter expression, and then supply the actual filter value when creating a response. This pattern lets a single agent definition serve users whose queries must be scoped to different subsets of an index without creating a separate agent version per filter value.
Use structured inputs with MCP servers
By using structured inputs, you can dynamically configure MCP server connections at runtime. You can set the server URL, authentication headers, and server label. By using this approach, a single agent definition can connect to different MCP servers depending on the context. The following JSON shows the request body for the Create Agent Version operation (POST /agents?api-version=v1). The agent definition includes MCP tool properties with handlebar template placeholders:
POST /openai/v1/responses):
Use structured inputs in the Responses API
You can use handlebar templates directly in Responses API calls without defining them in the agent definition. This approach works for response-level instructions and for system or developer messages in the input array.Response-level instructions with structured inputs
Pass structured inputs alongsideinstructions in a response request to parameterize the system prompt:
System and developer messages with structured inputs
Use handlebar templates in system and developer message content to inject runtime values into the conversation context:extra_body (Python), body (TypeScript), or AzureCreateResponseOptions (Java/C#) patterns shown in the previous examples.
The following Python example shows how to use response-level instructions with structured inputs:
Advanced template syntax
Structured inputs support full Handlebars template syntax beyond simple variable substitution. You can use conditionals, loops, and other built-in helpers to create dynamic instruction logic within a single agent definition. The following example creates a weather assistant whose behavior adapts based on runtime inputs. The instructions template uses{{#if}} for conditional sections and {{#each}} to iterate over a list of user preferences:
You are a weather assistant. Provide a helpful weather summary for the user. The user asked about: Seattle, WA Use the following units: Fahrenheit Include a brief multi-day forecast in your response. The user has these additional preferences:The following table summarizes the supported Handlebars helpers:Keep the final answer clear and easy to read.
- Highlight UV index
- Include wind speed
| Helper | Syntax | Description |
|---|---|---|
| Conditional | {{#if value}}...{{else}}...{{/if}} | Render content based on a truthy or falsy value |
| Negation | {{#unless value}}...{{/unless}} | Render content when a value is falsy |
| Loop | {{#each array}}{{this}}{{/each}} | Iterate over array items |
| Last item check | {{#unless @last}}, {{/unless}} | Conditionally render separators between loop items |