Skip to content

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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

Add builtin_tools to Agent #1722

wants to merge 10 commits into from

Conversation

Kludex
Copy link
Member

@Kludex Kludex commented May 14, 2025

No description provided.

Comment on lines +345 to +349
for tool in builtin_tools:
if tool == 'web-search':
self._builtin_tools.append(WebSearchTool())
else:
self._builtin_tools.append(tool)
Copy link
Member Author

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.

"""


class UserLocation(TypedDict, total=False):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's easier to handle this in the models if it's a TypedDict, since it matches the type.

Comment on lines +33 to +34
@dataclass
class WebSearchTool(AbstractBuiltinTool):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the DX POV, it's nicer for it to be a BaseModel or dataclass.

Copy link

github-actions bot commented May 14, 2025

Docs Preview

commit: fa7fd11
Preview URL: https://db239934-pydantic-ai-previews.pydantic.workers.dev

Comment on lines 622 to +623
tools = list(model_settings.get('openai_builtin_tools', [])) + tools
tools = self._get_builtin_tools(model_request_parameters) + tools
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should deprecate the openai_builtin_tools in this PR.

class AbstractBuiltinTool(ABC):
"""A builtin tool that can be used by an agent.

This class is abstract and cannot be instantiated directly.
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

@dmontagu dmontagu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than tests and docs

@Kludex Kludex marked this pull request as draft May 15, 2025 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants