-
Notifications
You must be signed in to change notification settings - Fork 903
Add builtin_tools
to Agent
#1722
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
base: main
Are you sure you want to change the base?
Changes from all commits
57e568b
97ab44b
e3dda9d
3ad6d38
0b43f65
fa7fd11
32324fa
f33e568
13d7433
ac85205
c93633f
3a8b640
360de87
cb4e539
4e3769a
ebb536f
c8bb611
6bcc1a8
97ff651
1d47e1e
5f89444
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
from __future__ import annotations as _annotations | ||
|
||
from abc import ABC | ||
from dataclasses import dataclass | ||
from typing import Any, Literal | ||
|
||
from typing_extensions import TypedDict | ||
|
||
__all__ = ('AbstractBuiltinTool', 'WebSearchTool', 'UserLocation') | ||
|
||
|
||
@dataclass | ||
class AbstractBuiltinTool(ABC): | ||
"""A builtin tool that can be used by an agent. | ||
|
||
This class is abstract and cannot be instantiated directly. | ||
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. I think worth including a sentence here explaining how the code execution works to make use of them — something like "these are passed to the model as part of the ModelRequestParameters" or whatever. (Not sure if that's true, haven't gotten there yet ..). But I imagine it helping someone who is trying to figure out how they are different from normal tools. |
||
|
||
The builtin tools are passed to the model as part of the `ModelRequestParameters`. | ||
""" | ||
|
||
def handle_custom_tool_definition(self, model: str) -> Any: ... | ||
|
||
|
||
@dataclass | ||
class WebSearchTool(AbstractBuiltinTool): | ||
Comment on lines
+24
to
+25
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. From the DX POV, it's nicer for it to be a |
||
"""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. | ||
""" | ||
|
||
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: UserLocation | 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) | ||
* MistralAI | ||
""" | ||
|
||
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 UserLocation(TypedDict, total=False): | ||
"""Allows you to localize search results based on a user's location. | ||
|
||
Supported by: | ||
* Anthropic | ||
* OpenAI | ||
""" | ||
|
||
city: str | ||
country: str | ||
region: str | ||
timezone: str | ||
|
||
|
||
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.
It's easier to not have to handle string on the models, so we already do the transformation here.