agent-work-layer 0.5.0__tar.gz → 0.6.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.5.0
3
+ Version: 0.6.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
@@ -66,7 +66,8 @@ if has_invalid(findings):
66
66
  | Function | Rules |
67
67
  |---|---|
68
68
  | `validate_order(order)` | O1–O5 |
69
- | `validate_report(report, order)` | R1–R12, R14–R16 |
69
+ | `validate_report(report, order, usage=None)` | R1–R12, R14–R16, and R17–R19 when `usage` (what the order's gateway measured) is given |
70
+ | `validate_usage(report, usage)` | R17–R19 only: the report agrees with the gateway's measurement, `{"tool_calls", "seconds"?, "tools_used", "refs"}` |
70
71
  | `validate_child_order(child, parent)` | C1–C3 and C5: a sub-order may only narrow its parent's budget, tools and deadline, and may not allow a tool its parent stages |
71
72
  | `validate_own_cost(report, order, sub_orders)` | R13: an order's own cost, plus what its sub-orders hold, stays within its budget |
72
73
  | `held_by_sub_orders(sub_orders)` | The budget an order's sub-orders hold |
@@ -45,7 +45,8 @@ if has_invalid(findings):
45
45
  | Function | Rules |
46
46
  |---|---|
47
47
  | `validate_order(order)` | O1–O5 |
48
- | `validate_report(report, order)` | R1–R12, R14–R16 |
48
+ | `validate_report(report, order, usage=None)` | R1–R12, R14–R16, and R17–R19 when `usage` (what the order's gateway measured) is given |
49
+ | `validate_usage(report, usage)` | R17–R19 only: the report agrees with the gateway's measurement, `{"tool_calls", "seconds"?, "tools_used", "refs"}` |
49
50
  | `validate_child_order(child, parent)` | C1–C3 and C5: a sub-order may only narrow its parent's budget, tools and deadline, and may not allow a tool its parent stages |
50
51
  | `validate_own_cost(report, order, sub_orders)` | R13: an order's own cost, plus what its sub-orders hold, stays within its budget |
51
52
  | `held_by_sub_orders(sub_orders)` | The budget an order's sub-orders hold |
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "agent-work-layer"
7
- version = "0.5.0"
7
+ version = "0.6.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"
@@ -37,18 +37,19 @@ from .validate import (
37
37
  validate_order,
38
38
  validate_own_cost,
39
39
  validate_report,
40
+ validate_usage,
40
41
  work_order_schema,
41
42
  work_report_schema,
42
43
  )
43
44
 
44
- __version__ = "0.5.0"
45
+ __version__ = "0.6.0"
45
46
 
46
47
  __all__ = [
47
48
  "Amounts", "Artifact", "Attempt", "ContextRef", "Criterion", "Decision", "Effect", "Evidence", "Handoff",
48
49
  "WorkOrder", "WorkReport", "WorkResult",
49
50
  "ORDER_SPEC", "ORDER_SPECS", "REPORT_SPEC", "REPORT_SPECS", "UNITS", "Finding",
50
51
  "effect_references", "order_spec_for", "report_spec_for", "has_invalid", "held_by_sub_orders", "is_work_order", "is_work_report", "pattern_covered", "tool_allowed",
51
- "validate_child_budgets", "validate_child_order", "validate_order", "validate_own_cost", "validate_report",
52
+ "validate_child_budgets", "validate_child_order", "validate_order", "validate_own_cost", "validate_report", "validate_usage",
52
53
  "work_order_schema", "work_report_schema",
53
54
  "__version__",
54
55
  ]
@@ -355,8 +355,9 @@ _MISSING = object()
355
355
  _CALL_NUMBER = re.compile(r"^[1-9][0-9]*\Z", re.ASCII)
356
356
 
357
357
 
358
- def validate_report(report: Any, order: Any) -> List[Finding]:
359
- """Runs report checks R1–R12 and R14–R16 against the order it answers. The order is assumed valid."""
358
+ def validate_report(report: Any, order: Any, usage: Optional[Mapping[str, Any]] = None) -> List[Finding]:
359
+ """Runs report checks R1–R12 and R14–R16 against the order it answers, and R17–R19 against what
360
+ the order's gateway measured when ``usage`` is given. The order is assumed valid."""
360
361
  report, order = _plain(report), _plain(order)
361
362
  shape = _schema_findings("R1", _report_shape.iter_errors(report))
362
363
  if shape:
@@ -426,6 +427,34 @@ def validate_report(report: Any, order: Any) -> List[Finding]:
426
427
  elif r["pointer"] != "" and not r["pointer"].startswith("/"):
427
428
  add("R16", "invalid", path, f'"{r["pointer"]}" is not a JSON Pointer')
428
429
  refs.add(e["ref"])
430
+ if usage is not None:
431
+ out.extend(validate_usage(report, usage))
432
+ return out
433
+
434
+
435
+ def validate_usage(report: Any, usage: Mapping[str, Any]) -> List[Finding]:
436
+ """Runs report checks R17–R19 (§7.3): the report agrees with what the order's gateway measured.
437
+
438
+ ``usage`` is ``{tool_calls, seconds?, tools_used, refs}``. A report may claim more than the
439
+ gateway saw, never less.
440
+ """
441
+ report = _plain(report)
442
+ out: List[Finding] = []
443
+ logged = set(usage["refs"])
444
+ for i, e in enumerate(report["evidence"]):
445
+ if e["type"] == "tool_call" and "ref" in e and e["ref"] not in logged:
446
+ out.append(Finding("R17", "invalid", f"/evidence/{i}/ref", f'"{e["ref"]}" is not a call the gateway logged'))
447
+ calls = report["cost"].get("tool_calls")
448
+ if usage["tool_calls"] > 0 and (calls is None or calls < usage["tool_calls"]):
449
+ reported = "no" if calls is None else _num(calls)
450
+ out.append(Finding("R18", "invalid", "/cost/tool_calls", f'reports {reported} tool calls; the gateway counted {usage["tool_calls"]}'))
451
+ seconds = report["cost"].get("seconds")
452
+ if usage.get("seconds") is not None and seconds is not None and seconds < usage["seconds"]:
453
+ out.append(Finding("R18", "invalid", "/cost/seconds", f'reports {_num(seconds)} seconds; the gateway measured at least {usage["seconds"]}'))
454
+ used = set(report["tools_used"])
455
+ for tool in dict.fromkeys(usage["tools_used"]):
456
+ if tool not in used:
457
+ out.append(Finding("R19", "invalid", "/tools_used", f'the gateway logged calls to "{tool}"'))
429
458
  return out
430
459
 
431
460