Skip to content

feat(examples): add Anthropic chat demo with UI-driven policy#220

Closed
karansohi wants to merge 1 commit into
fix/langchain-example-missing-telemetry-depfrom
feat/examples-anthropic-chat-demo
Closed

feat(examples): add Anthropic chat demo with UI-driven policy#220
karansohi wants to merge 1 commit into
fix/langchain-example-missing-telemetry-depfrom
feat/examples-anthropic-chat-demo

Conversation

@karansohi
Copy link
Copy Markdown
Collaborator

Summary

Stacked on top of #219. Adds a minimal example at examples/anthropic_chat_demo/:

  • Six prompts → Claude Sonnet (claude-sonnet-4-6 by default), one call per prompt
  • The Anthropic call is wrapped in @control
  • Agent is registered from code via agent_control.init()
  • Policy is created in the UI (no 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 changes

Four files: pyproject.toml, demo.py, .env.example, README.md. Uses editable workspace deps for the SDK, models, engine, evaluators, and telemetry.

How to demo

  1. Have the server + UI running (e.g. docker compose up -d from repo root with the override that adds ui).
  2. cd examples/anthropic_chat_demo && cp .env.example .env, fill in ANTHROPIC_API_KEY.
  3. uv run python demo.py — registers agent anthropic-chat-demo, runs through 6 prompts.
  4. In the UI at http://localhost:4000, attach a policy to anthropic-chat-demo (e.g. PII block — prompt feat(ui): Control Store Flow Updated #4 has a fake SSN).
  5. Re-run; blocked prompts surface as ControlViolationError.

Test plan

  • cd examples/anthropic_chat_demo && uv sync resolves cleanly
  • uv run python -c "from agent_control import control, ControlViolationError; from anthropic import Anthropic" succeeds
  • With ANTHROPIC_API_KEY set and no policy bound: all 6 prompts return Claude responses
  • After binding a PII-block policy in the UI: prompt feat(ui): Control Store Flow Updated #4 is blocked with ControlViolationError; the other 5 still return responses

🤖 Generated with Claude Code

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>
@karansohi karansohi marked this pull request as draft May 11, 2026 23:07
@karansohi karansohi closed this May 11, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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