Skip to content

[AAASM-3539] ✨ (examples): Add Smolagents tool-policy example#150

Merged
Chisanan232 merged 10 commits into
masterfrom
v0.0.1/AAASM-3539/feat/smolagents_support
Jun 22, 2026
Merged

[AAASM-3539] ✨ (examples): Add Smolagents tool-policy example#150
Chisanan232 merged 10 commits into
masterfrom
v0.0.1/AAASM-3539/feat/smolagents_support

Conversation

@Chisanan232

Copy link
Copy Markdown
Contributor

What changed

Adds python/smolagents-tool-policy/ — a runnable governance example for Smolagents (Hugging Face). It governs real smolagents.Tool instances through the SDK's native adapter, which hooks smolagents.tools.Tool.__call__ (the chokepoint every tool execution flows through; Tool.__call__ runs self.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 destructive run_shell_command is short-circuited with [BLOCKED by governance policy] before its forward() body executes.

This is genuine governance, not a no-op: the tools are real smolagents.Tool subclasses and the patch is the production SmolagentsPatch. 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 the google-adk example's offline-wiring pattern.

Related ticket

Refs AAASM-3539 (parent AAASM-3535)

How to verify

cd python/smolagents-tool-policy
uv sync --extra dev
uv run pytest tests/ -v      # 8 passed (incl. negative control)
uv run python src/main.py    # search_docs/summarize ALLOWED, run_shell_command BLOCKED

Validated locally against the SDK branch (ai-agent-assembly/python-sdk#161): main.py blocks the destructive tool, smoke suite passes 8/8.

Release-gated: the smolagents adapter ships with the python-sdk PR (#161). The example pins agent-assembly>=0.0.1b2 (sibling convention), but the new verify-python job will be green only once an agent-assembly release that includes the smolagents adapter is published to PyPI — the same cross-repo sequencing every framework example followed.

Checklist

  • PR title follows [AAASM-XXXX] <GitEmoji> (<scope>): <summary>
  • No secrets, API keys, or .env files committed
  • Example sub-project includes its own README.md with prerequisites and run instructions
  • SDK/runtime version dependencies are documented or pinned

🤖 Generated with Claude Code

Chisanan232 and others added 6 commits June 22, 2026 14:27
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>
@Chisanan232

Copy link
Copy Markdown
Contributor Author

Claude Code — review result (Smolagents example)

⚠️ smolagents-tool-policy smoke job is red for release-ordering onlyModuleNotFoundError: No module named 'agent_assembly.adapters.smolagents'. The adapter ships in python-sdk #161 (unmerged); resolves after #161 merges + a python-sdk b5 release on PyPI.

Validated locally: main.py shows run_shell_command genuinely BLOCKED while safe tools run; smoke suite 8/8 incl. an ungoverned-tool negative control.

Merge order: LAST — after python-sdk #161 + b5 release. Full cross-repo review on AAASM-3535.

Chisanan232 and others added 3 commits June 22, 2026 16:20
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>
@Chisanan232 Chisanan232 merged commit 4bc825b into master Jun 22, 2026
19 checks passed
@Chisanan232 Chisanan232 deleted the v0.0.1/AAASM-3539/feat/smolagents_support branch June 22, 2026 09:04
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant