withConstraint
Adds a behavioral constraint or guideline for the agent. Constraints define rules that govern the agent’s behavior with different levels of severity. They are organized by type in the generated prompt to communicate priority to the model:must: Absolute requirements that cannot be violatedmust_not: Absolute prohibitionsshould: Strong recommendations to follow when possibleshould_not: Strong recommendations to avoid
The constraint severity level:
"must", "must_not", "should", or "should_not"The constraint rule text. Should be clear, specific, and actionable. Use imperative mood (“Do X”, “Never Y”).
The builder instance for method chaining
Example
withConstraints
Adds one or more behavioral constraints with the same type. This overloaded method accepts either a single constraint rule or an array of rules, making it more convenient to add multiple constraints of the same type.The constraint severity level
Single rule string or array of rule strings
The builder instance for method chaining
Examples
- Single Constraint
- Multiple Constraints
withConstraintIf
Conditionally adds a behavioral constraint based on a condition. This method only adds the constraint if the condition evaluates to true, making it easier to build prompts with conditional logic without breaking the fluent chain.Boolean condition that determines if the constraint is added
The constraint severity level
The constraint rule text
The builder instance for method chaining