-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[WIP] Allow customization of all hard coded strings sent to the model #3656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
adtyavrdhn
wants to merge
79
commits into
pydantic:main
Choose a base branch
from
adtyavrdhn:custom_model_prompt_templates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
[WIP] Allow customization of all hard coded strings sent to the model #3656
adtyavrdhn
wants to merge
79
commits into
pydantic:main
from
adtyavrdhn:custom_model_prompt_templates
+1,442
−69
Conversation
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
…ustom_model_prompt_templates
Contributor
Author
|
Moving to draft, more of a WIP because I have to figure out how to keep it extendible for prompt optimizers use and how to make instructions, tool desc etc also overridable(if not in this PR then at least provide the interface and arch for it) |
…dd on ToolConfig as well on top of it wip
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.
Closes #3566
Add Customizable Prompt Configuration via PromptConfig
This PR introduces
PromptConfig, a new configuration system for customizing all system-generated messages and tool metadata that PydanticAI sends to models. This provides a clean, extensible interface for overriding any text the framework injects into conversations.PromptConfig Overview
PromptConfigserves as the central configuration class with two components:PromptTemplates: Customizes system-generated messages (retry prompts, tool return confirmations, validation errors, etc.)ToolConfig: Customizes tool metadata (currently supportstool_descriptions, with plans to add tool argument customization)PromptTemplates
Allows customization of system-injected messages. Each template can be either:
(part, RunContext) -> strfor dynamic, context-aware messagesAvailable template fields:
final_result_processedoutput_tool_not_executedfunction_tool_not_executedtool_call_deniedvalidation_errors_retrymodel_retry_string_toolModelRetryis raised from a toolmodel_retry_string_no_toolModelRetryis raised outside of a tool contextToolConfig
Allows overriding tool descriptions at runtime without modifying the original tool definitions. This is useful for providing different descriptions in different contexts or agent runs.
Future plans: Add support for customizing tool argument descriptions.
Integration Points
The
prompt_configparameter is integrated throughout the agent system:Agent(..., prompt_config=...)agent.run(..., prompt_config=...)— allows per-run overridesrun(),run_sync(),run_stream(),run_stream_events(),iter()agent.override(prompt_config=...)Templates are applied right before messages are sent to the model.
Additional Change:
return_kindfield onToolReturnPartAdded a new
return_kindfield toToolReturnPartthat provides contextual visibility into how a tool call was resolved:'tool-executed''final-result-processed''output-tool-not-executed''function-tool-not-executed''tool-denied'This field enables
PromptTemplatesto apply the appropriate template based on the tool return context, and provides useful debugging information when inspecting message history.