But WHY?
# marvin-ai
d
But WHY?
j
@Dave Aitel i'm revisiting this patch for BaseTools -- I think this is a langchain issue with how the subclass initialization is created. If you annotate the
args_schema
as
args_schema: type[BaseModel] = CommandRunnerInput
instead of leaving it unannotated I think it will work. This is how LangChain's docs show BaseTool use as well: https://python.langchain.com/v0.2/docs/how_to/custom_tools/#subclass-basetool. LangChain appears to strip the unannotated args_schema. I'm not sure why it's working for you in LC, though they seem to dive into the raw Pydantic annotations at one point during subclass initialization so maybe they grab it there. I think that's why you setting it forcefully in your init worked as well. This check runs without error for me, asserting the args schema is not present unless annotated in pure langchain and pydantic v1:
Copy code
from pydantic.v1 import BaseModel
from langchain_core.tools import BaseTool


class LCBaseToolInput(BaseModel):
    x: int


class LCBaseTool(BaseTool):
    name = "TestTool"
    description = "A test tool"
    args_schema = LCBaseToolInput

    def _run(self, x: int) -> str:
        return str(x)


class LCBaseToolWithAnnotation(LCBaseTool):

    # Note the annotation here
    args_schema: type[BaseModel] = LCBaseToolInput


assert not LCBaseTool().args_schema
assert LCBaseToolWithAnnotation().args_schema
however I am getting a unit test for basetools into the new branch now
https://github.com/PrefectHQ/ControlFlow/pull/256 (failing tests are due to P3 issue upstream)
d
Ok fair I definitely could see me doing it wrong ! (Or following older docs from LC)
j
Yeah entirely possible something changed there, just wanted to make you aware in case it unblocked you!
I am hoping to have the new CF branch released ASAP after P3 goes out
d
I unblocked at the moment btw - but my control flow code does have a bunch of weird patches from my work :)
😅 1
The big one was the messages fixing....
I really should have used control flow from git instead of pip :(