Skip to content

Commit b5d05ee

Browse files
committed
Merge branch 'main' of https://github.com/NOAA-GSL/zyra
Signed-off-by: Eric Hackathorn <erichackathorn@gmail.com>
2 parents 1d556a0 + 8ed8def commit b5d05ee

File tree

106 files changed

+16737
-825
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+16737
-825
lines changed

.github/workflows/test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
exit 1
7676
fi
7777
echo "Using project directory: $DIR"
78-
poetry -C "$DIR" install --no-root --with dev
78+
poetry -C "$DIR" install --no-root --with dev -E guardrails
7979
8080
- name: Ruff format check
8181
run: poetry run ruff format --check .
@@ -141,7 +141,7 @@ jobs:
141141
exit 1
142142
fi
143143
echo "Using project directory: $DIR"
144-
poetry -C "$DIR" install --no-root --with dev -E api
144+
poetry -C "$DIR" install --no-root --with dev -E api -E guardrails
145145
146146
- name: Show workspace root (post-install debug)
147147
run: |

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ See module-level READMEs under `src/zyra/` for focused examples and options:
5555
## Stage Map
5656
- Overview: https://github.com/NOAA-GSL/zyra/wiki/Workflow-Stages
5757

58+
### Swarm Orchestration
59+
- `zyra swarm --plan samples/swarm/mock_basic.yaml --dry-run` prints the instantiated agents.
60+
- Remove `--dry-run` to execute mock simulate→narrate agents; use `--memory provenance.db` to persist provenance and `--guardrails schema.rail` to enforce structured outputs.
61+
- Guardrail validation requires the optional extra: `pip install "zyra[guardrails]"` (or `poetry install --with guardrails`) before using `--guardrails schema.rail`.
62+
- To exercise the skeleton simulate/decide flow end-to-end, try `zyra swarm --plan samples/swarm/simulate_decide.yaml --dry-run` (or drop `--dry-run` to run the mock pipeline).
63+
- Add `--log-events` to echo provenance events live, and `--dump-memory provenance.db` to inspect existing runs without executing new stages.
64+
- Target specific stages or experiment with partial DAGs using `--agents acquire,visualize,narrate`; unknown stage names are rejected early so typos do not silently skip work.
65+
- Control concurrency explicitly with `--parallel/--no-parallel` (the latter forces `max-workers=1`) and use `--max-workers N` when you want a fixed pool size.
66+
- Override LLM settings for proposal/narrate stages with `--provider mock|openai|ollama|gemini|vertex`, `--model <name>`, and `--base-url <endpoint>` instead of editing `.env` or wizard config files. Gemini runs with either `GOOGLE_API_KEY` (Generative Language API) or Vertex credentials (`VERTEX_PROJECT`, `GOOGLE_APPLICATION_CREDENTIALS`, etc.).
67+
- A real-world example lives in `samples/swarm/drought_animation.yaml`; run it with
68+
`poetry run zyra swarm --plan samples/swarm/drought_animation.yaml --memory drought.db`.
69+
Create `data/drought/` ahead of time, place `earth_vegetation.jpg` in your working directory (or adjust the manifest),
70+
and ensure Pillow is installed for `process pad-missing`.
71+
- Preview planner output (JSON manifest with augmentation suggestions) before running: `poetry run zyra plan --intent "mock swarm plan"`.
72+
- Plans are YAML/JSON manifests listing agents, dependencies (`depends_on`), and CLI args; see `samples/swarm/` to get started.
73+
5874
### Import (acquire/ingest)
5975
- Docs: https://noaa-gsl.github.io/zyra/api/zyra.connectors.html
6076
- Examples: https://github.com/NOAA-GSL/zyra/wiki/Stage-Examples
@@ -83,6 +99,27 @@ See module-level READMEs under `src/zyra/` for focused examples and options:
8399
- Docs: https://noaa-gsl.github.io/zyra/api/zyra.connectors.html
84100
- Examples: https://github.com/NOAA-GSL/zyra/wiki/Stage-Examples
85101

