Skip to content

Callable classes can't be registered as tools as takes-RunContext detection fails #2898

@bitnahian

Description

@bitnahian

Initial Checks

Description

Consider the example code presented.

Ideally, this should return true so that we can support Callable Classes.

Feel free to reject this if it's an anti-pattern.

Example Code

from pydantic_ai import RunContext
from pydantic_ai._function_schema import _takes_ctx


# Create a concrete implementation for testing
class TestProcessor:
    def __call__(self, ctx: RunContext, messages: list):
        return messages

    def process(self, messages):
        return messages

    def post_process(self, messages):
        return messages


if __name__ == "__main__":
    processor = TestProcessor()

    result = _takes_ctx(processor)
    print(f"_takes_ctx result: {result}") # returns False

Python, Pydantic AI & LLM client version

Python 3.11.12
pydantic-ai 1.0.6

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions