Add model backend selector and Claude Agent SDK runner#42
Closed
SakshiKekre wants to merge 1 commit into
Closed
Conversation
|
@SakshiKekre is attempting to deploy a commit to the PolicyEngine Team on Vercel. A member of the Team first needs to authorize it. |
Backends: uk_compiled (Rust) and uk_python (Python), selected per request or via POLICYENGINE_CHAT_BACKEND. Each controls its own prompt context, tool description, and execution globals. ChatPage exposes a toggle persisted in localStorage. /chat/backends lists what's available. Rebased onto main: keeps main's structural plan-mode enforcement and cached-reference cache breakpoints; backend prompt context is injected into the cached first block via a template placeholder. Claude Agent SDK runner is opt-in (POLICYENGINE_CHAT_AGENT_RUNNER=claude_sdk), mirrors the existing SSE event contract, exposes run_python via an in-process MCP tool. Also: modal_app installs from backend/requirements.txt, pins policyengine_uk==2.88.0, adds GA tracking. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
16ae68c to
9fd7354
Compare
Collaborator
Author
|
Superseded by #51 — moved to an origin branch ( |
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
/chat/backendsand a frontend Engine selector with backend package version displayrun_pythonexecution environments behind the backend registryPOLICYENGINE_CHAT_AGENT_RUNNER=claude_sdkrun_pythonto the SDK runner through an in-process MCP tool while preserving the existing frontend SSE event contractbackend/requirements.txtto avoid deployment dependency driftNotes
The existing direct Anthropic Messages loop remains the default unless
POLICYENGINE_CHAT_AGENT_RUNNER=claude_sdkis set. This lets us merge the backend selector work while keeping the SDK runner gated for comparison/testing.Validation
cd backend && ../.venv/bin/python -m py_compile routes/chatbot.py claude_agent_sdk_runner.py model_backends.py agent_tools.py ../modal_app.pycd backend && ../.venv/bin/python -m pytest tests/test_agent_tools.py tests/test_api.py::TestChatBackends::test_lists_backends tests/test_api.py::TestChatMessage::test_unknown_model_backend_returns_400cd frontend && npm run buildPOLICYENGINE_CHAT_AGENT_RUNNER=claude_sdk:chunkanddonetool_start,tool_use,tool_result, and finaldoneManual test
Default runner:
cd backend && set -a; source ../.env; set +a; ../.venv/bin/python -m uvicorn main:app --host 127.0.0.1 --port 8002SDK runner:
cd backend && set -a; source ../.env; set +a; POLICYENGINE_CHAT_AGENT_RUNNER=claude_sdk ../.venv/bin/python -m uvicorn main:app --host 127.0.0.1 --port 8001Frontend examples:
cd frontend && PORT=3001 BACKEND_URL=http://127.0.0.1:8002 npm run devfor default runnercd frontend && BACKEND_URL=http://127.0.0.1:8001 npm run devfor SDK runner