feat: LLM chat backend with tool-use loop and AG-UI streaming#26
Draft
cdgaete wants to merge 7 commits into
Draft
feat: LLM chat backend with tool-use loop and AG-UI streaming#26cdgaete wants to merge 7 commits into
cdgaete wants to merge 7 commits into
Conversation
Codebase-only snapshot of dev-llm-implementation, prepared per the two-PR
strategy in .claude/project/main-pr-strategy.md. Tests, lockfiles, and
AI-context files are excluded; they ship in a stacked follow-up PR.
This PR contains:
- Backend: pypsa_app.llm module (service-architecture refactor + tools:
list_networks, get_network_detail, get_network_statistics), feature-flagged
via CHAT_ENABLED; LLMSettings extracted from backend.settings; provider-
agnostic client via LiteLLM with the openai/ prefix
- Frontend: Svelte chat panel built on AI Elements; modal UI with phase-
tagged tool calls inside Reasoning; NetworkCard/NetworksTable/Statistics/
ChatBar/Line/Pie/DataTable renderers; stick-to-bottom scroll, edit-and-
resend, copy actions; Tailwind typography
- Infra: SPA static file serving, alembic advisory lock, /version exposes
chat_enabled, compose + Dockerfile updates, sandcastle patch, seed data
- Docs: README + docs/configuration.md document the chat feature flag and
LLM env vars
Excludes (per main-pr-strategy.md):
- Category A — never on main: .claude/, .sandcastle/, CLAUDE.md, AGENTS.md
- Category B — split into follow-up PR: tests/, **/*.test.{ts,js},
vitest.config.*, uv.lock, package-lock.json, frontend/app/package-lock.json
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Remove files and references unrelated to the LLM chat MVP that leaked into the codebase-promotion PR: - delete seed.jsonl (private backlog dump) - delete patches/@ai-hero+sandcastle+0.5.7.patch (sandcastle-only) - delete root tsconfig.json (only typechecked .sandcastle/**) - package.json: drop sandcastle scripts + @ai-hero/sandcastle, patch-package, tsx devDeps (all sandcastle-only) - pyproject.toml: drop .sandcastle from ruff exclude Frontend continues to use frontend/app/tsconfig.json and its own package.json — root tooling was sandcastle-only. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Trim the M1 codebase promotion to only what the read-only chat MVP actually consumes: - Delete unused ai-elements subtrees: prompt-input/*, message/branching/*, message/attachments/*, MessageToolbar, MessageResponse. Verified zero consumers in src/lib/components/chat or src/routes. - Rewrite message/index.ts to export only Message / MessageContent / MessageActions / MessageAction. - Strip dead MessageBranchController / MessageAttachmentData from message-context.svelte.ts (only MessageRole is still consumed). - Rewrite CHANGELOG [Unreleased] to describe what the MVP actually ships: LiteLLM-backed chat, OpenAI-compatible LLM_* env vars, three read-only tools, and the supporting backend changes. The previous text referenced the Anthropic SDK and ANTHROPIC_* env names that the code no longer uses. - Patch README Quick Start to include LLM_PROVIDER and LLM_MODEL. Verified end-to-end in the dev stack: chat FAB renders, list_networks tool call and table render unchanged after the deletions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Remove three frontend artifacts not reached from the chat MVP path: button-group/, aspect-ratio/, and the app-navigation test stub. Tighten the CHANGELOG Added section to a concise summary. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Add llm/ package: LiteLLM client, chat service with tool-use loop, AG-UI SSE event streaming, system prompts - Add LLM tools: list_networks, get_network_detail, get_network_statistics - Add chat API routes (POST /chat/stream, GET /chat/health) - Add LLMSettings with provider-agnostic config (OpenRouter, Ollama, etc.) - Wire chat_enabled feature flag through version endpoint and schema - Add litellm dependency to pyproject.toml - Remove unused exception classes
89b5f84 to
375f07e
Compare
- Fix PERF401: replace .append loop with .extend in service.py - Apply ruff format to spa_static_files.py and tools/__init__.py - Add trailing newline to compose/.env.example - Default reasoning_effort to None (let provider decide) - Remove unused exception classes
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
Adds an LLM chat backend to pypsa-app with provider-agnostic configuration (OpenRouter, Ollama, or any OpenAI-compatible API).
What's included
llm/package: LiteLLM client, chat service with multi-step tool-use loop, AG-UI SSE event streaming, system promptslist_networks,get_network_detail,get_network_statisticsPOST /chat/stream(SSE),GET /chat/healthLLMSettings: provider-agnostic config via env vars (LLM_PROVIDER,LLM_API_KEY,LLM_API_BASE,LLM_MODEL)CHAT_ENABLEDwired through/versionendpointlitellm>=1.83added topyproject.tomlNot included (future PRs)