Agent Wranglers

Data shapes Recommended

Make data objects immutable

Make DTOs and value objects read-only. Create a new object for a change instead of editing one that others may hold.

How to do it

Use readonly classes or properties, frozen dataclasses or Readonly types. Add with methods that return a changed copy when needed.

Example

// Bad: anyone holding the order can change its total
class Order { total = 0; }

// Good: changes make a new object
class Order {
  constructor(readonly total: number) {}
  withTotal(total: number): Order { return new Order(total); }
}

How to check

The type checker rejects writes to fields. Examples are TypeScript readonly, PHP readonly, and Python @dataclass(frozen=True).

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers architecture playbook: https://agentwranglers.se/playbook/architecture/data-shapes/immutable-data.