102+
### LLM Providers for Wizard/Narrate
103+
104+
Zyra’s Wizard, narrative swarm, and discovery semantic search all share the same provider configuration. Install `google-auth` when needed with `pip install "zyra[llm]"` (or `poetry install --with llm`). Key options:
105+
106+
| Provider | Configuration |
107+
| --- | --- |
108+
| OpenAI | `OPENAI_API_KEY`, optional `OPENAI_BASE_URL` |
109+
| Ollama | Local server on `http://localhost:11434` (override with `OLLAMA_BASE_URL`) |
110+
| Gemini (Generative Language API) | Set `GOOGLE_API_KEY`; optional `GENLANG_BASE_URL`, `VERTEX_MODEL` (default `gemini-2.5-flash`) |
111+
| Gemini (Vertex AI) | Provide `VERTEX_PROJECT` (aliases: `GOOGLE_PROJECT_ID`, `GOOGLE_CLOUD_PROJECT`), `VERTEX_LOCATION` (default `us-central1`), and Application Default Credentials (`GOOGLE_APPLICATION_CREDENTIALS` pointing to a service-account JSON). Optional `VERTEX_MODEL`, `VERTEX_ENDPOINT`, `VERTEX_PUBLISHER`. |
112+
| Mock | No credentials needed; deterministic offline responses. Useful for testing. |
113+
114+
Example `~/.zyra_wizard.yaml` targeting Gemini via Vertex:
115+
116+
```yaml
117+
provider: gemini
118+
model: gemini-2.5-flash
119+
project: my-vertex-project
120+
location: us-central1
121+
```
122+
86123
## API & Reference Docs
87124
- GitHub Pages: https://noaa-gsl.github.io/zyra/
88125
- CLI reference: https://noaa-gsl.github.io/zyra/api/zyra.cli.html
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Programmatic API (Workflow, Manifest, Plugins)
2+
3+
- `Workflow`: load YAML/JSON pipelines and run them via the CLI for full parity.
4+
- `Manifest`: inspect packaged CLI capabilities (with optional plugin merge).
5+
- `plugins`: register local commands for discovery (CLI help epilog + manifest overlay).
6+
7+
## Examples
8+
9+
```python
10+
from zyra.workflow.api import Workflow
11+
from zyra.manifest import Manifest
12+
from zyra import plugins
13+
14+
wf = Workflow.load("samples/workflows/minimal.yml")
15+
print(wf.describe())
16+
run_result = wf.run(capture=True, stream=False)
17+
assert run_result.succeeded
18+
19+
plugins.register_command("process", "demo_plugin", description="Local demo")
20+
manifest = Manifest.load(include_plugins=True)
21+
print(manifest.list_commands(stage="process"))
22+
```
23+
24+
## Notes
25+
- Workflow execution uses subprocess calls to `zyra.cli` to mirror CLI behavior and logging.
26+
- Plugin registry is discovery-only for now; execution dispatch remains unchanged.
27+
- A companion notebook lives at `examples/api_and_programmatic_interface.ipynb` for interactive use.
28+
29+
## Notebook sessions
30+
31+
- `zyra.notebook.create_session()` builds stage namespaces from the same manifest used by `Manifest.load()`.
32+
- Plugins registered via `zyra.plugins.register_command` are merged into the manifest programmatically (registry overlay), and notebook sessions see them without writing files.
33+
- Workflow APIs stay subprocess-based for parity, while notebook tools call callable wrappers; use whichever fits your notebook flow.
34+
- Manifest/overlay loading is centralized in `zyra.manifest_utils.load_manifest_with_overlays` (honors `ZYRA_NOTEBOOK_OVERLAY` when set).
35+
- To disable automatic loading of local plugins from `.zyra/extensions/plugins.py`, set `ZYRA_DISABLE_LOCAL_PLUGINS=1`.
36+
37+
Example:
38+
39+
```python
40+
from zyra.notebook import create_session
41+
42+
sess = create_session()
43+
# Call a process tool directly from the manifest-driven namespace
44+
sess.process.convert_format(file_or_url="/tmp/in.grib2", output="/tmp/out.tif")
45+
46+
# Plugins registered earlier are also discoverable
47+
sess.process.demo_plugin()
48+
```

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Contents
6868
domain_apis
6969
mcp
7070
guides/narrate_swarm_quickstart
71+
guides/programmatic_api
7172

7273
.. toctree::
7374
:maxdepth: 2

