From 16577ddc5e154b937d5107743e61c712f8158b6a Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Fri, 10 Oct 2025 13:38:47 -0600 Subject: [PATCH] feat: Created the coder and sql agents --- assets/agents/coder/tools.sh | 6 ++++- assets/agents/sql/README.md | 5 ++++ assets/agents/sql/config.yaml | 17 +++++++++++++ assets/agents/sql/tools.sh | 46 +++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 assets/agents/sql/README.md create mode 100644 assets/agents/sql/config.yaml create mode 100755 assets/agents/sql/tools.sh diff --git a/assets/agents/coder/tools.sh b/assets/agents/coder/tools.sh index 8b36863..93486b5 100755 --- a/assets/agents/coder/tools.sh +++ b/assets/agents/coder/tools.sh @@ -3,7 +3,11 @@ set -e # @env LLM_OUTPUT=/dev/stdout The output path -# @cmd Create a new file at the specified path with contents. +PROMPT_UTILS="${LLM_ROOT_DIR:-$(dirname "${BASH_SOURCE[0]}")/..}/utils/prompt-utils.sh" +# shellcheck disable=SC1090 +source "$PROMPT_UTILS" + +# @cmd Create a new file at the specified path with the given contents. # @option --path! The path where the file should be created # @option --contents! The contents of the file # shellcheck disable=SC2154 diff --git a/assets/agents/sql/README.md b/assets/agents/sql/README.md new file mode 100644 index 0000000..88d8014 --- /dev/null +++ b/assets/agents/sql/README.md @@ -0,0 +1,5 @@ +# SQL + +An AI agent that helps you manage a SQL database. + +> The tool script uses [usql](https://github.com/xo/usql) to interact with SQL, it supports all mainstream databases. diff --git a/assets/agents/sql/config.yaml b/assets/agents/sql/config.yaml new file mode 100644 index 0000000..74459cf --- /dev/null +++ b/assets/agents/sql/config.yaml @@ -0,0 +1,17 @@ +name: Sql +description: An AI agent that helps you manage any SQL database +version: 0.1.0 +instructions: | + You are an AI agent that manages a SQL database. + Prefix all referenced tables with the name of the schema that they are in. + + For all sqlite databases, prefix each table name with 'main' as the schema + + + Available tools: + {{__tools__}} +variables: + - name: dsn + description: The database connection url. e.g. pgsql://user:pass@host:port +conversation_starters: + - What you can do? diff --git a/assets/agents/sql/tools.sh b/assets/agents/sql/tools.sh new file mode 100755 index 0000000..9204143 --- /dev/null +++ b/assets/agents/sql/tools.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +set -e + +# @meta require-tools usql +# @env LLM_OUTPUT=/dev/stdout The output path +# @env LLM_AGENT_VAR_DSN! The database connection url. e.g. pgsql://user:pass@host:port + +PROMPT_UTILS="${LLM_ROOT_DIR:-$(dirname "${BASH_SOURCE[0]}")/..}/utils/prompt-utils.sh" +# shellcheck disable=SC1090 +source "$PROMPT_UTILS" + +# @cmd Execute a SELECT query +# @option --query! SELECT SQL query to execute +read_query() { + # shellcheck disable=SC2154 + if ! grep -qi '^select' <<<"$argc_query"; then + error "only SELECT queries are allowed" >&2 + exit 1 + fi + + _run_sql "$argc_query" +} + +# @cmd Execute an SQL query +# @option --query! SQL query to execute +write_query() { + guard_operation "Execute SQL?" + _run_sql "$argc_query" +} + +# @cmd List all tables +list_tables() { + _run_sql "\dt+" +} + +# @cmd Get the schema information for a specific table +# @option --table-name! Name of the table to describe +describe_table() { + # shellcheck disable=SC2154 + _run_sql "\d $argc_table_name" +} + +_run_sql() { + usql "$LLM_AGENT_VAR_DSN" -c "$1" >> "$LLM_OUTPUT" +}