Skip to content
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

feat: support Tool classes #850

Open
mplemay opened this issue Feb 5, 2025 · 0 comments
Open

feat: support Tool classes #850

mplemay opened this issue Feb 5, 2025 · 0 comments

Comments

@mplemay
Copy link
Contributor

mplemay commented Feb 5, 2025

Currently the only way to define "tools" is via the following design patterns:

  1. The @agent.tool decorator is great for simple agents
  2. Wrapping an existing function in a Tool allows for re-usability, etc. tools

While these method are alright, they don't necessarily allow for a tool to have ClassVars or parameters. Given the shortcomings of the current approaches, I think it would be valuable to add a third approach which looks something like the following:

Note: this is a super simple example, but hopefully it illustrates the point.

from dataclasses import dataclass
from typing import ClassVar
from pydantic_ai import Agent

@dataclass
class MyTool:
    sum: ClassVar[int] = 0
    multiplier: int

    async def __call__(self, random_number: int) -> int:
        self.sum = sum + (random_number * self.multiplier)
        return self.sum

agent_1 = Agent(
    tools=[
        MyTool(multiplier=2)
    ],
    ...
)
@mplemay mplemay changed the title feat: Tool class feat: support Tool classes Feb 7, 2025
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

No branches or pull requests

1 participant