docs/source/wiki/Home.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ Zyra evokes growth and flow — small seeds of data can flourish into full workf
4141
- Install & Extras: [Install & Extras](Install-Extras)
4242
- Patterns: [Pipeline Patterns](Pipeline-Patterns)
4343
- Stage Examples: [Stage Examples](Stage-Examples)
44+
- Stage Agents: [Zyra Swarm](Stage-Agents-and-Planner-Overview)
4445
- CLI Reference: https://noaa-gsl.github.io/zyra/api/zyra.cli.html
4546

4647
---
4748

4849
## Explore More
4950

5051
### Assistant & Guidance
51-
- [![Chat with Zyra Assistant](https://img.shields.io/badge/ChatGPT-Zyra%20Assistant-00A67E?logo=openai&logoColor=white)](https://chatgpt.com/g/g-6897a3dd5a7481918a55ebe3795f7a26-zyra-assistant)
52+
- [![Chat with Zyra Assistant](https://img.shields.io/badge/ChatGPT-Zyra%20Assistant-00A67E?logo=openai&logoColor=white)](https://assistant.zyra-project.org/)
5253
- Zyra Assistant Instructions: [Zyra-Assistant-Instructions](Zyra-Assistant-Instructions)
5354
- Wizard Assistant: [Wizard-Interactive-Assistant](Wizard-Interactive-Assistant)
5455

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Stage Agents & Planner Overview
2+
3+
This page summarizes:
4+
5+
1. How stage agents map to the existing Zyra stages
6+
2. The new `zyra plan` capabilities (reasoning trace, suggestions, clarifications)
7+
3. Value Engine suggestions and how they influence the manifest
8+
4. Running the generated plan with `zyra swarm`
9+
10+
## Stage Agents at a Glance
11+
12+
Each Zyra workflow stage now corresponds to a **stage agent** with a normalized spec:
13+
14+
| Stage | Purpose | Implementation Notes |
15+
|------------|-------------------------------------------------|----------------------------------------------------|
16+
| acquire | Fetch/source data (HTTP, FTP, S3, etc.) | CLI agent (`zyra acquire …`) |
17+
| process | Transform/clean data (scan-frames, pad-missing) | CLI agent |
18+
| simulate | Skeleton mock (emits placeholder ensemble) | Mock agent (ready for future simulation logic) |
19+
| decide | Skeleton mock (scores/optimizes results) | Mock agent (ensures DAG coverage) |
20+
| visualize | Render plots/animations | CLI agent (e.g., `compose-video`) |
21+
| narrate | Narration/summary | Proposal → CLI (LLM-backed) |
22+
| verify | Quality/completeness checks | CLI agent (`verify evaluate`) |
23+
| export | Save or disseminate artifacts | CLI agent (`decimate local`, `export s3`, etc.) |
24+
25+
When you run `zyra swarm`, the orchestrator resolves each spec into an agent, honors `depends_on`, and executes the DAG with optional parallelism.
26+
27+
## Hybrid Design Workflow: Structured Tool Confirmation (The General Contractor Model)
28+
29+
Zyra includes the integration of the **ValueEngine** for proactive value suggestion, consistent with the architectural principles established in the sources.
30+
31+
**Analogy:** If the current implementation is like a factory floor manager (Orchestrator) specifying exactly which bolt (Tool) the worker (Stage Agent) must use, the hybrid design is like the manager telling the worker "Use the best high-strength fastener for this application" (Natural Language), and the worker replies, "I propose using a grade 8 titanium bolt with these specifications" (Structured Proposal). The manager then verifies that titanium is on the approved materials list (Validation) and logs the decision (Provenance) before allowing the work to proceed (Execution). This process is safer, more adaptable, and fully traceable.
32+
33+
The workflow is divided into three distinct phases, managing the transition from high-level user intent to validated, executable code.
34+
35+
### Phase 1: Planning, Value Augmentation, and Initial Validation (Central Control)
36+
37+
This phase establishes the complete, safe plan (DAG) and is primarily managed by the Orchestrator's LLM Reasoning, Planner, Validator, and ValueEngine components.
38+
39+
| Step | Component | Action / Description | Source Alignment |
40+
| :--- | :--- | :--- | :--- |
41+
| **1. User Intent and Interpretation** | LLM System Prompt / Reasoning Layer | Interprets the **natural-language user intent**, identifying verbs and objects, and maps them to high-level Zyra stages. Output is restricted to **Structured reasoning via JSON output**. | |
42+
| **2. Base DAG Construction** | Planner (Python) | Verifies requested actions exist in the **capabilities registry**. Builds the initial Dependency Graph (DAG) based on canonical stages (e.g., `import → process → visualize → export`). | |
43+
| **3. Proactive Value Suggestion** | **ValueEngine (LLM)** | Evaluates the initial DAG and provenance for potential low-cost, high-value augmentations (e.g., suggesting a `verify` or `narrate` stage). Returns structured suggestions (e.g., JSON containing stage, description, confidence). | |
44+
| **4. Augmentation Validation & Acceptance** | Validator / User Interaction | Orchestrator presents suggestions to the user for **acceptance or dismissal**. The Validator ensures accepted additions are **safe and compatible**; accepted suggestions are recorded (stage, confidence, rationale) in Provenance and inserted via the template registry (`insert_node`). | |
45+
| **5. Deterministic Stage Check** | Planner (Python) | Determines if the first executable stage is **deterministic** (e.g., `acquire ftp`, `process scan-frames`). Deterministic stages skip Phase 2 and proceed directly to execution (Step 9). **Ambiguous** stages (e.g., `visualize compose`, `narrate swarm`) enter Phase 2 for structured tool proposals. | |
46+
47+
---
48+
49+
### Phase 2: Specialized Reasoning and Proposal (Hybrid Loop – For Ambiguous Tasks Only)
50+
51+
This phase delegates specialized tool selection to the Stage Agent but retains central control via a structured contract and mandatory validation.
52+
53+
| Step | Component | Action / Description | Source Alignment |
54+
| :--- | :--- | :--- | :--- |
55+
| **6. Dispatch Natural Language Subtask** | Executor (Python) | Orchestrator dispatches the Stage Agent, providing a clear, high-level **natural language description** of the subtask. | |
56+
| **7. Local Reasoning and Structured Proposal** | Stage Agent (LLM Reasoning + Tools) | The specialized Stage Agent uses its **domain-specific tools or skills** to select the optimal low-level method and returns a **structured JSON proposal** (the execution contract) to the Orchestrator, e.g.: `{"stage_id":"visualize_1","proposed_tool":"visualize heatmap","args":{"input":"...","output":"..."}}`. | |
57+
| **Required Schema Contract** | JSON Payload | Must include: `stage_id`, **`proposed_tool`** (alias for capabilities lookup), mandatory **`args`**, optional `justification`, and structured outputs to match the capabilities registry. | |
58+
| **8. Proposal Validation and Hook** | Validator (Guardrails / Pydantic) | Validator performs **schema enforcement and safety checks**. It uses the `proposed_tool` alias to verify the command against the **capabilities registry** and ensure the `args` confirm **proper inputs/outputs**. | |
59+
| **8a. Validation Rejection Escalation** | Planner / User Interaction | If the proposal is rejected (e.g., safety failure, invalid schema): **1. Retry** with the same stage agent (keeping context) and request safer parameters. **2. Enter the Clarification Loop** if required inputs are missing. **3. Bubble an error** to the user if recovery is impossible (e.g., unsupported tool). | |
60+
61+
---
62+
63+
### Phase 3: Central Execution and Provenance
64+
65+
This phase maintains the core principle that the Orchestrator, running Python code, is the sole executor, ensuring the workflow is **deterministic and auditable**.
66+
67+
| Step | Component | Action / Description | Source Alignment |
68+
| :--- | :--- | :--- | :--- |
69+
| **9. Centralized Execution** | Executor (Python) | If validated (or if the stage was deterministic), the Orchestrator’s Python Executor invokes the necessary internal runtime function (e.g., `_run_cli` or `_run_function`) using the approved command and parameters from the structured proposal. **The Stage Agent does not execute code remotely**. | |
70+
| **10. Provenance Logging** | Provenance & Memory | The Executor ensures the stage **logs its artifacts, metadata, hash signatures, accepted/rejected suggestions, and tool proposals/validation results**. This achieves **full transparency and reproducibility**. | |
71+
| **11. Workflow Advancement** | Planner / Executor | The Planner updates the DAG state and dispatches the next dependent Stage Agent or signals workflow completion. | |
72+
73+
## Planner Enhancements
74+
75+
`poetry run zyra plan --intent "<request>" --output plan.json --verbose` now:
76+
77+
- Emits a reasoning trace explaining why each stage was selected
78+
- Prompts for missing arguments (e.g., FTP path, pad-missing fill mode)
79+
- Invokes the **Value Engine** to suggest optional stages (narrate summaries, verification checks, retry logic). Suggestions can be accepted interactively.
80+
- Automatically materializes verify stages when `scan-frames` detects missing or duplicate timestamps, wiring `verify evaluate --metric completeness --input <frames_meta>` into the manifest.
81+
82+
### Example Plan Intent
83+
84+
```bash
85+
poetry run zyra plan \
86+
--intent "Download the last year of Weekly Drought Risk PNG frames from FTP, fill missing frames, compose an MP4 animation, and save to disk." \
87+
--output plan.json --verbose
88+
```
89+
90+
**What to expect:**
91+
92+
- Verbose output logs the planner/LLM reasoning, clarification prompts, and suggestions.
93+
- `plan.json` contains agents for `fetch_frames`, `scan_frames`, `pad_missing`, `compose_animation`, `save_local`, `verify_animation`, and `narrate_animation`.
94+
- The Value Engine typically suggests adding narration and verification stages; accepting the narrate suggestion inserts a second proposal agent (e.g., `narrate_1`) with a specific intent like “Describe spatial patterns.”
95+
- `plan_summary` now lists human-readable justifications for each agent (helpful downstream and for provenance).
96+
97+
## Value Engine Suggestions
98+
99+
The Value Engine inspects the manifest + semantic intent tags and offers low-cost augmentations (narration, verification, logging, etc.). Key upgrades in this branch:
100+
101+
- Suggestions include `intent_text` so accepted items append context back into the manifest intent.
102+
- Verify suggestions can carry concrete `agent_template` payloads (e.g., `verify evaluate --metric completeness --input data/frames_meta.json`) so the planner inserts runnable agents rather than proposals.
103+
- Accepted suggestions are recorded under `accepted_suggestions`; unaccepted ones remain in `suggestions` for reference.
104+
105+
## Running the Plan with `zyra swarm`
106+
107+
```
108+
poetry run zyra swarm \
109+
--plan plan.json \
110+
--memory run.db \
111+
--log-events \
112+
--parallel \
113+
--provider ollama --model gemma --base-url http://host.docker.internal:11434
114+
```
115+
116+
**Highlights:**
117+
118+
- `--memory run.db` records provenance (agent stats, verify/narrate results). Use `--dump-memory run.db` to inspect past runs.
119+
- `--log-events` prints a stream like `[event agent_verify_result] agent=verify_animation stage=verify verdict=passed …`.
120+
- `--parallel/--no-parallel` toggles concurrency (defaults to auto). `--agents simulate,decide,narrate` runs a subset if you need to focus on specific stages.
121+
- `--provider/--model/--base-url` let you override the LLM client without editing `.env`; the planner and Value Engine honor the same settings.
122+
123+
### Sample Output (truncated)
124+
125+
```
126+
[event run_started] {"agent_count": 8, ...}
127+
[event agent_started] {"agent": "fetch_frames", "stage": "acquire"}
128+
...
129+
[event agent_verify_result] agent=verify_animation stage=verify verdict=passed metric=completeness message=verify evaluate: completeness PASSED - all frames present
130+
[event agent_completed] {"agent": "narrate_animation", "role": "narrate", "duration_ms": 15957}
131+
[event run_completed] agent_count=8 errors=0 failed=0 proposals=narrate_1:swarm, narrate_animation:swarm
132+
```
133+
134+
The narrate stages receive enriched inputs (plan summary, frames metadata, verify results) so `narrative_summary.yaml` references missing weeks, sample frames, and completeness verdicts instead of just codec info.
135+
136+
## Sample Manifests
137+
138+
- `samples/swarm/mock_basic.yaml`: Minimal simulate → narrate DAG (mock outputs).
139+
- `samples/swarm/drought_animation.yaml`: Full drought pipeline (FTP download, pad-missing, compose-video, narrate, verify, save).
140+
- `samples/swarm/simulate_decide.yaml` *(new)*: Chains simulate → decide → narrate to exercise the skeleton stages without real data.
141+
142+
Use `poetry run zyra swarm --plan samples/swarm/simulate_decide.yaml --dry-run` to verify the mock pipeline works end-to-end.
143+
144+

0 commit comments

Comments
 (0)