Skip to content

Add model backend selector and Claude Agent SDK runner#42

Open
SakshiKekre wants to merge 13 commits intoPolicyEngine:mainfrom
SakshiKekre:codex/claude-agent-sdk-spike
Open

Add model backend selector and Claude Agent SDK runner#42
SakshiKekre wants to merge 13 commits intoPolicyEngine:mainfrom
SakshiKekre:codex/claude-agent-sdk-spike

Conversation

@SakshiKekre
Copy link
Copy Markdown

@SakshiKekre SakshiKekre commented May 6, 2026

Summary

  • Adds a model backend abstraction for chat simulations with selectable UK compiled and UK Python backends
  • Adds /chat/backends and a frontend Engine selector with backend package version display
  • Keeps backend-specific prompts, tool descriptions, imports, and run_python execution environments behind the backend registry
  • Adds an opt-in Claude Agent SDK runner behind POLICYENGINE_CHAT_AGENT_RUNNER=claude_sdk
  • Exposes run_python to the SDK runner through an in-process MCP tool while preserving the existing frontend SSE event contract
  • Adds Plan mode support so the next turn can ask clarifying questions before running tools
  • Makes Modal install backend dependencies from backend/requirements.txt to avoid deployment dependency drift

Notes

The existing direct Anthropic Messages loop remains the default unless POLICYENGINE_CHAT_AGENT_RUNNER=claude_sdk is 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.py
  • cd 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_400
  • cd frontend && npm run build
  • Local SDK smoke tests with POLICYENGINE_CHAT_AGENT_RUNNER=claude_sdk:
    • simple text streaming returned chunk and done
    • Plan mode asked clarifying questions without running tools
    • tool-use prompt emitted tool_start, tool_use, tool_result, and final done

Manual test

Default runner:
cd backend && set -a; source ../.env; set +a; ../.venv/bin/python -m uvicorn main:app --host 127.0.0.1 --port 8002

SDK 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 8001

Frontend examples:

  • cd frontend && PORT=3001 BACKEND_URL=http://127.0.0.1:8002 npm run dev for default runner
  • cd frontend && BACKEND_URL=http://127.0.0.1:8001 npm run dev for SDK runner

@vercel
Copy link
Copy Markdown

vercel Bot commented May 6, 2026

@SakshiKekre is attempting to deploy a commit to the PolicyEngine Team on Vercel.

A member of the Team first needs to authorize it.

@SakshiKekre SakshiKekre changed the title Spike Claude Agent SDK chat runner Add model backend selector and Claude Agent SDK runner May 7, 2026
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