Context
Operations that must succeed completely or not at all.
Problem
Partial failures can leave data in inconsistent states.
Solution
Define transactional boundaries:
- Atomic: All steps succeed or all roll back
- Consistent: Data integrity maintained
- Isolated: Intermediate states not visible
- Durable: Committed changes persist
- Atomic: All steps succeed or all roll back
- Consistent: Data integrity maintained
- Isolated: Intermediate states not visible
- Durable: Committed changes persist
Examples
Python
@tool
def transfer_funds(
from_account: str,
to_account: str,
amount: float
) -> TransferResult:
"""Transfer funds atomically.
Either both accounts are updated or neither is.
No partial transfers possible.
"""
with transaction():
debit(from_account, amount)
credit(to_account, amount)
return TransferResult(success=True) Considerations
- Keep transactions as short as possible
- Document what's included in the transaction
- Use compensation for cross-system transactions