# WorkflowFunctionBinding

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.workflowfunctionbinding/
> Summary: WorkflowFunctionBinding: Binds functions registered with AddWorkflowFunction to a workflow graph defined in code.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Workflows.dll</code></div>

Binds functions registered with `AddWorkflowFunction` to a workflow graph defined in code.

```csharp
public static class WorkflowFunctionBinding
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.workflowfunctionbinding/">WorkflowFunctionBinding</a></dd><dt>Inherited Members</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Remarks

A stored workflow chain gets, for every function node, a time limit, a retry policy, a budget gate, a
concurrency limit, a cost line that names the node and a strict read of its settings. A graph built in
code with its own executors gets none of them: they live in a wrapper that only the stored chain's
compiler could reach, and the budget gate cannot be built in consumer code at all. This helper hands the
same executor to a graph built in code - the same registry entry, the same wrapper, the same order.

**The executor's id is the function's name.** The node name in the run's events, in the
cost lines and in the checkpoint is the name the function was registered with, so use a function once in a
graph; to use the same code twice, register it under a second name.

```csharp
tracon.AddWorkflow("review-and-revise", services =>
{
    var validate = services.GetWorkflowFunction("validate");
    var render = services.GetWorkflowFunction("render", step => step.Timeout = TimeSpan.FromMinutes(5));

    return new WorkflowBuilder(validate)
        .AddEdge(validate, render)
        .WithOutputFrom(render)
        .WithName("review-and-revise")
        .Build();
});
```

## Methods

### <a id="Tracon_WorkflowFunctionBinding_GetWorkflowFunction_System_IServiceProvider_System_String_"></a> GetWorkflowFunction\(IServiceProvider, string\)

Binds a registered function to a workflow graph defined in code.

```csharp
public static ExecutorBinding GetWorkflowFunction(this IServiceProvider services, string functionName)
```

#### Parameters

`services` [IServiceProvider](https://learn.microsoft.com/dotnet/api/system.iserviceprovider)

The service provider.

`functionName` [string](https://learn.microsoft.com/dotnet/api/system.string)

The name the function was registered with.

#### Returns

 ExecutorBinding

The executor binding to put in the graph.

#### Remarks

Everything the other overload says applies here too. The function runs with its registered time
limit, retry policy, concurrency limit and budget gate, and with no settings.

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

`services` is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

 [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)

`functionName` is empty.

 [TraconException](/api/tracon.traconexception/)

No function is registered with that name. The graph is built for every run, so the run ends
`Failed` before its first node, and the message names the workflow and the function.

### <a id="Tracon_WorkflowFunctionBinding_GetWorkflowFunction_System_IServiceProvider_System_String_System_Action_Tracon_WorkflowFunctionStepOptions__"></a> GetWorkflowFunction\(IServiceProvider, string, Action<WorkflowFunctionStepOptions\>\)

Binds a registered function to a workflow graph defined in code, with the node's own timeout and settings.

```csharp
public static ExecutorBinding GetWorkflowFunction(this IServiceProvider services, string functionName, Action<WorkflowFunctionStepOptions> configure)
```

#### Parameters

`services` [IServiceProvider](https://learn.microsoft.com/dotnet/api/system.iserviceprovider)

The service provider.

`functionName` [string](https://learn.microsoft.com/dotnet/api/system.string)

The name the function was registered with.

`configure` [Action](https://learn.microsoft.com/dotnet/api/system.action\-1)<[WorkflowFunctionStepOptions](/api/tracon.workflowfunctionstepoptions/)\>

Sets the node's timeout and settings; called once, here.

#### Returns

 ExecutorBinding

The executor binding to put in the graph.

#### Remarks

**The graph is built again for every run**, and so is the executor: Microsoft Agent
Framework does not allow one executor instance to serve two runs. The settings are read here, once
per build, so the handler sees exactly the object that was checked.

**Input and output types are the function's.** A node must take what the node before it
passes on; Microsoft Agent Framework drops a message no handler takes, without an error. The chain
check a stored workflow gets at save time does not run for a graph built in code.

```csharp
tracon.AddWorkflow("narrated", services =>
{
    var tts = services.GetWorkflowFunction("tts", step =>
    {
        step.Timeout = TimeSpan.FromMinutes(10);
        step.SetSettings(new TtsSettings { Voice = "mira" });
    });

    return new WorkflowBuilder(tts).WithOutputFrom(tts).WithName("narrated").Build();
});
```

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

One of the parameters is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

 [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)

`functionName` is empty.

 [ArgumentOutOfRangeException](https://learn.microsoft.com/dotnet/api/system.argumentoutofrangeexception)

[WorkflowFunctionStepOptions.Timeout](/api/tracon.workflowfunctionstepoptions/#Tracon_WorkflowFunctionStepOptions_Timeout) is outside one millisecond to about 49.7 days.

 [TraconException](/api/tracon.traconexception/)

No function is registered with that name, or the settings do not fit the settings type the function
declares (or the function declares none). The graph is built for every run, so the run ends
`Failed` before its first node, and the message names the workflow, the function and the member.
