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
-- test_agent_log_meta.lua — correlation ids, from the environment to both
-- places a run leaves a trace.
--
-- There is no option to pass them. `agent.run` reads AGENT_BLOCK_TRACE_ID /
-- _RUN_ID / _AGENT_ID / _AGENT_NAME off the environment, and they land in two
-- places from there:
--
-- * every model call is an `ab.obs` http_request / http_response line
-- carrying the four as `trace_id=` / `run_id=` / `agent_id=` /
-- `agent_name=` (RUST_LOG=info makes them visible);
-- * the run's seed event carries the same four as `meta` labels beside
-- `label = "prompt"`, so the session log is selected by the id the log
-- lines are grepped by:
--
-- session:query(
-- "SELECT * FROM events WHERE json_extract(meta, '$.run_id') = ?",
-- { std.env.get("AGENT_BLOCK_RUN_ID") })
--
-- Only the variables that are set become labels. `agent_id` is the one that
-- can differ: with AGENT_BLOCK_AGENT_ID unset the obs lines still carry a
-- per-process id the Rust side makes up, and the seed event carries no
-- `agent_id` at all — set it and both sides say the same thing.
--
-- Requires ANTHROPIC_API_KEY.
-- Suggested run:
-- RUST_LOG=info \
-- AGENT_BLOCK_TRACE_ID=trace-xyz \
-- AGENT_BLOCK_AGENT_ID=agent-42 \
-- AGENT_BLOCK_AGENT_NAME=planner \
-- AGENT_BLOCK_RUN_ID=run-001 \
-- agent-block -s examples/test_agent_log_meta.lua
local agent = require
tool.
local result = agent.
if not result.
log.