Find answers from the community

Updated 5 months ago

Tool

Loading tools, give me error of pydantic:

pydantic.v1.error_wrappers.ValidationError: 1 validation error for AgentToolCallEvent
tool -> fn_schema
subclass of BaseModel expected (type=type_error.subclass; expected_class=BaseModel)


Plain Text
        metadata = ToolMetadata(
            name=definition.get('name'), 
            description=definition.get('description', None), 
            fn_schema=tool.ToolSchema if hasattr(my_tool, 'ToolSchema') else None
        )
        tool_spec = my_tool.CustomToolSpec()
        new_tool = tool_spec.to_tool_list(func_to_metadata_mapping={tool_spec.spec_functions[0]: metadata})[0]
        self.tools.append(new_tool)
        
        self.agent = OpenAIAgent.from_tools(
                self.tools,
                verbose=True,
                llm=self.llm,
                memory=self.memory,
                system_prompt=system_prompt,
                tool_call_parser=custom_tool_call_parser
        )
        self.agent.chat("My message that invoke some tool")


My_tool:

Plain Text
from llama_index.core.bridge.pydantic import BaseModel, Field
from llama_index.core.tools.tool_spec.base import BaseToolSpec
# ...

class ToolSchema(BaseModel):
    summary:Optional[str] = Field(description="A concise summary (translated to english) of the problem.")

class CustomToolSpec(BaseToolSpec):
    spec_functions = ["helpdesk_open_ticket"]
L
a
7 comments
Seems like tool.ToolSchema is not a base model?
Probably you meant tool.ToolSchema()
not, same error
venv/lib/python3.11/site-packages/pydantic/v1/main.py", line 341, in init
raise validation_error
pydantic.v1.error_wrappers.ValidationError: 1 validation error for AgentToolCallEvent
tool -> fn_schema
subclass of BaseModel expected (type=type_error.subclass; expected_class=BaseModel)
you have some tutorial of how to load tools using BaseToolSpec and to_tool_list ?
what happens if you print isinstance(new_tool.fn_schema, BaseModel) ? (assuming it gets that far, its not 100% clear where in your code this error gets triggered)
I should probably just replicate this myself
Add a reply
Sign up and join the conversation on Discord