Using agenticspec · 3 of 4
Queries
Find the places in your sessions where something happened, with the sq query language.
Queries
sq is a small query language over your sessions. A query finds the places in sessions where something happened: a call a hook refused, an edit followed by a test run, a long wait on you.
$ agenticspec query --text '?- exposure{kind: K, channel: "ToolInput", verdict: "Unk"}.'
This lists the kinds of unconfirmed secrets and personal data that appeared in tool arguments in
the last 72 hours. query prints a JSON report with one row per answer and session.
Run a query
| form | what runs |
|---|---|
agenticspec query file.sq | the rules, queries and checks in the file |
agenticspec query --text '...' | sq given inline |
agenticspec query file.sq --text '...' | both, the text appended to the file |
agenticspec query file.sq --transcript <session>.jsonl | one transcript file, read directly, without the store |
More columns: swipe horizontally, or focus the table and use the arrow keys.
Without --transcript, a query runs over every session of the window. --since-hours and --root
choose the window.
Rules and queries
A rule gives a name to a combination of facts. A query, starting with ?-, prints every set of
values that makes it true.
refused(C, T, R) :- call{node: C, id: I, tool: T},
decided{call: I, decision: "Refuse", reason: R}.
?- refused(C, T, R).
This prints each refused tool call, its tool and the reason.
- Names starting with an upper-case letter are variables.
_matches anything. rel{field: Value}matches facts of a relation by field name. Fields you leave out match anything."text"is a literal.~"^(Edit|Execute)$"matches a regular expression.!p(X)holds whenp(X)has no answer.- Comparisons:
=,!=,<,<=,>,>=. - Durations are written
250ms,30s,5mor1hand compare as milliseconds. //,#and%start a comment.
Counting
count, sum, min and max aggregate over the answers inside the braces:
calls(A, N) :- agent{id: A, role: "Main"}, N = count{ call{agent: A, node: C} }, N >= 50.
?- calls(A, N).
count counts distinct answers. Bind a field that differs per fact, here node: C, or every call
counts once.
Order in time: seq
seq(A, B, ...) holds when the steps happen in this order. Each one is the nearest later step that
matches.
edit_then_run(E, X) :-
seq(E, X, scope: agent, within: 5m),
call{node: E, category: "Edit"}, call{node: X, category: "Execute"}.
?- edit_then_run(E, X).
| option | effect |
|---|---|
scope: agent | the steps belong to the same agent |
scope: session | the steps may belong to different agents of the session |
within: 10m | the whole sequence lies within this time |
gap: 3 | at most this many other steps between two matched steps |
pick: all | every later match, not only the nearest |
More columns: swipe horizontally, or focus the table and use the arrow keys.
Checks
A check turns a rule into a pass or fail result per session:
check refused-then-retried {
about "a call a hook refused was asked for again unchanged"
severity medium
expect none
find retried
}
expect none means the rule should have no answers. expect some means it should have at least
one. Each session gets one verdict per check:
| verdict | meaning |
|---|---|
Ok | the expectation holds |
Gap | it does not |
Unk | it depends on facts the transcript does not record for certain |
More columns: swipe horizontally, or focus the table and use the arrow keys.
The report counts the verdicts of each check under ok, gap and unk.
The checks that ship with agenticspec are in
queries/session.sq.
sync evaluates them for every session, and the dashboard shows the results.
| check | finds |
|---|---|
cache-bust-after-idle | a turn after an idle gap over 5 minutes that wrote the whole context again |
refused-then-retried | a call a hook refused that the agent asked for again unchanged |
fanout-unread | a sub-agent of a fan-out of three or more that ended after the parent's last turn, so its result was not read |
human-correction | a correction from you within 2 minutes of an edit or a command |
waiting-on-human | the main agent waiting more than 30 minutes for you |
More columns: swipe horizontally, or focus the table and use the arrow keys.
Definite and possible answers
Some facts are not certain: an author read from the opening words of a prompt, a decision the
transcript does not record, a sub-agent link that had to be inferred. An answer that rests on such a
fact is marked possible, and unknown lists the facts it rests on. Every other answer is
definite.
Rows of the building blocks
queries/blocks.sq lifts
a session into rows of the building blocks: the tasks it was given, the runs that
worked them, their steps, the questions asked, the messages sent and received, and the harness
sessions, turns and tool calls of its agents.
$ agenticspec query queries/blocks.sq --transcript <session>.jsonl
$ agenticspec blocks lift <session>.jsonl
query shows the answers of its rules. blocks lift writes one row per answer, checked against
the blocks, in the form of a scenario's given (see Scenarios).
| rule | block entity | from |
|---|---|---|
block_input | (the inputs of a draft scenario) | a prompt of the main agent by Human, Delegate or Peer; a Harness or Hook prompt is no input |
block_task | agentic. | an input classed Task |
block_run | agentic., with its agentic. | the main agent working a task from its prompt on; a sub-agent working the task of the run whose call spawned it |
block_step | agentic. | each model turn and tool call of a run, in order; kind Agent, Child (a spawn), Person (Ask) or Program |
block_question | agentic. | an Ask call, or an input classed Question |
block_message | agentic. | a Send call, or an input by a delegate or another session |
block_received | Message. | the first model turn of the turn an input started |
block_session | agentic. | each agent of role Main or Sub, from its first node; a sub-agent names its parent's session |
block_turn | agentic. | each model turn of such an agent, with its usage and context size |
block_call | agentic. | each tool call of such an agent: Denied when refused, Completed or Failed by its result, Requested when neither a decision nor a result is recorded |
More columns: swipe horizontally, or focus the table and use the arrow keys.
Every row names the node it was lifted from in evidence. The session, turn and call rows carry
the identifiers the other rows name: a run's and a step's harness_session_id, a sent message's
sent_by_call and a read message's received_in_turn each name a written row. A side call has no
session, so no session, turn or call row is written for it. A field the session does not record,
such as a question's options, the channel of a message, a session's harness, principal and limits,
a turn's inference or a call's tool, is listed in not_recorded, never guessed. No relation records a claim on a pool, so agentic.resource.Claim is reported in
not_observable and no row of it is written. Identifiers are UUIDs derived from the session's
nodes and agents, so two lifts of one session give the same rows.
blocks lift prints JSON:
| field | what |
|---|---|
session_id | the session |
given | { rows: [..., each row { entity, id, state, fields, not_ |
entities | the number of rows per entity |
not_observable | the entities the session cannot show |
More columns: swipe horizontally, or focus the table and use the arrow keys.
Relations
Every step of a session is a node, written <session>#<number>.
| relation | fields |
|---|---|
session | id, project, harness, opened_ |
agent | id, session, parent, role, depth, spawned_ |
cmd | node, session, agent, seq, at, actor, kind, outcome: every step |
prompt | node, agent, author, attribution, class, bytes, digest, mid_ |
call | node, id, agent, tool, category, bytes, digest, cwd, background |
| decided | node, call, decision, decider, reason |
completed | node, call, ok, bytes, digest, dur |
turn | node, agent, model, ctx, uncached, cache_ |
turn_end | node, agent |
compacted | node, agent, before |
exposure | node, id, agent, channel, class, kind, alias, verdict, call |
refused_cmd | node, error: a step agenticspec could not replay |
at | node, t: the time of a node |
next | a, b: b is the next step of the same agent |
turn_of | node, prompt: the step belongs to the turn this prompt started |
interval | agent, state, on, from, to, dur, open: when an agent was Idle or Working, and what it waited on |
bust | node, agent, cause, written: a cache bust, see KPIs |
spawned | call, child: the call started this sub-agent |
More columns: swipe horizontally, or focus the table and use the arrow keys.
Values you will match on:
| field | values |
|---|---|
call.category | Read, Search, Edit, Execute, Network, Spawn, Message, Plan, Other |
prompt.class | Task, Correction, Approval, Question, Continue, Unknown |
prompt.author | Human, Delegate, Peer, Parent, Harness, Hook |
decided.decision | Accept, Refuse |
agent.role | Main, Sub, Side (a model call of the tool outside every conversation, such as a title) |
More columns: swipe horizontally, or focus the table and use the arrow keys.
bytes and digest stand for content: its length and its SHA-256. The text itself is not stored,
so a query never sees it.
Relations of an architecture
The same language selects in an architecture document, over the relations part, setting,
link and marker. agenticstudio uses them in the selectors of its patches; their fields are on
the agenticstudio page.