···6969 "cache_control": {"type": "ephemeral"},
7070 }
7171 ],
7272- "messages": messages,
7272+ "messages": self._inject_cache_breakpoints(messages),
7373 }
74747575 if tools:
···9797 content=content,
9898 stop_reason=msg.stop_reason or "end_turn", # type: ignore TODO: fix this
9999 )
100100+101101+ @staticmethod
102102+ def _inject_cache_breakpoints(
103103+ messages: list[dict[str, Any]],
104104+ ) -> list[dict[str, Any]]:
105105+ """
106106+ a helper that adds cache_control breakpoints to the conversation so that
107107+ the conversation prefix is cached across successive calls. we place a single
108108+ breakpoint in th last message's content block, combined with the sys-prompt
109109+ and tool defs breakpoints. ensures that we stay in the 4-breakpoint limit
110110+ that ant requires
111111+ """
112112+ if not messages:
113113+ return messages
114114+115115+ # shallow-copy the list so we don't mutate the caller's conversation
116116+ messages = list(messages)
117117+ last_msg = dict(messages[-1])
118118+ content = last_msg["content"]
119119+120120+ if isinstance(content, str):
121121+ last_msg["content"] = [
122122+ {
123123+ "type": "text",
124124+ "text": content,
125125+ "cache_control": {"type": "ephemeral"},
126126+ }
127127+ ]
128128+ elif isinstance(content, list) and content:
129129+ content = [dict(b) for b in content]
130130+ content[-1] = dict(content[-1])
131131+ content[-1]["cache_control"] = {"type": "ephemeral"}
132132+ last_msg["content"] = content
133133+134134+ messages[-1] = last_msg
135135+ return messages
100136101137102138class OpenAICompatibleClient(AgentClient):
+21
src/agent/prompt.py
···208208"""
209209210210211211+CLICKHOUSE_SQL_TIPS = """
212212+# ClickHouse SQL Tips
213213+214214+- **DateTime filtering**: The `__timestamp` column is `DateTime64(3)`. Do NOT use raw ISO strings. Use `parseDateTimeBestEffort()`:
215215+ ```sql
216216+ WHERE __timestamp >= parseDateTimeBestEffort('2026-02-06 04:30:00')
217217+ ```
218218+ To compute a relative time in TypeScript, format it as `YYYY-MM-DD HH:MM:SS`:
219219+ ```typescript
220220+ const ts = new Date(Date.now() - 30 * 60 * 1000).toISOString().slice(0, 19).replace('T', ' ');
221221+ ```
222222+- **Array slicing**: ClickHouse does NOT support `array[1:5]` syntax. Use `arraySlice(array, offset, length)`:
223223+ ```sql
224224+ arraySlice(groupArray(DISTINCT UserId), 1, 5) as sample_accounts
225225+ ```
226226+- **Error handling**: When running multiple independent queries, use `Promise.allSettled()` instead of `Promise.all()` so one failure doesn't crash the rest. Check each result's `.status` field.
227227+"""
228228+229229+211230def build_system_prompt():
212231 """
213232 Here we put together the base system prompt for the agent. The system prompt does _not_ change based on inputs, so that proper caching across sessions can take place.
···226245# Osprey Documentation
227246228247{OSPREY_RULE_GUIDANCE}
248248+249249+{CLICKHOUSE_SQL_TIPS}
229250 """
230251231252 return system_prompt
+20
src/tools/deno/tools.ts
···99 query: (sql: string): Promise<unknown> => callTool("clickhouse.query", { sql }),
1010};
11111212+export const content = {
1313+ /** Find similar posts in the network using ClickHouse's ngramDistance function. Useful for detecting coordinated spam, copypasta, or templated abuse content. Returns posts ordered by similarity score. */
1414+ similarity: (text: string, threshold?: number, limit?: number): Promise<unknown> => callTool("content.similarity", { text, threshold, limit }),
1515+};
1616+1217export const domain = {
1318 /** Lookup A, AAAA, NS, MX, TXT, CNAME, and SOA for a given input domain */
1419 checkDomain: (domain: string): Promise<unknown> => callTool("domain.checkDomain", { domain }),
2020+};
2121+2222+export const ip = {
2323+ /** GeoIP and ASN lookup for an IP address. Returns geographic location (country, region, city, coordinates, timezone), network information (ISP, org, ASN), and flags for mobile, proxy, and hosting IPs. */
2424+ lookup: (ip: string): Promise<unknown> => callTool("ip.lookup", { ip }),
1525};
16261727export const osprey = {
···4151 /** Remove a moderation label from a subject (account or record) */
4252 removeLabel: (subject: string, label: string): Promise<unknown> => callTool("ozone.removeLabel", { subject, label }),
4353};
5454+5555+export const url = {
5656+ /** Follow a URL through its redirect chain (up to 10 hops), recording each hop's URL and HTTP status code. Flags known URL shorteners. Useful for investigating obfuscated or shortened links in spam/phishing content. */
5757+ expand: (url: string): Promise<unknown> => callTool("url.expand", { url }),
5858+};
5959+6060+export const whois = {
6161+ /** Look up WHOIS registration data for a domain. Returns registrar, creation/expiration dates, name servers, registrant info, and domain age in days. Domain age is a key T&S signal — newly registered domains are heavily used for spam and phishing. */
6262+ lookup: (domain: string): Promise<unknown> => callTool("whois.lookup", { domain }),
6363+};
-16
src/tools/executor.py
···302302{self._database_schema}
303303304304Use these exact column names when writing SQL queries. Do NOT guess column names.
305305-306306-## ClickHouse SQL Tips
307307-308308-- **DateTime filtering**: The `__timestamp` column is `DateTime64(3)`. Do NOT use raw ISO strings. Use `parseDateTimeBestEffort()`:
309309- ```sql
310310- WHERE __timestamp >= parseDateTimeBestEffort('2026-02-06 04:30:00')
311311- ```
312312- To compute a relative time in TypeScript, format it as `YYYY-MM-DD HH:MM:SS`:
313313- ```typescript
314314- const ts = new Date(Date.now() - 30 * 60 * 1000).toISOString().slice(0, 19).replace('T', ' ');
315315- ```
316316-- **Array slicing**: ClickHouse does NOT support `array[1:5]` syntax. Use `arraySlice(array, offset, length)`:
317317- ```sql
318318- arraySlice(groupArray(DISTINCT UserId), 1, 5) as sample_accounts
319319- ```
320320-- **Error handling**: When running multiple independent queries, use `Promise.allSettled()` instead of `Promise.all()` so one failure doesn't crash the rest. Check each result's `.status` field.
321305"""
322306323307 osprey_section = ""