Termination

Termination conditions in AgentOpera provide flexible mechanisms to control when a conversation should end, whether it's because a goal has been reached, a certain limit has been hit, or a specific message pattern has been detected.

Overview

A termination condition in AgentOpera is a stateful callable object that:

  1. Takes a sequence of messages as input

  2. Determines whether the conversation should be terminated

Built-in Termination Conditions

AgentOpera provides several built-in termination conditions to cover common scenarios:

MaxMessageTermination

Terminates the conversation after a maximum number of messages have been exchanged:

from agentopera.chatflow.conditions import MaxMessageTermination

# Terminate after 10 messages
termination = MaxMessageTermination(max_messages=10, include_agent_event=False)

The include_agent_event parameter specifies whether AgentEvent objects are included in the message count.

TextMentionTermination

Terminates the conversation if specific text is mentioned in a message:

TimeoutTermination

Terminates the conversation after a specified duration:

TextMessageTermination

Terminates the conversation when a TextMessage is received:

Combining Termination Conditions

AgentOpera’s termination system allows you to combine conditions using logical operators:

OR Combination

Terminate when ANY of the conditions are met:

AND Combination

Terminate when ALL of the conditions are met:

Complete Example

Here's a complete example demonstrating how to use termination conditions with an agent team:

Last updated