-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add builtin_tools to Agent
#2102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 86 commits
57e568b
97ab44b
e3dda9d
3ad6d38
0b43f65
fa7fd11
32324fa
f33e568
13d7433
ac85205
c93633f
3a8b640
360de87
cb4e539
4e3769a
ebb536f
c8bb611
6bcc1a8
97ff651
1d47e1e
5f89444
9512987
800a71a
d0f4643
bc298d6
46c06c2
3496567
c193059
427dec2
866ad21
4c2622d
c13736e
a42a75d
e2f1daa
3094a9a
6a3c987
ac0edb6
374e034
7cccdd2
2393c87
21094a7
8ac5294
de8f32d
13bc865
c0fc35c
b4b3752
3a2481a
306514e
c84be82
a77030b
93e26d6
bfb4eef
4376fc2
c029d4b
87f59f1
3fca6d4
37a1845
5b031d6
e1085fa
ae1d4d9
3ee4aa9
9d24f5b
07f7892
7d867ee
ba3f6b2
1ae6155
3f8cc2d
ba962a7
bfd9b21
e2fef42
b1ef2f8
e9cacc3
aa91640
2d451a7
38b5b7d
359b9e1
bd6e5f7
69267ca
1a4a0f3
c9d0d18
a631229
78fe612
a673c90
df2ad47
b4add90
dec1ba3
e134d43
ef4ab6a
bb98ccf
739f142
cc7ab39
5534bf4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,3 +19,4 @@ node_modules/ | |
| **.idea/ | ||
| .coverage* | ||
| /test_tmp/ | ||
| .mcp.json | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| from __future__ import annotations as _annotations | ||
|
|
||
| from abc import ABC | ||
| from dataclasses import dataclass | ||
| from typing import Literal | ||
|
|
||
| from typing_extensions import TypedDict | ||
|
|
||
| __all__ = ('AbstractBuiltinTool', 'WebSearchTool', 'WebSearchUserLocation') | ||
|
|
||
|
|
||
| @dataclass | ||
| class AbstractBuiltinTool(ABC): | ||
| """A builtin tool that can be used by an agent. | ||
|
|
||
| This class is abstract and cannot be instantiated directly. | ||
|
|
||
| The builtin tools are passed to the model as part of the `ModelRequestParameters`. | ||
| """ | ||
|
|
||
|
|
||
| @dataclass | ||
| class WebSearchTool(AbstractBuiltinTool): | ||
| """A builtin tool that allows your agent to search the web for information. | ||
|
|
||
| The parameters that PydanticAI passes depend on the model, as some parameters may not be supported by certain models. | ||
|
|
||
| Supported by: | ||
| * Anthropic | ||
| * OpenAI | ||
| * Groq | ||
| """ | ||
|
|
||
| search_context_size: Literal['low', 'medium', 'high'] = 'medium' | ||
| """The `search_context_size` parameter controls how much context is retrieved from the web to help the tool formulate a response. | ||
|
|
||
| Supported by: | ||
| * OpenAI | ||
| """ | ||
|
|
||
| user_location: WebSearchUserLocation | None = None | ||
| """The `user_location` parameter allows you to localize search results based on a user's location. | ||
|
|
||
| Supported by: | ||
| * Anthropic | ||
| * OpenAI | ||
| """ | ||
|
|
||
| blocked_domains: list[str] | None = None | ||
| """If provided, these domains will never appear in results. | ||
|
|
||
| With Anthropic, you can only use one of `blocked_domains` or `allowed_domains`, not both. | ||
|
|
||
| Supported by: | ||
| * Anthropic (https://docs.anthropic.com/en/docs/build-with-claude/tool-use/web-search-tool#domain-filtering) | ||
| * Groq (https://console.groq.com/docs/agentic-tooling#search-settings) | ||
| """ | ||
|
|
||
| allowed_domains: list[str] | None = None | ||
| """If provided, only these domains will be included in results. | ||
|
|
||
| With Anthropic, you can only use one of `blocked_domains` or `allowed_domains`, not both. | ||
|
|
||
| Supported by: | ||
| * Anthropic (https://docs.anthropic.com/en/docs/build-with-claude/tool-use/web-search-tool#domain-filtering) | ||
| * Groq (https://console.groq.com/docs/agentic-tooling#search-settings) | ||
| """ | ||
|
|
||
| max_uses: int | None = None | ||
| """If provided, the tool will stop searching the web after the given number of uses. | ||
|
|
||
| Supported by: | ||
| * Anthropic | ||
| """ | ||
|
|
||
|
|
||
| class WebSearchUserLocation(TypedDict, total=False): | ||
| """Allows you to localize search results based on a user's location. | ||
|
|
||
| Supported by: | ||
| * Anthropic | ||
| * OpenAI | ||
| """ | ||
|
|
||
| city: str | ||
| """The city where the user is located.""" | ||
|
|
||
| country: str | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On OpenAI, these needs to be a 2-letter country code: https://platform.openai.com/docs/guides/tools-web-search?api-mode=responses#user-location
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check doesn't seem necessary. It seems it works fine with 3 characters. |
||
| """The country where the user is located. For OpenAI, this must be a 2-letter country code (e.g., 'US', 'GB').""" | ||
|
|
||
| region: str | ||
Kludex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """The region or state where the user is located.""" | ||
|
|
||
| timezone: str | ||
| """The timezone of the user's location.""" | ||
|
|
||
|
|
||
| class CodeExecutionTool(AbstractBuiltinTool): | ||
| """A builtin tool that allows your agent to execute code. | ||
|
|
||
| Supported by: | ||
| * Anthropic | ||
| * OpenAI | ||
| """ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For curiosity, why MCP servers did you use here?