Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Semantic kernel ProcessFunctionTargetBuilder

From Leeroopedia
Knowledge Sources
Domains Process_Orchestration, Event_Driven_Architecture
Last Updated 2026-02-11 19:00 GMT

Overview

Concrete API for connecting process steps through event-based message routing using ProcessFunctionTargetBuilder, OnInputEvent, OnFunctionResult, OnEvent, SendEventTo, and StopProcess.

Description

ProcessFunctionTargetBuilder is a record class that specifies the target step, function, and parameter for an event route in a Semantic Kernel process. It works in conjunction with the process edge builder methods (OnInputEvent, OnFunctionResult, OnEvent) and the routing methods (SendEventTo, StopProcess) to form a complete event routing API.

When a ProcessFunctionTargetBuilder is constructed, it validates the target by resolving the function and parameter against the step's kernel function metadata. If the step has only one function, the function name can be omitted and will be inferred. If the function has only one parameter, the parameter name can be omitted and will be inferred. This validation at construction time ensures routing errors are caught during process definition rather than at runtime.

Usage

Use ProcessFunctionTargetBuilder as the argument to SendEventTo whenever you need to route an event from one step to another within a process definition. Combine with OnInputEvent, OnFunctionResult, OnEvent, and StopProcess to define complete routing topologies.

Code Reference

Source Location

  • Repository: semantic-kernel
  • File: dotnet/src/Experimental/Process.Core/ProcessFunctionTargetBuilder.cs:L10-92

Signature

public record ProcessFunctionTargetBuilder : ProcessTargetBuilder
{
    public ProcessFunctionTargetBuilder(
        ProcessStepBuilder step,
        string? functionName = null,
        string? parameterName = null);

    public ProcessStepBuilder Step { get; init; }
    public string FunctionName { get; init; }
    public string? ParameterName { get; init; }
    public string? TargetEventId { get; init; }
}

Import

using Microsoft.SemanticKernel;

I/O Contract

Constructor Inputs

Name Type Required Description
step ProcessStepBuilder Yes The target step builder, obtained from AddStepFromType<T>().
functionName string? No Name of the target function on the step. Inferred if the step has exactly one [KernelFunction].
parameterName string? No Name of the target parameter on the function. Inferred if the function has exactly one parameter.

Routing Methods

Method Returns Description
process.OnInputEvent(eventId) ProcessEdgeBuilder Declares that the process accepts an external event with the given Id.
step.OnFunctionResult() ProcessEdgeBuilder Captures the implicit result event emitted when a step function completes.
step.OnEvent(eventId) ProcessEdgeBuilder Captures a named event explicitly emitted by the step via EmitEventAsync.
edge.SendEventTo(target) ProcessEdgeBuilder Routes the event to the specified ProcessFunctionTargetBuilder target. Returns the edge builder for chaining.
edge.StopProcess() void Terminates the process when this event fires.

Usage Examples

Process Entry Point

The OnInputEvent method on the process builder declares which external event starts the process. SendEventTo routes that event to the first step.

ProcessBuilder process = new("ChatBot");
var startStep = process.AddStepFromType<StartStep>();

// Route the external "StartProcess" event to the start step
process
    .OnInputEvent(ProcessEvents.StartProcess)
    .SendEventTo(new ProcessFunctionTargetBuilder(startStep));

Linear Step Chain

OnFunctionResult captures the implicit result of a step's function execution and routes it to the next step.

var stepA = process.AddStepFromType<StepA>();
var stepB = process.AddStepFromType<StepB>();
var stepC = process.AddStepFromType<StepC>();

stepA
    .OnFunctionResult()
    .SendEventTo(new ProcessFunctionTargetBuilder(stepB));

stepB
    .OnFunctionResult()
    .SendEventTo(new ProcessFunctionTargetBuilder(stepC));

stepC
    .OnFunctionResult()
    .StopProcess();

Routing Named Events

When a step emits named events via EmitEventAsync, use OnEvent(eventId) to capture them and route to different targets based on the event name.

var userInputStep = process.AddStepFromType<UserInputStep>();
var responseStep = process.AddStepFromType<ChatBotResponseStep>();

// Route user input to the response step with a specific parameter
userInputStep
    .OnEvent(CommonEvents.UserInputReceived)
    .SendEventTo(new ProcessFunctionTargetBuilder(
        responseStep, parameterName: "userMessage"));

// Route the exit event to stop the process
userInputStep
    .OnEvent(ChatBotEvents.Exit)
    .StopProcess();

// Route the response back to user input (creating a cycle)
responseStep
    .OnEvent(ChatBotEvents.AssistantResponseGenerated)
    .SendEventTo(new ProcessFunctionTargetBuilder(userInputStep));

Targeting Specific Functions and Parameters

When a step has multiple [KernelFunction] methods, specify the function name explicitly. When a function has multiple parameters, specify the parameter name.

var formStep = process.AddStepFromType<CompleteNewCustomerFormStep>();

// Target a specific function by name
process
    .OnInputEvent("StartProcess")
    .SendEventTo(new ProcessFunctionTargetBuilder(
        formStep,
        CompleteNewCustomerFormStep.ProcessStepFunctions.NewAccountWelcome));

// Target a specific function and parameter
userInputStep
    .OnEvent(CommonEvents.UserInputReceived)
    .SendEventTo(new ProcessFunctionTargetBuilder(
        formStep,
        CompleteNewCustomerFormStep.ProcessStepFunctions.NewAccountProcessUserInfo,
        "userMessage"));

Fan-Out: One Event to Multiple Targets

Chain multiple SendEventTo calls on the same edge builder to route one event to multiple targets simultaneously.

var managerAgent = process.AddStepFromType<ManagerAgentStep>();
var renderStep = process.AddStepFromType<RenderMessageStep>();

// Fan-out: user input goes to both the agent and the renderer
userInputStep
    .OnEvent(CommonEvents.UserInputReceived)
    .SendEventTo(new ProcessFunctionTargetBuilder(
        managerAgent,
        ManagerAgentStep.ProcessStepFunctions.InvokeAgent))
    .SendEventTo(new ProcessFunctionTargetBuilder(
        renderStep,
        RenderMessageStep.ProcessStepFunctions.RenderUserText,
        parameterName: "message"));

Error Handling Routes

Use OnFunctionError to route errors from a specific function to an error handler step.

agentStep
    .OnFunctionError()
    .SendEventTo(new ProcessFunctionTargetBuilder(
        renderStep,
        RenderMessageStep.ProcessStepFunctions.RenderError,
        "error"))
    .StopProcess();

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment