Learn how to define contracts and requirements for AI agents
Contracts define the expected behavior of an AI agent through requirements. They help ensure that agents follow business rules and handle interactions appropriately. A contract is essentially a set of requirements for a specific scenario.
Requirements are the atomic units of contracts. Each requirement represents a specific condition or constraint that must be satisfied. They come in three types, each serving a distinct purpose in controlling and validating agent behavior:
Each requirement has several properties:
Level.MUST
: Critical requirements that must be met (default when level is not specified)Level.SHOULD
: Important but not critical requirements that represent best practicesPreconditions verify that necessary inputs or conditions are met before the agent proceeds. They serve two critical purposes:
Offline Verification: OPTIONAL to have Preconditions. They help validate if the agent received the correct inputs to act. If preconditions aren’t met (e.g., customer never provided an order number), the contract is invalidated since the agent didn’t have the necessary information to proceed.
Runtime Certification: REQUIRED to have Preconditions. They act as scenario detectors during runtime enforcement. When preconditions are met, we know we’re in a specific scenario and can apply the corresponding path and post conditions.
Example preconditions:
Pathconditions are the most flexible type of requirement, designed to validate the agent’s execution process. They can check:
Example pathconditions:
Postconditions verify the final output or result. They must specify what they’re checking using the on
field:
on="output"
: Checks the final output of the system (e.g., database entries, generated reports)on="conversation"
: Checks every agent response message in a conversation systemExamples with conditional requirements:
:::tip
The Postcondition
class can be extended to use custom logic to check the output. For example, a function that queries the database to confirm if a transasction is made.
:::
A contract combines these requirements to fully specify how an agent should handle a scenario:
When writing agent contracts, it’s crucial to follow several key principles that ensure they provide meaningful verification while remaining practical to implement and maintain:
Clearly define the scope of each condition
Ensure conditions are measurable and verifiable
Consider both functional and non-functional requirements
Account for edge cases and error conditions
Maintain consistency across related contracts
Balance precision with adaptability
Learn how to define contracts and requirements for AI agents
Contracts define the expected behavior of an AI agent through requirements. They help ensure that agents follow business rules and handle interactions appropriately. A contract is essentially a set of requirements for a specific scenario.
Requirements are the atomic units of contracts. Each requirement represents a specific condition or constraint that must be satisfied. They come in three types, each serving a distinct purpose in controlling and validating agent behavior:
Each requirement has several properties:
Level.MUST
: Critical requirements that must be met (default when level is not specified)Level.SHOULD
: Important but not critical requirements that represent best practicesPreconditions verify that necessary inputs or conditions are met before the agent proceeds. They serve two critical purposes:
Offline Verification: OPTIONAL to have Preconditions. They help validate if the agent received the correct inputs to act. If preconditions aren’t met (e.g., customer never provided an order number), the contract is invalidated since the agent didn’t have the necessary information to proceed.
Runtime Certification: REQUIRED to have Preconditions. They act as scenario detectors during runtime enforcement. When preconditions are met, we know we’re in a specific scenario and can apply the corresponding path and post conditions.
Example preconditions:
Pathconditions are the most flexible type of requirement, designed to validate the agent’s execution process. They can check:
Example pathconditions:
Postconditions verify the final output or result. They must specify what they’re checking using the on
field:
on="output"
: Checks the final output of the system (e.g., database entries, generated reports)on="conversation"
: Checks every agent response message in a conversation systemExamples with conditional requirements:
:::tip
The Postcondition
class can be extended to use custom logic to check the output. For example, a function that queries the database to confirm if a transasction is made.
:::
A contract combines these requirements to fully specify how an agent should handle a scenario:
When writing agent contracts, it’s crucial to follow several key principles that ensure they provide meaningful verification while remaining practical to implement and maintain:
Clearly define the scope of each condition
Ensure conditions are measurable and verifiable
Consider both functional and non-functional requirements
Account for edge cases and error conditions
Maintain consistency across related contracts
Balance precision with adaptability