Skip to content

Commit 5d15e4b

Browse files
authored
Merge branch 'main' into support-typed-runcontext-in-textoutput-signature
2 parents b6ae5b9 + 4f7d803 commit 5d15e4b

File tree

75 files changed

+7856
-491
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+7856
-491
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ repos:
4444
types: [python]
4545
language: system
4646
pass_filenames: false
47-
- id: clai-help
48-
name: clai help output
49-
entry: uv
50-
args: [run, pytest, "clai/update_readme.py"]
51-
language: system
52-
types_or: [python, markdown]
53-
pass_filenames: false
5447
- id: typecheck
5548
name: Typecheck
5649
entry: make

clai/README.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,32 @@ Either way, running `clai` will start an interactive session where you can chat
5151
- `/multiline`: Toggle multiline input mode (use Ctrl+D to submit)
5252
- `/cp`: Copy the last response to clipboard
5353

54-
## Help
54+
For full CLI documentation, see the [CLI documentation](https://ai.pydantic.dev/cli/).
5555

56+
## Web Chat UI
57+
58+
Launch a web-based chat interface:
59+
60+
```bash
61+
clai web -m openai:gpt-5
5662
```
57-
usage: clai [-h] [-m [MODEL]] [-a AGENT] [-l] [-t [CODE_THEME]] [--no-stream] [--version] [prompt]
58-
59-
Pydantic AI CLI v...
60-
61-
Special prompts:
62-
* `/exit` - exit the interactive mode (ctrl-c and ctrl-d also work)
63-
* `/markdown` - show the last markdown output of the last question
64-
* `/multiline` - toggle multiline mode
65-
* `/cp` - copy the last response to clipboard
66-
67-
positional arguments:
68-
prompt AI Prompt, if omitted fall into interactive mode
69-
70-
options:
71-
-h, --help show this help message and exit
72-
-m [MODEL], --model [MODEL]
73-
Model to use, in format "<provider>:<model>" e.g. "openai:gpt-5" or "anthropic:claude-sonnet-4-5". Defaults to "openai:gpt-5".
74-
-a AGENT, --agent AGENT
75-
Custom Agent to use, in format "module:variable", e.g. "mymodule.submodule:my_agent"
76-
-l, --list-models List all available models and exit
77-
-t [CODE_THEME], --code-theme [CODE_THEME]
78-
Which colors to use for code, can be "dark", "light" or any theme from pygments.org/styles/. Defaults to "dark" which works well on dark terminals.
79-
--no-stream Disable streaming from the model
80-
--version Show version and exit
63+
64+
![Web Chat UI](https://ai.pydantic.dev/img/web-chat-ui.png)
65+
66+
This will start a web server (default: http://127.0.0.1:7932) with a chat interface.
67+
68+
You can also serve an existing agent. For example, if you have an agent defined in `my_agent.py`:
69+
70+
```python
71+
from pydantic_ai import Agent
72+
73+
my_agent = Agent('openai:gpt-5', instructions='You are a helpful assistant.')
74+
```
75+
76+
Launch the web UI with:
77+
78+
```bash
79+
clai web --agent my_agent:my_agent
8180
```
81+
82+
For full Web UI documentation, see [Web Chat UI](https://ai.pydantic.dev/web/).

clai/update_readme.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

docs/builtin-tools.md

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Pydantic AI supports the following built-in tools:
1212
- **[`WebFetchTool`][pydantic_ai.builtin_tools.WebFetchTool]**: Enables agents to fetch web pages
1313
- **[`MemoryTool`][pydantic_ai.builtin_tools.MemoryTool]**: Enables agents to use memory
1414
- **[`MCPServerTool`][pydantic_ai.builtin_tools.MCPServerTool]**: Enables agents to use remote MCP servers with communication handled by the model provider
15+
- **[`FileSearchTool`][pydantic_ai.builtin_tools.FileSearchTool]**: Enables agents to search through uploaded files using vector search (RAG)
1516

1617
These tools are passed to the agent via the `builtin_tools` parameter and are executed by the model provider's infrastructure.
1718

@@ -353,6 +354,23 @@ assert isinstance(result.output, BinaryImage)
353354

354355
_(This example is complete, it can be run "as is")_
355356

357+
To control the image resolution with Google image generation models (starting with Gemini 3 Pro Image), use the `size` parameter:
358+
359+
```py {title="image_generation_google_resolution.py"}
360+
from pydantic_ai import Agent, BinaryImage, ImageGenerationTool
361+
362+
agent = Agent(
363+
'google-gla:gemini-3-pro-image-preview',
364+
builtin_tools=[ImageGenerationTool(aspect_ratio='16:9', size='4K')],
365+
output_type=BinaryImage,
366+
)
367+
368+
result = agent.run_sync('Generate a high-resolution wide landscape illustration of an axolotl.')
369+
assert isinstance(result.output, BinaryImage)
370+
```
371+
372+
_(This example is complete, it can be run "as is")_
373+
356374
For more details, check the [API documentation][pydantic_ai.builtin_tools.ImageGenerationTool].
357375

358376
#### Provider Support
@@ -366,8 +384,10 @@ For more details, check the [API documentation][pydantic_ai.builtin_tools.ImageG
366384
| `output_format` |||
367385
| `partial_images` |||
368386
| `quality` |||
369-
| `size` |||
370-
| `aspect_ratio` | ✅ (1:1, 2:3, 3:2) ||
387+
| `size` | ✅ (auto (default), 1024x1024, 1024x1536, 1536x1024) | ✅ (1K (default), 2K, 4K) |
388+
| `aspect_ratio` | ✅ (1:1, 2:3, 3:2) | ✅ (1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9) |
389+
390+
**Note:** For OpenAI, `auto` lets the model select the value.
371391

372392
## Web Fetch Tool
373393

@@ -672,6 +692,100 @@ _(This example is complete, it can be run "as is")_
672692
| `description` |||
673693
| `headers` |||
674694

695+
## File Search Tool
696+
697+
The [`FileSearchTool`][pydantic_ai.builtin_tools.FileSearchTool] enables your agent to search through uploaded files using vector search, providing a fully managed Retrieval-Augmented Generation (RAG) system. This tool handles file storage, chunking, embedding generation, and context injection into prompts.
698+
699+
### Provider Support
700+
701+
| Provider | Supported | Notes |
702+
|----------|-----------|-------|
703+
| OpenAI Responses || Full feature support. Requires files to be uploaded to vector stores via the [OpenAI Files API](https://platform.openai.com/docs/api-reference/files). To include search results on the [`BuiltinToolReturnPart`][pydantic_ai.messages.BuiltinToolReturnPart] available via [`ModelResponse.builtin_tool_calls`][pydantic_ai.messages.ModelResponse.builtin_tool_calls], enable the [`OpenAIResponsesModelSettings.openai_include_file_search_results`][pydantic_ai.models.openai.OpenAIResponsesModelSettings.openai_include_file_search_results] [model setting](agents.md#model-run-settings). |
704+
| Google (Gemini) || Requires files to be uploaded via the [Gemini Files API](https://ai.google.dev/gemini-api/docs/files). Files are automatically deleted after 48 hours. Supports up to 2 GB per file and 20 GB per project. Using built-in tools and function tools (including [output tools](output.md#tool-output)) at the same time is not supported; to use structured output, use [`PromptedOutput`](output.md#prompted-output) instead. |
705+
|| Google (Vertex AI) || Not supported |
706+
| Anthropic || Not supported |
707+
| Groq || Not supported |
708+
| OpenAI Chat Completions || Not supported |
709+
| Bedrock || Not supported |
710+
| Mistral || Not supported |
711+
| Cohere || Not supported |
712+
| HuggingFace || Not supported |
713+
| Outlines || Not supported |
714+
715+
### Usage
716+
717+
#### OpenAI Responses
718+
719+
With OpenAI, you need to first [upload files to a vector store](https://platform.openai.com/docs/assistants/tools/file-search), then reference the vector store IDs when using the `FileSearchTool`.
720+
721+
```py {title="file_search_openai_upload.py" test="skip"}
722+
import asyncio
723+
724+
from pydantic_ai import Agent, FileSearchTool
725+
from pydantic_ai.models.openai import OpenAIResponsesModel
726+
727+
728+
async def main():
729+
model = OpenAIResponsesModel('gpt-5')
730+
731+
with open('my_document.txt', 'rb') as f:
732+
file = await model.client.files.create(file=f, purpose='assistants')
733+
734+
vector_store = await model.client.vector_stores.create(name='my-docs')
735+
await model.client.vector_stores.files.create(
736+
vector_store_id=vector_store.id,
737+
file_id=file.id
738+
)
739+
740+
agent = Agent(
741+
model,
742+
builtin_tools=[FileSearchTool(file_store_ids=[vector_store.id])]
743+
)
744+
745+
result = await agent.run('What information is in my documents about pydantic?')
746+
print(result.output)
747+
#> Based on your documents, Pydantic is a data validation library for Python...
748+
749+
asyncio.run(main())
750+
```
751+
752+
#### Google (Gemini)
753+
754+
With Gemini, you need to first [create a file search store via the Files API](https://ai.google.dev/gemini-api/docs/files), then reference the file search store names.
755+
756+
```py {title="file_search_google_upload.py" test="skip"}
757+
import asyncio
758+
759+
from pydantic_ai import Agent, FileSearchTool
760+
from pydantic_ai.models.google import GoogleModel
761+
762+
763+
async def main():
764+
model = GoogleModel('gemini-2.5-flash')
765+
766+
store = await model.client.aio.file_search_stores.create(
767+
config={'display_name': 'my-docs'}
768+
)
769+
770+
with open('my_document.txt', 'rb') as f:
771+
await model.client.aio.file_search_stores.upload_to_file_search_store(
772+
file_search_store_name=store.name,
773+
file=f,
774+
config={'mime_type': 'text/plain'}
775+
)
776+
777+
agent = Agent(
778+
model,
779+
builtin_tools=[FileSearchTool(file_store_ids=[store.name])]
780+
)
781+
782+
result = await agent.run('Summarize the key points from my uploaded documents.')
783+
print(result.output)
784+
#> The documents discuss the following key points: ...
785+
786+
asyncio.run(main())
787+
```
788+
675789
## API Reference
676790

677791
For complete API documentation, see the [API Reference](api/builtin_tools.md).

0 commit comments

Comments
 (0)