pydantic-ai-slim 0.0.46__py3-none-any.whl → 0.0.47__py3-none-any.whl

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.

@@ -1,5 +1,6 @@
1
1
  from __future__ import annotations as _annotations
2
2
 
3
+ import os
3
4
  from typing import overload
4
5
 
5
6
  from pydantic_ai.exceptions import UserError
@@ -8,6 +9,7 @@ from pydantic_ai.providers import Provider
8
9
  try:
9
10
  import boto3
10
11
  from botocore.client import BaseClient
12
+ from botocore.config import Config
11
13
  from botocore.exceptions import NoRegionError
12
14
  except ImportError as _import_error:
13
15
  raise ImportError(
@@ -42,6 +44,8 @@ class BedrockProvider(Provider[BaseClient]):
42
44
  aws_access_key_id: str | None = None,
43
45
  aws_secret_access_key: str | None = None,
44
46
  aws_session_token: str | None = None,
47
+ aws_read_timeout: float | None = None,
48
+ aws_connect_timeout: float | None = None,
45
49
  ) -> None: ...
46
50
 
47
51
  def __init__(
@@ -52,6 +56,8 @@ class BedrockProvider(Provider[BaseClient]):
52
56
  aws_access_key_id: str | None = None,
53
57
  aws_secret_access_key: str | None = None,
54
58
  aws_session_token: str | None = None,
59
+ aws_read_timeout: float | None = None,
60
+ aws_connect_timeout: float | None = None,
55
61
  ) -> None:
56
62
  """Initialize the Bedrock provider.
57
63
 
@@ -61,17 +67,22 @@ class BedrockProvider(Provider[BaseClient]):
61
67
  aws_access_key_id: The AWS access key ID.
62
68
  aws_secret_access_key: The AWS secret access key.
63
69
  aws_session_token: The AWS session token.
70
+ aws_read_timeout: The read timeout for Bedrock client.
71
+ aws_connect_timeout: The connect timeout for Bedrock client.
64
72
  """
65
73
  if bedrock_client is not None:
66
74
  self._client = bedrock_client
67
75
  else:
68
76
  try:
77
+ read_timeout = aws_read_timeout or float(os.getenv('AWS_READ_TIMEOUT', 300))
78
+ connect_timeout = aws_connect_timeout or float(os.getenv('AWS_CONNECT_TIMEOUT', 60))
69
79
  self._client = boto3.client( # type: ignore[reportUnknownMemberType]
70
80
  'bedrock-runtime',
71
81
  aws_access_key_id=aws_access_key_id,
72
82
  aws_secret_access_key=aws_secret_access_key,
73
83
  aws_session_token=aws_session_token,
74
84
  region_name=region_name,
85
+ config=Config(read_timeout=read_timeout, connect_timeout=connect_timeout),
75
86
  )
76
87
  except NoRegionError as exc: # pragma: no cover
77
88
  raise UserError('You must provide a `region_name` or a boto3 client for Bedrock Runtime.') from exc
pydantic_ai/tools.py CHANGED
@@ -2,10 +2,12 @@ from __future__ import annotations as _annotations
2
2
 
3
3
  import dataclasses
4
4
  import inspect
5
+ import json
5
6
  from collections.abc import Awaitable, Sequence
6
7
  from dataclasses import dataclass, field
7
8
  from typing import TYPE_CHECKING, Any, Callable, Generic, Literal, Union, cast
8
9
 
10
+ from opentelemetry.trace import Tracer
9
11
  from pydantic import ValidationError
10
12
  from pydantic.json_schema import GenerateJsonSchema, JsonSchemaValue
11
13
  from pydantic_core import SchemaValidator, core_schema
@@ -286,9 +288,38 @@ class Tool(Generic[AgentDepsT]):
286
288
  return tool_def
287
289
 
288
290
  async def run(
291
+ self, message: _messages.ToolCallPart, run_context: RunContext[AgentDepsT], tracer: Tracer
292
+ ) -> _messages.ToolReturnPart | _messages.RetryPromptPart:
293
+ """Run the tool function asynchronously.
294
+
295
+ This method wraps `_run` in an OpenTelemetry span.
296
+
297
+ See <https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/#execute-tool-span>.
298
+ """
299
+ span_attributes = {
300
+ 'gen_ai.tool.name': self.name,
301
+ # NOTE: this means `gen_ai.tool.call.id` will be included even if it was generated by pydantic-ai
302
+ 'gen_ai.tool.call.id': message.tool_call_id,
303
+ 'tool_arguments': message.args_as_json_str(),
304
+ 'logfire.msg': f'running tool: {self.name}',
305
+ # add the JSON schema so these attributes are formatted nicely in Logfire
306
+ 'logfire.json_schema': json.dumps(
307
+ {
308
+ 'type': 'object',
309
+ 'properties': {
310
+ 'tool_arguments': {'type': 'object'},
311
+ 'gen_ai.tool.name': {},
312
+ 'gen_ai.tool.call.id': {},
313
+ },
314
+ }
315
+ ),
316
+ }
317
+ with tracer.start_as_current_span('running tool', attributes=span_attributes):
318
+ return await self._run(message, run_context)
319
+
320
+ async def _run(
289
321
  self, message: _messages.ToolCallPart, run_context: RunContext[AgentDepsT]
290
322
  ) -> _messages.ToolReturnPart | _messages.RetryPromptPart:
