Examples · agents · 40 of 339
11-timestamps
64-bit integers at the agent boundary.
tin run examples/agents/11-timestamps.tin// 64-bit integers at the agent boundary.
//
// JSON numbers are exact only to 2^53, so a nanosecond timestamp would lose digits on its way
// to a model and back. An i64 in a tool or a typed reply travels as a decimal string instead:
// the schema says {"type": "string", "pattern": "^-?[0-9]+$"}, and the runtime parses it back
// exactly, refusing anything that isn't a whole number in range.
//
// tin run examples/agents/11-timestamps.tin
// tin tools examples/agents/11-timestamps.tin # see the schema the model gets
/// Move a timestamp forward.
tool fn later(
/// Nanoseconds since the epoch
at: i64,
/// Nanoseconds to add
by: i64,
): i64 => at + by
type Event = {
/// Nanoseconds since the epoch
at: i64
name: string
}
agent Clock {
model: "mock"
tools: [later]
}
agent Logger { model: "mock" }
fn main() {
// 2^53 + 1: a float64 would round this to 9007199254740992
print(Clock("later \"9007199254740993\" \"2\""))
let e: Event = Logger("'1731660000123456789' 'boot'")
print("{e.name} at {e.at}, one tick later {e.at + 1}")
} mock: 9007199254740995
boot at 1731660000123456789, one tick later 1731660000123456790