Pydantic AI is an interesting library … it’s the best way to create agents and one of their examples is a basic one which acts as a bank account agent, where you can either find out what your balance is, or block your card.
You can see the rest of the source code on the page but what’s interesting is how it uses LLMs to interpret your request to see if it will take a certain action or not.
So you can run the agent with
result = support_agent.run_sync('what is my balance?', deps=deps)
This returns:
support_advice=’Your current account balance is $123.45.’ block_card=False risk=1
But I can also do something like
result = support_agent.run_sync('i need to see if i have enough to buy a dog, my wife has spent it all', deps=deps)
support_advice=”Your current account balance is $123.45. Please check the price of the dog you want to buy to see if it’s within your budget.” block_card=False risk=5
Which is quite funny really … so it’s shown the user to see the balance because its interpreted it as a show balance action, and whilst I’m not sure banks would want the rest of it, it’s quite funny.
However if I dont indicate balance intent …
result = support_agent.run_sync('My dog died :-(', deps=deps)
support_advice=”I’m very sorry to hear about your loss, John. Losing a pet is incredibly difficult. If there’s anything I can do to help you with your banking needs during this tough time, please let me know.” block_card=False risk=0
In this above case, it just sends a message back but doesnt show the balance.
Leave a Reply