Repository navigation
Expand file tree
/
Copy pathtool_runtime.py
More file actions
77 lines (66 loc) · 2.05 KB
/
Copy pathtool_runtime.py
File metadata and controls
77 lines (66 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""Gavio Tool Runtime - validate tool results before model context reuse.
pip install -r requirements.txt
python tool_runtime.py
"""
import asyncio
from gavio import Gateway, ToolRuntimeError
from gavio.interceptors.tool_runtime import ToolRuntimeInterceptor, analyze_tool_runtime
fresh_conflict_tools = {
"now": "2026-07-12T12:00:30Z",
"conflict_keys": ["delivery_date"],
"calls": [
{
"id": "ship-a",
"name": "shipping",
"source": "carrier-a",
"created_at": "2026-07-12T12:00:00Z",
"confidence": 0.8,
"result": {"delivery_date": "Monday"},
},
{
"id": "ship-b",
"name": "shipping",
"source": "carrier-b",
"created_at": "2026-07-12T12:00:00Z",
"confidence": 0.7,
"result": {"delivery_date": "Wednesday"},
},
],
}
stale_tools = {
"now": "2026-07-12T12:03:00Z",
"max_age_seconds": 60,
"calls": [
{
"id": "price-1",
"name": "price",
"source": "pricing-cache",
"created_at": "2026-07-12T12:00:00Z",
"result": {"sku": "SKU-3", "price": 9.99},
"output_schema": {
"required": ["sku", "price"],
"properties": {"sku": "string", "price": "number"},
},
}
],
}
async def main() -> None:
decision = analyze_tool_runtime(fresh_conflict_tools)
print("conflicts :", decision["conflicts"])
print("confidence:", decision["confidence"])
print("sources :", [p["source"] for p in decision["provenance"]])
gw = (
Gateway.builder()
.dev_mode(True)
.use(ToolRuntimeInterceptor(on_failure="error"))
.build()
)
try:
await gw.complete(
messages=[{"role": "user", "content": "reuse the cached price quote"}],
metadata={"tools": stale_tools},
)
except ToolRuntimeError as exc:
print("blocked :", str(exc))
if __name__ == "__main__":
asyncio.run(main())