Create AI Agent tool for query DB
Step 1: create ducks.db file
Step 2: Seeding data
import duckdb
# Connect to or create a DuckDB database file
con = duckdb.connect("ducks.duckdb")
# Create the ducks table
con.execute("""
CREATE TABLE ducks (
id VARCHAR,
color VARCHAR,
firstName VARCHAR,
lastName VARCHAR,
gender VARCHAR
);
""")
# Insert data
con.execute("""
INSERT INTO ducks VALUES
('kA0KgL', 'red', 'Marty', 'McFly', 'male'),
('dx3ngL', 'teal', 'Duckota', 'Fanning', 'female'),
('FQ4dU1', 'yellow', 'Duck', 'Norris', 'male'),
('JqS7ZZ', 'red', 'James', 'Pond', 'male'),
('ZM5uJL', 'black', 'Darth', 'Wader', 'male'),
('05FuKa', 'yellow', 'Clint', 'Beakwood', 'male'),
('wKq9zD', 'yellow', 'Mary', 'Quackens', 'female'),
('QCab5l', 'orange', 'Ducky', 'Balboa', 'male'),
('eKiyA5', 'orange', 'Captain', 'Quack', 'male'),
('YiSGQl', 'teal', 'Wonder', 'Duck', 'female');
""")
# Confirm the data
result = con.execute("SELECT * FROM ducks LIMIT 10").fetchall()
for row in result:
print(row)
# Close connection
con.close()Step 3: Build AI Agent
Here is output:
Last updated