pydantic-ai-slim 1.0.16__py3-none-any.whl → 1.0.18__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.
- pydantic_ai/_parts_manager.py +3 -0
- pydantic_ai/agent/__init__.py +15 -2
- pydantic_ai/agent/abstract.py +27 -0
- pydantic_ai/agent/wrapper.py +6 -0
- pydantic_ai/builtin_tools.py +4 -1
- pydantic_ai/durable_exec/dbos/_agent.py +31 -2
- pydantic_ai/durable_exec/temporal/__init__.py +2 -0
- pydantic_ai/durable_exec/temporal/_agent.py +26 -0
- pydantic_ai/messages.py +12 -1
- pydantic_ai/models/__init__.py +1 -0
- pydantic_ai/models/openai.py +17 -10
- pydantic_ai/providers/__init__.py +4 -0
- pydantic_ai/providers/nebius.py +102 -0
- {pydantic_ai_slim-1.0.16.dist-info → pydantic_ai_slim-1.0.18.dist-info}/METADATA +3 -3
- {pydantic_ai_slim-1.0.16.dist-info → pydantic_ai_slim-1.0.18.dist-info}/RECORD +18 -17
- {pydantic_ai_slim-1.0.16.dist-info → pydantic_ai_slim-1.0.18.dist-info}/WHEEL +0 -0
- {pydantic_ai_slim-1.0.16.dist-info → pydantic_ai_slim-1.0.18.dist-info}/entry_points.txt +0 -0
- {pydantic_ai_slim-1.0.16.dist-info → pydantic_ai_slim-1.0.18.dist-info}/licenses/LICENSE +0 -0
pydantic_ai/_parts_manager.py
CHANGED
|
@@ -312,6 +312,7 @@ class ModelResponsePartsManager:
|
|
|
312
312
|
tool_name: str,
|
|
313
313
|
args: str | dict[str, Any] | None,
|
|
314
314
|
tool_call_id: str | None = None,
|
|
315
|
+
id: str | None = None,
|
|
315
316
|
) -> ModelResponseStreamEvent:
|
|
316
317
|
"""Immediately create or fully-overwrite a ToolCallPart with the given information.
|
|
317
318
|
|
|
@@ -323,6 +324,7 @@ class ModelResponsePartsManager:
|
|
|
323
324
|
tool_name: The name of the tool being invoked.
|
|
324
325
|
args: The arguments for the tool call, either as a string, a dictionary, or None.
|
|
325
326
|
tool_call_id: An optional string identifier for this tool call.
|
|
327
|
+
id: An optional identifier for this tool call part.
|
|
326
328
|
|
|
327
329
|
Returns:
|
|
328
330
|
ModelResponseStreamEvent: A `PartStartEvent` indicating that a new tool call part
|
|
@@ -332,6 +334,7 @@ class ModelResponsePartsManager:
|
|
|
332
334
|
tool_name=tool_name,
|
|
333
335
|
args=args,
|
|
334
336
|
tool_call_id=tool_call_id or _generate_tool_call_id(),
|
|
337
|
+
id=id,
|
|
335
338
|
)
|
|
336
339
|
if vendor_part_id is None:
|
|
337
340
|
# vendor_part_id is None, so we unconditionally append a new ToolCallPart to the end of the list
|
pydantic_ai/agent/__init__.py
CHANGED
|
@@ -426,6 +426,7 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
426
426
|
usage: _usage.RunUsage | None = None,
|
|
427
427
|
infer_name: bool = True,
|
|
428
428
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
429
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
429
430
|
) -> AbstractAsyncContextManager[AgentRun[AgentDepsT, OutputDataT]]: ...
|
|
430
431
|
|
|
431
432
|
@overload
|
|
@@ -443,6 +444,7 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
443
444
|
usage: _usage.RunUsage | None = None,
|
|
444
445
|
infer_name: bool = True,
|
|
445
446
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
447
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
446
448
|
) -> AbstractAsyncContextManager[AgentRun[AgentDepsT, RunOutputDataT]]: ...
|
|
447
449
|
|
|
448
450
|
@asynccontextmanager
|
|
@@ -460,6 +462,7 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
460
462
|
usage: _usage.RunUsage | None = None,
|
|
461
463
|
infer_name: bool = True,
|
|
462
464
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
465
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
463
466
|
) -> AsyncIterator[AgentRun[AgentDepsT, Any]]:
|
|
464
467
|
"""A contextmanager which can be used to iterate over the agent graph's nodes as they are executed.
|
|
465
468
|
|
|
@@ -532,6 +535,7 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
532
535
|
usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
|
|
533
536
|
infer_name: Whether to try to infer the agent name from the call frame if it's not set.
|
|
534
537
|
toolsets: Optional additional toolsets for this run.
|
|
538
|
+
builtin_tools: Optional additional builtin tools for this run.
|
|
535
539
|
|
|
536
540
|
Returns:
|
|
537
541
|
The result of the run.
|
|
@@ -603,7 +607,16 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
603
607
|
else:
|
|
604
608
|
instrumentation_settings = None
|
|
605
609
|
tracer = NoOpTracer()
|
|
606
|
-
|
|
610
|
+
if builtin_tools:
|
|
611
|
+
# Deduplicate builtin tools passed to the agent and the run based on type
|
|
612
|
+
builtin_tools = list(
|
|
613
|
+
{
|
|
614
|
+
**({type(tool): tool for tool in self._builtin_tools or []}),
|
|
615
|
+
**({type(tool): tool for tool in builtin_tools}),
|
|
616
|
+
}.values()
|
|
617
|
+
)
|
|
618
|
+
else:
|
|
619
|
+
builtin_tools = list(self._builtin_tools)
|
|
607
620
|
graph_deps = _agent_graph.GraphAgentDeps[AgentDepsT, RunOutputDataT](
|
|
608
621
|
user_deps=deps,
|
|
609
622
|
prompt=user_prompt,
|
|
@@ -616,7 +629,7 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
616
629
|
output_schema=output_schema,
|
|
617
630
|
output_validators=output_validators,
|
|
618
631
|
history_processors=self.history_processors,
|
|
619
|
-
builtin_tools=
|
|
632
|
+
builtin_tools=builtin_tools,
|
|
620
633
|
tool_manager=tool_manager,
|
|
621
634
|
tracer=tracer,
|
|
622
635
|
get_instructions=get_instructions,
|
pydantic_ai/agent/abstract.py
CHANGED
|
@@ -25,6 +25,7 @@ from .. import (
|
|
|
25
25
|
usage as _usage,
|
|
26
26
|
)
|
|
27
27
|
from .._tool_manager import ToolManager
|
|
28
|
+
from ..builtin_tools import AbstractBuiltinTool
|
|
28
29
|
from ..output import OutputDataT, OutputSpec
|
|
29
30
|
from ..result import AgentStream, FinalResult, StreamedRunResult
|
|
30
31
|
from ..run import AgentRun, AgentRunResult, AgentRunResultEvent
|
|
@@ -137,6 +138,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
137
138
|
usage: _usage.RunUsage | None = None,
|
|
138
139
|
infer_name: bool = True,
|
|
139
140
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
141
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
140
142
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
141
143
|
) -> AgentRunResult[OutputDataT]: ...
|
|
142
144
|
|
|
@@ -155,6 +157,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
155
157
|
usage: _usage.RunUsage | None = None,
|
|
156
158
|
infer_name: bool = True,
|
|
157
159
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
160
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
158
161
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
159
162
|
) -> AgentRunResult[RunOutputDataT]: ...
|
|
160
163
|
|
|
@@ -172,6 +175,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
172
175
|
usage: _usage.RunUsage | None = None,
|
|
173
176
|
infer_name: bool = True,
|
|
174
177
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
178
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
175
179
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
176
180
|
) -> AgentRunResult[Any]:
|
|
177
181
|
"""Run the agent with a user prompt in async mode.
|
|
@@ -205,6 +209,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
205
209
|
infer_name: Whether to try to infer the agent name from the call frame if it's not set.
|
|
206
210
|
toolsets: Optional additional toolsets for this run.
|
|
207
211
|
event_stream_handler: Optional handler for events from the model's streaming response and the agent's execution of tools to use for this run.
|
|
212
|
+
builtin_tools: Optional additional builtin tools for this run.
|
|
208
213
|
|
|
209
214
|
Returns:
|
|
210
215
|
The result of the run.
|
|
@@ -225,6 +230,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
225
230
|
usage_limits=usage_limits,
|
|
226
231
|
usage=usage,
|
|
227
232
|
toolsets=toolsets,
|
|
233
|
+
builtin_tools=builtin_tools,
|
|
228
234
|
) as agent_run:
|
|
229
235
|
async for node in agent_run:
|
|
230
236
|
if event_stream_handler is not None and (
|
|
@@ -251,6 +257,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
251
257
|
usage: _usage.RunUsage | None = None,
|
|
252
258
|
infer_name: bool = True,
|
|
253
259
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
260
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
254
261
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
255
262
|
) -> AgentRunResult[OutputDataT]: ...
|
|
256
263
|
|
|
@@ -269,6 +276,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
269
276
|
usage: _usage.RunUsage | None = None,
|
|
270
277
|
infer_name: bool = True,
|
|
271
278
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
279
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
272
280
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
273
281
|
) -> AgentRunResult[RunOutputDataT]: ...
|
|
274
282
|
|
|
@@ -286,6 +294,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
286
294
|
usage: _usage.RunUsage | None = None,
|
|
287
295
|
infer_name: bool = True,
|
|
288
296
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
297
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
289
298
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
290
299
|
) -> AgentRunResult[Any]:
|
|
291
300
|
"""Synchronously run the agent with a user prompt.
|
|
@@ -318,6 +327,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
318
327
|
infer_name: Whether to try to infer the agent name from the call frame if it's not set.
|
|
319
328
|
toolsets: Optional additional toolsets for this run.
|
|
320
329
|
event_stream_handler: Optional handler for events from the model's streaming response and the agent's execution of tools to use for this run.
|
|
330
|
+
builtin_tools: Optional additional builtin tools for this run.
|
|
321
331
|
|
|
322
332
|
Returns:
|
|
323
333
|
The result of the run.
|
|
@@ -338,6 +348,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
338
348
|
usage=usage,
|
|
339
349
|
infer_name=False,
|
|
340
350
|
toolsets=toolsets,
|
|
351
|
+
builtin_tools=builtin_tools,
|
|
341
352
|
event_stream_handler=event_stream_handler,
|
|
342
353
|
)
|
|
343
354
|
)
|
|
@@ -357,6 +368,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
357
368
|
usage: _usage.RunUsage | None = None,
|
|
358
369
|
infer_name: bool = True,
|
|
359
370
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
371
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
360
372
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
361
373
|
) -> AbstractAsyncContextManager[result.StreamedRunResult[AgentDepsT, OutputDataT]]: ...
|
|
362
374
|
|
|
@@ -375,6 +387,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
375
387
|
usage: _usage.RunUsage | None = None,
|
|
376
388
|
infer_name: bool = True,
|
|
377
389
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
390
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
378
391
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
379
392
|
) -> AbstractAsyncContextManager[result.StreamedRunResult[AgentDepsT, RunOutputDataT]]: ...
|
|
380
393
|
|
|
@@ -393,6 +406,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
393
406
|
usage: _usage.RunUsage | None = None,
|
|
394
407
|
infer_name: bool = True,
|
|
395
408
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
409
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
396
410
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
397
411
|
) -> AsyncIterator[result.StreamedRunResult[AgentDepsT, Any]]:
|
|
398
412
|
"""Run the agent with a user prompt in async streaming mode.
|
|
@@ -432,6 +446,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
432
446
|
usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
|
|
433
447
|
infer_name: Whether to try to infer the agent name from the call frame if it's not set.
|
|
434
448
|
toolsets: Optional additional toolsets for this run.
|
|
449
|
+
builtin_tools: Optional additional builtin tools for this run.
|
|
435
450
|
event_stream_handler: Optional handler for events from the model's streaming response and the agent's execution of tools to use for this run.
|
|
436
451
|
It will receive all the events up until the final result is found, which you can then read or stream from inside the context manager.
|
|
437
452
|
Note that it does _not_ receive any events after the final result is found.
|
|
@@ -459,6 +474,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
459
474
|
usage=usage,
|
|
460
475
|
infer_name=False,
|
|
461
476
|
toolsets=toolsets,
|
|
477
|
+
builtin_tools=builtin_tools,
|
|
462
478
|
) as agent_run:
|
|
463
479
|
first_node = agent_run.next_node # start with the first node
|
|
464
480
|
assert isinstance(first_node, _agent_graph.UserPromptNode) # the first node should be a user prompt node
|
|
@@ -568,6 +584,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
568
584
|
usage: _usage.RunUsage | None = None,
|
|
569
585
|
infer_name: bool = True,
|
|
570
586
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
587
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
571
588
|
) -> AsyncIterator[_messages.AgentStreamEvent | AgentRunResultEvent[OutputDataT]]: ...
|
|
572
589
|
|
|
573
590
|
@overload
|
|
@@ -585,6 +602,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
585
602
|
usage: _usage.RunUsage | None = None,
|
|
586
603
|
infer_name: bool = True,
|
|
587
604
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
605
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
588
606
|
) -> AsyncIterator[_messages.AgentStreamEvent | AgentRunResultEvent[RunOutputDataT]]: ...
|
|
589
607
|
|
|
590
608
|
def run_stream_events(
|
|
@@ -601,6 +619,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
601
619
|
usage: _usage.RunUsage | None = None,
|
|
602
620
|
infer_name: bool = True,
|
|
603
621
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
622
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
604
623
|
) -> AsyncIterator[_messages.AgentStreamEvent | AgentRunResultEvent[Any]]:
|
|
605
624
|
"""Run the agent with a user prompt in async mode and stream events from the run.
|
|
606
625
|
|
|
@@ -646,6 +665,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
646
665
|
usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
|
|
647
666
|
infer_name: Whether to try to infer the agent name from the call frame if it's not set.
|
|
648
667
|
toolsets: Optional additional toolsets for this run.
|
|
668
|
+
builtin_tools: Optional additional builtin tools for this run.
|
|
649
669
|
|
|
650
670
|
Returns:
|
|
651
671
|
An async iterable of stream events `AgentStreamEvent` and finally a `AgentRunResultEvent` with the final
|
|
@@ -666,6 +686,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
666
686
|
usage=usage,
|
|
667
687
|
infer_name=infer_name,
|
|
668
688
|
toolsets=toolsets,
|
|
689
|
+
builtin_tools=builtin_tools,
|
|
669
690
|
)
|
|
670
691
|
|
|
671
692
|
async def _run_stream_events(
|
|
@@ -682,6 +703,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
682
703
|
usage: _usage.RunUsage | None = None,
|
|
683
704
|
infer_name: bool = True,
|
|
684
705
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
706
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
685
707
|
) -> AsyncIterator[_messages.AgentStreamEvent | AgentRunResultEvent[Any]]:
|
|
686
708
|
send_stream, receive_stream = anyio.create_memory_object_stream[
|
|
687
709
|
_messages.AgentStreamEvent | AgentRunResultEvent[Any]
|
|
@@ -707,6 +729,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
707
729
|
usage=usage,
|
|
708
730
|
infer_name=infer_name,
|
|
709
731
|
toolsets=toolsets,
|
|
732
|
+
builtin_tools=builtin_tools,
|
|
710
733
|
event_stream_handler=event_stream_handler,
|
|
711
734
|
)
|
|
712
735
|
|
|
@@ -734,6 +757,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
734
757
|
usage: _usage.RunUsage | None = None,
|
|
735
758
|
infer_name: bool = True,
|
|
736
759
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
760
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
737
761
|
) -> AbstractAsyncContextManager[AgentRun[AgentDepsT, OutputDataT]]: ...
|
|
738
762
|
|
|
739
763
|
@overload
|
|
@@ -751,6 +775,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
751
775
|
usage: _usage.RunUsage | None = None,
|
|
752
776
|
infer_name: bool = True,
|
|
753
777
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
778
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
754
779
|
) -> AbstractAsyncContextManager[AgentRun[AgentDepsT, RunOutputDataT]]: ...
|
|
755
780
|
|
|
756
781
|
@asynccontextmanager
|
|
@@ -769,6 +794,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
769
794
|
usage: _usage.RunUsage | None = None,
|
|
770
795
|
infer_name: bool = True,
|
|
771
796
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
797
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
772
798
|
) -> AsyncIterator[AgentRun[AgentDepsT, Any]]:
|
|
773
799
|
"""A contextmanager which can be used to iterate over the agent graph's nodes as they are executed.
|
|
774
800
|
|
|
@@ -841,6 +867,7 @@ class AbstractAgent(Generic[AgentDepsT, OutputDataT], ABC):
|
|
|
841
867
|
usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
|
|
842
868
|
infer_name: Whether to try to infer the agent name from the call frame if it's not set.
|
|
843
869
|
toolsets: Optional additional toolsets for this run.
|
|
870
|
+
builtin_tools: Optional additional builtin tools for this run.
|
|
844
871
|
|
|
845
872
|
Returns:
|
|
846
873
|
The result of the run.
|
pydantic_ai/agent/wrapper.py
CHANGED
|
@@ -10,6 +10,7 @@ from .. import (
|
|
|
10
10
|
models,
|
|
11
11
|
usage as _usage,
|
|
12
12
|
)
|
|
13
|
+
from ..builtin_tools import AbstractBuiltinTool
|
|
13
14
|
from ..output import OutputDataT, OutputSpec
|
|
14
15
|
from ..run import AgentRun
|
|
15
16
|
from ..settings import ModelSettings
|
|
@@ -81,6 +82,7 @@ class WrapperAgent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
81
82
|
usage: _usage.RunUsage | None = None,
|
|
82
83
|
infer_name: bool = True,
|
|
83
84
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
85
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
84
86
|
) -> AbstractAsyncContextManager[AgentRun[AgentDepsT, OutputDataT]]: ...
|
|
85
87
|
|
|
86
88
|
@overload
|
|
@@ -98,6 +100,7 @@ class WrapperAgent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
98
100
|
usage: _usage.RunUsage | None = None,
|
|
99
101
|
infer_name: bool = True,
|
|
100
102
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
103
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
101
104
|
) -> AbstractAsyncContextManager[AgentRun[AgentDepsT, RunOutputDataT]]: ...
|
|
102
105
|
|
|
103
106
|
@asynccontextmanager
|
|
@@ -115,6 +118,7 @@ class WrapperAgent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
115
118
|
usage: _usage.RunUsage | None = None,
|
|
116
119
|
infer_name: bool = True,
|
|
117
120
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
121
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
118
122
|
) -> AsyncIterator[AgentRun[AgentDepsT, Any]]:
|
|
119
123
|
"""A contextmanager which can be used to iterate over the agent graph's nodes as they are executed.
|
|
120
124
|
|
|
@@ -187,6 +191,7 @@ class WrapperAgent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
187
191
|
usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
|
|
188
192
|
infer_name: Whether to try to infer the agent name from the call frame if it's not set.
|
|
189
193
|
toolsets: Optional additional toolsets for this run.
|
|
194
|
+
builtin_tools: Optional additional builtin tools for this run.
|
|
190
195
|
|
|
191
196
|
Returns:
|
|
192
197
|
The result of the run.
|
|
@@ -203,6 +208,7 @@ class WrapperAgent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
203
208
|
usage=usage,
|
|
204
209
|
infer_name=infer_name,
|
|
205
210
|
toolsets=toolsets,
|
|
211
|
+
builtin_tools=builtin_tools,
|
|
206
212
|
) as run:
|
|
207
213
|
yield run
|
|
208
214
|
|
pydantic_ai/builtin_tools.py
CHANGED
|
@@ -2,10 +2,13 @@ from __future__ import annotations as _annotations
|
|
|
2
2
|
|
|
3
3
|
from abc import ABC
|
|
4
4
|
from dataclasses import dataclass
|
|
5
|
-
from typing import Literal
|
|
5
|
+
from typing import TYPE_CHECKING, Literal
|
|
6
6
|
|
|
7
7
|
from typing_extensions import TypedDict
|
|
8
8
|
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from .builtin_tools import AbstractBuiltinTool
|
|
11
|
+
|
|
9
12
|
__all__ = (
|
|
10
13
|
'AbstractBuiltinTool',
|
|
11
14
|
'WebSearchTool',
|
|
@@ -15,8 +15,9 @@ from pydantic_ai import (
|
|
|
15
15
|
models,
|
|
16
16
|
usage as _usage,
|
|
17
17
|
)
|
|
18
|
-
from pydantic_ai.agent import AbstractAgent, AgentRun, AgentRunResult, EventStreamHandler,
|
|
19
|
-
from pydantic_ai.agent.abstract import Instructions
|
|
18
|
+
from pydantic_ai.agent import AbstractAgent, AgentRun, AgentRunResult, EventStreamHandler, WrapperAgent
|
|
19
|
+
from pydantic_ai.agent.abstract import Instructions, RunOutputDataT
|
|
20
|
+
from pydantic_ai.builtin_tools import AbstractBuiltinTool
|
|
20
21
|
from pydantic_ai.exceptions import UserError
|
|
21
22
|
from pydantic_ai.models import Model
|
|
22
23
|
from pydantic_ai.output import OutputDataT, OutputSpec
|
|
@@ -121,6 +122,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
121
122
|
usage: _usage.RunUsage | None = None,
|
|
122
123
|
infer_name: bool = True,
|
|
123
124
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
125
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
124
126
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
125
127
|
**_deprecated_kwargs: Never,
|
|
126
128
|
) -> AgentRunResult[Any]:
|
|
@@ -137,6 +139,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
137
139
|
usage=usage,
|
|
138
140
|
infer_name=infer_name,
|
|
139
141
|
toolsets=toolsets,
|
|
142
|
+
builtin_tools=builtin_tools,
|
|
140
143
|
event_stream_handler=event_stream_handler,
|
|
141
144
|
**_deprecated_kwargs,
|
|
142
145
|
)
|
|
@@ -158,6 +161,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
158
161
|
usage: _usage.RunUsage | None = None,
|
|
159
162
|
infer_name: bool = True,
|
|
160
163
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
164
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
161
165
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
162
166
|
**_deprecated_kwargs: Never,
|
|
163
167
|
) -> AgentRunResult[Any]:
|
|
@@ -174,6 +178,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
174
178
|
usage=usage,
|
|
175
179
|
infer_name=infer_name,
|
|
176
180
|
toolsets=toolsets,
|
|
181
|
+
builtin_tools=builtin_tools,
|
|
177
182
|
event_stream_handler=event_stream_handler,
|
|
178
183
|
**_deprecated_kwargs,
|
|
179
184
|
)
|
|
@@ -246,6 +251,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
246
251
|
usage: _usage.RunUsage | None = None,
|
|
247
252
|
infer_name: bool = True,
|
|
248
253
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
254
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
249
255
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
250
256
|
) -> AgentRunResult[OutputDataT]: ...
|
|
251
257
|
|
|
@@ -264,6 +270,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
264
270
|
usage: _usage.RunUsage | None = None,
|
|
265
271
|
infer_name: bool = True,
|
|
266
272
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
273
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
267
274
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
268
275
|
) -> AgentRunResult[RunOutputDataT]: ...
|
|
269
276
|
|
|
@@ -281,6 +288,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
281
288
|
usage: _usage.RunUsage | None = None,
|
|
282
289
|
infer_name: bool = True,
|
|
283
290
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
291
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
284
292
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
285
293
|
**_deprecated_kwargs: Never,
|
|
286
294
|
) -> AgentRunResult[Any]:
|
|
@@ -314,6 +322,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
314
322
|
usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
|
|
315
323
|
infer_name: Whether to try to infer the agent name from the call frame if it's not set.
|
|
316
324
|
toolsets: Optional additional toolsets for this run.
|
|
325
|
+
builtin_tools: Optional additional builtin tools for this run.
|
|
317
326
|
event_stream_handler: Optional event stream handler to use for this run.
|
|
318
327
|
|
|
319
328
|
Returns:
|
|
@@ -331,6 +340,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
331
340
|
usage=usage,
|
|
332
341
|
infer_name=infer_name,
|
|
333
342
|
toolsets=toolsets,
|
|
343
|
+
builtin_tools=builtin_tools,
|
|
334
344
|
event_stream_handler=event_stream_handler,
|
|
335
345
|
**_deprecated_kwargs,
|
|
336
346
|
)
|
|
@@ -350,6 +360,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
350
360
|
usage: _usage.RunUsage | None = None,
|
|
351
361
|
infer_name: bool = True,
|
|
352
362
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
363
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
353
364
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
354
365
|
) -> AgentRunResult[OutputDataT]: ...
|
|
355
366
|
|
|
@@ -368,6 +379,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
368
379
|
usage: _usage.RunUsage | None = None,
|
|
369
380
|
infer_name: bool = True,
|
|
370
381
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
382
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
371
383
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
372
384
|
) -> AgentRunResult[RunOutputDataT]: ...
|
|
373
385
|
|
|
@@ -385,6 +397,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
385
397
|
usage: _usage.RunUsage | None = None,
|
|
386
398
|
infer_name: bool = True,
|
|
387
399
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
400
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
388
401
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
389
402
|
**_deprecated_kwargs: Never,
|
|
390
403
|
) -> AgentRunResult[Any]:
|
|
@@ -417,6 +430,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
417
430
|
usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
|
|
418
431
|
infer_name: Whether to try to infer the agent name from the call frame if it's not set.
|
|
419
432
|
toolsets: Optional additional toolsets for this run.
|
|
433
|
+
builtin_tools: Optional additional builtin tools for this run.
|
|
420
434
|
event_stream_handler: Optional event stream handler to use for this run.
|
|
421
435
|
|
|
422
436
|
Returns:
|
|
@@ -434,6 +448,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
434
448
|
usage=usage,
|
|
435
449
|
infer_name=infer_name,
|
|
436
450
|
toolsets=toolsets,
|
|
451
|
+
builtin_tools=builtin_tools,
|
|
437
452
|
event_stream_handler=event_stream_handler,
|
|
438
453
|
**_deprecated_kwargs,
|
|
439
454
|
)
|
|
@@ -453,6 +468,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
453
468
|
usage: _usage.RunUsage | None = None,
|
|
454
469
|
infer_name: bool = True,
|
|
455
470
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
471
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
456
472
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
457
473
|
) -> AbstractAsyncContextManager[StreamedRunResult[AgentDepsT, OutputDataT]]: ...
|
|
458
474
|
|
|
@@ -471,6 +487,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
471
487
|
usage: _usage.RunUsage | None = None,
|
|
472
488
|
infer_name: bool = True,
|
|
473
489
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
490
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
474
491
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
475
492
|
) -> AbstractAsyncContextManager[StreamedRunResult[AgentDepsT, RunOutputDataT]]: ...
|
|
476
493
|
|
|
@@ -489,6 +506,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
489
506
|
usage: _usage.RunUsage | None = None,
|
|
490
507
|
infer_name: bool = True,
|
|
491
508
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
509
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
492
510
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
493
511
|
**_deprecated_kwargs: Never,
|
|
494
512
|
) -> AsyncIterator[StreamedRunResult[AgentDepsT, Any]]:
|
|
@@ -519,6 +537,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
519
537
|
usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
|
|
520
538
|
infer_name: Whether to try to infer the agent name from the call frame if it's not set.
|
|
521
539
|
toolsets: Optional additional toolsets for this run.
|
|
540
|
+
builtin_tools: Optional additional builtin tools for this run.
|
|
522
541
|
event_stream_handler: Optional event stream handler to use for this run. It will receive all the events up until the final result is found, which you can then read or stream from inside the context manager.
|
|
523
542
|
|
|
524
543
|
Returns:
|
|
@@ -542,6 +561,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
542
561
|
usage=usage,
|
|
543
562
|
infer_name=infer_name,
|
|
544
563
|
toolsets=toolsets,
|
|
564
|
+
builtin_tools=builtin_tools,
|
|
545
565
|
event_stream_handler=event_stream_handler,
|
|
546
566
|
**_deprecated_kwargs,
|
|
547
567
|
) as result:
|
|
@@ -562,6 +582,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
562
582
|
usage: _usage.RunUsage | None = None,
|
|
563
583
|
infer_name: bool = True,
|
|
564
584
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
585
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
565
586
|
) -> AsyncIterator[_messages.AgentStreamEvent | AgentRunResultEvent[OutputDataT]]: ...
|
|
566
587
|
|
|
567
588
|
@overload
|
|
@@ -579,6 +600,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
579
600
|
usage: _usage.RunUsage | None = None,
|
|
580
601
|
infer_name: bool = True,
|
|
581
602
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
603
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
582
604
|
) -> AsyncIterator[_messages.AgentStreamEvent | AgentRunResultEvent[RunOutputDataT]]: ...
|
|
583
605
|
|
|
584
606
|
def run_stream_events(
|
|
@@ -595,6 +617,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
595
617
|
usage: _usage.RunUsage | None = None,
|
|
596
618
|
infer_name: bool = True,
|
|
597
619
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
620
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
598
621
|
) -> AsyncIterator[_messages.AgentStreamEvent | AgentRunResultEvent[Any]]:
|
|
599
622
|
"""Run the agent with a user prompt in async mode and stream events from the run.
|
|
600
623
|
|
|
@@ -640,6 +663,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
640
663
|
usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
|
|
641
664
|
infer_name: Whether to try to infer the agent name from the call frame if it's not set.
|
|
642
665
|
toolsets: Optional additional toolsets for this run.
|
|
666
|
+
builtin_tools: Optional additional builtin tools for this run.
|
|
643
667
|
|
|
644
668
|
Returns:
|
|
645
669
|
An async iterable of stream events `AgentStreamEvent` and finally a `AgentRunResultEvent` with the final
|
|
@@ -665,6 +689,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
665
689
|
usage: _usage.RunUsage | None = None,
|
|
666
690
|
infer_name: bool = True,
|
|
667
691
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
692
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
668
693
|
**_deprecated_kwargs: Never,
|
|
669
694
|
) -> AbstractAsyncContextManager[AgentRun[AgentDepsT, OutputDataT]]: ...
|
|
670
695
|
|
|
@@ -683,6 +708,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
683
708
|
usage: _usage.RunUsage | None = None,
|
|
684
709
|
infer_name: bool = True,
|
|
685
710
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
711
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
686
712
|
**_deprecated_kwargs: Never,
|
|
687
713
|
) -> AbstractAsyncContextManager[AgentRun[AgentDepsT, RunOutputDataT]]: ...
|
|
688
714
|
|
|
@@ -701,6 +727,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
701
727
|
usage: _usage.RunUsage | None = None,
|
|
702
728
|
infer_name: bool = True,
|
|
703
729
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
730
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
704
731
|
**_deprecated_kwargs: Never,
|
|
705
732
|
) -> AsyncIterator[AgentRun[AgentDepsT, Any]]:
|
|
706
733
|
"""A contextmanager which can be used to iterate over the agent graph's nodes as they are executed.
|
|
@@ -774,6 +801,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
774
801
|
usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
|
|
775
802
|
infer_name: Whether to try to infer the agent name from the call frame if it's not set.
|
|
776
803
|
toolsets: Optional additional toolsets for this run.
|
|
804
|
+
builtin_tools: Optional additional builtin tools for this run.
|
|
777
805
|
|
|
778
806
|
Returns:
|
|
779
807
|
The result of the run.
|
|
@@ -796,6 +824,7 @@ class DBOSAgent(WrapperAgent[AgentDepsT, OutputDataT], DBOSConfiguredInstance):
|
|
|
796
824
|
usage=usage,
|
|
797
825
|
infer_name=infer_name,
|
|
798
826
|
toolsets=toolsets,
|
|
827
|
+
builtin_tools=builtin_tools,
|
|
799
828
|
**_deprecated_kwargs,
|
|
800
829
|
) as run:
|
|
801
830
|
yield run
|
|
@@ -62,6 +62,8 @@ class PydanticAIPlugin(ClientPlugin, WorkerPlugin):
|
|
|
62
62
|
'logfire',
|
|
63
63
|
'rich',
|
|
64
64
|
'httpx',
|
|
65
|
+
'anyio',
|
|
66
|
+
'httpcore',
|
|
65
67
|
# Imported inside `logfire._internal.json_encoder` when running `logfire.info` inside an activity with attributes to serialize
|
|
66
68
|
'attrs',
|
|
67
69
|
# Imported inside `logfire._internal.json_schema` when running `logfire.info` inside an activity with attributes to serialize
|
|
@@ -25,6 +25,7 @@ from pydantic_ai import (
|
|
|
25
25
|
)
|
|
26
26
|
from pydantic_ai.agent import AbstractAgent, AgentRun, AgentRunResult, EventStreamHandler, WrapperAgent
|
|
27
27
|
from pydantic_ai.agent.abstract import Instructions, RunOutputDataT
|
|
28
|
+
from pydantic_ai.builtin_tools import AbstractBuiltinTool
|
|
28
29
|
from pydantic_ai.exceptions import UserError
|
|
29
30
|
from pydantic_ai.models import Model
|
|
30
31
|
from pydantic_ai.output import OutputDataT, OutputSpec
|
|
@@ -268,6 +269,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
268
269
|
usage: _usage.RunUsage | None = None,
|
|
269
270
|
infer_name: bool = True,
|
|
270
271
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
272
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
271
273
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
272
274
|
) -> AgentRunResult[OutputDataT]: ...
|
|
273
275
|
|
|
@@ -286,6 +288,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
286
288
|
usage: _usage.RunUsage | None = None,
|
|
287
289
|
infer_name: bool = True,
|
|
288
290
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
291
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
289
292
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
290
293
|
) -> AgentRunResult[RunOutputDataT]: ...
|
|
291
294
|
|
|
@@ -303,6 +306,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
303
306
|
usage: _usage.RunUsage | None = None,
|
|
304
307
|
infer_name: bool = True,
|
|
305
308
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
309
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
306
310
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
307
311
|
**_deprecated_kwargs: Never,
|
|
308
312
|
) -> AgentRunResult[Any]:
|
|
@@ -337,6 +341,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
337
341
|
infer_name: Whether to try to infer the agent name from the call frame if it's not set.
|
|
338
342
|
toolsets: Optional additional toolsets for this run.
|
|
339
343
|
event_stream_handler: Optional event stream handler to use for this run.
|
|
344
|
+
builtin_tools: Optional additional builtin tools for this run.
|
|
340
345
|
|
|
341
346
|
Returns:
|
|
342
347
|
The result of the run.
|
|
@@ -359,6 +364,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
359
364
|
usage=usage,
|
|
360
365
|
infer_name=infer_name,
|
|
361
366
|
toolsets=toolsets,
|
|
367
|
+
builtin_tools=builtin_tools,
|
|
362
368
|
event_stream_handler=event_stream_handler or self.event_stream_handler,
|
|
363
369
|
**_deprecated_kwargs,
|
|
364
370
|
)
|
|
@@ -378,6 +384,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
378
384
|
usage: _usage.RunUsage | None = None,
|
|
379
385
|
infer_name: bool = True,
|
|
380
386
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
387
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
381
388
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
382
389
|
) -> AgentRunResult[OutputDataT]: ...
|
|
383
390
|
|
|
@@ -396,6 +403,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
396
403
|
usage: _usage.RunUsage | None = None,
|
|
397
404
|
infer_name: bool = True,
|
|
398
405
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
406
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
399
407
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
400
408
|
) -> AgentRunResult[RunOutputDataT]: ...
|
|
401
409
|
|
|
@@ -413,6 +421,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
413
421
|
usage: _usage.RunUsage | None = None,
|
|
414
422
|
infer_name: bool = True,
|
|
415
423
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
424
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
416
425
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
417
426
|
**_deprecated_kwargs: Never,
|
|
418
427
|
) -> AgentRunResult[Any]:
|
|
@@ -446,6 +455,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
446
455
|
infer_name: Whether to try to infer the agent name from the call frame if it's not set.
|
|
447
456
|
toolsets: Optional additional toolsets for this run.
|
|
448
457
|
event_stream_handler: Optional event stream handler to use for this run.
|
|
458
|
+
builtin_tools: Optional additional builtin tools for this run.
|
|
449
459
|
|
|
450
460
|
Returns:
|
|
451
461
|
The result of the run.
|
|
@@ -467,6 +477,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
467
477
|
usage=usage,
|
|
468
478
|
infer_name=infer_name,
|
|
469
479
|
toolsets=toolsets,
|
|
480
|
+
builtin_tools=builtin_tools,
|
|
470
481
|
event_stream_handler=event_stream_handler,
|
|
471
482
|
**_deprecated_kwargs,
|
|
472
483
|
)
|
|
@@ -486,6 +497,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
486
497
|
usage: _usage.RunUsage | None = None,
|
|
487
498
|
infer_name: bool = True,
|
|
488
499
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
500
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
489
501
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
490
502
|
) -> AbstractAsyncContextManager[StreamedRunResult[AgentDepsT, OutputDataT]]: ...
|
|
491
503
|
|
|
@@ -504,6 +516,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
504
516
|
usage: _usage.RunUsage | None = None,
|
|
505
517
|
infer_name: bool = True,
|
|
506
518
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
519
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
507
520
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
508
521
|
) -> AbstractAsyncContextManager[StreamedRunResult[AgentDepsT, RunOutputDataT]]: ...
|
|
509
522
|
|
|
@@ -522,6 +535,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
522
535
|
usage: _usage.RunUsage | None = None,
|
|
523
536
|
infer_name: bool = True,
|
|
524
537
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
538
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
525
539
|
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
|
|
526
540
|
**_deprecated_kwargs: Never,
|
|
527
541
|
) -> AsyncIterator[StreamedRunResult[AgentDepsT, Any]]:
|
|
@@ -552,6 +566,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
552
566
|
usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
|
|
553
567
|
infer_name: Whether to try to infer the agent name from the call frame if it's not set.
|
|
554
568
|
toolsets: Optional additional toolsets for this run.
|
|
569
|
+
builtin_tools: Optional additional builtin tools for this run.
|
|
555
570
|
event_stream_handler: Optional event stream handler to use for this run. It will receive all the events up until the final result is found, which you can then read or stream from inside the context manager.
|
|
556
571
|
|
|
557
572
|
Returns:
|
|
@@ -576,6 +591,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
576
591
|
infer_name=infer_name,
|
|
577
592
|
toolsets=toolsets,
|
|
578
593
|
event_stream_handler=event_stream_handler,
|
|
594
|
+
builtin_tools=builtin_tools,
|
|
579
595
|
**_deprecated_kwargs,
|
|
580
596
|
) as result:
|
|
581
597
|
yield result
|
|
@@ -595,6 +611,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
595
611
|
usage: _usage.RunUsage | None = None,
|
|
596
612
|
infer_name: bool = True,
|
|
597
613
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
614
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
598
615
|
) -> AsyncIterator[_messages.AgentStreamEvent | AgentRunResultEvent[OutputDataT]]: ...
|
|
599
616
|
|
|
600
617
|
@overload
|
|
@@ -612,6 +629,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
612
629
|
usage: _usage.RunUsage | None = None,
|
|
613
630
|
infer_name: bool = True,
|
|
614
631
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
632
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
615
633
|
) -> AsyncIterator[_messages.AgentStreamEvent | AgentRunResultEvent[RunOutputDataT]]: ...
|
|
616
634
|
|
|
617
635
|
def run_stream_events(
|
|
@@ -628,6 +646,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
628
646
|
usage: _usage.RunUsage | None = None,
|
|
629
647
|
infer_name: bool = True,
|
|
630
648
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
649
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
631
650
|
) -> AsyncIterator[_messages.AgentStreamEvent | AgentRunResultEvent[Any]]:
|
|
632
651
|
"""Run the agent with a user prompt in async mode and stream events from the run.
|
|
633
652
|
|
|
@@ -673,6 +692,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
673
692
|
usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
|
|
674
693
|
infer_name: Whether to try to infer the agent name from the call frame if it's not set.
|
|
675
694
|
toolsets: Optional additional toolsets for this run.
|
|
695
|
+
builtin_tools: Optional additional builtin tools for this run.
|
|
676
696
|
|
|
677
697
|
Returns:
|
|
678
698
|
An async iterable of stream events `AgentStreamEvent` and finally a `AgentRunResultEvent` with the final
|
|
@@ -696,6 +716,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
696
716
|
usage=usage,
|
|
697
717
|
infer_name=infer_name,
|
|
698
718
|
toolsets=toolsets,
|
|
719
|
+
builtin_tools=builtin_tools,
|
|
699
720
|
)
|
|
700
721
|
|
|
701
722
|
@overload
|
|
@@ -712,6 +733,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
712
733
|
usage_limits: _usage.UsageLimits | None = None,
|
|
713
734
|
usage: _usage.RunUsage | None = None,
|
|
714
735
|
infer_name: bool = True,
|
|
736
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
715
737
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
716
738
|
**_deprecated_kwargs: Never,
|
|
717
739
|
) -> AbstractAsyncContextManager[AgentRun[AgentDepsT, OutputDataT]]: ...
|
|
@@ -731,6 +753,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
731
753
|
usage: _usage.RunUsage | None = None,
|
|
732
754
|
infer_name: bool = True,
|
|
733
755
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
756
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
734
757
|
**_deprecated_kwargs: Never,
|
|
735
758
|
) -> AbstractAsyncContextManager[AgentRun[AgentDepsT, RunOutputDataT]]: ...
|
|
736
759
|
|
|
@@ -749,6 +772,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
749
772
|
usage: _usage.RunUsage | None = None,
|
|
750
773
|
infer_name: bool = True,
|
|
751
774
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
775
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
752
776
|
**_deprecated_kwargs: Never,
|
|
753
777
|
) -> AsyncIterator[AgentRun[AgentDepsT, Any]]:
|
|
754
778
|
"""A contextmanager which can be used to iterate over the agent graph's nodes as they are executed.
|
|
@@ -822,6 +846,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
822
846
|
usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
|
|
823
847
|
infer_name: Whether to try to infer the agent name from the call frame if it's not set.
|
|
824
848
|
toolsets: Optional additional toolsets for this run.
|
|
849
|
+
builtin_tools: Optional additional builtin tools for this run.
|
|
825
850
|
|
|
826
851
|
Returns:
|
|
827
852
|
The result of the run.
|
|
@@ -854,6 +879,7 @@ class TemporalAgent(WrapperAgent[AgentDepsT, OutputDataT]):
|
|
|
854
879
|
usage=usage,
|
|
855
880
|
infer_name=infer_name,
|
|
856
881
|
toolsets=toolsets,
|
|
882
|
+
builtin_tools=builtin_tools,
|
|
857
883
|
**_deprecated_kwargs,
|
|
858
884
|
) as run:
|
|
859
885
|
yield run
|
pydantic_ai/messages.py
CHANGED
|
@@ -595,9 +595,13 @@ class BinaryImage(BinaryContent):
|
|
|
595
595
|
media_type: str,
|
|
596
596
|
identifier: str | None = None,
|
|
597
597
|
vendor_metadata: dict[str, Any] | None = None,
|
|
598
|
+
# Required for inline-snapshot which expects all dataclass `__init__` methods to take all field names as kwargs.
|
|
598
599
|
kind: Literal['binary'] = 'binary',
|
|
600
|
+
_identifier: str | None = None,
|
|
599
601
|
):
|
|
600
|
-
super().__init__(
|
|
602
|
+
super().__init__(
|
|
603
|
+
data=data, media_type=media_type, identifier=identifier or _identifier, vendor_metadata=vendor_metadata
|
|
604
|
+
)
|
|
601
605
|
|
|
602
606
|
if not self.is_image:
|
|
603
607
|
raise ValueError('`BinaryImage` must be have a media type that starts with "image/"') # pragma: no cover
|
|
@@ -1048,6 +1052,13 @@ class BaseToolCallPart:
|
|
|
1048
1052
|
In case the tool call id is not provided by the model, Pydantic AI will generate a random one.
|
|
1049
1053
|
"""
|
|
1050
1054
|
|
|
1055
|
+
_: KW_ONLY
|
|
1056
|
+
|
|
1057
|
+
id: str | None = None
|
|
1058
|
+
"""An optional identifier of the tool call part, separate from the tool call ID.
|
|
1059
|
+
|
|
1060
|
+
This is used by some APIs like OpenAI Responses."""
|
|
1061
|
+
|
|
1051
1062
|
def args_as_dict(self) -> dict[str, Any]:
|
|
1052
1063
|
"""Return the arguments as a Python dictionary.
|
|
1053
1064
|
|
pydantic_ai/models/__init__.py
CHANGED
pydantic_ai/models/openai.py
CHANGED
|
@@ -284,6 +284,7 @@ class OpenAIChatModel(Model):
|
|
|
284
284
|
'together',
|
|
285
285
|
'vercel',
|
|
286
286
|
'litellm',
|
|
287
|
+
'nebius',
|
|
287
288
|
]
|
|
288
289
|
| Provider[AsyncOpenAI] = 'openai',
|
|
289
290
|
profile: ModelProfileSpec | None = None,
|
|
@@ -312,6 +313,7 @@ class OpenAIChatModel(Model):
|
|
|
312
313
|
'together',
|
|
313
314
|
'vercel',
|
|
314
315
|
'litellm',
|
|
316
|
+
'nebius',
|
|
315
317
|
]
|
|
316
318
|
| Provider[AsyncOpenAI] = 'openai',
|
|
317
319
|
profile: ModelProfileSpec | None = None,
|
|
@@ -339,6 +341,7 @@ class OpenAIChatModel(Model):
|
|
|
339
341
|
'together',
|
|
340
342
|
'vercel',
|
|
341
343
|
'litellm',
|
|
344
|
+
'nebius',
|
|
342
345
|
]
|
|
343
346
|
| Provider[AsyncOpenAI] = 'openai',
|
|
344
347
|
profile: ModelProfileSpec | None = None,
|
|
@@ -899,7 +902,7 @@ class OpenAIResponsesModel(Model):
|
|
|
899
902
|
self,
|
|
900
903
|
model_name: OpenAIModelName,
|
|
901
904
|
*,
|
|
902
|
-
provider: Literal['openai', 'deepseek', 'azure', 'openrouter', 'grok', 'fireworks', 'together']
|
|
905
|
+
provider: Literal['openai', 'deepseek', 'azure', 'openrouter', 'grok', 'fireworks', 'together', 'nebius']
|
|
903
906
|
| Provider[AsyncOpenAI] = 'openai',
|
|
904
907
|
profile: ModelProfileSpec | None = None,
|
|
905
908
|
settings: ModelSettings | None = None,
|
|
@@ -1005,7 +1008,12 @@ class OpenAIResponsesModel(Model):
|
|
|
1005
1008
|
items.append(TextPart(content.text, id=item.id))
|
|
1006
1009
|
elif isinstance(item, responses.ResponseFunctionToolCall):
|
|
1007
1010
|
items.append(
|
|
1008
|
-
ToolCallPart(
|
|
1011
|
+
ToolCallPart(
|
|
1012
|
+
item.name,
|
|
1013
|
+
item.arguments,
|
|
1014
|
+
tool_call_id=item.call_id,
|
|
1015
|
+
id=item.id,
|
|
1016
|
+
)
|
|
1009
1017
|
)
|
|
1010
1018
|
elif isinstance(item, responses.ResponseCodeInterpreterToolCall):
|
|
1011
1019
|
call_part, return_part, file_parts = _map_code_interpreter_tool_call(item, self.system)
|
|
@@ -1178,7 +1186,7 @@ class OpenAIResponsesModel(Model):
|
|
|
1178
1186
|
truncation=model_settings.get('openai_truncation', NOT_GIVEN),
|
|
1179
1187
|
timeout=model_settings.get('timeout', NOT_GIVEN),
|
|
1180
1188
|
service_tier=model_settings.get('openai_service_tier', NOT_GIVEN),
|
|
1181
|
-
previous_response_id=previous_response_id,
|
|
1189
|
+
previous_response_id=previous_response_id or NOT_GIVEN,
|
|
1182
1190
|
reasoning=reasoning,
|
|
1183
1191
|
user=model_settings.get('openai_user', NOT_GIVEN),
|
|
1184
1192
|
text=text or NOT_GIVEN,
|
|
@@ -1361,6 +1369,7 @@ class OpenAIResponsesModel(Model):
|
|
|
1361
1369
|
elif isinstance(item, ToolCallPart):
|
|
1362
1370
|
call_id = _guard_tool_call_id(t=item)
|
|
1363
1371
|
call_id, id = _split_combined_tool_call_id(call_id)
|
|
1372
|
+
id = id or item.id
|
|
1364
1373
|
|
|
1365
1374
|
param = responses.ResponseFunctionToolCallParam(
|
|
1366
1375
|
name=item.tool_name,
|
|
@@ -1724,7 +1733,8 @@ class OpenAIResponsesStreamedResponse(StreamedResponse):
|
|
|
1724
1733
|
vendor_part_id=chunk.item.id,
|
|
1725
1734
|
tool_name=chunk.item.name,
|
|
1726
1735
|
args=chunk.item.arguments,
|
|
1727
|
-
tool_call_id=
|
|
1736
|
+
tool_call_id=chunk.item.call_id,
|
|
1737
|
+
id=chunk.item.id,
|
|
1728
1738
|
)
|
|
1729
1739
|
elif isinstance(chunk.item, responses.ResponseReasoningItem):
|
|
1730
1740
|
pass
|
|
@@ -1963,18 +1973,15 @@ def _map_usage(response: chat.ChatCompletion | ChatCompletionChunk | responses.R
|
|
|
1963
1973
|
return u
|
|
1964
1974
|
|
|
1965
1975
|
|
|
1966
|
-
def
|
|
1976
|
+
def _split_combined_tool_call_id(combined_id: str) -> tuple[str, str | None]:
|
|
1967
1977
|
# When reasoning, the Responses API requires the `ResponseFunctionToolCall` to be returned with both the `call_id` and `id` fields.
|
|
1968
|
-
#
|
|
1969
|
-
return f'{call_id}|{id}' if id else call_id
|
|
1978
|
+
# Before our `ToolCallPart` gained the `id` field alongside `tool_call_id` field, we combined the two fields into a single string stored on `tool_call_id`.
|
|
1970
1979
|
|
|
1971
|
-
|
|
1972
|
-
def _split_combined_tool_call_id(combined_id: str) -> tuple[str, str | None]:
|
|
1973
1980
|
if '|' in combined_id:
|
|
1974
1981
|
call_id, id = combined_id.split('|', 1)
|
|
1975
1982
|
return call_id, id
|
|
1976
1983
|
else:
|
|
1977
|
-
return combined_id, None
|
|
1984
|
+
return combined_id, None
|
|
1978
1985
|
|
|
1979
1986
|
|
|
1980
1987
|
def _map_code_interpreter_tool_call(
|
|
@@ -142,6 +142,10 @@ def infer_provider_class(provider: str) -> type[Provider[Any]]: # noqa: C901
|
|
|
142
142
|
from .litellm import LiteLLMProvider
|
|
143
143
|
|
|
144
144
|
return LiteLLMProvider
|
|
145
|
+
elif provider == 'nebius':
|
|
146
|
+
from .nebius import NebiusProvider
|
|
147
|
+
|
|
148
|
+
return NebiusProvider
|
|
145
149
|
else: # pragma: no cover
|
|
146
150
|
raise ValueError(f'Unknown provider: {provider}')
|
|
147
151
|
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
from __future__ import annotations as _annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from typing import overload
|
|
5
|
+
|
|
6
|
+
import httpx
|
|
7
|
+
|
|
8
|
+
from pydantic_ai import ModelProfile
|
|
9
|
+
from pydantic_ai.exceptions import UserError
|
|
10
|
+
from pydantic_ai.models import cached_async_http_client
|
|
11
|
+
from pydantic_ai.profiles.deepseek import deepseek_model_profile
|
|
12
|
+
from pydantic_ai.profiles.google import google_model_profile
|
|
13
|
+
from pydantic_ai.profiles.harmony import harmony_model_profile
|
|
14
|
+
from pydantic_ai.profiles.meta import meta_model_profile
|
|
15
|
+
from pydantic_ai.profiles.mistral import mistral_model_profile
|
|
16
|
+
from pydantic_ai.profiles.moonshotai import moonshotai_model_profile
|
|
17
|
+
from pydantic_ai.profiles.openai import OpenAIJsonSchemaTransformer, OpenAIModelProfile
|
|
18
|
+
from pydantic_ai.profiles.qwen import qwen_model_profile
|
|
19
|
+
from pydantic_ai.providers import Provider
|
|
20
|
+
|
|
21
|
+
try:
|
|
22
|
+
from openai import AsyncOpenAI
|
|
23
|
+
except ImportError as _import_error: # pragma: no cover
|
|
24
|
+
raise ImportError(
|
|
25
|
+
'Please install the `openai` package to use the Nebius provider, '
|
|
26
|
+
'you can use the `openai` optional group — `pip install "pydantic-ai-slim[openai]"`'
|
|
27
|
+
) from _import_error
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class NebiusProvider(Provider[AsyncOpenAI]):
|
|
31
|
+
"""Provider for Nebius AI Studio API."""
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def name(self) -> str:
|
|
35
|
+
return 'nebius'
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def base_url(self) -> str:
|
|
39
|
+
return 'https://api.studio.nebius.com/v1'
|
|
40
|
+
|
|
41
|
+
@property
|
|
42
|
+
def client(self) -> AsyncOpenAI:
|
|
43
|
+
return self._client
|
|
44
|
+
|
|
45
|
+
def model_profile(self, model_name: str) -> ModelProfile | None:
|
|
46
|
+
provider_to_profile = {
|
|
47
|
+
'meta-llama': meta_model_profile,
|
|
48
|
+
'deepseek-ai': deepseek_model_profile,
|
|
49
|
+
'qwen': qwen_model_profile,
|
|
50
|
+
'google': google_model_profile,
|
|
51
|
+
'openai': harmony_model_profile, # used for gpt-oss models on Nebius
|
|
52
|
+
'mistralai': mistral_model_profile,
|
|
53
|
+
'moonshotai': moonshotai_model_profile,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
profile = None
|
|
57
|
+
|
|
58
|
+
try:
|
|
59
|
+
model_name = model_name.lower()
|
|
60
|
+
provider, model_name = model_name.split('/', 1)
|
|
61
|
+
except ValueError:
|
|
62
|
+
raise UserError(f"Model name must be in 'provider/model' format, got: {model_name!r}")
|
|
63
|
+
if provider in provider_to_profile:
|
|
64
|
+
profile = provider_to_profile[provider](model_name)
|
|
65
|
+
|
|
66
|
+
# As NebiusProvider is always used with OpenAIChatModel, which used to unconditionally use OpenAIJsonSchemaTransformer,
|
|
67
|
+
# we need to maintain that behavior unless json_schema_transformer is set explicitly
|
|
68
|
+
return OpenAIModelProfile(json_schema_transformer=OpenAIJsonSchemaTransformer).update(profile)
|
|
69
|
+
|
|
70
|
+
@overload
|
|
71
|
+
def __init__(self) -> None: ...
|
|
72
|
+
|
|
73
|
+
@overload
|
|
74
|
+
def __init__(self, *, api_key: str) -> None: ...
|
|
75
|
+
|
|
76
|
+
@overload
|
|
77
|
+
def __init__(self, *, api_key: str, http_client: httpx.AsyncClient) -> None: ...
|
|
78
|
+
|
|
79
|
+
@overload
|
|
80
|
+
def __init__(self, *, openai_client: AsyncOpenAI | None = None) -> None: ...
|
|
81
|
+
|
|
82
|
+
def __init__(
|
|
83
|
+
self,
|
|
84
|
+
*,
|
|
85
|
+
api_key: str | None = None,
|
|
86
|
+
openai_client: AsyncOpenAI | None = None,
|
|
87
|
+
http_client: httpx.AsyncClient | None = None,
|
|
88
|
+
) -> None:
|
|
89
|
+
api_key = api_key or os.getenv('NEBIUS_API_KEY')
|
|
90
|
+
if not api_key and openai_client is None:
|
|
91
|
+
raise UserError(
|
|
92
|
+
'Set the `NEBIUS_API_KEY` environment variable or pass it via '
|
|
93
|
+
'`NebiusProvider(api_key=...)` to use the Nebius AI Studio provider.'
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
if openai_client is not None:
|
|
97
|
+
self._client = openai_client
|
|
98
|
+
elif http_client is not None:
|
|
99
|
+
self._client = AsyncOpenAI(base_url=self.base_url, api_key=api_key, http_client=http_client)
|
|
100
|
+
else:
|
|
101
|
+
http_client = cached_async_http_client(provider='nebius')
|
|
102
|
+
self._client = AsyncOpenAI(base_url=self.base_url, api_key=api_key, http_client=http_client)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pydantic-ai-slim
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.18
|
|
4
4
|
Summary: Agent Framework / shim to use Pydantic with LLMs, slim package
|
|
5
5
|
Project-URL: Homepage, https://github.com/pydantic/pydantic-ai/tree/main/pydantic_ai_slim
|
|
6
6
|
Project-URL: Source, https://github.com/pydantic/pydantic-ai/tree/main/pydantic_ai_slim
|
|
@@ -33,7 +33,7 @@ Requires-Dist: genai-prices>=0.0.30
|
|
|
33
33
|
Requires-Dist: griffe>=1.3.2
|
|
34
34
|
Requires-Dist: httpx>=0.27
|
|
35
35
|
Requires-Dist: opentelemetry-api>=1.28.0
|
|
36
|
-
Requires-Dist: pydantic-graph==1.0.
|
|
36
|
+
Requires-Dist: pydantic-graph==1.0.18
|
|
37
37
|
Requires-Dist: pydantic>=2.10
|
|
38
38
|
Requires-Dist: typing-inspection>=0.4.0
|
|
39
39
|
Provides-Extra: a2a
|
|
@@ -57,7 +57,7 @@ Requires-Dist: dbos>=1.14.0; extra == 'dbos'
|
|
|
57
57
|
Provides-Extra: duckduckgo
|
|
58
58
|
Requires-Dist: ddgs>=9.0.0; extra == 'duckduckgo'
|
|
59
59
|
Provides-Extra: evals
|
|
60
|
-
Requires-Dist: pydantic-evals==1.0.
|
|
60
|
+
Requires-Dist: pydantic-evals==1.0.18; extra == 'evals'
|
|
61
61
|
Provides-Extra: google
|
|
62
62
|
Requires-Dist: google-genai>=1.31.0; extra == 'google'
|
|
63
63
|
Provides-Extra: groq
|
|
@@ -10,19 +10,19 @@ pydantic_ai/_json_schema.py,sha256=Br48srbwCTVIie98a9UEMGcCcTIa3E4zVvCbkxqQRso,7
|
|
|
10
10
|
pydantic_ai/_mcp.py,sha256=PuvwnlLjv7YYOa9AZJCrklevBug99zGMhwJCBGG7BHQ,5626
|
|
11
11
|
pydantic_ai/_otel_messages.py,sha256=SsMpbyI1fIISOck_wQcZJPIOei8lOmvwARkdPSCx8y8,1650
|
|
12
12
|
pydantic_ai/_output.py,sha256=gHS1qwM701cH5FGGRUrMxgWlJhY1vNgdM6ylnHRa-Ew,40784
|
|
13
|
-
pydantic_ai/_parts_manager.py,sha256=
|
|
13
|
+
pydantic_ai/_parts_manager.py,sha256=05m8q2JZQk9Z8vNKOocxGDJQwYgbUGABGBRnXYJcsg8,19914
|
|
14
14
|
pydantic_ai/_run_context.py,sha256=-ah9Ipf3mLTbvuYqmJSqBmBexaCcED7HGA1Llzs0dKU,2324
|
|
15
15
|
pydantic_ai/_system_prompt.py,sha256=WdDW_DTGHujcFFaK-J7J6mA4ZDJZ0IOKpyizJA-1Y5Q,1142
|
|
16
16
|
pydantic_ai/_thinking_part.py,sha256=_0DajGyWPa50WUTPWN1UPfZw0xD8_hHcuSt0T3fgRr0,1295
|
|
17
17
|
pydantic_ai/_tool_manager.py,sha256=se5Fikg4HaiTOnxJ4LFrezktZ2Zfv9a2OH0V9PtFE54,10464
|
|
18
18
|
pydantic_ai/_utils.py,sha256=TBzJ03szJPrmDdqRqKTyhRboTsyP6wppnCCprpZFBMw,16620
|
|
19
19
|
pydantic_ai/ag_ui.py,sha256=X3b4P_IraypCE3r-L2ETIo8G951A1MDdP4P5TQ8Fces,32067
|
|
20
|
-
pydantic_ai/builtin_tools.py,sha256=
|
|
20
|
+
pydantic_ai/builtin_tools.py,sha256=O7wcE18kDdp2DFsxPZdoBrmgreDC6DP9t87nM6TxA34,5751
|
|
21
21
|
pydantic_ai/direct.py,sha256=i5yZ9Tx8IiwXg6Nz9CW4-fyXzxnjP59fsklExCh5sjA,15111
|
|
22
22
|
pydantic_ai/exceptions.py,sha256=zsXZMKf2BJuVsfuHl1fWTkogLU37bd4yq7D6BKHAzVs,4968
|
|
23
23
|
pydantic_ai/format_prompt.py,sha256=cLyWO8g77Y4JzqVSikqodXaAfTn6i-k206rNhYTiIsE,9710
|
|
24
24
|
pydantic_ai/mcp.py,sha256=7Ouwepk-p2rOq_Rkv-MSZYyEGJ6FfrJvR7ySghuSLwc,36693
|
|
25
|
-
pydantic_ai/messages.py,sha256=
|
|
25
|
+
pydantic_ai/messages.py,sha256=GBuRGeq3ZpEuSNdq96Mb7l-UVEl7cNuNUN1LpwaAaxQ,64848
|
|
26
26
|
pydantic_ai/output.py,sha256=q91oqvJ-FqV9GbUUil7WVWbii66SVsVZ54AEm_NWSEo,13002
|
|
27
27
|
pydantic_ai/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
28
28
|
pydantic_ai/result.py,sha256=sVabgrAJXmj96I7NM-w0RBz1rH5x_zZql1V6epei4JU,26700
|
|
@@ -31,20 +31,20 @@ pydantic_ai/run.py,sha256=dV3zIztC-lfOCKecXg_Mcx2CyOfUbxQC0JbZuPvQhTI,16227
|
|
|
31
31
|
pydantic_ai/settings.py,sha256=0mr6KudxKKjTG8e3nsv_8vDLxNhu_1-WvefCOzCGSYM,3565
|
|
32
32
|
pydantic_ai/tools.py,sha256=dCecmJtRkF1ioqFYbfT00XGGqzGB4PPO9n6IrHCQtnc,20343
|
|
33
33
|
pydantic_ai/usage.py,sha256=_xXoPIfpENghWcjBvMj0URXQV6YwHWxxZYma4WZ4vUg,15710
|
|
34
|
-
pydantic_ai/agent/__init__.py,sha256=
|
|
35
|
-
pydantic_ai/agent/abstract.py,sha256=
|
|
36
|
-
pydantic_ai/agent/wrapper.py,sha256=
|
|
34
|
+
pydantic_ai/agent/__init__.py,sha256=nScl8k_IK20lcajj4ym9u214bb7sqw5Yu00FxP4HgyI,65395
|
|
35
|
+
pydantic_ai/agent/abstract.py,sha256=69kTaR-ZMEmLJ4tD3oGQS5VuomXtNL8t5mxmPz8Ao50,54587
|
|
36
|
+
pydantic_ai/agent/wrapper.py,sha256=ygwfMq24mGe3pGIK-TtPAy3cV7M8VZJW3ulEHvwNTck,10293
|
|
37
37
|
pydantic_ai/common_tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
38
38
|
pydantic_ai/common_tools/duckduckgo.py,sha256=1ae_o3zqMGrC6KFqAmuqPwJqQgNBTisuvU2jX9KU8PI,2273
|
|
39
39
|
pydantic_ai/common_tools/tavily.py,sha256=a7p2X03l9GS9B_0mvZZV3jePlCwf2TLNeej62-sPycs,2505
|
|
40
40
|
pydantic_ai/durable_exec/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
41
41
|
pydantic_ai/durable_exec/dbos/__init__.py,sha256=H_dT0ERuNCBP0Im8eVGl8F9h7E9Aj87-pvmnLpDelF0,199
|
|
42
|
-
pydantic_ai/durable_exec/dbos/_agent.py,sha256=
|
|
42
|
+
pydantic_ai/durable_exec/dbos/_agent.py,sha256=5yKDlsMVNKzX3Tth-HC-TAwtEhCUbhL4TBpPCcQ-LJ8,40014
|
|
43
43
|
pydantic_ai/durable_exec/dbos/_mcp_server.py,sha256=cLMCKmXQHqhqnn_E3Nf4IsNFIbqk-V7gnIvpmYeDCSA,2989
|
|
44
44
|
pydantic_ai/durable_exec/dbos/_model.py,sha256=_Cxh0zYFF3cungXiSXpGHmjyBQF7KnksfurV7hMKp-E,5106
|
|
45
45
|
pydantic_ai/durable_exec/dbos/_utils.py,sha256=_aNceFvTcNeqb78sTDYM2TdYph85tbdeLueyXY1lbTA,242
|
|
46
|
-
pydantic_ai/durable_exec/temporal/__init__.py,sha256=
|
|
47
|
-
pydantic_ai/durable_exec/temporal/_agent.py,sha256=
|
|
46
|
+
pydantic_ai/durable_exec/temporal/__init__.py,sha256=H8y0jMv5Q2aFvHZ4rm48cYn07nc1nWEQbYpcO9P6zpA,5624
|
|
47
|
+
pydantic_ai/durable_exec/temporal/_agent.py,sha256=BKbKKo6FM2zx-5ohc9voDyMYONH_8sZwUNypjonWDlA,44458
|
|
48
48
|
pydantic_ai/durable_exec/temporal/_function_toolset.py,sha256=3n_A5uHzygsT88LM105kKuYqwxC1sjI4bOzETeUbT4E,5553
|
|
49
49
|
pydantic_ai/durable_exec/temporal/_logfire.py,sha256=ASd7vb0cd61yESI0mgU2w9SCGxsOegz95HtQjKdlQkE,2472
|
|
50
50
|
pydantic_ai/durable_exec/temporal/_mcp_server.py,sha256=vxfWeI7ZtYyXVgX621rPtG-WOZjlKWnqJhcvR9eBgIo,6014
|
|
@@ -54,7 +54,7 @@ pydantic_ai/durable_exec/temporal/_toolset.py,sha256=IlPQrumm2MpZrb518ru15s0jIl8
|
|
|
54
54
|
pydantic_ai/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
55
55
|
pydantic_ai/ext/aci.py,sha256=YWYLXzTQJ6hS7qfgNycA8cRl69gogGgThqEU6II7eMA,2527
|
|
56
56
|
pydantic_ai/ext/langchain.py,sha256=kmbbV3Cx2BiNYEJCZMHVYQquUQD-zG2L_bwDangy0Ww,2317
|
|
57
|
-
pydantic_ai/models/__init__.py,sha256=
|
|
57
|
+
pydantic_ai/models/__init__.py,sha256=VlVcZZJsrZNTKbvq09khQlzGay5PZqWHsFmg9O9p0_I,35718
|
|
58
58
|
pydantic_ai/models/anthropic.py,sha256=-vW7aoPrELKnJzbooCEhMu8__jY6iqvWdFJbIKeQPa8,38087
|
|
59
59
|
pydantic_ai/models/bedrock.py,sha256=fha8zVZgDFYgDqO5nvBkZ2CEv4GV92yq_YnK4qmD73E,33639
|
|
60
60
|
pydantic_ai/models/cohere.py,sha256=_ccK7XBts1OwD-RP8puU3z425SZ4PeJGts1WFhPjikg,14051
|
|
@@ -67,7 +67,7 @@ pydantic_ai/models/huggingface.py,sha256=711C0ysjLYKriGfSxPiaF6lqjGcNmIaJaCvAXou
|
|
|
67
67
|
pydantic_ai/models/instrumented.py,sha256=J8eVTutr3UP1r_wd5sM5c0BIdzkRqT-EGgd2NiF0ssQ,22319
|
|
68
68
|
pydantic_ai/models/mcp_sampling.py,sha256=qY4y4nXbRpNp2QbkfjzWLvF_8KLZGXypz4cc0lYRHXU,3553
|
|
69
69
|
pydantic_ai/models/mistral.py,sha256=fi57hADjYxZw8wEpAcNI6mqY32VG9hHK9GGRQ-9vlZg,33905
|
|
70
|
-
pydantic_ai/models/openai.py,sha256=
|
|
70
|
+
pydantic_ai/models/openai.py,sha256=nCqFy2sRihygbBbTYSbMy_W9LiXwNoRzIUNHSJk5ctc,99861
|
|
71
71
|
pydantic_ai/models/test.py,sha256=5ER66nwZG7Iwm-KkzPo4vwNd3rulzgkpgysu4YcT1W4,20568
|
|
72
72
|
pydantic_ai/models/wrapper.py,sha256=nwh8Gea59blbr1JDKlUnkYICuI9TUubC4qP7iZRRW28,2440
|
|
73
73
|
pydantic_ai/profiles/__init__.py,sha256=UHknN-CYsQexUaxfsgz_J_uSZ9QwistLSuAErQkvbcM,3385
|
|
@@ -84,7 +84,7 @@ pydantic_ai/profiles/mistral.py,sha256=ll01PmcK3szwlTfbaJLQmfd0TADN8lqjov9HpPJzC
|
|
|
84
84
|
pydantic_ai/profiles/moonshotai.py,sha256=e1RJnbEvazE6aJAqfmYLYGNtwNwg52XQDRDkcLrv3fU,272
|
|
85
85
|
pydantic_ai/profiles/openai.py,sha256=MXOsktUqfcF2pBgYJMyFWMZafPJ7tejwyoFM2mjKzaY,9689
|
|
86
86
|
pydantic_ai/profiles/qwen.py,sha256=9SnTpMKndxNQMFyumyaOczJa5JGWbYQdpVKKW4OzKjk,749
|
|
87
|
-
pydantic_ai/providers/__init__.py,sha256=
|
|
87
|
+
pydantic_ai/providers/__init__.py,sha256=UAyyyGhYypWcfJybom0yUS8lbwWD5wmOtbTDG81Wl9E,4718
|
|
88
88
|
pydantic_ai/providers/anthropic.py,sha256=vwNjO2JJ0Ux_3PXI9_XvzNZ24PKessm8z2ja1uzbBwM,3327
|
|
89
89
|
pydantic_ai/providers/azure.py,sha256=PFRykTOfARMdANODnTLq__0ZynX7DlQ35GVf2Qs9VBY,5814
|
|
90
90
|
pydantic_ai/providers/bedrock.py,sha256=efb9YWAz6ram5QEIHNO0K-dL8chTMsjRPCNQhpbQSBY,6513
|
|
@@ -104,6 +104,7 @@ pydantic_ai/providers/huggingface.py,sha256=bCN7vX8JuzKM_bXjyLBCh-imsyCiVPXBUB1F
|
|
|
104
104
|
pydantic_ai/providers/litellm.py,sha256=a669KrAbaj8YYMm3N3yRQduzCMtGDCoHXAQ54_XAo8o,5070
|
|
105
105
|
pydantic_ai/providers/mistral.py,sha256=YqvUoqOq-wiJYnRLwUwp3lUvyApumrohSwysZaQfeBc,3074
|
|
106
106
|
pydantic_ai/providers/moonshotai.py,sha256=iaQHZRYJb7hqeq-Di7Qb0LYJ8EEoE7a_wWtlt_oNa0A,3251
|
|
107
|
+
pydantic_ai/providers/nebius.py,sha256=nGpgbZnBZgNz4wHTi1vgvc-9tO2_zj5r3vRzEUbhPKM,3877
|
|
107
108
|
pydantic_ai/providers/ollama.py,sha256=jg48g_3fYsvK8g-V3UOmR9HOsvnvb533BAB-rZZDxdA,4733
|
|
108
109
|
pydantic_ai/providers/openai.py,sha256=cVVf99GgBnYBKYeWKBscvnkoRCu0ctWuKulG19lgWMo,3401
|
|
109
110
|
pydantic_ai/providers/openrouter.py,sha256=o33Fk7kMyMhEM4NcSXU6IuG0cIUc45ySaenozrRypBI,4145
|
|
@@ -121,8 +122,8 @@ pydantic_ai/toolsets/prefixed.py,sha256=0KwcDkW8OM36ZUsOLVP5h-Nj2tPq78L3_E2c-1Fb
|
|
|
121
122
|
pydantic_ai/toolsets/prepared.py,sha256=Zjfz6S8In6PBVxoKFN9sKPN984zO6t0awB7Lnq5KODw,1431
|
|
122
123
|
pydantic_ai/toolsets/renamed.py,sha256=JuLHpi-hYPiSPlaTpN8WiXLiGsywYK0axi2lW2Qs75k,1637
|
|
123
124
|
pydantic_ai/toolsets/wrapper.py,sha256=KRzF1p8dncHbva8CE6Ud-IC5E_aygIHlwH5atXK55k4,1673
|
|
124
|
-
pydantic_ai_slim-1.0.
|
|
125
|
-
pydantic_ai_slim-1.0.
|
|
126
|
-
pydantic_ai_slim-1.0.
|
|
127
|
-
pydantic_ai_slim-1.0.
|
|
128
|
-
pydantic_ai_slim-1.0.
|
|
125
|
+
pydantic_ai_slim-1.0.18.dist-info/METADATA,sha256=XpATENr_fKE6BLbNaZACxFcVn8VHEb2sllDF8z5vhKc,4631
|
|
126
|
+
pydantic_ai_slim-1.0.18.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
127
|
+
pydantic_ai_slim-1.0.18.dist-info/entry_points.txt,sha256=kbKxe2VtDCYS06hsI7P3uZGxcVC08-FPt1rxeiMpIps,50
|
|
128
|
+
pydantic_ai_slim-1.0.18.dist-info/licenses/LICENSE,sha256=vA6Jc482lEyBBuGUfD1pYx-cM7jxvLYOxPidZ30t_PQ,1100
|
|
129
|
+
pydantic_ai_slim-1.0.18.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|