diff --git a/docs/api/models/test.md b/docs/api/models/test.md index cb41550efd..4e23524ed6 100644 --- a/docs/api/models/test.md +++ b/docs/api/models/test.md @@ -8,7 +8,7 @@ Here's a minimal example: from pydantic_ai import Agent from pydantic_ai.models.test import TestModel -my_agent = Agent('openai:gpt-5', system_prompt='...') +my_agent = Agent('openai:gpt-5', instructions='...') async def test_my_agent(): diff --git a/docs/common-tools.md b/docs/common-tools.md index 78baaaad02..539d2b5a5d 100644 --- a/docs/common-tools.md +++ b/docs/common-tools.md @@ -27,7 +27,7 @@ from pydantic_ai.common_tools.duckduckgo import duckduckgo_search_tool agent = Agent( 'openai:o3-mini', tools=[duckduckgo_search_tool()], - system_prompt='Search DuckDuckGo for the given query and return the results.', + instructions='Search DuckDuckGo for the given query and return the results.', ) result = agent.run_sync( @@ -115,7 +115,7 @@ assert api_key is not None agent = Agent( 'openai:o3-mini', tools=[tavily_search_tool(api_key)], - system_prompt='Search Tavily for the given query and return the results.', + instructions='Search Tavily for the given query and return the results.', ) result = agent.run_sync('Tell me the top news in the GenAI world, give me links.') diff --git a/docs/evals/evaluators/llm-judge.md b/docs/evals/evaluators/llm-judge.md index 7c70f6335b..2f95c4bf03 100644 --- a/docs/evals/evaluators/llm-judge.md +++ b/docs/evals/evaluators/llm-judge.md @@ -302,7 +302,7 @@ class Recipe(BaseModel): recipe_agent = Agent( 'openai:gpt-5-mini', output_type=Recipe, - system_prompt=( + instructions=( 'Generate a recipe to cook the dish that meets the dietary restrictions.' ), ) diff --git a/docs/evals/how-to/metrics-attributes.md b/docs/evals/how-to/metrics-attributes.md index 213edfcc84..de82ffdd7e 100644 --- a/docs/evals/how-to/metrics-attributes.md +++ b/docs/evals/how-to/metrics-attributes.md @@ -525,9 +525,9 @@ from pydantic_evals import Case, Dataset # Module constants as single source of truth MODEL_NAME = 'openai:gpt-5-mini' TEMPERATURE = 0.7 -SYSTEM_PROMPT = 'You are a helpful assistant.' +INSTRUCTIONS = 'You are a helpful assistant.' -agent = Agent(MODEL_NAME, model_settings={'temperature': TEMPERATURE}, system_prompt=SYSTEM_PROMPT) +agent = Agent(MODEL_NAME, model_settings={'temperature': TEMPERATURE}, instructions=INSTRUCTIONS) async def task(inputs: str) -> str: @@ -544,7 +544,7 @@ async def main(): metadata={ 'model': MODEL_NAME, 'temperature': TEMPERATURE, - 'system_prompt': SYSTEM_PROMPT, + 'instructions': INSTRUCTIONS, }, ) ``` diff --git a/docs/graph.md b/docs/graph.md index 9bbe3bb011..d6616bcb90 100644 --- a/docs/graph.md +++ b/docs/graph.md @@ -385,7 +385,7 @@ class State: email_writer_agent = Agent( 'google-gla:gemini-2.5-pro', output_type=Email, - system_prompt='Write a welcome email to our tech blog.', + instructions='Write a welcome email to our tech blog.', ) @@ -425,7 +425,7 @@ class EmailOk(BaseModel): feedback_agent = Agent[None, EmailRequiresWrite | EmailOk]( 'openai:gpt-5', output_type=EmailRequiresWrite | EmailOk, # type: ignore - system_prompt=( + instructions=( 'Review the email and provide feedback, email must reference the users specific interests.' ), ) @@ -708,7 +708,7 @@ class EvaluationResult(BaseModel, use_attribute_docstrings=True): evaluate_agent = Agent( 'openai:gpt-5', output_type=EvaluationResult, - system_prompt='Given a question and answer, evaluate if the answer is correct.', + instructions='Given a question and answer, evaluate if the answer is correct.', ) @@ -951,7 +951,7 @@ class EvaluationResult(BaseModel, use_attribute_docstrings=True): evaluate_agent = Agent( 'openai:gpt-5', output_type=EvaluationResult, - system_prompt='Given a question and answer, evaluate if the answer is correct.', + instructions='Given a question and answer, evaluate if the answer is correct.', ) diff --git a/docs/index.md b/docs/index.md index 6ca676faf5..e8423db80e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -204,7 +204,7 @@ support_agent = Agent( 'openai:gpt-5', deps_type=SupportDependencies, output_type=SupportOutput, - system_prompt=( + instructions=( 'You are a support agent in our bank, give the ' 'customer support and judge the risk level of their query.' ), diff --git a/docs/mcp/server.md b/docs/mcp/server.md index 2d88aa0168..b1103c4ae9 100644 --- a/docs/mcp/server.md +++ b/docs/mcp/server.md @@ -13,7 +13,7 @@ from pydantic_ai import Agent server = FastMCP('Pydantic AI Server') server_agent = Agent( - 'anthropic:claude-haiku-4-5', system_prompt='always reply in rhyme' + 'anthropic:claude-haiku-4-5', instructions='always reply in rhyme' ) @@ -77,7 +77,7 @@ from pydantic_ai import Agent from pydantic_ai.models.mcp_sampling import MCPSamplingModel server = FastMCP('Pydantic AI Server with sampling') -server_agent = Agent(system_prompt='always reply in rhyme') +server_agent = Agent(instructions='always reply in rhyme') @server.tool() diff --git a/docs/message-history.md b/docs/message-history.md index 3363312fed..fcdbbd3dad 100644 --- a/docs/message-history.md +++ b/docs/message-history.md @@ -30,7 +30,7 @@ Example of accessing methods on a [`RunResult`][pydantic_ai.agent.AgentRunResult ```python {title="run_result_messages.py" hl_lines="10"} from pydantic_ai import Agent -agent = Agent('openai:gpt-5', system_prompt='Be a helpful assistant.') +agent = Agent('openai:gpt-5', instructions='Be a helpful assistant.') result = agent.run_sync('Tell me a joke.') print(result.output) @@ -42,15 +42,12 @@ print(result.all_messages()) [ ModelRequest( parts=[ - SystemPromptPart( - content='Be a helpful assistant.', - timestamp=datetime.datetime(...), - ), UserPromptPart( content='Tell me a joke.', timestamp=datetime.datetime(...), - ), + ) ], + instructions='Be a helpful assistant.', run_id='...', ), ModelResponse( @@ -59,7 +56,7 @@ print(result.all_messages()) content='Did you hear about the toothpaste scandal? They called it Colgate.' ) ], - usage=RequestUsage(input_tokens=60, output_tokens=12), + usage=RequestUsage(input_tokens=55, output_tokens=12), model_name='gpt-5', timestamp=datetime.datetime(...), run_id='...', @@ -75,7 +72,7 @@ Example of accessing methods on a [`StreamedRunResult`][pydantic_ai.result.Strea ```python {title="streamed_run_result_messages.py" hl_lines="9 40"} from pydantic_ai import Agent -agent = Agent('openai:gpt-5', system_prompt='Be a helpful assistant.') +agent = Agent('openai:gpt-5', instructions='Be a helpful assistant.') async def main(): @@ -86,15 +83,12 @@ async def main(): [ ModelRequest( parts=[ - SystemPromptPart( - content='Be a helpful assistant.', - timestamp=datetime.datetime(...), - ), UserPromptPart( content='Tell me a joke.', timestamp=datetime.datetime(...), - ), + ) ], + instructions='Be a helpful assistant.', run_id='...', ) ] @@ -113,15 +107,12 @@ async def main(): [ ModelRequest( parts=[ - SystemPromptPart( - content='Be a helpful assistant.', - timestamp=datetime.datetime(...), - ), UserPromptPart( content='Tell me a joke.', timestamp=datetime.datetime(...), - ), + ) ], + instructions='Be a helpful assistant.', run_id='...', ), ModelResponse( @@ -154,7 +145,7 @@ If `message_history` is set and not empty, a new system prompt is not generated ```python {title="Reusing messages in a conversation" hl_lines="9 13"} from pydantic_ai import Agent -agent = Agent('openai:gpt-5', system_prompt='Be a helpful assistant.') +agent = Agent('openai:gpt-5', instructions='Be a helpful assistant.') result1 = agent.run_sync('Tell me a joke.') print(result1.output) @@ -169,15 +160,12 @@ print(result2.all_messages()) [ ModelRequest( parts=[ - SystemPromptPart( - content='Be a helpful assistant.', - timestamp=datetime.datetime(...), - ), UserPromptPart( content='Tell me a joke.', timestamp=datetime.datetime(...), - ), + ) ], + instructions='Be a helpful assistant.', run_id='...', ), ModelResponse( @@ -186,7 +174,7 @@ print(result2.all_messages()) content='Did you hear about the toothpaste scandal? They called it Colgate.' ) ], - usage=RequestUsage(input_tokens=60, output_tokens=12), + usage=RequestUsage(input_tokens=55, output_tokens=12), model_name='gpt-5', timestamp=datetime.datetime(...), run_id='...', @@ -198,6 +186,7 @@ print(result2.all_messages()) timestamp=datetime.datetime(...), ) ], + instructions='Be a helpful assistant.', run_id='...', ), ModelResponse( @@ -206,7 +195,7 @@ print(result2.all_messages()) content='This is an excellent joke invented by Samuel Colvin, it needs no explanation.' ) ], - usage=RequestUsage(input_tokens=61, output_tokens=26), + usage=RequestUsage(input_tokens=56, output_tokens=26), model_name='gpt-5', timestamp=datetime.datetime(...), run_id='...', @@ -235,7 +224,7 @@ from pydantic_ai import ( ModelMessagesTypeAdapter, # (1)! ) -agent = Agent('openai:gpt-5', system_prompt='Be a helpful assistant.') +agent = Agent('openai:gpt-5', instructions='Be a helpful assistant.') result1 = agent.run_sync('Tell me a joke.') history_step_1 = result1.all_messages() @@ -275,7 +264,7 @@ In the example below, we reuse the message from the first agent run, which uses ```python {title="Reusing messages with a different model" hl_lines="17"} from pydantic_ai import Agent -agent = Agent('openai:gpt-5', system_prompt='Be a helpful assistant.') +agent = Agent('openai:gpt-5', instructions='Be a helpful assistant.') result1 = agent.run_sync('Tell me a joke.') print(result1.output) @@ -294,15 +283,12 @@ print(result2.all_messages()) [ ModelRequest( parts=[ - SystemPromptPart( - content='Be a helpful assistant.', - timestamp=datetime.datetime(...), - ), UserPromptPart( content='Tell me a joke.', timestamp=datetime.datetime(...), - ), + ) ], + instructions='Be a helpful assistant.', run_id='...', ), ModelResponse( @@ -311,7 +297,7 @@ print(result2.all_messages()) content='Did you hear about the toothpaste scandal? They called it Colgate.' ) ], - usage=RequestUsage(input_tokens=60, output_tokens=12), + usage=RequestUsage(input_tokens=55, output_tokens=12), model_name='gpt-5', timestamp=datetime.datetime(...), run_id='...', @@ -323,6 +309,7 @@ print(result2.all_messages()) timestamp=datetime.datetime(...), ) ], + instructions='Be a helpful assistant.', run_id='...', ), ModelResponse( @@ -331,7 +318,7 @@ print(result2.all_messages()) content='This is an excellent joke invented by Samuel Colvin, it needs no explanation.' ) ], - usage=RequestUsage(input_tokens=61, output_tokens=26), + usage=RequestUsage(input_tokens=56, output_tokens=26), model_name='gemini-2.5-pro', timestamp=datetime.datetime(...), run_id='...', diff --git a/docs/models/anthropic.md b/docs/models/anthropic.md index 81ed245de6..be48092cb4 100644 --- a/docs/models/anthropic.md +++ b/docs/models/anthropic.md @@ -100,7 +100,7 @@ from pydantic_ai.models.anthropic import AnthropicModelSettings agent = Agent( 'anthropic:claude-sonnet-4-5', - system_prompt='You are a helpful assistant.', + instructions='You are a helpful assistant.', model_settings=AnthropicModelSettings( anthropic_cache_messages=True, # Automatically caches the last message ), @@ -125,7 +125,7 @@ from pydantic_ai.models.anthropic import AnthropicModelSettings agent = Agent( 'anthropic:claude-sonnet-4-5', - system_prompt='Detailed instructions...', + instructions='Detailed instructions...', model_settings=AnthropicModelSettings( anthropic_cache_instructions=True, # Cache system instructions anthropic_cache_tool_definitions='1h', # Cache tool definitions with 1h TTL @@ -152,7 +152,7 @@ from pydantic_ai import Agent, CachePoint agent = Agent( 'anthropic:claude-sonnet-4-5', - system_prompt='Instructions...', + instructions='Instructions...', ) # Manually control cache points for specific content blocks @@ -174,7 +174,7 @@ from pydantic_ai.models.anthropic import AnthropicModelSettings agent = Agent( 'anthropic:claude-sonnet-4-5', - system_prompt='Instructions...', + instructions='Instructions...', model_settings=AnthropicModelSettings( anthropic_cache_instructions=True # Default 5m TTL ), @@ -210,7 +210,7 @@ from pydantic_ai.models.anthropic import AnthropicModelSettings agent = Agent( 'anthropic:claude-sonnet-4-5', - system_prompt='Detailed instructions...', + instructions='Detailed instructions...', model_settings=AnthropicModelSettings( anthropic_cache_instructions=True, # 1 cache point anthropic_cache_tool_definitions=True, # 1 cache point @@ -247,7 +247,7 @@ from pydantic_ai.models.anthropic import AnthropicModelSettings agent = Agent( 'anthropic:claude-sonnet-4-5', - system_prompt='Instructions...', + instructions='Instructions...', model_settings=AnthropicModelSettings( anthropic_cache_instructions=True, # 1 cache point anthropic_cache_tool_definitions=True, # 1 cache point diff --git a/docs/multi-agent-applications.md b/docs/multi-agent-applications.md index 8b95011345..3039f883d6 100644 --- a/docs/multi-agent-applications.md +++ b/docs/multi-agent-applications.md @@ -26,7 +26,7 @@ from pydantic_ai import Agent, RunContext, UsageLimits joke_selection_agent = Agent( # (1)! 'openai:gpt-5', - system_prompt=( + instructions=( 'Use the `joke_factory` to generate some jokes, then choose the best. ' 'You must return just a single joke.' ), @@ -52,7 +52,7 @@ result = joke_selection_agent.run_sync( print(result.output) #> Did you hear about the toothpaste scandal? They called it Colgate. print(result.usage()) -#> RunUsage(input_tokens=204, output_tokens=24, requests=3, tool_calls=1) +#> RunUsage(input_tokens=166, output_tokens=24, requests=3, tool_calls=1) ``` 1. The "parent" or controlling agent. @@ -99,7 +99,7 @@ class ClientAndKey: # (1)! joke_selection_agent = Agent( 'openai:gpt-5', deps_type=ClientAndKey, # (2)! - system_prompt=( + instructions=( 'Use the `joke_factory` tool to generate some jokes on the given subject, ' 'then choose the best. You must return just a single joke.' ), @@ -108,7 +108,7 @@ joke_generation_agent = Agent( 'google-gla:gemini-2.5-flash', deps_type=ClientAndKey, # (4)! output_type=list[str], - system_prompt=( + instructions=( 'Use the "get_jokes" tool to get some jokes on the given subject, ' 'then extract each joke into a list.' ), @@ -143,7 +143,7 @@ async def main(): print(result.output) #> Did you hear about the toothpaste scandal? They called it Colgate. print(result.usage()) # (6)! - #> RunUsage(input_tokens=309, output_tokens=32, requests=4, tool_calls=2) + #> RunUsage(input_tokens=221, output_tokens=32, requests=4, tool_calls=2) ``` 1. Define a dataclass to hold the client and API key dependencies. @@ -199,7 +199,7 @@ class Failed(BaseModel): flight_search_agent = Agent[None, FlightDetails | Failed]( # (1)! 'openai:gpt-5', output_type=FlightDetails | Failed, # type: ignore - system_prompt=( + instructions=( 'Use the "flight_search" tool to find a flight ' 'from the given origin to the given destination.' ), @@ -247,7 +247,7 @@ class SeatPreference(BaseModel): seat_preference_agent = Agent[None, SeatPreference | Failed]( # (5)! 'openai:gpt-5', output_type=SeatPreference | Failed, # type: ignore - system_prompt=( + instructions=( "Extract the user's seat preference. " 'Seats A and F are window seats. ' 'Row 1 is the front row and has extra leg room. ' diff --git a/docs/output.md b/docs/output.md index b2f786ef8a..e36c44c1bc 100644 --- a/docs/output.md +++ b/docs/output.md @@ -72,7 +72,7 @@ class Box(BaseModel): agent = Agent( 'openai:gpt-5-mini', output_type=[Box, str], # (1)! - system_prompt=( + instructions=( "Extract me the dimensions of a box, " "if you can't extract all data, ask the user to try again." ), @@ -99,7 +99,7 @@ from pydantic_ai import Agent agent = Agent[None, list[str] | list[int]]( 'openai:gpt-5-mini', output_type=list[str] | list[int], # type: ignore # (1)! - system_prompt='Extract either colors or sizes from the shapes provided.', + instructions='Extract either colors or sizes from the shapes provided.', ) result = agent.run_sync('red square, blue circle, green triangle') @@ -501,7 +501,7 @@ agent = Agent[DatabaseConn, Output]( 'google-gla:gemini-2.5-flash', output_type=Output, # type: ignore deps_type=DatabaseConn, - system_prompt='Generate PostgreSQL flavored SQL queries based on user input.', + instructions='Generate PostgreSQL flavored SQL queries based on user input.', ) @@ -689,7 +689,7 @@ class UserProfile(TypedDict): agent = Agent( 'openai:gpt-5', output_type=UserProfile, - system_prompt='Extract a user profile from the input', + instructions='Extract a user profile from the input', ) diff --git a/docs/testing.md b/docs/testing.md index 3089585ab0..66d660cd85 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -39,7 +39,7 @@ from weather_service import WeatherService # (2)! weather_agent = Agent( 'openai:gpt-5', deps_type=WeatherService, - system_prompt='Providing a weather forecast at the locations the user provides.', + instructions='Providing a weather forecast at the locations the user provides.', ) @@ -90,7 +90,6 @@ from pydantic_ai import models, capture_run_messages, RequestUsage from pydantic_ai.models.test import TestModel from pydantic_ai import ( ModelResponse, - SystemPromptPart, TextPart, ToolCallPart, ToolReturnPart, @@ -119,15 +118,12 @@ async def test_forecast(): assert messages == [ # (6)! ModelRequest( parts=[ - SystemPromptPart( - content='Providing a weather forecast at the locations the user provides.', - timestamp=IsNow(tz=timezone.utc), - ), UserPromptPart( content='What will the weather be like in London on 2024-11-28?', timestamp=IsNow(tz=timezone.utc), # (7)! ), ], + instructions='Providing a weather forecast at the locations the user provides.', run_id=IsStr(), ), ModelResponse( @@ -142,7 +138,7 @@ async def test_forecast(): ) ], usage=RequestUsage( - input_tokens=71, + input_tokens=60, output_tokens=7, ), model_name='test', @@ -158,6 +154,7 @@ async def test_forecast(): timestamp=IsNow(tz=timezone.utc), ), ], + instructions='Providing a weather forecast at the locations the user provides.', run_id=IsStr(), ), ModelResponse( @@ -167,7 +164,7 @@ async def test_forecast(): ) ], usage=RequestUsage( - input_tokens=77, + input_tokens=66, output_tokens=16, ), model_name='test', diff --git a/docs/tools.md b/docs/tools.md index 40dcf5c810..8e553d4cb8 100644 --- a/docs/tools.md +++ b/docs/tools.md @@ -36,7 +36,7 @@ from pydantic_ai import Agent, RunContext agent = Agent( 'google-gla:gemini-2.5-flash', # (1)! deps_type=str, # (2)! - system_prompt=( + instructions=( "You're a dice game, you should roll the die and see if the number " "you get back matches the user's guess. If so, tell them they're a winner. " "Use the player's name in the response." @@ -79,15 +79,12 @@ print(dice_result.all_messages()) [ ModelRequest( parts=[ - SystemPromptPart( - content="You're a dice game, you should roll the die and see if the number you get back matches the user's guess. If so, tell them they're a winner. Use the player's name in the response.", - timestamp=datetime.datetime(...), - ), UserPromptPart( content='My guess is 4', timestamp=datetime.datetime(...), - ), + ) ], + instructions="You're a dice game, you should roll the die and see if the number you get back matches the user's guess. If so, tell them they're a winner. Use the player's name in the response.", run_id='...', ), ModelResponse( @@ -96,7 +93,7 @@ print(dice_result.all_messages()) tool_name='roll_dice', args={}, tool_call_id='pyd_ai_tool_call_id' ) ], - usage=RequestUsage(input_tokens=90, output_tokens=2), + usage=RequestUsage(input_tokens=54, output_tokens=2), model_name='gemini-2.5-flash', timestamp=datetime.datetime(...), run_id='...', @@ -110,6 +107,7 @@ print(dice_result.all_messages()) timestamp=datetime.datetime(...), ) ], + instructions="You're a dice game, you should roll the die and see if the number you get back matches the user's guess. If so, tell them they're a winner. Use the player's name in the response.", run_id='...', ), ModelResponse( @@ -118,7 +116,7 @@ print(dice_result.all_messages()) tool_name='get_player_name', args={}, tool_call_id='pyd_ai_tool_call_id' ) ], - usage=RequestUsage(input_tokens=91, output_tokens=4), + usage=RequestUsage(input_tokens=55, output_tokens=4), model_name='gemini-2.5-flash', timestamp=datetime.datetime(...), run_id='...', @@ -132,6 +130,7 @@ print(dice_result.all_messages()) timestamp=datetime.datetime(...), ) ], + instructions="You're a dice game, you should roll the die and see if the number you get back matches the user's guess. If so, tell them they're a winner. Use the player's name in the response.", run_id='...', ), ModelResponse( @@ -140,7 +139,7 @@ print(dice_result.all_messages()) content="Congratulations Anne, you guessed correctly! You're a winner!" ) ], - usage=RequestUsage(input_tokens=92, output_tokens=12), + usage=RequestUsage(input_tokens=56, output_tokens=12), model_name='gemini-2.5-flash', timestamp=datetime.datetime(...), run_id='...', @@ -194,7 +193,7 @@ import random from pydantic_ai import Agent, RunContext, Tool -system_prompt = """\ +instructions = """\ You're a dice game, you should roll the die and see if the number you get back matches the user's guess. If so, tell them they're a winner. Use the player's name in the response. @@ -215,7 +214,7 @@ agent_a = Agent( 'google-gla:gemini-2.5-flash', deps_type=str, tools=[roll_dice, get_player_name], # (1)! - system_prompt=system_prompt, + instructions=instructions, ) agent_b = Agent( 'google-gla:gemini-2.5-flash', @@ -224,7 +223,7 @@ agent_b = Agent( Tool(roll_dice, takes_ctx=False), Tool(get_player_name, takes_ctx=True), ], - system_prompt=system_prompt, + instructions=instructions, ) dice_result = {} diff --git a/tests/models/test_anthropic.py b/tests/models/test_anthropic.py index 95fb44c502..808cfad218 100644 --- a/tests/models/test_anthropic.py +++ b/tests/models/test_anthropic.py @@ -1107,7 +1107,7 @@ async def test_request_tool_call(allow_model_requests: None): mock_client = MockAnthropic.create_mock(responses) m = AnthropicModel('claude-haiku-4-5', provider=AnthropicProvider(anthropic_client=mock_client)) - agent = Agent(m, system_prompt='this is the system prompt') + agent = Agent(m, instructions='this is the system prompt') @agent.tool_plain async def get_location(loc_name: str) -> str: @@ -1122,9 +1122,9 @@ async def get_location(loc_name: str) -> str: [ ModelRequest( parts=[ - SystemPromptPart(content='this is the system prompt', timestamp=IsNow(tz=timezone.utc)), UserPromptPart(content='hello', timestamp=IsNow(tz=timezone.utc)), ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( @@ -1153,6 +1153,7 @@ async def get_location(loc_name: str) -> str: timestamp=IsNow(tz=timezone.utc), ) ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( @@ -1181,6 +1182,7 @@ async def get_location(loc_name: str) -> str: timestamp=IsNow(tz=timezone.utc), ) ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( @@ -2123,22 +2125,19 @@ async def test_anthropic_model_thinking_part_from_other_model( provider = OpenAIProvider(api_key=openai_api_key) m = OpenAIResponsesModel('gpt-5', provider=provider) settings = OpenAIResponsesModelSettings(openai_reasoning_effort='high', openai_reasoning_summary='detailed') - agent = Agent(m, system_prompt='You are a helpful assistant.', model_settings=settings) + agent = Agent(m, instructions='You are a helpful assistant.', model_settings=settings) result = await agent.run('How do I cross the street?') assert result.all_messages() == snapshot( [ ModelRequest( parts=[ - SystemPromptPart( - content='You are a helpful assistant.', - timestamp=IsDatetime(), - ), UserPromptPart( content='How do I cross the street?', timestamp=IsDatetime(), ), ], + instructions='You are a helpful assistant.', run_id=IsStr(), ), ModelResponse( @@ -2201,6 +2200,7 @@ async def test_anthropic_model_thinking_part_from_other_model( timestamp=IsDatetime(), ) ], + instructions='You are a helpful assistant.', run_id=IsStr(), ), ModelResponse( diff --git a/tests/models/test_bedrock.py b/tests/models/test_bedrock.py index ceb0e76680..c5f68de797 100644 --- a/tests/models/test_bedrock.py +++ b/tests/models/test_bedrock.py @@ -268,7 +268,7 @@ def test_remove_inference_geo_prefix(model_name: str, expected: str): async def test_bedrock_model_structured_output(allow_model_requests: None, bedrock_provider: BedrockProvider): model = BedrockConverseModel('us.amazon.nova-micro-v1:0', provider=bedrock_provider) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.', retries=5) + agent = Agent(model=model, instructions='You are a helpful chatbot.', retries=5) class Response(TypedDict): temperature: str @@ -295,15 +295,12 @@ async def temperature(city: str, date: datetime.date) -> str: [ ModelRequest( parts=[ - SystemPromptPart( - content='You are a helpful chatbot.', - timestamp=IsDatetime(), - ), UserPromptPart( content='What was the temperature in London 1st January 2022?', timestamp=IsDatetime(), ), ], + instructions='You are a helpful chatbot.', run_id=IsStr(), ), ModelResponse( @@ -334,6 +331,7 @@ async def temperature(city: str, date: datetime.date) -> str: timestamp=IsDatetime(), ) ], + instructions='You are a helpful chatbot.', run_id=IsStr(), ), ModelResponse( @@ -372,7 +370,7 @@ async def temperature(city: str, date: datetime.date) -> str: async def test_bedrock_model_stream(allow_model_requests: None, bedrock_provider: BedrockProvider): model = BedrockConverseModel('us.amazon.nova-micro-v1:0', provider=bedrock_provider) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.', model_settings={'temperature': 0.0}) + agent = Agent(model=model, instructions='You are a helpful chatbot.', model_settings={'temperature': 0.0}) async with agent.run_stream('What is the capital of France?') as result: data = await result.get_output() assert data == snapshot( @@ -382,7 +380,7 @@ async def test_bedrock_model_stream(allow_model_requests: None, bedrock_provider async def test_bedrock_model_anthropic_model_with_tools(allow_model_requests: None, bedrock_provider: BedrockProvider): model = BedrockConverseModel('anthropic.claude-v2', provider=bedrock_provider) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.', model_settings={'temperature': 0.0}) + agent = Agent(model=model, instructions='You are a helpful chatbot.', model_settings={'temperature': 0.0}) @agent.tool_plain async def get_current_temperature(city: str) -> str: @@ -406,7 +404,7 @@ async def test_bedrock_model_anthropic_model_without_tools( allow_model_requests: None, bedrock_provider: BedrockProvider ): model = BedrockConverseModel('anthropic.claude-v2', provider=bedrock_provider) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.', model_settings={'temperature': 0.0}) + agent = Agent(model=model, instructions='You are a helpful chatbot.', model_settings={'temperature': 0.0}) result = await agent.run('What is the capital of France?') assert result.output == snapshot('Paris is the capital of France.') @@ -414,7 +412,7 @@ async def test_bedrock_model_anthropic_model_without_tools( async def test_bedrock_model_retry(allow_model_requests: None, bedrock_provider: BedrockProvider): model = BedrockConverseModel('us.amazon.nova-micro-v1:0', provider=bedrock_provider) agent = Agent( - model=model, system_prompt='You are a helpful chatbot.', model_settings={'temperature': 0.0}, retries=2 + model=model, instructions='You are a helpful chatbot.', model_settings={'temperature': 0.0}, retries=2 ) @agent.tool_plain @@ -431,15 +429,12 @@ async def get_capital(country: str) -> str: [ ModelRequest( parts=[ - SystemPromptPart( - content='You are a helpful chatbot.', - timestamp=IsDatetime(), - ), UserPromptPart( content='What is the capital of France?', timestamp=IsDatetime(), ), ], + instructions='You are a helpful chatbot.', run_id=IsStr(), ), ModelResponse( @@ -470,6 +465,7 @@ async def get_capital(country: str) -> str: timestamp=IsDatetime(), ) ], + instructions='You are a helpful chatbot.', run_id=IsStr(), ), ModelResponse( @@ -496,14 +492,14 @@ async def get_capital(country: str) -> str: async def test_bedrock_model_max_tokens(allow_model_requests: None, bedrock_provider: BedrockProvider): model = BedrockConverseModel('us.amazon.nova-micro-v1:0', provider=bedrock_provider) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.', model_settings={'max_tokens': 5}) + agent = Agent(model=model, instructions='You are a helpful chatbot.', model_settings={'max_tokens': 5}) result = await agent.run('What is the capital of France?') assert result.output == snapshot('The capital of France is') async def test_bedrock_model_top_p(allow_model_requests: None, bedrock_provider: BedrockProvider): model = BedrockConverseModel('us.amazon.nova-micro-v1:0', provider=bedrock_provider) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.', model_settings={'top_p': 0.5}) + agent = Agent(model=model, instructions='You are a helpful chatbot.', model_settings={'top_p': 0.5}) result = await agent.run('What is the capital of France?') assert result.output == snapshot( 'The capital of France is Paris. Paris is not only the capital city but also the most populous city in France, known for its significant cultural, political, and economic influence both within the country and globally. It is famous for landmarks such as the Eiffel Tower, the Louvre Museum, and the Notre-Dame Cathedral, among many other historical and architectural treasures.' @@ -513,7 +509,7 @@ async def test_bedrock_model_top_p(allow_model_requests: None, bedrock_provider: async def test_bedrock_model_performance_config(allow_model_requests: None, bedrock_provider: BedrockProvider): model = BedrockConverseModel('us.amazon.nova-micro-v1:0', provider=bedrock_provider) model_settings = BedrockModelSettings(bedrock_performance_configuration={'latency': 'optimized'}) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.', model_settings=model_settings) + agent = Agent(model=model, instructions='You are a helpful chatbot.', model_settings=model_settings) result = await agent.run('What is the capital of France?') assert result.output == snapshot( 'The capital of France is Paris. Paris is not only the capital city but also the most populous city in France, known for its significant cultural, political, and economic influence both within the country and globally. It is famous for landmarks such as the Eiffel Tower, the Louvre Museum, and the Notre-Dame Cathedral, among many other historical and architectural treasures.' @@ -525,7 +521,7 @@ async def test_bedrock_model_guardrail_config(allow_model_requests: None, bedroc model_settings = BedrockModelSettings( bedrock_guardrail_config={'guardrailIdentifier': 'guardrailv1', 'guardrailVersion': 'v1', 'trace': 'enabled'} ) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.', model_settings=model_settings) + agent = Agent(model=model, instructions='You are a helpful chatbot.', model_settings=model_settings) result = await agent.run('What is the capital of France?') assert result.output == snapshot( 'The capital of France is Paris. Paris is not only the capital city but also the most populous city in France, known for its significant cultural, political, and economic influence both within the country and globally. It is famous for landmarks such as the Eiffel Tower, the Louvre Museum, and the Notre-Dame Cathedral, among many other historical and architectural treasures.' @@ -540,7 +536,7 @@ async def test_bedrock_model_other_parameters(allow_model_requests: None, bedroc bedrock_request_metadata={'test': 'test'}, bedrock_additional_model_response_fields_paths=['test'], ) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.', model_settings=model_settings) + agent = Agent(model=model, instructions='You are a helpful chatbot.', model_settings=model_settings) result = await agent.run('What is the capital of France?') assert result.output == snapshot( 'The capital of France is Paris. Paris is not only the capital city but also the most populous city in France, known for its significant cultural, political, and economic influence both within the country and globally. It is famous for landmarks such as the Eiffel Tower, the Louvre Museum, and the Notre-Dame Cathedral, among many other historical and architectural treasures.' @@ -549,7 +545,7 @@ async def test_bedrock_model_other_parameters(allow_model_requests: None, bedroc async def test_bedrock_model_iter_stream(allow_model_requests: None, bedrock_provider: BedrockProvider): model = BedrockConverseModel('us.amazon.nova-micro-v1:0', provider=bedrock_provider) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.', model_settings={'top_p': 0.5}) + agent = Agent(model=model, instructions='You are a helpful chatbot.', model_settings={'top_p': 0.5}) @agent.tool_plain async def get_capital(country: str) -> str: @@ -648,7 +644,7 @@ async def test_image_as_binary_content_input( allow_model_requests: None, image_content: BinaryContent, bedrock_provider: BedrockProvider ): m = BedrockConverseModel('us.amazon.nova-pro-v1:0', provider=bedrock_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.') + agent = Agent(m, instructions='You are a helpful chatbot.') result = await agent.run(['What fruit is in the image?', image_content]) assert result.output == snapshot( @@ -661,7 +657,7 @@ async def test_video_as_binary_content_input( allow_model_requests: None, video_content: BinaryContent, bedrock_provider: BedrockProvider ): m = BedrockConverseModel('us.amazon.nova-pro-v1:0', provider=bedrock_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.') + agent = Agent(m, instructions='You are a helpful chatbot.') result = await agent.run(['Explain me this video', video_content]) assert result.output == snapshot( @@ -672,7 +668,7 @@ async def test_video_as_binary_content_input( @pytest.mark.vcr() async def test_image_url_input(allow_model_requests: None, bedrock_provider: BedrockProvider): m = BedrockConverseModel('us.amazon.nova-pro-v1:0', provider=bedrock_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.') + agent = Agent(m, instructions='You are a helpful chatbot.') result = await agent.run( [ @@ -688,7 +684,7 @@ async def test_image_url_input(allow_model_requests: None, bedrock_provider: Bed @pytest.mark.vcr() async def test_video_url_input(allow_model_requests: None, bedrock_provider: BedrockProvider): m = BedrockConverseModel('us.amazon.nova-pro-v1:0', provider=bedrock_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.') + agent = Agent(m, instructions='You are a helpful chatbot.') result = await agent.run( [ @@ -704,7 +700,7 @@ async def test_video_url_input(allow_model_requests: None, bedrock_provider: Bed @pytest.mark.vcr() async def test_document_url_input(allow_model_requests: None, bedrock_provider: BedrockProvider): m = BedrockConverseModel('anthropic.claude-v2', provider=bedrock_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.') + agent = Agent(m, instructions='You are a helpful chatbot.') document_url = DocumentUrl(url='https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf') @@ -717,7 +713,7 @@ async def test_document_url_input(allow_model_requests: None, bedrock_provider: @pytest.mark.vcr() async def test_text_document_url_input(allow_model_requests: None, bedrock_provider: BedrockProvider): m = BedrockConverseModel('anthropic.claude-v2', provider=bedrock_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.') + agent = Agent(m, instructions='You are a helpful chatbot.') text_document_url = DocumentUrl(url='https://example-files.online-convert.com/document/txt/example.txt') @@ -732,7 +728,7 @@ async def test_text_document_url_input(allow_model_requests: None, bedrock_provi @pytest.mark.vcr() async def test_text_as_binary_content_input(allow_model_requests: None, bedrock_provider: BedrockProvider): m = BedrockConverseModel('us.amazon.nova-pro-v1:0', provider=bedrock_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.') + agent = Agent(m, instructions='You are a helpful chatbot.') text_content = BinaryContent(data=b'This is a test document.', media_type='text/plain') @@ -1180,22 +1176,19 @@ async def test_bedrock_model_thinking_part_from_other_model( provider = OpenAIProvider(api_key=openai_api_key) m = OpenAIResponsesModel('gpt-5', provider=provider) settings = OpenAIResponsesModelSettings(openai_reasoning_effort='high', openai_reasoning_summary='detailed') - agent = Agent(m, system_prompt='You are a helpful assistant.', model_settings=settings) + agent = Agent(m, instructions='You are a helpful assistant.', model_settings=settings) result = await agent.run('How do I cross the street?') assert result.all_messages() == snapshot( [ ModelRequest( parts=[ - SystemPromptPart( - content='You are a helpful assistant.', - timestamp=IsDatetime(), - ), UserPromptPart( content='How do I cross the street?', timestamp=IsDatetime(), ), ], + instructions='You are a helpful assistant.', run_id=IsStr(), ), ModelResponse( @@ -1256,6 +1249,7 @@ async def test_bedrock_model_thinking_part_from_other_model( timestamp=IsDatetime(), ) ], + instructions='You are a helpful assistant.', run_id=IsStr(), ), ModelResponse( diff --git a/tests/models/test_gemini.py b/tests/models/test_gemini.py index 0f2e51c0ce..975d5dce33 100644 --- a/tests/models/test_gemini.py +++ b/tests/models/test_gemini.py @@ -25,7 +25,6 @@ ModelResponse, ModelRetry, RetryPromptPart, - SystemPromptPart, TextPart, ThinkingPart, ToolCallPart, @@ -665,7 +664,7 @@ async def test_request_tool_call(get_gemini_client: GetGeminiClient): ] gemini_client = get_gemini_client(responses) m = GeminiModel('gemini-1.5-flash', provider=GoogleGLAProvider(http_client=gemini_client)) - agent = Agent(m, system_prompt='this is the system prompt') + agent = Agent(m, instructions='this is the system prompt') @agent.tool_plain async def get_location(loc_name: str) -> str: @@ -682,9 +681,9 @@ async def get_location(loc_name: str) -> str: [ ModelRequest( parts=[ - SystemPromptPart(content='this is the system prompt', timestamp=IsNow(tz=timezone.utc)), UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc)), ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( @@ -706,6 +705,7 @@ async def get_location(loc_name: str) -> str: timestamp=IsNow(tz=timezone.utc), ) ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( @@ -734,6 +734,7 @@ async def get_location(loc_name: str) -> str: tool_call_id=IsStr(), ), ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( @@ -757,7 +758,7 @@ def handler(_: httpx.Request): gemini_client = client_with_handler(handler) m = GeminiModel('gemini-1.5-flash', provider=GoogleGLAProvider(http_client=gemini_client)) - agent = Agent(m, system_prompt='this is the system prompt') + agent = Agent(m, instructions='this is the system prompt') with pytest.raises(ModelHTTPError) as exc_info: await agent.run('Hello') @@ -1308,7 +1309,7 @@ async def test_video_as_binary_content_input( allow_model_requests: None, gemini_api_key: str, video_content: BinaryContent ) -> None: m = GeminiModel('gemini-1.5-flash', provider=GoogleGLAProvider(api_key=gemini_api_key)) - agent = Agent(m, system_prompt='You are a helpful chatbot.') + agent = Agent(m, instructions='You are a helpful chatbot.') result = await agent.run(['Explain me this video', video_content]) assert result.output.strip() == snapshot( @@ -1319,7 +1320,7 @@ async def test_video_as_binary_content_input( @pytest.mark.vcr() async def test_video_url_input(allow_model_requests: None, gemini_api_key: str) -> None: m = GeminiModel('gemini-1.5-flash', provider=GoogleGLAProvider(api_key=gemini_api_key)) - agent = Agent(m, system_prompt='You are a helpful chatbot.') + agent = Agent(m, instructions='You are a helpful chatbot.') video_url = VideoUrl(url='https://data.grepit.app/assets/tiny_video.mp4') diff --git a/tests/models/test_google.py b/tests/models/test_google.py index bdb3f0a864..905d7b3b2a 100644 --- a/tests/models/test_google.py +++ b/tests/models/test_google.py @@ -112,7 +112,7 @@ async def test_google_model(allow_model_requests: None, google_provider: GoogleP model = GoogleModel('gemini-1.5-flash', provider=google_provider) assert model.base_url == 'https://generativelanguage.googleapis.com/' assert model.system == 'google-gla' - agent = Agent(model=model, system_prompt='You are a chatbot.') + agent = Agent(model=model, instructions='You are a chatbot.') result = await agent.run('Hello!') assert result.output == snapshot('Hello there! How can I help you today?\n') @@ -128,15 +128,12 @@ async def test_google_model(allow_model_requests: None, google_provider: GoogleP [ ModelRequest( parts=[ - SystemPromptPart( - content='You are a chatbot.', - timestamp=IsDatetime(), - ), UserPromptPart( content='Hello!', timestamp=IsDatetime(), ), ], + instructions='You are a chatbot.', run_id=IsStr(), ), ModelResponse( @@ -158,7 +155,7 @@ async def test_google_model(allow_model_requests: None, google_provider: GoogleP async def test_google_model_structured_output(allow_model_requests: None, google_provider: GoogleProvider): model = GoogleModel('gemini-2.0-flash', provider=google_provider) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.', retries=5) + agent = Agent(model=model, instructions='You are a helpful chatbot.', retries=5) class Response(TypedDict): temperature: str @@ -193,15 +190,12 @@ async def temperature(city: str, date: datetime.date) -> str: [ ModelRequest( parts=[ - SystemPromptPart( - content='You are a helpful chatbot.', - timestamp=IsDatetime(), - ), UserPromptPart( content='What was the temperature in London 1st January 2022?', timestamp=IsDatetime(), - ), + ) ], + instructions='You are a helpful chatbot.', run_id=IsStr(), ), ModelResponse( @@ -229,6 +223,7 @@ async def temperature(city: str, date: datetime.date) -> str: tool_name='temperature', content='30°C', tool_call_id=IsStr(), timestamp=IsDatetime() ) ], + instructions='You are a helpful chatbot.', run_id=IsStr(), ), ModelResponse( @@ -269,7 +264,7 @@ async def temperature(city: str, date: datetime.date) -> str: async def test_google_model_stream(allow_model_requests: None, google_provider: GoogleProvider): model = GoogleModel('gemini-2.0-flash-exp', provider=google_provider) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.', model_settings={'temperature': 0.0}) + agent = Agent(model=model, instructions='You are a helpful chatbot.', model_settings={'temperature': 0.0}) async with agent.run_stream('What is the capital of France?') as result: data = await result.get_output() async for response, is_last in result.stream_responses(debounce_by=None): @@ -301,7 +296,7 @@ async def test_google_model_builtin_code_execution_stream( model = GoogleModel('gemini-2.5-pro', provider=google_provider) agent = Agent( model=model, - system_prompt='Be concise and always use Python to do calculations no matter how small.', + instructions='Be concise and always use Python to do calculations no matter how small.', builtin_tools=[CodeExecutionTool()], ) @@ -318,15 +313,12 @@ async def test_google_model_builtin_code_execution_stream( [ ModelRequest( parts=[ - SystemPromptPart( - content='Be concise and always use Python to do calculations no matter how small.', - timestamp=IsDatetime(), - ), UserPromptPart( content='what is 65465-6544 * 65464-6+1.02255', timestamp=IsDatetime(), - ), + ) ], + instructions='Be concise and always use Python to do calculations no matter how small.', run_id=IsStr(), ), ModelResponse( @@ -655,14 +647,14 @@ async def get_capital(country: str) -> str: async def test_google_model_max_tokens(allow_model_requests: None, google_provider: GoogleProvider): model = GoogleModel('gemini-1.5-flash', provider=google_provider) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.', model_settings={'max_tokens': 5}) + agent = Agent(model=model, instructions='You are a helpful chatbot.', model_settings={'max_tokens': 5}) result = await agent.run('What is the capital of France?') assert result.output == snapshot('The capital of France is') async def test_google_model_top_p(allow_model_requests: None, google_provider: GoogleProvider): model = GoogleModel('gemini-1.5-flash', provider=google_provider) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.', model_settings={'top_p': 0.5}) + agent = Agent(model=model, instructions='You are a helpful chatbot.', model_settings={'top_p': 0.5}) result = await agent.run('What is the capital of France?') assert result.output == snapshot('The capital of France is Paris.\n') @@ -670,7 +662,7 @@ async def test_google_model_top_p(allow_model_requests: None, google_provider: G async def test_google_model_thinking_config(allow_model_requests: None, google_provider: GoogleProvider): model = GoogleModel('gemini-2.5-pro-preview-03-25', provider=google_provider) settings = GoogleModelSettings(google_thinking_config={'include_thoughts': False}) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.', model_settings=settings) + agent = Agent(model=model, instructions='You are a helpful chatbot.', model_settings=settings) result = await agent.run('What is the capital of France?') assert result.output == snapshot('The capital of France is **Paris**.') @@ -678,7 +670,7 @@ async def test_google_model_thinking_config(allow_model_requests: None, google_p async def test_google_model_gla_labels_raises_value_error(allow_model_requests: None, google_provider: GoogleProvider): model = GoogleModel('gemini-2.0-flash', provider=google_provider) settings = GoogleModelSettings(google_labels={'environment': 'test', 'team': 'analytics'}) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.', model_settings=settings) + agent = Agent(model=model, instructions='You are a helpful chatbot.', model_settings=settings) # Raises before any request is made. with pytest.raises(ValueError, match='labels parameter is not supported in Gemini API.'): @@ -689,7 +681,7 @@ async def test_google_model_vertex_provider( allow_model_requests: None, vertex_provider: GoogleProvider ): # pragma: lax no cover model = GoogleModel('gemini-2.0-flash', provider=vertex_provider) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.') + agent = Agent(model=model, instructions='You are a helpful chatbot.') result = await agent.run('What is the capital of France?') assert result.output == snapshot('The capital of France is Paris.\n') @@ -699,14 +691,14 @@ async def test_google_model_vertex_labels( ): # pragma: lax no cover model = GoogleModel('gemini-2.0-flash', provider=vertex_provider) settings = GoogleModelSettings(google_labels={'environment': 'test', 'team': 'analytics'}) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.', model_settings=settings) + agent = Agent(model=model, instructions='You are a helpful chatbot.', model_settings=settings) result = await agent.run('What is the capital of France?') assert result.output == snapshot('The capital of France is Paris.\n') async def test_google_model_iter_stream(allow_model_requests: None, google_provider: GoogleProvider): model = GoogleModel('gemini-2.0-flash', provider=google_provider) - agent = Agent(model=model, system_prompt='You are a helpful chatbot.') + agent = Agent(model=model, instructions='You are a helpful chatbot.') @agent.tool_plain async def get_capital(country: str) -> str: @@ -784,7 +776,7 @@ async def test_google_model_image_as_binary_content_input( allow_model_requests: None, image_content: BinaryContent, google_provider: GoogleProvider ): m = GoogleModel('gemini-2.0-flash', provider=google_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.') + agent = Agent(m, instructions='You are a helpful chatbot.') result = await agent.run(['What fruit is in the image?', image_content]) assert result.output == snapshot('The fruit in the image is a kiwi.') @@ -794,7 +786,7 @@ async def test_google_model_video_as_binary_content_input( allow_model_requests: None, video_content: BinaryContent, google_provider: GoogleProvider ): m = GoogleModel('gemini-2.0-flash', provider=google_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.') + agent = Agent(m, instructions='You are a helpful chatbot.') result = await agent.run(['Explain me this video', video_content]) assert result.output == snapshot("""\ @@ -814,7 +806,7 @@ async def test_google_model_video_as_binary_content_input_with_vendor_metadata( allow_model_requests: None, video_content: BinaryContent, google_provider: GoogleProvider ): m = GoogleModel('gemini-2.0-flash', provider=google_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.') + agent = Agent(m, instructions='You are a helpful chatbot.') video_content.vendor_metadata = {'start_offset': '2s', 'end_offset': '10s'} result = await agent.run(['Explain me this video', video_content]) @@ -829,7 +821,7 @@ async def test_google_model_video_as_binary_content_input_with_vendor_metadata( async def test_google_model_image_url_input(allow_model_requests: None, google_provider: GoogleProvider): m = GoogleModel('gemini-2.0-flash', provider=google_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.') + agent = Agent(m, instructions='You are a helpful chatbot.') result = await agent.run( [ @@ -842,7 +834,7 @@ async def test_google_model_image_url_input(allow_model_requests: None, google_p async def test_google_model_video_url_input(allow_model_requests: None, google_provider: GoogleProvider): m = GoogleModel('gemini-2.0-flash', provider=google_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.') + agent = Agent(m, instructions='You are a helpful chatbot.') result = await agent.run( [ @@ -867,7 +859,7 @@ async def test_google_model_youtube_video_url_input_with_vendor_metadata( allow_model_requests: None, google_provider: GoogleProvider ): m = GoogleModel('gemini-2.0-flash', provider=google_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.') + agent = Agent(m, instructions='You are a helpful chatbot.') result = await agent.run( [ @@ -891,7 +883,7 @@ async def test_google_model_youtube_video_url_input_with_vendor_metadata( async def test_google_model_document_url_input(allow_model_requests: None, google_provider: GoogleProvider): m = GoogleModel('gemini-2.0-flash', provider=google_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.') + agent = Agent(m, instructions='You are a helpful chatbot.') document_url = DocumentUrl(url='https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf') @@ -901,7 +893,7 @@ async def test_google_model_document_url_input(allow_model_requests: None, googl async def test_google_model_text_document_url_input(allow_model_requests: None, google_provider: GoogleProvider): m = GoogleModel('gemini-2.0-flash', provider=google_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.') + agent = Agent(m, instructions='You are a helpful chatbot.') text_document_url = DocumentUrl(url='https://example-files.online-convert.com/document/txt/example.txt') @@ -913,7 +905,7 @@ async def test_google_model_text_document_url_input(allow_model_requests: None, async def test_google_model_text_as_binary_content_input(allow_model_requests: None, google_provider: GoogleProvider): m = GoogleModel('gemini-2.0-flash', provider=google_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.') + agent = Agent(m, instructions='You are a helpful chatbot.') text_content = BinaryContent(data=b'This is a test document.', media_type='text/plain') @@ -991,22 +983,19 @@ async def test_google_model_safety_settings(allow_model_requests: None, google_p async def test_google_model_web_search_tool(allow_model_requests: None, google_provider: GoogleProvider): m = GoogleModel('gemini-2.5-pro', provider=google_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.', builtin_tools=[WebSearchTool()]) + agent = Agent(m, instructions='You are a helpful chatbot.', builtin_tools=[WebSearchTool()]) result = await agent.run('What is the weather in San Francisco today?') assert result.all_messages() == snapshot( [ ModelRequest( parts=[ - SystemPromptPart( - content='You are a helpful chatbot.', - timestamp=IsDatetime(), - ), UserPromptPart( content='What is the weather in San Francisco today?', timestamp=IsDatetime(), - ), + ) ], + instructions='You are a helpful chatbot.', run_id=IsStr(), ), ModelResponse( @@ -1086,6 +1075,7 @@ async def test_google_model_web_search_tool(allow_model_requests: None, google_p timestamp=IsDatetime(), ) ], + instructions='You are a helpful chatbot.', run_id=IsStr(), ), ModelResponse( @@ -1155,7 +1145,7 @@ async def test_google_model_web_search_tool(allow_model_requests: None, google_p async def test_google_model_web_search_tool_stream(allow_model_requests: None, google_provider: GoogleProvider): m = GoogleModel('gemini-2.5-pro', provider=google_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.', builtin_tools=[WebSearchTool()]) + agent = Agent(m, instructions='You are a helpful chatbot.', builtin_tools=[WebSearchTool()]) event_parts: list[Any] = [] async with agent.iter(user_prompt='What is the weather in San Francisco today?') as agent_run: @@ -1171,15 +1161,12 @@ async def test_google_model_web_search_tool_stream(allow_model_requests: None, g [ ModelRequest( parts=[ - SystemPromptPart( - content='You are a helpful chatbot.', - timestamp=IsDatetime(), - ), UserPromptPart( content='What is the weather in San Francisco today?', timestamp=IsDatetime(), - ), + ) ], + instructions='You are a helpful chatbot.', run_id=IsStr(), ), ModelResponse( @@ -1325,6 +1312,7 @@ async def test_google_model_web_search_tool_stream(allow_model_requests: None, g timestamp=IsDatetime(), ) ], + instructions='You are a helpful chatbot.', run_id=IsStr(), ), ModelResponse( @@ -1409,7 +1397,7 @@ async def test_google_model_web_fetch_tool( else: tool = WebFetchTool() - agent = Agent(m, system_prompt='You are a helpful chatbot.', builtin_tools=[tool]) + agent = Agent(m, instructions='You are a helpful chatbot.', builtin_tools=[tool]) result = await agent.run( 'What is the first sentence on the page https://ai.pydantic.dev? Reply with only the sentence.' @@ -1424,12 +1412,12 @@ async def test_google_model_web_fetch_tool( [ ModelRequest( parts=[ - SystemPromptPart(content='You are a helpful chatbot.', timestamp=IsDatetime()), UserPromptPart( content='What is the first sentence on the page https://ai.pydantic.dev? Reply with only the sentence.', timestamp=IsDatetime(), - ), + ) ], + instructions='You are a helpful chatbot.', run_id=IsStr(), ), ModelResponse( @@ -1483,7 +1471,7 @@ async def test_google_model_web_fetch_tool_stream(allow_model_requests: None, go m = GoogleModel('gemini-2.5-flash', provider=google_provider) tool = WebFetchTool() - agent = Agent(m, system_prompt='You are a helpful chatbot.', builtin_tools=[tool]) + agent = Agent(m, instructions='You are a helpful chatbot.', builtin_tools=[tool]) event_parts: list[Any] = [] async with agent.iter( @@ -1503,12 +1491,12 @@ async def test_google_model_web_fetch_tool_stream(allow_model_requests: None, go [ ModelRequest( parts=[ - SystemPromptPart(content='You are a helpful chatbot.', timestamp=IsDatetime()), UserPromptPart( content='What is the first sentence on the page https://ai.pydantic.dev? Reply with only the sentence.', timestamp=IsDatetime(), - ), + ) ], + instructions='You are a helpful chatbot.', run_id=IsStr(), ), ModelResponse( @@ -1624,16 +1612,14 @@ async def test_google_model_web_fetch_tool_stream(allow_model_requests: None, go async def test_google_model_code_execution_tool(allow_model_requests: None, google_provider: GoogleProvider): m = GoogleModel('gemini-2.5-pro', provider=google_provider) - agent = Agent(m, system_prompt='You are a helpful chatbot.', builtin_tools=[CodeExecutionTool()]) + agent = Agent(m, instructions='You are a helpful chatbot.', builtin_tools=[CodeExecutionTool()]) result = await agent.run('What day is today in Utrecht?') assert result.all_messages() == snapshot( [ ModelRequest( - parts=[ - SystemPromptPart(content='You are a helpful chatbot.', timestamp=IsDatetime()), - UserPromptPart(content='What day is today in Utrecht?', timestamp=IsDatetime()), - ], + parts=[UserPromptPart(content='What day is today in Utrecht?', timestamp=IsDatetime())], + instructions='You are a helpful chatbot.', run_id=IsStr(), ), ModelResponse( @@ -1702,6 +1688,7 @@ async def test_google_model_code_execution_tool(allow_model_requests: None, goog [ ModelRequest( parts=[UserPromptPart(content='What day is tomorrow?', timestamp=IsDatetime())], + instructions='You are a helpful chatbot.', run_id=IsStr(), ), ModelResponse( @@ -1910,7 +1897,7 @@ async def test_google_model_empty_assistant_response(allow_model_requests: None, async def test_google_model_thinking_part(allow_model_requests: None, google_provider: GoogleProvider): m = GoogleModel('gemini-3-pro-preview', provider=google_provider) settings = GoogleModelSettings(google_thinking_config={'include_thoughts': True}) - agent = Agent(m, system_prompt='You are a helpful assistant.', model_settings=settings) + agent = Agent(m, instructions='You are a helpful assistant.', model_settings=settings) # Google only emits thought signatures when there are tools: https://ai.google.dev/gemini-api/docs/thinking#signatures @agent.tool_plain @@ -1921,15 +1908,12 @@ def dummy() -> None: ... # pragma: no cover [ ModelRequest( parts=[ - SystemPromptPart( - content='You are a helpful assistant.', - timestamp=IsDatetime(), - ), UserPromptPart( content='How do I cross the street?', timestamp=IsDatetime(), - ), + ) ], + instructions='You are a helpful assistant.', run_id=IsStr(), ), ModelResponse( @@ -1967,6 +1951,7 @@ def dummy() -> None: ... # pragma: no cover timestamp=IsDatetime(), ) ], + instructions='You are a helpful assistant.', run_id=IsStr(), ), ModelResponse( @@ -1998,7 +1983,7 @@ async def test_google_model_thinking_part_from_other_model( provider = OpenAIProvider(api_key=openai_api_key) m = OpenAIResponsesModel('gpt-5', provider=provider) settings = OpenAIResponsesModelSettings(openai_reasoning_effort='high', openai_reasoning_summary='detailed') - agent = Agent(m, system_prompt='You are a helpful assistant.', model_settings=settings) + agent = Agent(m, instructions='You are a helpful assistant.', model_settings=settings) # Google only emits thought signatures when there are tools: https://ai.google.dev/gemini-api/docs/thinking#signatures @agent.tool_plain @@ -2009,15 +1994,12 @@ def dummy() -> None: ... # pragma: no cover [ ModelRequest( parts=[ - SystemPromptPart( - content='You are a helpful assistant.', - timestamp=IsDatetime(), - ), UserPromptPart( content='How do I cross the street?', timestamp=IsDatetime(), - ), + ) ], + instructions='You are a helpful assistant.', run_id=IsStr(), ), ModelResponse( @@ -2076,6 +2058,7 @@ def dummy() -> None: ... # pragma: no cover timestamp=IsDatetime(), ) ], + instructions='You are a helpful assistant.', run_id=IsStr(), ), ModelResponse( @@ -2104,7 +2087,7 @@ def dummy() -> None: ... # pragma: no cover async def test_google_model_thinking_part_iter(allow_model_requests: None, google_provider: GoogleProvider): m = GoogleModel('gemini-2.5-pro', provider=google_provider) settings = GoogleModelSettings(google_thinking_config={'include_thoughts': True}) - agent = Agent(m, system_prompt='You are a helpful assistant.', model_settings=settings) + agent = Agent(m, instructions='You are a helpful assistant.', model_settings=settings) # Google only emits thought signatures when there are tools: https://ai.google.dev/gemini-api/docs/thinking#signatures @agent.tool_plain @@ -2123,15 +2106,12 @@ def dummy() -> None: ... # pragma: no cover [ ModelRequest( parts=[ - SystemPromptPart( - content='You are a helpful assistant.', - timestamp=IsDatetime(), - ), UserPromptPart( content='How do I cross the street?', timestamp=IsDatetime(), - ), + ) ], + instructions='You are a helpful assistant.', run_id=IsStr(), ), ModelResponse( @@ -2979,7 +2959,7 @@ async def test_google_vertexai_model_usage_limit_exceeded( ): # pragma: lax no cover model = GoogleModel('gemini-2.0-flash', provider=vertex_provider, settings=ModelSettings(max_tokens=100)) - agent = Agent(model, system_prompt='You are a chatbot.') + agent = Agent(model, instructions='You are a chatbot.') @agent.tool_plain async def get_user_country() -> str: @@ -3952,7 +3932,7 @@ class TopModel(BaseModel): agent = Agent( m, output_type=TopModel, - system_prompt='You are a helpful assistant that creates structured data.', + instructions='You are a helpful assistant that creates structured data.', retries=5, ) @@ -3997,7 +3977,7 @@ class TopModel(BaseModel): agent = Agent( m, output_type=NativeOutput(TopModel), - system_prompt='You are a helpful assistant that creates structured data.', + instructions='You are a helpful assistant that creates structured data.', ) result = await agent.run('Create a simple example with 2 pages, each with 2 items') diff --git a/tests/models/test_mistral.py b/tests/models/test_mistral.py index 32a56c6395..683e5e6e30 100644 --- a/tests/models/test_mistral.py +++ b/tests/models/test_mistral.py @@ -544,7 +544,7 @@ async def test_request_output_type_with_arguments_str_response(allow_model_reque ) mock_client = MockMistralAI.create_mock(completion) model = MistralModel('mistral-large-latest', provider=MistralProvider(mistral_client=mock_client)) - agent = Agent(model=model, output_type=int, system_prompt='System prompt value') + agent = Agent(model=model, output_type=int, instructions='System prompt value') result = await agent.run('User prompt value') @@ -556,9 +556,9 @@ async def test_request_output_type_with_arguments_str_response(allow_model_reque [ ModelRequest( parts=[ - SystemPromptPart(content='System prompt value', timestamp=IsNow(tz=timezone.utc)), UserPromptPart(content='User prompt value', timestamp=IsNow(tz=timezone.utc)), ], + instructions='System prompt value', run_id=IsStr(), ), ModelResponse( @@ -1250,7 +1250,7 @@ class MyTypedDict(TypedDict, total=False): ] mock_client = MockMistralAI.create_mock(completion) model = MistralModel('mistral-large-latest', provider=MistralProvider(mistral_client=mock_client)) - agent = Agent(model, system_prompt='this is the system prompt', output_type=MyTypedDict) + agent = Agent(model, instructions='this is the system prompt', output_type=MyTypedDict) @agent.tool_plain async def get_location(loc_name: str) -> str: @@ -1268,9 +1268,9 @@ async def get_location(loc_name: str) -> str: [ ModelRequest( parts=[ - SystemPromptPart(content='this is the system prompt', timestamp=IsNow(tz=timezone.utc)), UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc)), ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( @@ -1299,6 +1299,7 @@ async def get_location(loc_name: str) -> str: timestamp=IsNow(tz=timezone.utc), ) ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( @@ -1327,6 +1328,7 @@ async def get_location(loc_name: str) -> str: timestamp=IsNow(tz=timezone.utc), ) ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( @@ -1407,7 +1409,7 @@ class MyTypedDict(TypedDict, total=False): mock_client = MockMistralAI.create_stream_mock(completion) model = MistralModel('mistral-large-latest', provider=MistralProvider(mistral_client=mock_client)) - agent = Agent(model, system_prompt='this is the system prompt', output_type=MyTypedDict) + agent = Agent(model, instructions='this is the system prompt', output_type=MyTypedDict) @agent.tool_plain async def get_location(loc_name: str) -> str: @@ -1429,9 +1431,9 @@ async def get_location(loc_name: str) -> str: [ ModelRequest( parts=[ - SystemPromptPart(content='this is the system prompt', timestamp=IsNow(tz=timezone.utc)), UserPromptPart(content='User prompt value', timestamp=IsNow(tz=timezone.utc)), ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( @@ -1460,6 +1462,7 @@ async def get_location(loc_name: str) -> str: timestamp=IsNow(tz=timezone.utc), ) ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( @@ -1521,7 +1524,7 @@ async def test_stream_tool_call(allow_model_requests: None): mock_client = MockMistralAI.create_stream_mock(completion) model = MistralModel('mistral-large-latest', provider=MistralProvider(mistral_client=mock_client)) - agent = Agent(model, system_prompt='this is the system prompt') + agent = Agent(model, instructions='this is the system prompt') @agent.tool_plain async def get_location(loc_name: str) -> str: @@ -1543,9 +1546,9 @@ async def get_location(loc_name: str) -> str: [ ModelRequest( parts=[ - SystemPromptPart(content='this is the system prompt', timestamp=IsNow(tz=timezone.utc)), UserPromptPart(content='User prompt value', timestamp=IsNow(tz=timezone.utc)), ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( @@ -1574,6 +1577,7 @@ async def get_location(loc_name: str) -> str: timestamp=IsNow(tz=timezone.utc), ) ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( @@ -1634,7 +1638,7 @@ async def test_stream_tool_call_with_retry(allow_model_requests: None): mock_client = MockMistralAI.create_stream_mock(completion) model = MistralModel('mistral-large-latest', provider=MistralProvider(mistral_client=mock_client)) - agent = Agent(model, system_prompt='this is the system prompt') + agent = Agent(model, instructions='this is the system prompt') @agent.tool_plain async def get_location(loc_name: str) -> str: @@ -1659,9 +1663,9 @@ async def get_location(loc_name: str) -> str: [ ModelRequest( parts=[ - SystemPromptPart(content='this is the system prompt', timestamp=IsNow(tz=timezone.utc)), UserPromptPart(content='User prompt value', timestamp=IsNow(tz=timezone.utc)), ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( @@ -1690,6 +1694,7 @@ async def get_location(loc_name: str) -> str: timestamp=IsNow(tz=timezone.utc), ) ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( @@ -1718,6 +1723,7 @@ async def get_location(loc_name: str) -> str: timestamp=IsNow(tz=timezone.utc), ) ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( diff --git a/tests/models/test_openai.py b/tests/models/test_openai.py index ed68edd94f..cc677f56aa 100644 --- a/tests/models/test_openai.py +++ b/tests/models/test_openai.py @@ -27,7 +27,6 @@ ModelResponse, ModelRetry, RetryPromptPart, - SystemPromptPart, TextPart, ThinkingPart, ToolCallPart, @@ -315,7 +314,7 @@ async def test_request_tool_call(allow_model_requests: None): ] mock_client = MockOpenAI.create_mock(responses) m = OpenAIChatModel('gpt-4o', provider=OpenAIProvider(openai_client=mock_client)) - agent = Agent(m, system_prompt='this is the system prompt') + agent = Agent(m, instructions='this is the system prompt') @agent.tool_plain async def get_location(loc_name: str) -> str: @@ -330,9 +329,9 @@ async def get_location(loc_name: str) -> str: [ ModelRequest( parts=[ - SystemPromptPart(content='this is the system prompt', timestamp=IsNow(tz=timezone.utc)), UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc)), ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( @@ -365,6 +364,7 @@ async def get_location(loc_name: str) -> str: timestamp=IsNow(tz=timezone.utc), ) ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( @@ -397,6 +397,7 @@ async def get_location(loc_name: str) -> str: timestamp=IsNow(tz=timezone.utc), ) ], + instructions='this is the system prompt', run_id=IsStr(), ), ModelResponse( diff --git a/tests/test_agent.py b/tests/test_agent.py index 9c44f4adfb..20dcd89bf9 100644 --- a/tests/test_agent.py +++ b/tests/test_agent.py @@ -5297,7 +5297,7 @@ def model_function(messages: list[ModelMessage], info: AgentInfo) -> ModelRespon ) model = FunctionModel(model_function) - agent = Agent(model, system_prompt='You are a helpful assistant.') + agent = Agent(model, instructions='You are a helpful assistant.') result = await agent.run('Hello') @@ -5305,20 +5305,17 @@ def model_function(messages: list[ModelMessage], info: AgentInfo) -> ModelRespon [ ModelRequest( parts=[ - SystemPromptPart( - content='You are a helpful assistant.', - timestamp=IsDatetime(), - ), UserPromptPart( content='Hello', timestamp=IsDatetime(), ), ], + instructions='You are a helpful assistant.', run_id=IsStr(), ), ModelResponse( parts=[ThinkingPart(content='Let me think about this...')], - usage=RequestUsage(input_tokens=57, output_tokens=6), + usage=RequestUsage(input_tokens=51, output_tokens=6), model_name='function:model_function:', timestamp=IsDatetime(), run_id=IsStr(), @@ -5331,11 +5328,12 @@ def model_function(messages: list[ModelMessage], info: AgentInfo) -> ModelRespon timestamp=IsDatetime(), ) ], + instructions='You are a helpful assistant.', run_id=IsStr(), ), ModelResponse( parts=[TextPart(content='Final answer')], - usage=RequestUsage(input_tokens=73, output_tokens=8), + usage=RequestUsage(input_tokens=67, output_tokens=8), model_name='function:model_function:', timestamp=IsDatetime(), run_id=IsStr(),