291
- """Run the tool function asynchronously."""
292
323
  try:
293
324
  if isinstance(message.args, str):
294
325
  args_dict = self._validator.validate_json(message.args)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pydantic-ai-slim
3
- Version: 0.0.46
3
+ Version: 0.0.47
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,7 +29,7 @@ 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.46
32
+ Requires-Dist: pydantic-graph==0.0.47
33
33
  Requires-Dist: pydantic>=2.10
34
34
  Requires-Dist: typing-inspection>=0.4.0
35
35
  Provides-Extra: anthropic
@@ -41,13 +41,15 @@ Requires-Dist: argcomplete>=3.5.0; extra == 'cli'
41
41
  Requires-Dist: prompt-toolkit>=3; extra == 'cli'
42
42
  Requires-Dist: rich>=13; extra == 'cli'
43
43
  Provides-Extra: cohere
44
- Requires-Dist: cohere>=5.13.11; extra == 'cohere'
44
+ Requires-Dist: cohere>=5.13.11; (platform_system != 'Emscripten') and extra == 'cohere'
45
45
  Provides-Extra: duckduckgo
46
46
  Requires-Dist: duckduckgo-search>=7.0.0; extra == 'duckduckgo'
47
+ Provides-Extra: evals
48
+ Requires-Dist: pydantic-evals==0.0.41; extra == 'evals'
47
49
  Provides-Extra: groq
48
50
  Requires-Dist: groq>=0.15.0; extra == 'groq'
49
51
  Provides-Extra: logfire
50
- Requires-Dist: logfire>=2.3; extra == 'logfire'
52
+ Requires-Dist: logfire>=3.11.0; extra == 'logfire'
51
53
  Provides-Extra: mcp
52
54
  Requires-Dist: mcp>=1.4.1; (python_version >= '3.10') and extra == 'mcp'
53
55
  Provides-Extra: mistral
@@ -1,42 +1,43 @@
1
1
  pydantic_ai/__init__.py,sha256=5or1fE25gmemJGCznkFHC4VMeNT7vTLU6BiGxkmSA2A,959
2
- pydantic_ai/_agent_graph.py,sha256=aZHgDDEL0kYl7G0LAAPrrf4UufqB_FUN8s4PlnVqA-o,32557
3
- pydantic_ai/_cli.py,sha256=YrNi4vodEH-o5MlfG4CemdkdJl5kQx56nyCMp2QqRMw,8610
2
+ pydantic_ai/__main__.py,sha256=AW8FzscUWPFtIrQBG0QExLxTQehKtt5FnFVnOT200OE,122
3
+ pydantic_ai/_agent_graph.py,sha256=MWNNug-bGJcgOVonkkD38Yz3X4R0XfUxzFJ9_fpNnyQ,32532
4
+ pydantic_ai/_cli.py,sha256=_uK04vLLT08suu-VNd0ynMtzpUiF-jw8YpZaEVTiUUk,10360
4
5
  pydantic_ai/_griffe.py,sha256=Sf_DisE9k2TA0VFeVIK2nf1oOct5MygW86PBCACJkFA,5244
5
6
  pydantic_ai/_parts_manager.py,sha256=HIi6eth7z2g0tOn6iQYc633xMqy4d_xZ8vwka8J8150,12016
6
7
  pydantic_ai/_pydantic.py,sha256=12hX5hON88meO1QxbWrEPXSvr6RTNgr6ubKY6KRwab4,8890
7
- pydantic_ai/_result.py,sha256=SlxqR-AKWzDoc7cRRN2jmIZ7pCv3DKzaP-dnZW-e7us,10117
8
+ pydantic_ai/_result.py,sha256=32wDrq4F93f0BI9gcXeWposN49YaifF77qnyd_D57f0,10213
8
9
  pydantic_ai/_system_prompt.py,sha256=602c2jyle2R_SesOrITBDETZqsLk4BZ8Cbo8yEhmx04,1120
