Repository navigation
Conversation
…talog - Add navigation README for docs/examples/sampling/ - Standardize header docstrings in sampling and agent scripts - Index react_using_mellea.py in docs/examples/agents/README.md - Register sampling/, requirements/, and audio_text_models/ in docs/docs/examples/index.md Assisted-by: IBM Bob Signed-off-by: Rafael Vasquez <rafvasq21@gmail.com>
planetf1
left a comment
There was a problem hiding this comment.
Useful docs-only change: it makes sampling/ and the stdlib react() example discoverable, and the READMEs and index rows match the source. I ran both sampling examples against Ollama and they run. Three non-blocking points below, plus one follow-up suggestion.
Separately, not for this PR: presets.py:220 tells users to run uv sync --extra plotting, but no such extra exists in pyproject.toml.
| | [`python_code_generation_preset.py`](./python_code_generation_preset.py) | Python code generation preset bundling extraction, syntax, and execution requirements with automatic repair feedback. | | ||
| | [`python_plotting_preset.py`](./python_plotting_preset.py) | Matplotlib plotting preset bundling headless backend setup, plot file output validation, and sandbox execution. | |
There was a problem hiding this comment.
"Execution requirements" and "sandbox execution" read as if the generated code is run. In these examples it mostly isn't. With use_sandbox=False the tier is static, which only parses and import-checks (python_tools.py:424). That is the code-generation default and what four of the five plotting examples use. Suggest wording like "validates generated code, with optional Docker-sandboxed execution". Same wording at python_code_generation_preset.py:5 and python_plotting_preset.py:6.
Follow-up, not for this PR: the examples show the validate-and-repair loop but never execute generated code, so timeout_seconds, output_limit_chars and the savefig output aren't exercised. A real example with use_sandbox=True that runs the code and checks the result would show the preset's main value. A couple of docstrings still describe sandboxed behaviour too (python_plotting_preset.py:26 and :147).
There was a problem hiding this comment.
Fixed to be more specific about sandbox use.
There was a problem hiding this comment.
Partially fixed, thanks. The README rows and both module docstrings now separate static validation from Docker execution, which reads well.
Two docstrings from my original comment are still unchanged: python_plotting_preset.py:38 says "Code executes without errors in isolated sandbox" while :45 passes use_sandbox=False, and :166 says "use_sandbox: Keep sandbox enabled for security" directly above use_sandbox=False at :177.
One wording issue in the new text: "import-check" overstates the default. With allowed_imports=None the bundle appends NoImportRestrictions, and StaticAnalysisEnvironment only checks imports when an allowlist is set (interpreter.py:257), so the default is parse-only. This affects python_code_generation_preset.py:5 and :8-9, python_plotting_preset.py:9-10, and the README's codegen row. "Parses the code, and checks imports when allowed_imports is set" would match the behaviour.
There was a problem hiding this comment.
Thanks! I've fixed both docstrings and replaced the "import-check" wording in both module docstrings and the README codegen row.
| | File | Description | | ||
| | :--- | :--- | | ||
| | [`python_code_generation_preset.py`](./python_code_generation_preset.py) | Python code generation preset bundling extraction, syntax, and execution requirements with automatic repair feedback. | | ||
| | [`python_plotting_preset.py`](./python_plotting_preset.py) | Matplotlib plotting preset bundling headless backend setup, plot file output validation, and sandbox execution. | |
There was a problem hiding this comment.
These examples need a running Ollama with the default model (granite4.2:3b), and the plotting ones need matplotlib, which isn't in any extra. example_without_output_path is the only one that runs generated code in Docker, so it also needs llm-sandbox (mellea[sandbox]), a running Docker daemon, and a sandbox image that runs on your machine. The default image is amd64-only, which can matter on Apple Silicon. A short prerequisites line would help.
It would also help that, when the sandbox can't run, the failure is hard to spot. The run reports Valid: 5/6 with the unmet requirement shown only as "sandbox execution with policy", and the underlying error never appears in the output. The script still prints "✓ completed", because it doesn't check the sampling result.
There was a problem hiding this comment.
Updated the scripts to include ollama and dependency install commands in their Prerequisites. I think this helps towards keeping the examples self-contained and in case future examples are added under this directory that may not need the same prerequisites.
There was a problem hiding this comment.
Partially fixed. I walked through these as someone running the examples fresh:
ollama pullis listed beforeollama serve, but pull needs the server up. Worth phrasing for users running Ollama as a service or via the desktop app too, e.g. "Ollama running (service, desktop app, orollama serve), thenollama pull granite4.2:3b".pip install matplotlib numpybeside auv runUsage line is a trap: uv-managed venvs don't includepip, and a systempipinstalls into a different environment thanuv runuses.uv pip install matplotlib numpyis the drop-in fix. (Aplottingextra would also fix the--extra plottingreference inpresets.py:220, but that's a follow-up.)- The plotting module's Prerequisites are incomplete for its own Usage line: running the module executes
main(), which includesexample_without_output_path, so it needs Docker anduv sync --extra sandbox. Those are only in that function's docstring. The amd64-only default sandbox image note is also still missing; on Apple Silicon that example can't pass as shipped even with Docker running, and the preset installs no packages into the container, so matplotlib may be missing there too.
On failure visibility: the docstring note is good, but the behaviour is unchanged. A newcomer sees four check lines, a Valid: 5/6 buried in the output, then a completed message, and reasonably concludes everything passed. SamplingResult.success exists (core/sampling.py:41), so checking it before printing a pass would close the gap. If documenting rather than fixing is preferred, I'd drop "fails silently" in the note, since the next sentence describes exactly what is reported.
P.S. while checking model tags: requirements/README.md:31 says ollama pull granite4.1:3b, but its examples use the default session, which is granite4.2:3b (session.py:271). Anyone following that README pulls the wrong 2 GB model and then triggers an auto-pull of the right one.
There was a problem hiding this comment.
I reordered to ollama serve/ollama pull across all five scripts and switched to uv pip install matplotlib numpy.
The plotting module's Prerequisites now include uv sync --extra sandbox, and the docstring notes the Docker requirement and the amd64-only image.
On failure visibility, I went with the second option for this PR and dropped the "fails silently" message. The --extra plotting hint is tracked in the issue I opened #1763.
…ings Assisted-by: IBM Bob Signed-off-by: Rafael Vasquez <rafvasq21@gmail.com>
Assisted-by: IBM Bob Signed-off-by: Rafael Vasquez <rafvasq21@gmail.com>
| using Mellea's stdlib react() function and LangChain tool interoperability. | ||
|
|
||
| Usage: | ||
| uv run python docs/examples/agents/react/react_using_mellea.py |
There was a problem hiding this comment.
The new Usage line can't work on a base install: the file imports langchain_community at :15, which only exists in the test extra (pyproject.toml:148). The documented command fails with an ImportError before reaching the inline comment at :23 that mentions the dependency. A Prerequisites block would fix it (uv pip install langchain-community ddgs). The other two react examples run on base deps but need Ollama with granite4.2:3b, and neither got a Prerequisites block, unlike the sampling files in this PR.
There was a problem hiding this comment.
Added Prerequisites block to react_using_mellea.py and the README row also notes the two deps. The two react_from_scratch examples now have Prerequisites blocks too.
| - See `mellea/stdlib/requirements/tool_reqs.py` for tool requirements No newline at end of file | ||
| | File | Description | | ||
| | :--- | :--- | | ||
| | [`react/react_using_mellea.py`](./react/react_using_mellea.py) | ReACT agent using Mellea's stdlib `react()` framework with LangChain tool integration. | |
There was a problem hiding this comment.
The table reads clean, but a newcomer can't tell which row to start with, and the first row is the one needing an extra dependency. One sentence above the table would fix it, e.g. "Start with react_using_mellea.py for the shortest path; the react_from_scratch/ examples build the same loop by hand to show what the framework does for you." Separately, the old README's pointer to mellea/stdlib/requirements/tool_reqs.py was dropped. The react examples don't use it and tools/README.md:256 still points there, so this is fine if deliberate, just confirming it was a choice.
There was a problem hiding this comment.
Added a line for starters.
Signed-off-by: Rafael Vasquez <rafvasq21@gmail.com>
Signed-off-by: Rafael Vasquez <rafvasq21@gmail.com>
Signed-off-by: Rafael Vasquez <rafvasq21@gmail.com>
Pull Request
Issue
Towards #1746
Docstrings
Prerequisites:andUsage:blocks.READMEs
sampling/README.md: defines a preset, links torequirements/, and has an## Examplestable.agents/README.md: a short description and an## Examplestable.Other fixes
react_using_mellea.py: documented thelangchain-communityandddgsdependencies.python_plotting_preset.pythat described sandboxed execution while passinguse_sandbox=False.Testing
Attribution
Adding a new component, requirement, sampling strategy, or tool?
If your PR adds or modifies one of the types below, check the matching box. A checklist of type-specific review items will be posted as a comment.
NOTE: Please ensure you have an issue that has been acknowledged by a core contributor and routed you to open a pull request against this repository. Otherwise, please open an issue before continuing with this pull request.