Repository navigation
feat(py): list an app's prompts with ai.list_prompts() - #139
Open
huangjeff5 wants to merge 3 commits into
Open
huangjeff5 wants to merge 3 commits into
huangjeff5 wants to merge 3 commits into
Conversation
ai.list_prompts() returns one Prompt handle per registered prompt, sorted by registered name: the same handle ai.prompt(name, variant=...) returns, so each entry can be called, rendered, or described. A variant is its own entry (greet.formal), a .prompt file in a subfolder keeps its folder (myns/a), and partials are not listed. Plugins start first, so a plugin whose init() fails makes it raise. Prompt gains a name property and an async describe() that returns a PromptDescription(name, description, input_schema). describe() loads the prompt first, including a .prompt file nothing has run, so every handle for the same prompt gives the same answer. An unknown name raises the same NOT_FOUND that calling the prompt raises. ai.list_tools() is covered by #92; this adds prompts only.
The registry is a dict, so registration order is already stable. Leave ordering unspecified rather than make sorted-by-name part of the API, matching the ask on list_tools() in #92.
This branch has not been 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.
You can now ask a Genkit app which prompts it has.
await ai.list_prompts()returns every prompt as the samePrompthandleai.prompt(name)gives you, so each entry can be called, rendered, or described.Promptalso gets anameand an asyncdescribe()that returns the prompt's description and input JSON schema.This is the core piece #96 needs to serve prompts over MCP:
prompts/listreadsdescribe(), andprompts/getreadsrender(). Tools are covered by #92 (ai.list_tools()), so this PR adds prompts only.Changes
Genkit.list_prompts() -> list[Prompt]: one handle per registered prompt. A variant is its own entry (greet.formal), a.promptfile in a subfolder keeps its folder (myns/a), and partials are not listed. Plugins start first, so if a plugin'sinit()fails this raises instead of returning a list that is missing that plugin's prompts.Prompt.name: the registered name, including variant and folder;Nonefor a prompt defined withoutname=.Prompt.ref['name']now reads from it.await Prompt.describe() -> PromptDescription: loads the prompt first if needed, including a.promptfile nothing has run yet. An unknown name raises the sameNOT_FOUNDGenkitErrorthat calling the prompt raises; an unnamed prompt raisesFAILED_PRECONDITION.PromptDescriptionexported fromgenkit: frozen, keyword-only dataclass withname,description,input_schema.Decisions
Prompt, not rawAction: users already know thePrompthandle fromdefine_prompt()andai.prompt(). AnActionwould expose plugin-API types onGenkitand couldn't generate when called. MCP needs onlydescribe()andrender(), both onPrompt.await describe(), not sync properties: a handle fromai.prompt('greet'), or a.promptfile nobody has run, has not loaded its definition yet. A syncp.descriptionwould returnNonefor a prompt that does have one.describe()loads first, so every handle for the same prompt gives the same answer.ai.list_tools()in feat(py): list an app's tools with ai.list_tools() #92 should follow the same rule.Breaking changes
None.