9
- pydantic_ai/_utils.py,sha256=s_cVIKiJk1wkLhXDRxxWZGd1QgXFey6HYJ0OGU8Kezs,9657
10
- pydantic_ai/agent.py,sha256=MvJb3625-btxeIUxVBjtKRWJ0k1Ty9hirsLsV57nrQQ,69504
10
+ pydantic_ai/_utils.py,sha256=VXbR6FG6WQU_TTN1NMmBDbZ6e6DT7PDiUiBHFHf348U,9703
11
+ pydantic_ai/agent.py,sha256=qBUE9uPgomSj09sHe6kQYxjXGMVsRs3nkPn5neRVlYg,69285
11
12
  pydantic_ai/exceptions.py,sha256=gvbFsFkAzSXOo_d1nfjy09kDHUGv1j5q70Uk-wKYGi8,3167
12
13
  pydantic_ai/format_as_xml.py,sha256=QE7eMlg5-YUMw1_2kcI3h0uKYPZZyGkgXFDtfZTMeeI,4480
13
14
  pydantic_ai/mcp.py,sha256=2Unphn9azcQVtf4_wXsqypkrWaLUoKoUCK9WAp-OOsI,8108
14
- pydantic_ai/messages.py,sha256=KQXG8BLnQtZzgU4ykOJT6LIs03Vem2eb0VqMyXmFt7I,27067
15
+ pydantic_ai/messages.py,sha256=IQS6vabH72yhvTQY1ciQxRqJDHpGMMR0MKiO5xcJ0SE,27112
15
16
  pydantic_ai/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
17
  pydantic_ai/result.py,sha256=LXKxRzy_rGMkdZ8xJ7yknPP3wGZtGNeZl-gh5opXbaQ,22542
17
18
  pydantic_ai/settings.py,sha256=q__Hordc4dypesNxpy_cBT5rFdSiEY-rQt9G6zfyFaM,3101
18
- pydantic_ai/tools.py,sha256=ImFy3V4fw_tvh5h8FZFpCrgnzlmoHCo-Y_9EjMwOSWc,14393
19
+ pydantic_ai/tools.py,sha256=5BGwmZYx4Aer6REoGPbk4CbrPJ3Uutass1RdcOhogKk,15744
19
20
  pydantic_ai/usage.py,sha256=9sqoIv_RVVUhKXQScTDqUJc074gifsuSzc9_NOt7C3g,5394
20
21
  pydantic_ai/common_tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
22
  pydantic_ai/common_tools/duckduckgo.py,sha256=Iw8Dl2YQ28S483mzfa8CXs-dc-ujS8un085R2O6oOEw,2241
22
23
  pydantic_ai/common_tools/tavily.py,sha256=h8deBDrpG-8BGzydM_zXs7z1ASrhdVvUxL4-CAbncBo,2589
23
- pydantic_ai/models/__init__.py,sha256=TEnxe6W7N0mdFQEDKaHiTBheXH1PQhXUApwc-FMDLUc,17107
24
- pydantic_ai/models/anthropic.py,sha256=O7gHDqM6V4zQLwjg5xyB6zDCAUXGaXcWtyXjV6vHLu0,21640
25
- pydantic_ai/models/bedrock.py,sha256=Fh5kNnH0H_OyKOUzSlVJYhc0K_wz3mrOH5Y4-oS6lmU,20532
26
- pydantic_ai/models/cohere.py,sha256=ogu97Strxsp6wzlNqT22SfgvltTeP1lLC5S86d037Ic,11249
24
+ pydantic_ai/models/__init__.py,sha256=kDGQmOsOyHNgp1VHdDRyfQeg-JSuDdDKbrB6OVol-Ek,18270
25
+ pydantic_ai/models/anthropic.py,sha256=fUX_iID4s3FRzm451xOlFXTg7_eg-GR1PM0ZrR-B_8A,21732
26
+ pydantic_ai/models/bedrock.py,sha256=EmnBwxx_FzKMM8xAed_1aTmDwASWo26GA6Q8Z92waVc,20706
27
+ pydantic_ai/models/cohere.py,sha256=ePOWml56gQcGgV1__pxbhMts0ZLDOfxrpiqsC4WutQM,11338
27
28
  pydantic_ai/models/fallback.py,sha256=y0bYXM3DfzJNAsyyMzclt33lzZazL-5_hwdgc33gfuM,4876
28
29
  pydantic_ai/models/function.py,sha256=HUSgPB3mKVfYI0OSJJJJRiQN-yeewjYIbrtrPfsvlgI,11365
