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:
Takes a sequence of messages as input
Determines whether the conversation should be terminated
Built-in Termination Conditions
AgentOpera provides several built-in termination conditions to cover common scenarios:
MaxMessageTermination
MaxMessageTerminationTerminates 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
TextMentionTerminationTerminates the conversation if specific text is mentioned in a message:
TimeoutTermination
TimeoutTerminationTerminates the conversation after a specified duration:
TextMessageTermination
TextMessageTerminationTerminates 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