pydantic-ai-slim 0.0.35__tar.gz → 0.0.37__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pydantic-ai-slim might be problematic. Click here for more details.

Files changed (45) hide show
  1. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/PKG-INFO +4 -2
  2. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/_pydantic.py +2 -2
  3. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/agent.py +18 -4
  4. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/common_tools/duckduckgo.py +1 -1
  5. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/common_tools/tavily.py +2 -1
  6. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/messages.py +3 -1
  7. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/models/__init__.py +53 -1
  8. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/models/anthropic.py +4 -0
  9. pydantic_ai_slim-0.0.37/pydantic_ai/models/bedrock.py +455 -0
  10. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/models/cohere.py +5 -0
  11. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/models/fallback.py +4 -0
  12. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/models/gemini.py +3 -2
  13. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/models/groq.py +4 -0
  14. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/models/instrumented.py +10 -2
  15. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/models/mistral.py +4 -0
  16. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/models/openai.py +4 -0
  17. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/models/vertexai.py +15 -24
  18. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/providers/__init__.py +5 -0
  19. pydantic_ai_slim-0.0.37/pydantic_ai/providers/bedrock.py +76 -0
  20. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/providers/google_vertex.py +64 -28
  21. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/settings.py +3 -0
  22. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pyproject.toml +4 -2
  23. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/.gitignore +0 -0
  24. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/README.md +0 -0
  25. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/__init__.py +0 -0
  26. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/_agent_graph.py +0 -0
  27. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/_cli.py +0 -0
  28. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/_griffe.py +0 -0
  29. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/_parts_manager.py +0 -0
  30. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/_result.py +0 -0
  31. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/_system_prompt.py +0 -0
  32. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/_utils.py +0 -0
  33. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/common_tools/__init__.py +0 -0
  34. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/exceptions.py +0 -0
  35. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/format_as_xml.py +0 -0
  36. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/models/function.py +0 -0
  37. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/models/test.py +0 -0
  38. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/models/wrapper.py +0 -0
  39. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/providers/deepseek.py +0 -0
  40. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/providers/google_gla.py +0 -0
  41. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/providers/openai.py +0 -0
  42. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/py.typed +0 -0
  43. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/result.py +0 -0
  44. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/tools.py +0 -0
  45. {pydantic_ai_slim-0.0.35 → pydantic_ai_slim-0.0.37}/pydantic_ai/usage.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pydantic-ai-slim
3
- Version: 0.0.35
3
+ Version: 0.0.37
4
4
  Summary: Agent Framework / shim to use Pydantic with LLMs, slim package
5
5
  Author-email: Samuel Colvin <samuel@pydantic.dev>
6
6
  License-Expression: MIT
@@ -29,11 +29,13 @@ Requires-Dist: exceptiongroup; python_version < '3.11'
29
29
  Requires-Dist: griffe>=1.3.2
30
30
  Requires-Dist: httpx>=0.27
31
31
  Requires-Dist: opentelemetry-api>=1.28.0
32
- Requires-Dist: pydantic-graph==0.0.35
32
+ Requires-Dist: pydantic-graph==0.0.37
33
33
  Requires-Dist: pydantic>=2.10
34
34
  Requires-Dist: typing-inspection>=0.4.0
35
35
  Provides-Extra: anthropic
36
36
  Requires-Dist: anthropic>=0.49.0; extra == 'anthropic'
37
+ Provides-Extra: bedrock
38
+ Requires-Dist: boto3>=1.34.116; extra == 'bedrock'
37
39
  Provides-Extra: cli
38
40
  Requires-Dist: argcomplete>=3.5.0; extra == 'cli'
39
41
  Requires-Dist: prompt-toolkit>=3; extra == 'cli'
@@ -6,7 +6,7 @@ This module has to use numerous internal Pydantic APIs and is therefore brittle
6
6
  from __future__ import annotations as _annotations
7
7
 
8
8
  from inspect import Parameter, signature
9
- from typing import TYPE_CHECKING, Any, Callable, TypedDict, cast
9
+ from typing import TYPE_CHECKING, Any, Callable, cast
10
10
 
11
11
  from pydantic import ConfigDict
12
12
  from pydantic._internal import _decorators, _generate_schema, _typing_extra
@@ -15,7 +15,7 @@ from pydantic.fields import FieldInfo
15
15
  from pydantic.json_schema import GenerateJsonSchema
