| Requirement | Version |
|---|---|
| Agent Assembly Python SDK (agent-assembly) | >= 0.0.1rc3 |
Install:
uv add agent-assembly==0.0.1rc3
# or
pip install agent-assembly==0.0.1rc3Demonstrates how to integrate Agent Assembly with Pydantic AI to enforce governance policy on tool calls before execution.
- Initializing Agent Assembly with
init_assembly()in offlinesdk-onlymode. - Installing tool-level governance hooks with
PydanticAIAdapter, which patches Pydantic AI's tool-execution path (AbstractToolset.call_toolon>=0.3.0,Tool._runon<0.3.0). - Driving a real Pydantic AI
Agentwith the built-inTestModel, so the demo runs offline with no API key. - Running an allowed tool call (
get_weather), a denied tool call (delete_records), and a pending tool call (send_email— requires approval, auto-denied offline). - How
PolicyViolationErroris raised when a tool is blocked or rejected during approval.
| Requirement | Version |
|---|---|
| Python | >= 3.12 |
| uv | latest |
| Agent Assembly Python SDK | >= 0.0.1rc3 |
No running Agent Assembly gateway is required for the offline demo.
Version note — the Agent Assembly Pydantic AI adapter installs a version-tolerant tool hook. On
pydantic-ai>=0.3.0it patchesAbstractToolset.call_tool(including concrete toolsets such asFunctionToolset); on<0.3.0it falls back to the internalTool._run.pyproject.tomltherefore requirespydantic-ai>=0.3.0with no upper pin — governance attaches across the0.3.x–1.xline.
cd python/pydantic-ai
uv sync --extra devuv run python src/main.py==============================================================
Agent Assembly — Pydantic AI Governed Agent Demo
==============================================================
Initializing Agent Assembly (gateway: http://localhost:8080, sdk-only mode)...
Agent: pydantic-ai-demo-agent
Gateway: http://localhost:8080
Mode: sdk-only (offline demo)
Policy rules (local simulation of gateway policy):
DENY — delete_records, write_file (destructive operations)
PENDING — send_email (requires human approval)
ALLOW — everything else
Running governed tool calls (driven offline by TestModel):
--------------------------------------------
→ agent run that calls get_weather
✅ ALLOWED — get_weather executed (mock response)
→ agent run that calls delete_records
❌ BLOCKED — Tool 'delete_records' blocked by governance policy: Tool 'delete_records' is blocked by policy rule 'deny_destructive_operations'.
→ agent run that calls send_email
❌ BLOCKED — Tool 'send_email' rejected during approval: Tool 'send_email' requires approval, but no approver is available in offline mode.
Assembly context shut down.
uv run pytest tests/ -v- Start an Agent Assembly gateway or use your SaaS workspace URL.
- Copy
.env.exampleto.envand fill in your credentials. - Swap
TestModelfor a real model (e.g.openai:gpt-4o) insrc/agent.pyand setOPENAI_API_KEY. - Run with gateway environment variables:
AGENT_ASSEMBLY_GATEWAY_URL=http://localhost:8080 \
AGENT_ASSEMBLY_API_KEY=your-key \
uv run python src/main.pyIn production, init_assembly() auto-detects Pydantic AI and registers the adapter automatically, and the gateway enforces the policy rules — replace LocalPolicyEngine with the gateway-backed interceptor.
| Problem | Fix |
|---|---|
ModuleNotFoundError: agent_assembly |
Run uv sync first |
ModuleNotFoundError: pydantic_ai |
Run uv sync — pydantic-ai is a required dependency |
| Governance hooks do not fire | Ensure pydantic-ai resolves to >=0.3.0 (or <0.3.0 for the legacy Tool._run path) |
PolicyViolationError in tests |
Expected — the deny/pending policy rules are intentional |