29
- pydantic_ai/models/gemini.py,sha256=ox9WoqWgZ7Q-xTRJBv9loTy9P49uAwvJwCPoiqljhPM,33215
30
- pydantic_ai/models/groq.py,sha256=H-7Eu61EOxKoIPjI6wvofrA2PxSQxhd-BJOHT1p7KiA,15862
31
- pydantic_ai/models/instrumented.py,sha256=FMEcQ8RnASD7bR8Ol5a16W6yTq1P1F8FojgBIUXdt3w,10962
32
- pydantic_ai/models/mistral.py,sha256=0bA5vRGXOJulY7r-8jUT8gicAuTSg_sSN0riDP_j9oY,27243
33
- pydantic_ai/models/openai.py,sha256=W_J_pnoJLSYKTfs_4G9SpFzLPdD2trIDFqtNVSmJ1D4,20060
30
+ pydantic_ai/models/gemini.py,sha256=hcIB3TU6jnHHAYJDKobc3VDPNhr0jhRv_73-HmI-khQ,33304
31
+ pydantic_ai/models/groq.py,sha256=IbO2jMNC5yiYRuUJf-j4blpPvoQDromQNBKJyPjs2A4,16518
32
+ pydantic_ai/models/instrumented.py,sha256=ErFRDiOehOYlJBp4mSNj7yEIMtMqjlGcamEAwgW_Il4,11163
33
+ pydantic_ai/models/mistral.py,sha256=8pdG9oRW6Dx7H5P88ZgiRIZbkGkPUfEateuyvzoULOE,27439
34
+ pydantic_ai/models/openai.py,sha256=7i8KRbuiqAdt-UUILPuVlNJh1DiHriFlhu1azO1l_XA,20163
34
35
  pydantic_ai/models/test.py,sha256=qQ8ZIaVRdbJv-tKGu6lrdakVAhOsTlyf68TFWyGwOWE,16861
35
36
  pydantic_ai/models/wrapper.py,sha256=ff6JPTuIv9C_6Zo4kyYIO7Cn0VI1uSICz1v1aKUyeOc,1506
36
37
  pydantic_ai/providers/__init__.py,sha256=lsJn3BStrPMMAFWEkCYPyfMj3fEVfaeS2xllnvE6Gdk,2489
37
38
  pydantic_ai/providers/anthropic.py,sha256=0WzWEDseBaJ5eyEatvnDXBtDZKA9-od4BuPZn9NoTPw,2812
38
39
  pydantic_ai/providers/azure.py,sha256=1mJalM4W8Do4g6ZXAZ2u6EUHBTrDR_sAuAePLnI25CA,4213
39
- pydantic_ai/providers/bedrock.py,sha256=lSfK0mDqrmWLxzDKvtiY_nN2J3S_GGSPMRLJYeyvLrQ,2544
40
+ pydantic_ai/providers/bedrock.py,sha256=BV1Zi4asU4Bmcv4t7VRIy2U44Tk_Jrf26x8_mPJiYHQ,3216
40
41
  pydantic_ai/providers/cohere.py,sha256=WOFZCllgVbWciF4nNkG3pCqw4poy57VEGyux2mVntbQ,2667
41
42
  pydantic_ai/providers/deepseek.py,sha256=_5JPzDGWsyVyTBX-yYYdy5aZwUOWNCVgoWI-UoBamms,2193
42
43
  pydantic_ai/providers/google_gla.py,sha256=MJM7aRZRdP4kFlNg0ZHgC95O0wH02OQgbNiDQeK9fZo,1600
@@ -44,7 +45,7 @@ pydantic_ai/providers/google_vertex.py,sha256=WAwPxKTARVzs8DFs2veEUOJSur0krDOo9-
44
45
  pydantic_ai/providers/groq.py,sha256=DoY6qkfhuemuKB5JXhUkqG-3t1HQkxwSXoE_kHQIAK0,2788
45
46
  pydantic_ai/providers/mistral.py,sha256=fcR1uSwORo0jtevX7-wOjvcfT8ojMAaKY81uN5uYymM,2661
46
47
  pydantic_ai/providers/openai.py,sha256=ePF-QWwLkGkSE5w245gTTDVR3VoTIUqFoIhQ0TAoUiA,2866
47
- pydantic_ai_slim-0.0.46.dist-info/METADATA,sha256=j5pwFUPw48s3jN7ePCsspU3ztSJJbj3UaXpJw5Pr3Z8,3436
48
- pydantic_ai_slim-0.0.46.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
49
- pydantic_ai_slim-0.0.46.dist-info/entry_points.txt,sha256=KxQSmlMS8GMTkwTsl4_q9a5nJvBjj3HWeXx688wLrKg,45
50
- pydantic_ai_slim-0.0.46.dist-info/RECORD,,
48
+ pydantic_ai_slim-0.0.47.dist-info/METADATA,sha256=Df32-4l7OYVBjxRByOvG3XjV0XWEMbozcZDaIrMzNAs,3555
49
+ pydantic_ai_slim-0.0.47.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
50
+ pydantic_ai_slim-0.0.47.dist-info/entry_points.txt,sha256=KxQSmlMS8GMTkwTsl4_q9a5nJvBjj3HWeXx688wLrKg,45
51
+ pydantic_ai_slim-0.0.47.dist-info/RECORD,,