feat: add LLMRuntime for prompt and model routing - #1778
Draft
paul-paliychuk wants to merge 4 commits into
Draft
paul-paliychuk wants to merge 4 commits into
paul-paliychuk wants to merge 4 commits into
Conversation
Allow Graphiti callers to inject prompt libraries (or partial overrides via create_prompt_library) so prompt selection is per-client instead of process-global. Co-authored-by: Cursor <cursoragent@cursor.com>
…facade Replace Protocol/TypedDict prompt wrappers with ABC groups returning ChatPrompt, add fixed PromptSpec schemas, migrate maintenance LLM stitches through GraphitiClients.complete_prompt, and add opt-in PromptBoundLLM multi-model routing on a single provider transport. Co-authored-by: Cursor <cursoragent@cursor.com>
Replace PromptBoundLLM with an opt-in runtime that routes prompt text and model ids on one transport via generate_response(model=, small_model=), without cloning or mutating the client. Co-authored-by: Cursor <cursoragent@cursor.com>
This branch was successfully deployed
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
Graphiti(..., llm_runtime=)that couples oneLLMClienttransport with a required defaultLLMModel, optionalPromptRoutes, and optionalLLMPromptOverrides.model=/small_model=intogenerate_responsefor that call. The transport is never cloned or mutated. Omitting the new kwargs keeps today'sself.model/self.small_modelbehavior.Motivation / context
Ingest already builds prompts and calls the LLM in many places. Customers want (1) a few prompt rewrites, (2) cheaper/faster models on 1–2 prompts, and (3) existing provider subclasses — without a second Graphiti instance or a new client hierarchy. The legacy
llm_client=/prompt_library=path stays unchanged and is mutually exclusive withllm_runtime.Impact
LLMRuntime,LLMModel,PromptRoutes,LLMPromptOverrides. Nested dataclasses so unknown prompt names are constructor/type errors. No Graphiti nicknames — bindLLMModelinstances to local variables.generate_response(model=, small_model=)is keyword-only and optional. v1 is multi-model on one transport; a Claude id on an OpenAI client is unsupported. GLiNER2 native extraction cannot be routed per prompt.Testing
complete_promptfacade,PromptName, and per-callmodel=on OpenAI / generic / Anthropic / Gemini / base client.make lint(ruff + pyright) passed. Targeted pytest: 122 passed on the files above.make testagainst Neo4j, live provider integration tests.Risks / follow-ups
LLMClientsubclasses with the old_generate_responsesignature still work on the legacy path; using them insideLLMRuntimerequires accepting the new kwargs (or**kwargs).ModelSize.small(unchanged). Traces still recordmodel.size, not the resolved model id.LLMModelfields (temperature, structured output, …) are not wired yet. Cross-provider routing is out of scope for v1.Test plan
Graphiti(..., llm_runtime=runtime)and confirmllm_client/prompt_librarytogether raiseextract_nodes.extract_attributesto a second model id; confirm other prompts stay on the defaultsmall_idon the default model and confirmModelSize.smallstill uses the transportsmall_modelGraphiti(llm_client=..., prompt_library=...)callers are unchangedMade with Cursor