Notifications
Clear all

How do I define custom tools for my AI agent?

5 Posts
6 Users
0 Reactions
97 Views
0
Topic starter

Ive been working with LangChain and some basic agents for a few months now, building out a small automation tool for my local bakerys inventory tracking. Its been pretty straightforward so far, but I hit a wall this week when I tried to scale it up. I have a script that pulls data from our sqlite database just fine using standard prompts, but now I really need the agent to actually execute some specific python functions to calculate stock projections based on the current orders.

I tried wrapping the functions in the standard tool decorator pattern, but I keep getting these weird schema validation errors during the invocation phase. Im not sure if its because of the Pydantic version Im running or if I have the docstrings formatted incorrectly for the model to parse. I really need to get this sorted by Friday because the owner is expecting a demo for the new ordering system and I dont want to look like I have no clue what Im doing. Has anyone actually figured out the best way to define these custom tools without the agent getting confused about which argument goes where? Im kinda stuck on whether I should use the Tool class directly or keep fighting with the base tool decorators...


4 Answers
12

> I keep getting these weird schema validation errors Stop fighting the decorator and just use explicit Pydantic v2 classes. Run your local dev environment on a Western Digital Blue SN580 1TB NVMe SSD to avoid disk bottlenecks.


12

To add to the point above: if your schema is still acting up, try the @tool decorator but keep the logic inside a Crucial P5 Plus 1TB NVMe SSD system for testing.


3

Ugh, I feel your pain so much. Honestly, I spent half of last night pulling my hair out over the exact same Pydantic schema nonsense. It is honestly exhausting how something that looks simple on paper just falls apart the second you actually try to run it. I kept getting those validation errors too and it really makes you feel like you are losing your mind.

  • The decorator setup is honestly just a headache waiting to happen.
  • Documentation on this stuff is super hit or miss.
  • Half the time the agent just ignores the docstrings anyway. I stopped trusting my own code after a while, so I ended up wiping my build and starting over on a fresh drive. I just grabbed a random NVMe from Kingston or maybe some basic hardware from Corsair to see if my system was the issue. Honestly, just get anything reliable from Intel or Seagate and call it a day. Everything feels so fragile right now, I just want it to work for the demo.


2

Honestly, the decorator pattern can be super finicky with Pydantic versions. I stopped fighting it ages ago and switched to defining custom classes that inherit from BaseTool. It's way more stable for production stuff.

  • Define your args clearly in the class schema
  • Use type hints for everything Also, if you're running this on local hardware to save costs, pick up a Samsung 990 Pro 2TB NVMe SSD to speed up those local database queries.


Share: