agent-work-layer 0.1.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: agent-work-layer
3
- Version: 0.1.0
3
+ Version: 0.3.0
4
4
  Summary: Work Orders and Work Reports for AI agents: Pydantic models and the spec's validation rules.
5
5
  Project-URL: Homepage, https://github.com/probita-ai/agent-work-layer/tree/main/python#readme
6
6
  Project-URL: Repository, https://github.com/probita-ai/agent-work-layer
@@ -68,6 +68,9 @@ if has_invalid(findings):
68
68
  | `validate_order(order)` | O1–O4 |
69
69
  | `validate_report(report, order)` | R1–R12 |
70
70
  | `validate_child_order(child, parent)` | C1–C3: a sub-order may only narrow its parent's budget, tools and deadline |
71
+ | `validate_own_cost(report, order, sub_orders)` | R13: an order's own cost, plus what its sub-orders hold, stays within its budget |
72
+ | `held_by_sub_orders(sub_orders)` | The budget an order's sub-orders hold |
73
+ | `validate_child_budgets(child, parent, siblings)` | C4: a parent's sub-orders together stay within its budget. `siblings` are `{"order": ..., "state": ...}` |
71
74
  | `is_work_order(value)`, `is_work_report(value)` | Structure only (O1, R1) |
72
75
  | `tool_allowed(tool, patterns)`, `pattern_covered(child, parents)` | Tool pattern matching (`server/tool`, `server/*`, `*`) |
73
76
 
@@ -47,6 +47,9 @@ if has_invalid(findings):
47
47
  | `validate_order(order)` | O1–O4 |
48
48
  | `validate_report(report, order)` | R1–R12 |
49
49
  | `validate_child_order(child, parent)` | C1–C3: a sub-order may only narrow its parent's budget, tools and deadline |
50
+ | `validate_own_cost(report, order, sub_orders)` | R13: an order's own cost, plus what its sub-orders hold, stays within its budget |
51
+ | `held_by_sub_orders(sub_orders)` | The budget an order's sub-orders hold |
52
+ | `validate_child_budgets(child, parent, siblings)` | C4: a parent's sub-orders together stay within its budget. `siblings` are `{"order": ..., "state": ...}` |
50
53
  | `is_work_order(value)`, `is_work_report(value)` | Structure only (O1, R1) |
51
54
  | `tool_allowed(tool, patterns)`, `pattern_covered(child, parents)` | Tool pattern matching (`server/tool`, `server/*`, `*`) |
52
55
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "agent-work-layer"
7
- version = "0.1.0"
7
+ version = "0.3.0"
8
8
  description = "Work Orders and Work Reports for AI agents: Pydantic models and the spec's validation rules."
9
9
  readme = "README.md"
10
10
  license = "Apache-2.0"
@@ -23,24 +23,28 @@ from .validate import (
23
23
  UNITS,
24
24
  Finding,
25
25
  has_invalid,
26
+ held_by_sub_orders,
26
27
  is_work_order,
27
28
  is_work_report,
28
29
  pattern_covered,
29
30
  tool_allowed,
31
+ validate_child_budgets,
30
32
  validate_child_order,
31
33
  validate_order,
34
+ validate_own_cost,
32
35
  validate_report,
33
36
  work_order_schema,
34
37
  work_report_schema,
35
38
  )
36
39
 
37
- __version__ = "0.1.0"
40
+ __version__ = "0.3.0"
38
41
 
39
42
  __all__ = [
40
43
  "Amounts", "Artifact", "Attempt", "ContextRef", "Criterion", "Decision", "Evidence", "Handoff",
41
44
  "WorkOrder", "WorkReport", "WorkResult",
42
45
  "ORDER_SPEC", "ORDER_SPECS", "REPORT_SPEC", "REPORT_SPECS", "UNITS", "Finding",
43
- "has_invalid", "is_work_order", "is_work_report", "pattern_covered", "tool_allowed",
44
- "validate_child_order", "validate_order", "validate_report", "work_order_schema", "work_report_schema",
46
+ "has_invalid", "held_by_sub_orders", "is_work_order", "is_work_report", "pattern_covered", "tool_allowed",
47
+ "validate_child_budgets", "validate_child_order", "validate_order", "validate_own_cost", "validate_report",
48
+ "work_order_schema", "work_report_schema",
45
49
  "__version__",
46
50
  ]
@@ -100,7 +100,7 @@ class Handoff(_Part):
100
100
 
101
101
 
102
102
  class WorkOrder(_Document):
103
- spec: Literal["awl/work-order@0.1", "awl/work-order@0.2"] = ORDER_SPEC
103
+ spec: Literal["awl/work-order@0.1", "awl/work-order@0.2", "awl/work-order@0.3"] = ORDER_SPEC
104
104
  id: Annotated[str, Field(min_length=1, max_length=128)]
105
105
  created_at: Timestamp
106
106
  from_: AgentRef = Field(alias="from")
@@ -117,6 +117,8 @@ class WorkOrder(_Document):
117
117
  handoff: Optional[Handoff] = None
118
118
  output_schema: Optional[Dict[str, Any]] = None
119
119
  parent_id: Optional[Text] = None
120
+ #: The order this one picks up from, after it stopped (SPEC.md §4.5). Not a sub-order.
121
+ continues: Optional[Text] = None
120
122
  metadata: Optional[Dict[str, Any]] = None
121
123
 
122
124
  @model_validator(mode="after")
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://awl.dev/schemas/work-order-0.2.json",
4
- "title": "AWL Work Order v0.2",
3
+ "$id": "https://awl.dev/schemas/work-order-0.3.json",
4
+ "title": "AWL Work Order v0.3",
5
5
  "type": "object",
