From 02e335c99526fe52dee0d0a016aee6bf62d874c2 Mon Sep 17 00:00:00 2001 From: sigoden Date: Tue, 9 Jul 2024 21:17:12 +0800 Subject: refactor: demo tools/agents (#67) --- agents/demo/README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ agents/demo/index.yaml | 17 +++++++++++++++++ agents/demo/tools.js | 9 +++++++++ agents/demo/tools.py | 12 ++++++++++++ agents/demo/tools.sh | 12 ++++++++++++ agents/demo/tools.txt | 1 + 6 files changed, 95 insertions(+) create mode 100644 agents/demo/README.md create mode 100644 agents/demo/index.yaml create mode 100644 agents/demo/tools.js create mode 100644 agents/demo/tools.py create mode 100755 agents/demo/tools.sh create mode 100644 agents/demo/tools.txt (limited to 'agents') diff --git a/agents/demo/README.md b/agents/demo/README.md new file mode 100644 index 0000000..888b236 --- /dev/null +++ b/agents/demo/README.md @@ -0,0 +1,44 @@ +# Demo + +This is demo agent. + +## tools.{sh,js,py} + +You only need one of the `tools.sh`, `tools.js`, or `tools.py` files. All three are provided so that everyone can understand how to implement the tools in each language. + +## tools.txt + +The `tools.txt` is used to reuse the tools in the `tools/` directory. + +## index.yaml + +This document is essential as it defines the agent. + +### variables + +Variables are generally used to record a certain behavior or preference of a user. + +```yaml +variables: + - name: foo + description: This is a foo + - name: bar + description: This is a bar with default value + default: val +``` + +Variables can be used in the `instructions`. + +```yaml +instructions: | + The instructions can inline {{foo}} and {{bar}} variables. +``` + +### documents + +Documents are used for RAG. + +```yaml +documents: + - https://raw.githubusercontent.com/sigoden/llm-functions/main/README.md +``` \ No newline at end of file diff --git a/agents/demo/index.yaml b/agents/demo/index.yaml new file mode 100644 index 0000000..44cd616 --- /dev/null +++ b/agents/demo/index.yaml @@ -0,0 +1,17 @@ +name: Demo +description: This is demo agent. +version: 0.1.0 +instructions: | + You are a AI agent designed to demonstrate agent capabilities. + Use prefer language {{lang}} to answer the question, regardless of the input language. + When the user asks for the system info, retrieve it by running the get_sysinfo tool. + When the user asks for the current time, retrieve it by using the get_current_time tool. +variables: + - name: lang + description: Your prefer language +conversation_starters: + - What is the prefer language + - Show me the system info + - Tell me the current time +documents: + - https://raw.githubusercontent.com/sigoden/llm-functions/main/README.md \ No newline at end of file diff --git a/agents/demo/tools.js b/agents/demo/tools.js new file mode 100644 index 0000000..37f8937 --- /dev/null +++ b/agents/demo/tools.js @@ -0,0 +1,9 @@ +const os = require("node:os"); +/** + * Get the system info + */ +exports.get_sysinfo = function getSysinfo() { + return `OS: ${os.type()} +Arch: ${os.arch()} +User: ${process.env["USER"]}` +} diff --git a/agents/demo/tools.py b/agents/demo/tools.py new file mode 100644 index 0000000..5f1a4fc --- /dev/null +++ b/agents/demo/tools.py @@ -0,0 +1,12 @@ +import os +import platform + +def get_sysinfo(): + """ + Get the system info + """ + return "\n".join([ + f"OS: {platform.system()}", + f"Arch: {platform.machine()}", + f"User: {os.environ.get('USER')}" + ]) \ No newline at end of file diff --git a/agents/demo/tools.sh b/agents/demo/tools.sh new file mode 100755 index 0000000..4b5849b --- /dev/null +++ b/agents/demo/tools.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -e + +# @cmd Get the system info +get_sysinfo() { + echo "OS: $(uname)" + echo "Arch: $(arch)" + echo "User: $USER" +} + +# See more details at https://github.com/sigoden/argc +eval "$(argc --argc-eval "$0" "$@")" diff --git a/agents/demo/tools.txt b/agents/demo/tools.txt new file mode 100644 index 0000000..35fdac3 --- /dev/null +++ b/agents/demo/tools.txt @@ -0,0 +1 @@ +get_current_time.sh \ No newline at end of file -- cgit v1.2.3