-
Notifications
You must be signed in to change notification settings - Fork 1
Using Zyra in Python Notebooks
Eric Hackathorn edited this page Nov 30, 2025
·
1 revision
- Run Zyra stages directly in notebooks with
create_session(). - Register custom tools inline; they are exposed to the planner via a capabilities overlay.
- Provenance is logged to SQLite; pipelines/CLI equivalents can be exported.
- Narrate/swarm works in notebooks with provider selection and debug output.
- Install:
poetry install --with dev(or pip equivalents in your env). - Env vars:
-
ZYRA_NOTEBOOK_DIR(workspace),ZYRA_NOTEBOOK_PROVENANCE(provenance DB, defaults under workspace). - LLM:
GOOGLE_API_KEY(Gemini),OPENAI_API_KEY,OLLAMA_BASE_URL. Fallback ismockif none set. - Verbose swarm logs:
ZYRA_VERBOSITY=debug.
-
from zyra.notebook import create_session
sess = create_session() # uses ZYRA_NOTEBOOK_DIR or cwd
# Acquire/process example
data = sess.acquire.http(url="https://example.com/file.bin")
# Register an inline tool (with templates for planner)
def smooth(ns): ...
sess.process.register(
"smooth",
smooth,
returns="object",
args_template={"input": "frames_padded"},
outputs_template={"output": "analysis.json"},
)
# Export
print(sess.to_pipeline())
print(sess.to_cli())- Registration writes
notebook_capabilities_overlay.jsonin the workspace. - Planner loads this overlay (env
ZYRA_NOTEBOOK_OVERLAYset by session/notebook cells). - Inline suggestions are labeled (e.g.,
[inline: notebook_register]); consent prompts include the origin. - Overlays include templates (args/outputs) and inline serialization metadata; replay currently warns/skips if inline code is absent.
-
sess.plan(...)wrapszyra planwith prompts enabled in notebooks; provenance goes to the session DB. - Inline planner demo cell:
- Prompts for missing args (FTP path/pattern, etc.).
- Runs value engine; prints accepted vs. remaining suggestions.
- Ensures scan/pad/compose/local wiring; saves plan to
plan_session_inline.json.
- Replay example:
poetry run zyra swarm --plan /app/data/drought_notebook/plan_session_inline.json --stage acquire,process,visualize,decimate.
- Provider selector defaults to Gemini (if creds) → OpenAI → Ollama → mock.
- Narrate cell builds frame/location bullets, sets a rubric, runs
sess.narrate.swarm, and logs pack/provenance. - Input preview and agent outputs live in
narrate_pack.yaml; final narration prefers the edited output.
- Default DB:
${ZYRA_NOTEBOOK_DIR}/provenance.sqlite(configurable viaZYRA_NOTEBOOK_PROVENANCE). - Inspect via notebook cell (tables, last events) or
zyra swarm --dump-memory <db>.
- Registers a custom drought-frame analyzer (overlay makes it plannable).
- Planner intent mentions analyzing frames; inline planner suggests the analyzer and wires dependencies.
- Plan outputs:
plan_session_inline.json, overlays, provenance DB, and narrate packs.
- Inline tools must be serializable; overlays warn and skip inline replay if code isn’t available.
- Consent prompts label inline origins before suggesting user code.
- Connectors (docs): https://noaa-gsl.github.io/zyra/api/zyra.connectors.html
- Processing (docs): https://noaa-gsl.github.io/zyra/api/zyra.processing.html
- Visualization (docs): https://noaa-gsl.github.io/zyra/api/zyra.visualization.html
- Transform (docs): https://noaa-gsl.github.io/zyra/api/zyra.transform.html
- Utils (docs): https://noaa-gsl.github.io/zyra/api/zyra.utils.html