Briefing toolkit for Crude Code inner agents — widget builders, SQL helpers, and worked example templates.
Project description
crude-analyst — briefing toolkit for the data analyst agent
A composer for oil & gas briefings. Read this whole file before composing any briefing — most questions can be answered in 4-5 tool calls if you follow the loop below.
The loop
For every question, do this:
-
Pick the example shape that matches the question.
cat /usr/local/lib/python3.11/dist-packages/crude_analyst/examples/<shape>.pyQuestion shape Example file "What is X right now" snapshot.py"How has X changed over T" trend.py"Top N by metric" ranking.py"X vs Y" comparison.py"Find rows where X happens" detection.pyInvestigative, several themes multi_section.py -
Sanity-check the data with at most 3
run_sqlcalls (BATCH THEM in one assistant message — don't serialize). Usecrude_analyst.describe,date_range,peekto skip writing schema SQL by hand. -
Write
/tmp/briefing.pyby copying the example and editing the CONFIG block + headline/tldr/commentary. Use the file editor tool (str_replace_based_edit_tool) for clean multi-line writes — DO NOT use bash heredocs for the briefing script; quoting will bite you. -
Run it:
python3 /tmp/briefing.pyPrints "Saved." on success, or
PERSIST_ERROR: 422 {widgets: [...]}if a widget query failed. Read the error, fix the query, re-run.
That's the loop. 4-5 tool calls total. If you're past 8 you're over-exploring.
Hard rules
- The sandbox cannot connect to the database.
run_sqlis the only path. Do not trypsycopg2,psql,pg_dump, hunt for.envfiles, orpip installa DB driver — none of it works. - Widgets carry SQL strings. The server runs the SQL after you persist. You do not need to (and should not) compute final result rows in this sandbox.
- One bash call should compose + persist. If you're regenerating
the whole
/tmp/briefing.pymore than twice, stop and read the example again. persist()reads the URL from$CRUDE_PERSIST_URL. Don't hardcode it.
Public API at a glance
from crude_analyst import (
# Widget builders
callout, table, line_chart, bar_chart, commentary,
# Composition
section, briefing, error,
# I/O
persist, PersistError,
# SQL: time-series
bucket_time, auto_granularity,
# SQL: window functions
rolling, lag, lead, pct_change,
# SQL: filters (compose with AND)
last_n_days, last_n_months, last_n_years, ytd, between,
# SQL: ranking
top_n,
# SQL: event detection
threshold_events,
# SQL: schema introspection
describe, date_range, peek,
)
Every function has docstring docs (help(crude_analyst.X)).
What each layer does
Mechanical (widget builders)
Build validated widget dicts. Each builder enforces the spec shape — no domain knowledge.
callout(label, code='WTI_USD')— commodity callout fromspot_pricescallout(label, query='SELECT count(*) AS n ...', value_template='{n} rigs')— query calloutline_chart(label, query=...)— query must alias columns asxandybar_chart(label, query=..., orientation='horizontal')— same shape as linetable(columns=[{key, label, align}], query=...)— query column keys must matchcommentary(text, tone='neutral|bullish|bearish|warning')
Composition
briefing(headline, tldr, widgets=[...])— flat: wraps in one sectionbriefing(headline, tldr, sections=[section(...), ...])— sectionedsection(label, layout, widgets)— layouts:full-width,3-col,2-col
SQL builders (return strings — drop into query=)
bucket_time(table=, date_col=, value_cols={col: fn}, days_back=, granularity='auto')— full SELECT withdate_truncand auto-bucketing per the palette rulerolling(col, window=10, fn='AVG', order_col='price_date')— fragmentpct_change(col, periods=1, order_col='date')— fragmenttop_n(table=, group_by=, order_by='SUM(x)', n=10, where=)— full SELECTthreshold_events(table=, date_col=, value_col=, rolling_window=, threshold_pct=)— full SELECT; returns event_start, event_peak, start_value, peak_value, pct_movelast_n_days(date_col, 90),between(date_col, '2024-01-01', '2024-12-31')— fragmentsdescribe(table),date_range(table, date_col),peek(table, n=5)— full SELECTs
Examples
Six runnable templates in crude_analyst/examples/. Pick by shape,
not topic.
When examples don't fit
For unusual question shapes, compose by hand using the widget + SQL helpers above. The examples are starting points, not the only allowed shapes. But: first try to fit the question into one of the six. Most questions do.
Where it runs
The Managed Agents data-analyst sandbox installs this package from PyPI at environment build time. The agent imports it inside the sandbox to compose briefing specs and POST them to the persist endpoint.
Source
https://github.com/petroleumPythoneer/crudecode (packages/crude-analyst/)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file crudecode_analyst-0.3.1.tar.gz.
File metadata
- Download URL: crudecode_analyst-0.3.1.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd69c30fe54ff2d915ef705963dc0fd3d8817cefd565b502d402e0596167024f
|
|
| MD5 |
b993cfa4dd364940c801ab2ff30c87be
|
|
| BLAKE2b-256 |
f33219aa85a2bee5f7739e79b0f9b85bb623b7578fa62ee2eedae946e65364d8
|
File details
Details for the file crudecode_analyst-0.3.1-py3-none-any.whl.
File metadata
- Download URL: crudecode_analyst-0.3.1-py3-none-any.whl
- Upload date:
- Size: 28.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8aafb405bdd297e7d5d521820ce91d4c95bc8cf663b77043b18fe8a1b9b76758
|
|
| MD5 |
9065212d05513c798981710ef39d7792
|
|
| BLAKE2b-256 |
53508a6ccc77876fffbf9a4242ca6b83662e0e40af0120393035c59b0df4dafe
|