Selective Registration And Config
This page covers function selection and the serialized harness reference. Configuration, dependencies, and run overrides have focused guides:
- Configure A Tool Harness
- Inject Harness Dependencies
- Configure A Harness Per Run
- Tool Harness Configuration Reference
Select One Function
Use WithTool<T>() when the model should see one generated function:
var assistant = new AgentConfig()
.WithOpenAI(model: "gpt-5-mini")
.WithTool<WeatherTools>("get_weather");The function name is exactly the name the harness declares. Multiple registrations for the same harness merge their function filters. Unknown names fail with the generated function list.
Serialized Harness Reference
A serialized reference names its harness by the exact activation identity, Assembly:Namespace:Name, the identity WithToolHarness<T>() writes. runtime.Composition.ToolHarnesses lists the identities a definition can use. AgentConfig.ToolHarnesses supports the shorthand string form:
{
"toolHarnesses": [
"MyApp:MyApp.Tools:WeatherTools"
]
}Use object syntax to select functions:
{
"toolHarnesses": [
{
"name": "MyApp:MyApp.Tools:WeatherTools",
"functions": [
"get_weather"
]
}
]
}functions: null exposes every generated function.
A reference outside the composition is refused with agent_harness_unknown, and a functions entry the harness does not declare with agent_harness_function_unknown. Each error names the path, such as toolHarnesses[0].functions[0], and the closest valid name. A code agent is checked at BuildAsync(); a stored definition is checked when it is created or updated.
Property names are case-sensitive camelCase. Unknown and duplicate reference properties fail instead of being skipped.
Serialized Construction Config
toolHarnesses:
- name: MyApp:MyApp.Tools:SearchHarness
config:
maxResults: 20
endpoint: https://search.internalThe registered harness library binds config through its generated immutable settings codec. Config fields are patched over library defaults.
See Configure A Tool Harness for C#, YAML, precedence, and validation.
Run Config
Per-run settings use a separate harnesses property:
{
"harnesses": [
{
"name": "SearchHarness",
"config": {
"maxResults": 5
}
}
]
}This is a partial execution override, not another construction document. A run override may name the harness by its class name when that name is unique among the agent's selected harnesses. See Configure A Harness Per Run.
Typed Metadata
Generic metadata remains separate from construction settings:
{
"toolHarnesses": [
{
"name": "MyApp:MyApp.Tools:SearchHarness",
"metadata": {
"defaultProvider": "tavily",
"hasTavilyProvider": true
}
}
]
}The harness must declare a compatible metadata contract. Metadata affects capability descriptions, visibility, and conditions; it does not provide constructor settings or dependencies.
Middleware Configuration
Settings for middleware a harness declares go in the harness config, addressed by the middleware's identity:
toolHarnesses:
- name: MyApp:MyApp.Tools:DatabaseToolHarness
config:
middlewares:
- name: databaseRateLimit
config:
requestsPerMinute: 20The entry configures declared middleware only; it does not activate or reorder it. Harness-owned settings sit beside middlewares in the same config object.
Composition
- A harness selected in code and its serialized reference resolve to one exact owner.
.Configure(...)inWithToolHarness<T>(opts => ...)replaces serialized harness-owned settings. Serializedmiddlewaresentries are kept.- A run override patches the effective agent setting.
- Duplicate harness entries and duplicate owner registrations fail.
- Explicit instances retain their existing settings and dependencies.
Native AOT
The harness library's source generator emits the activation and settings codecs. Keep the generator on in the library project and rebuild referenced harness packages when adopting this contract.
No application-side copy of the harness settings type is required.