[AAASM-3539] ✨ (examples): Add Smolagents tool-policy example#150
Merged
Conversation
uv project (agent-assembly + smolagents>=1.0,<2.0 in base deps since smolagents is light), .env.example, and package init files for the smolagents governance example. Refs AAASM-3539 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Three genuine smolagents.Tool subclasses (search_docs, summarize, run_shell_command) and a LocalPolicyEngine that denies destructive tools, matching the SDK adapter's check_tool_start/record_result interceptor contract. Refs AAASM-3539 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Applies the real SmolagentsPatch with the local policy before init_assembly() (so the offline policy wins the idempotent Tool.__call__ hook) and drives real governed tools: allow runs the body, deny short-circuits before forward(). Refs AAASM-3539 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Drives the real adapter governing real smolagents.Tool instances: allow runs, deny blocks the body, plus a negative control proving the interception is real (an ungoverned destructive tool runs). Refs AAASM-3539 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Refs AAASM-3539 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Refs AAASM-3539 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Prerequisites, setup, run + expected output, the offline-wiring note, and the production-mode switch for the smolagents governance example. Refs AAASM-3539 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Claude Code — review result (Smolagents example)
Validated locally: Merge order: LAST — after python-sdk #161 + b5 release. Full cross-repo review on AAASM-3535. |
The PyPI release of agent-assembly does not yet ship agent_assembly.adapters.smolagents (it is merged on the SDK's git master but unreleased), so uv sync pulled a too-old SDK and the smoke test failed with ModuleNotFoundError. Pin the SDK to the git master branch via [tool.uv.sources] until 0.0.1b5 publishes the adapter to PyPI, then revert to the PyPI pin. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Reformat the example to ruff defaults and make it pass mypy --strict: declare the untyped smolagents import via a per-module mypy override (matching the python-sdk's pattern for code it does not own) instead of a blanket ignore. No runtime behavior changes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Resolve shared-file overlaps after the Haystack example (#149) merged: keep BOTH the smolagents-tool-policy and haystack-tool-policy CI jobs (each with its own steps) and both gallery README rows. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What changed
Adds
python/smolagents-tool-policy/— a runnable governance example for Smolagents (Hugging Face). It governs realsmolagents.Toolinstances through the SDK's native adapter, which hookssmolagents.tools.Tool.__call__(the chokepoint every tool execution flows through;Tool.__call__runsself.forward(...)). The demo invokes the real governed tools directly (the same call a smolagents agent makes), so it runs fully offline with no model or gateway: two safe tools run, and a destructiverun_shell_commandis short-circuited with[BLOCKED by governance policy]before itsforward()body executes.This is genuine governance, not a no-op: the tools are real
smolagents.Toolsubclasses and the patch is the productionSmolagentsPatch. The smoke suite includes a negative control proving that without the adapter the destructive tool runs — so the governed cases are real interception.The example applies the policy patch before
init_assembly()(which auto-detects smolagents and would otherwise install its default interceptor on the idempotent hook first), mirroring thegoogle-adkexample's offline-wiring pattern.Related ticket
Refs AAASM-3539 (parent AAASM-3535)
How to verify
Validated locally against the SDK branch (ai-agent-assembly/python-sdk#161):
main.pyblocks the destructive tool, smoke suite passes 8/8.Release-gated: the
smolagentsadapter ships with the python-sdk PR (#161). The example pinsagent-assembly>=0.0.1b2(sibling convention), but the newverify-pythonjob will be green only once anagent-assemblyrelease that includes the smolagents adapter is published to PyPI — the same cross-repo sequencing every framework example followed.Checklist
[AAASM-XXXX] <GitEmoji> (<scope>): <summary>.envfiles committedREADME.mdwith prerequisites and run instructions🤖 Generated with Claude Code