16
16
  from pydantic.plugin._schema_validator import create_schema_validator
17
17
  from pydantic_core import SchemaValidator, core_schema
18
- from typing_extensions import get_origin
18
+ from typing_extensions import TypedDict, get_origin
19
19
 
20
20
  from ._griffe import doc_descriptions
21
21
  from ._utils import check_object_json_schema, is_model_like
@@ -922,6 +922,7 @@ class Agent(Generic[AgentDepsT, ResultDataT]):
922
922
  self,
923
923
  /,
924
924
  *,
925
+ name: str | None = None,
925
926
  retries: int | None = None,
926
927
  prepare: ToolPrepareFunc[AgentDepsT] | None = None,
927
928
  docstring_format: DocstringFormat = 'auto',
@@ -933,6 +934,7 @@ class Agent(Generic[AgentDepsT, ResultDataT]):
933
934
  func: ToolFuncContext[AgentDepsT, ToolParams] | None = None,
934
935
  /,
935
936
  *,
937
+ name: str | None = None,
936
938
  retries: int | None = None,
937
939
  prepare: ToolPrepareFunc[AgentDepsT] | None = None,
938
940
  docstring_format: DocstringFormat = 'auto',
@@ -969,6 +971,7 @@ class Agent(Generic[AgentDepsT, ResultDataT]):
969
971
 
970
972
  Args:
971
973
  func: The tool function to register.
974
+ name: The name of the tool, defaults to the function name.
972
975
  retries: The number of retries to allow for this tool, defaults to the agent's default retries,
973
976
  which defaults to 1.
974
977
  prepare: custom method to prepare the tool definition for each step, return `None` to omit this
@@ -984,13 +987,17 @@ class Agent(Generic[AgentDepsT, ResultDataT]):
984
987
  func_: ToolFuncContext[AgentDepsT, ToolParams],
985
988
  ) -> ToolFuncContext[AgentDepsT, ToolParams]:
986
989
  # noinspection PyTypeChecker
987
- self._register_function(func_, True, retries, prepare, docstring_format, require_parameter_descriptions)
990
+ self._register_function(
991
+ func_, True, name, retries, prepare, docstring_format, require_parameter_descriptions
992
+ )
988
993
  return func_
989
994
 
990
995
  return tool_decorator
991
996
  else:
992
997
  # noinspection PyTypeChecker
993
- self._register_function(func, True, retries, prepare, docstring_format, require_parameter_descriptions)
998
+ self._register_function(
999
+ func, True, name, retries, prepare, docstring_format, require_parameter_descriptions
1000
+ )
994
1001
  return func
995
1002
 
996
1003
  @overload
@@ -1001,6 +1008,7 @@ class Agent(Generic[AgentDepsT, ResultDataT]):
1001
1008
  self,
1002
1009
  /,
1003
1010
  *,
1011
+ name: str | None = None,
1004
1012
  retries: int | None = None,
1005
1013
  prepare: ToolPrepareFunc[AgentDepsT] | None = None,
1006
1014
  docstring_format: DocstringFormat = 'auto',
@@ -1012,6 +1020,7 @@ class Agent(Generic[AgentDepsT, ResultDataT]):
1012
1020
  func: ToolFuncPlain[ToolParams] | None = None,
1013
1021
  /,
1014
1022
  *,
1023
+ name: str | None = None,
1015
1024
  retries: int | None = None,
1016
1025
  prepare: ToolPrepareFunc[AgentDepsT] | None = None,
1017
1026
  docstring_format: DocstringFormat = 'auto',
@@ -1048,6 +1057,7 @@ class Agent(Generic[AgentDepsT, ResultDataT]):
1048
1057
 
1049
1058
  Args:
1050
1059
  func: The tool function to register.
1060
+ name: The name of the tool, defaults to the function name.
1051
1061
  retries: The number of retries to allow for this tool, defaults to the agent's default retries,
1052
1062
  which defaults to 1.
1053
1063
  prepare: custom method to prepare the tool definition for each step, return `None` to omit this
@@ -1062,19 +1072,22 @@ class Agent(Generic[AgentDepsT, ResultDataT]):
1062
1072
  def tool_decorator(func_: ToolFuncPlain[ToolParams]) -> ToolFuncPlain[ToolParams]:
