Skip to content

ToolCallTerminationCondition

NexusLabs.Needlr.AgentFramework.Workflows

NexusLabs.Needlr.AgentFramework.Workflows

ToolCallTerminationCondition Class

Terminates a workflow when an agent calls a specific tool/function during its turn. Unlike KeywordTerminationCondition which matches response text, this condition matches on structured tool call data — eliminating false positives from keywords appearing in natural language.

public sealed class ToolCallTerminationCondition : NexusLabs.Needlr.AgentFramework.IWorkflowTerminationCondition

Inheritance System.Object 🡒 ToolCallTerminationCondition

Implements NexusLabs.Needlr.AgentFramework.IWorkflowTerminationCondition

Example

// Declare on the reviewer agent class:
[AgentGroupChatMember("article-writing")]
[AgentTerminationCondition(typeof(ToolCallTerminationCondition), "ApproveArticle", "ReviewerAgent")]
public sealed class ReviewerAgent;

// The reviewer's instructions tell it to call ApproveArticle() when satisfied:
// "If no Critical or Major issues remain, call the ApproveArticle tool."

Remarks

This condition inspects NexusLabs.Needlr.AgentFramework.TerminationContext.ToolCallNames which is populated from FunctionCallContent entries in the agent's response message. The match is exact and case-sensitive on the tool name.

Designed for scenarios where an agent should signal approval or completion via a dedicated tool call rather than embedding a keyword in free text. For example, a reviewer agent calls ApproveArticle() instead of writing "APPROVED" — which avoids the problem of the LLM accidentally including the keyword in rejection text.

Constructors

ToolCallTerminationCondition(string) Constructor

Initializes a new instance that fires when \<em>any\</em> agent calls the specified tool.

public ToolCallTerminationCondition(string toolName);

Parameters

toolName System.String

The exact tool/function name to match (case-sensitive).

ToolCallTerminationCondition(string, string) Constructor

Initializes a new instance that fires when a specific agent calls the specified tool.

public ToolCallTerminationCondition(string toolName, string? agentId);

Parameters

toolName System.String

The exact tool/function name to match (case-sensitive).

agentId System.String

The agent name or executor ID to restrict the match to, or null to match any agent. Supports MAF's GUID-suffixed executor IDs via prefix matching.

Methods

ToolCallTerminationCondition.ShouldTerminate(TerminationContext) Method

Determines whether the workflow should terminate after the given agent response.

public bool ShouldTerminate(NexusLabs.Needlr.AgentFramework.TerminationContext context);

Parameters

context NexusLabs.Needlr.AgentFramework.TerminationContext

Context for the completed agent turn.

Implements ShouldTerminate(TerminationContext)

Returns

System.Boolean
true to stop the workflow; false to continue.