6
6
  "required": ["spec", "id", "created_at", "from", "to", "goal", "criteria", "budget", "deadline", "tools"],
7
7
  "properties": {
8
- "spec": { "enum": ["awl/work-order@0.1", "awl/work-order@0.2"] },
8
+ "spec": { "enum": ["awl/work-order@0.1", "awl/work-order@0.2", "awl/work-order@0.3"] },
9
9
  "id": { "type": "string", "minLength": 1, "maxLength": 128 },
10
10
  "created_at": { "type": "string", "format": "date-time" },
11
11
  "from": { "$ref": "#/$defs/agentRef" },
@@ -41,6 +41,7 @@
41
41
  "handoff": { "$ref": "#/$defs/handoff" },
42
42
  "output_schema": { "type": "object" },
43
43
  "parent_id": { "type": "string", "minLength": 1 },
44
+ "continues": { "type": "string", "minLength": 1 },
44
45
  "metadata": { "type": "object" }
45
46
  },
46
47
  "patternProperties": { "^x-": {} },
@@ -18,10 +18,10 @@ from jsonschema import Draft202012Validator, FormatChecker, ValidationError
18
18
  from jsonschema.exceptions import SchemaError
19
19
  from jsonschema.validators import extend
20
20
 
21
- ORDER_SPEC = "awl/work-order@0.2"
21
+ ORDER_SPEC = "awl/work-order@0.3"
22
22
  REPORT_SPEC = "awl/work-report@0.2"
23
23
  #: Every spec version this package reads (SPEC.md §11).
24
- ORDER_SPECS = ("awl/work-order@0.1", ORDER_SPEC)
24
+ ORDER_SPECS = ("awl/work-order@0.1", "awl/work-order@0.2", ORDER_SPEC)
25
25
  REPORT_SPECS = ("awl/work-report@0.1", REPORT_SPEC)
26
26
  #: Budget and cost units (SPEC.md §4.2).
27
27
  UNITS = ("usd", "tokens", "tool_calls", "seconds")
@@ -365,6 +365,63 @@ def validate_child_order(child: Any, parent: Any) -> List[Finding]:
365
365
  return out
366
366
 
367
367
 
368
+ #: Units whose sub-order budgets add up (C4, R13). ``seconds`` is wall-clock time, and sub-orders run side by side.
369
+ _SHARED_UNITS = ("usd", "tokens", "tool_calls")
370
+ #: Absorbs floating-point error in sums of money, so 0.1 + 0.2 fits a budget of 0.3.
371
+ _EPSILON = 1e-9
372
+
373
+
374
+ def held_by_sub_orders(sub_orders: Sequence[Mapping[str, Any]]) -> Dict[str, Any]:
375
+ """The budget an order's sub-orders hold (§8): their budgets added up, leaving out declined ones.
376
+
377
+ ``sub_orders`` are ``{"order": ..., "state": ...}``, as the desk stores them.
378
+ """
379
+ held: Dict[str, Any] = {}
380
+ for s in sub_orders:
381
+ if s["state"] == "declined":
382
+ continue
383
+ budget = _plain(s["order"])["budget"]
384
+ for unit in _SHARED_UNITS:
385
+ if unit in budget:
386
+ held[unit] = round(held.get(unit, 0) + budget[unit], 9)
387
+ return held
388
+
389
+
390
+ def validate_child_budgets(child: Any, parent: Any, siblings: Sequence[Mapping[str, Any]]) -> List[Finding]:
391
+ """Runs sub-order check C4: a parent's sub-orders, this one included, stay within its budget together.
392
+
393
+ ``siblings`` are the parent's existing sub-orders as ``{"order": ..., "state": ...}``; declined ones are not counted.
394
+ """
395
+ held = held_by_sub_orders([*siblings, {"order": child, "state": "offered"}])
396
+ parent = _plain(parent)
397
+ out: List[Finding] = []
398
+ for unit in _SHARED_UNITS:
399
+ limit = parent["budget"].get(unit)
400
+ total = held.get(unit, 0)
401
+ if limit is not None and total - limit > _EPSILON:
402
+ out.append(Finding("C4", "invalid", f"/budget/{unit}", f"sub-orders would total {_num(total)} {unit}, parent's budget is {_num(limit)}"))
403
+ return out
404
+
405
+
406
+ def validate_own_cost(report: Any, order: Any, sub_orders: Sequence[Mapping[str, Any]]) -> List[Finding]:
407
+ """Runs report check R13: the order's own cost, plus what its sub-orders hold, stays within its budget.
408
+
409
+ Units already over budget on their own are left to R7, and units missing from the cost to R6.
410
+ """
411
+ report, order = _plain(report), _plain(order)
412
+ held = held_by_sub_orders(sub_orders)
413
+ out: List[Finding] = []
414
+ for unit in _SHARED_UNITS:
415
+ limit = order["budget"].get(unit)
416
+ spent = report["cost"].get(unit)
417
+ hold = held.get(unit, 0)
418
+ if limit is None or spent is None or spent > limit or not hold:
419
+ continue
420
+ if spent + hold - limit > _EPSILON:
421
+ out.append(Finding("R13", "limit", f"/cost/{unit}", f"spent {_num(spent)} {unit} while sub-orders hold {_num(hold)}; budget is {_num(limit)}"))
422
+ return out
423
+
424
+
368
425
  def has_invalid(findings: Sequence[Finding]) -> bool:
369
426
  """True when any finding rejects the document."""
370
427
  return any(f.kind == "invalid" for f in findings)