feat(examples): add Anthropic chat demo with UI-driven policy#220
Closed
karansohi wants to merge 1 commit into
Closed
feat(examples): add Anthropic chat demo with UI-driven policy#220karansohi wants to merge 1 commit into
karansohi wants to merge 1 commit into
Conversation
Minimal example: six prompts → Claude Sonnet (claude-sonnet-4-6 by default), with the call wrapped in @control. The agent is registered in code via agent_control.init(); the guardrail policy is created in the UI (http://localhost:4000) and bound to the agent. Use case: showcase that @control + a server-side policy can guardrail an existing LLM call with zero code changes once the agent is wired. The fourth prompt deliberately contains a fake SSN to exercise a PII rule once one is configured. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Summary
Stacked on top of #219. Adds a minimal example at
examples/anthropic_chat_demo/:claude-sonnet-4-6by default), one call per prompt@controlagent_control.init()setup_controls.py) — the demo's purpose is to show that once an agent is wired with@control, a UI-defined policy can guardrail it with zero code changesFour files:
pyproject.toml,demo.py,.env.example,README.md. Uses editable workspace deps for the SDK, models, engine, evaluators, and telemetry.How to demo
docker compose up -dfrom repo root with the override that addsui).cd examples/anthropic_chat_demo && cp .env.example .env, fill inANTHROPIC_API_KEY.uv run python demo.py— registers agentanthropic-chat-demo, runs through 6 prompts.anthropic-chat-demo(e.g. PII block — prompt feat(ui): Control Store Flow Updated #4 has a fake SSN).ControlViolationError.Test plan
cd examples/anthropic_chat_demo && uv syncresolves cleanlyuv run python -c "from agent_control import control, ControlViolationError; from anthropic import Anthropic"succeedsANTHROPIC_API_KEYset and no policy bound: all 6 prompts return Claude responsesControlViolationError; the other 5 still return responses🤖 Generated with Claude Code