1063
1073
  # noinspection PyTypeChecker
1064
1074
  self._register_function(
1065
- func_, False, retries, prepare, docstring_format, require_parameter_descriptions
1075
+ func_, False, name, retries, prepare, docstring_format, require_parameter_descriptions
1066
1076
  )
1067
1077
  return func_
1068
1078
 
1069
1079
  return tool_decorator
1070
1080
  else:
1071
- self._register_function(func, False, retries, prepare, docstring_format, require_parameter_descriptions)
1081
+ self._register_function(
1082
+ func, False, name, retries, prepare, docstring_format, require_parameter_descriptions
1083
+ )
1072
1084
  return func
1073
1085
 
1074
1086
  def _register_function(
1075
1087
  self,
1076
1088
  func: ToolFuncEither[AgentDepsT, ToolParams],
1077
1089
  takes_ctx: bool,
1090
+ name: str | None,
1078
1091
  retries: int | None,
1079
1092
  prepare: ToolPrepareFunc[AgentDepsT] | None,
1080
1093
  docstring_format: DocstringFormat,
@@ -1085,6 +1098,7 @@ class Agent(Generic[AgentDepsT, ResultDataT]):
1085
1098
  tool = Tool[AgentDepsT](
1086
1099
  func,
1087
1100
  takes_ctx=takes_ctx,
1101
+ name=name,
1088
1102
  max_retries=retries_,
1089
1103
  prepare=prepare,
1090
1104
  docstring_format=docstring_format,
@@ -1,10 +1,10 @@
1
1
  import functools
2
2
  from dataclasses import dataclass
3
- from typing import TypedDict
4
3
 
5
4
  import anyio
6
5
  import anyio.to_thread
7
6
  from pydantic import TypeAdapter
7
+ from typing_extensions import TypedDict
8
8
 
9
9
  from pydantic_ai.tools import Tool
10
10
 
@@ -1,7 +1,8 @@
1
1
  from dataclasses import dataclass
2
- from typing import Literal, TypedDict
2
+ from typing import Literal
3
3
 
4
4
  from pydantic import TypeAdapter
5
+ from typing_extensions import TypedDict
5
6
 
6
7
  from pydantic_ai.tools import Tool
7
8
 
@@ -395,7 +395,9 @@ class ModelResponse:
395
395
  ModelMessage = Annotated[Union[ModelRequest, ModelResponse], pydantic.Discriminator('kind')]
396
396
  """Any message sent to or returned by a model."""
397
397
 
398
- ModelMessagesTypeAdapter = pydantic.TypeAdapter(list[ModelMessage], config=pydantic.ConfigDict(defer_build=True))
398
+ ModelMessagesTypeAdapter = pydantic.TypeAdapter(
399
+ list[ModelMessage], config=pydantic.ConfigDict(defer_build=True, ser_json_bytes='base64')
400
+ )
399
401
  """Pydantic [`TypeAdapter`][pydantic.type_adapter.TypeAdapter] for (de)serializing messages."""
400
402
 
401
403
 
@@ -34,6 +34,49 @@ KnownModelName = Literal[
34
34
  'anthropic:claude-3-opus-latest',
35
35
  'claude-3-7-sonnet-latest',
36
36
  'claude-3-5-haiku-latest',
37
+ 'bedrock:amazon.titan-tg1-large',
38
+ 'bedrock:amazon.titan-text-lite-v1',
39
+ 'bedrock:amazon.titan-text-express-v1',
40
+ 'bedrock:us.amazon.nova-pro-v1:0',
41
+ 'bedrock:us.amazon.nova-lite-v1:0',
42
+ 'bedrock:us.amazon.nova-micro-v1:0',
43
+ 'bedrock:anthropic.claude-3-5-sonnet-20241022-v2:0',
44
+ 'bedrock:us.anthropic.claude-3-5-sonnet-20241022-v2:0',
45
+ 'bedrock:anthropic.claude-3-5-haiku-20241022-v1:0',
46
+ 'bedrock:us.anthropic.claude-3-5-haiku-20241022-v1:0',
47
+ 'bedrock:anthropic.claude-instant-v1',
48
+ 'bedrock:anthropic.claude-v2:1',
49
+ 'bedrock:anthropic.claude-v2',
50
+ 'bedrock:anthropic.claude-3-sonnet-20240229-v1:0',
51
+ 'bedrock:us.anthropic.claude-3-sonnet-20240229-v1:0',
52
+ 'bedrock:anthropic.claude-3-haiku-20240307-v1:0',
53
+ 'bedrock:us.anthropic.claude-3-haiku-20240307-v1:0',
54
+ 'bedrock:anthropic.claude-3-opus-20240229-v1:0',
55
+ 'bedrock:us.anthropic.claude-3-opus-20240229-v1:0',
56
+ 'bedrock:anthropic.claude-3-5-sonnet-20240620-v1:0',
57
+ 'bedrock:us.anthropic.claude-3-5-sonnet-20240620-v1:0',
58
+ 'bedrock:anthropic.claude-3-7-sonnet-20250219-v1:0',
59
+ 'bedrock:us.anthropic.claude-3-7-sonnet-20250219-v1:0',
60
+ 'bedrock:cohere.command-text-v14',
61
+ 'bedrock:cohere.command-r-v1:0',
62
+ 'bedrock:cohere.command-r-plus-v1:0',
63
+ 'bedrock:cohere.command-light-text-v14',
64
+ 'bedrock:meta.llama3-8b-instruct-v1:0',
65
+ 'bedrock:meta.llama3-70b-instruct-v1:0',
66
+ 'bedrock:meta.llama3-1-8b-instruct-v1:0',
67
+ 'bedrock:us.meta.llama3-1-8b-instruct-v1:0',
68
+ 'bedrock:meta.llama3-1-70b-instruct-v1:0',
69
+ 'bedrock:us.meta.llama3-1-70b-instruct-v1:0',
70
+ 'bedrock:meta.llama3-1-405b-instruct-v1:0',
71
+ 'bedrock:us.meta.llama3-2-11b-instruct-v1:0',
72
+ 'bedrock:us.meta.llama3-2-90b-instruct-v1:0',
73
+ 'bedrock:us.meta.llama3-2-1b-instruct-v1:0',
74
+ 'bedrock:us.meta.llama3-2-3b-instruct-v1:0',
75
+ 'bedrock:us.meta.llama3-3-70b-instruct-v1:0',
76
+ 'bedrock:mistral.mistral-7b-instruct-v0:2',
77
+ 'bedrock:mistral.mixtral-8x7b-instruct-v0:1',
78
+ 'bedrock:mistral.mistral-large-2402-v1:0',
79
+ 'bedrock:mistral.mistral-large-2407-v1:0',
37
80
  'claude-3-5-sonnet-latest',
38
81
  'claude-3-opus-latest',
39
82
  'cohere:c4ai-aya-expanse-32b',
@@ -223,6 +266,11 @@ class Model(ABC):
223
266
  """The system / model provider, ex: openai."""
224
267
  raise NotImplementedError()
225
268
 
269
+ @property
270
+ def base_url(self) -> str | None:
271
+ """The base URL for the provider API, if available."""
272
+ return None
273
+
226
274
 
227
275
  @dataclass
228
276
  class StreamedResponse(ABC):
@@ -324,7 +372,7 @@ def infer_model(model: Model | KnownModelName) -> Model:
324
372
  return TestModel()
325
373
 
326
374
  try:
327
- provider, model_name = model.split(':')
375
+ provider, model_name = model.split(':', maxsplit=1)
328
376
  except ValueError:
329
377
  model_name = model
330
378
  # TODO(Marcelo): We should deprecate this way.
@@ -368,6 +416,10 @@ def infer_model(model: Model | KnownModelName) -> Model:
368
416
 
369
417
  # TODO(Marcelo): Missing provider API.
370
418
  return AnthropicModel(model_name)
419
+ elif provider == 'bedrock':
420
+ from .bedrock import BedrockConverseModel
421
+
422
+ return BedrockConverseModel(model_name)
371
423
  else:
372
424
  raise UserError(f'Unknown model: {model}')
373
425
 
@@ -143,6 +143,10 @@ class AnthropicModel(Model):
143
143
  else:
144
144
  self.client = AsyncAnthropic(api_key=api_key, http_client=cached_async_http_client())
145
145
 
146
+ @property
147
+ def base_url(self) -> str:
148
+ return str(self.client.base_url)
149
+
146
150
  async def request(
147
151
  self,
148
152
  messages: list[ModelMessage],