refactor: demo tools/agents (#67)
This commit is contained in:
+20
-31
@@ -289,7 +289,7 @@ build-declarations@agent() {
|
||||
fi
|
||||
if [[ "$ok" == "true" ]]; then
|
||||
if [[ -n "$agent_json_data" ]] && [[ -n "$tools_json_data" ]]; then
|
||||
json_data="$(jq -s '.[0] + .[1]' <(echo "$agent_json_data") <(echo "$tools_json_data"))"
|
||||
json_data="$(echo "[$agent_json_data,$tools_json_data]" | jq 'flatten')"
|
||||
elif [[ -n "$agent_json_data" ]]; then
|
||||
json_data="$agent_json_data"
|
||||
elif [[ -n "$tools_json_data" ]]; then
|
||||
@@ -397,9 +397,10 @@ test-execute-code-tools() {
|
||||
test-demo-tools() {
|
||||
for item in "${LANG_CMDS[@]}"; do
|
||||
lang="${item%:*}"
|
||||
echo "---- Test demo_tool.$lang ---"
|
||||
argc build-bin@tool "demo_tool.$lang"
|
||||
argc run@tool demo_tool '{
|
||||
tool="demo_$lang.$lang"
|
||||
echo "---- Test $tool ---"
|
||||
argc build-bin@tool "$tool"
|
||||
argc run@tool $tool '{
|
||||
"boolean": true,
|
||||
"string": "Hello",
|
||||
"string_enum": "foo",
|
||||
@@ -428,37 +429,24 @@ test@agent() {
|
||||
names_file="$tmp_dir/agents.txt"
|
||||
argc list@agent > "$names_file"
|
||||
argc build@agent --names-file "$names_file"
|
||||
test-todo-agents
|
||||
test-demo-agents
|
||||
}
|
||||
|
||||
# @cmd Test todo-* agents
|
||||
# @alias agent:test-todo
|
||||
test-todo-agents() {
|
||||
if _is_win; then
|
||||
ext=".cmd"
|
||||
fi
|
||||
test_cases=( \
|
||||
'add_todo#{"desc":"Add a todo item"}' \
|
||||
'add_todo#{"desc":"Add another todo item"}' \
|
||||
'del_todo#{"id":1}' \
|
||||
'list_todos#{}' \
|
||||
'clear_todos#{}' \
|
||||
)
|
||||
# @cmd Test demo agents
|
||||
# @alias agent:test-demo
|
||||
test-demo-agents() {
|
||||
echo "Test demo agent:"
|
||||
argc run@agent demo get_sysinfo '{}'
|
||||
for item in "${LANG_CMDS[@]}"; do
|
||||
cmd="${item#*:}"
|
||||
if command -v "$cmd" &> /dev/null; then
|
||||
lang="${item%:*}"
|
||||
agent_name="todo-$lang"
|
||||
rm -rf "cache/$agent_name/todos.json"
|
||||
for test_case in "${test_cases[@]}"; do
|
||||
IFS='#' read -r action data <<<"${test_case}"
|
||||
cmd_path="$BIN_DIR/$agent_name$ext"
|
||||
echo "Test $cmd_path: "
|
||||
"$cmd_path" "$action" "$data"
|
||||
done
|
||||
lang="${item%:*}"
|
||||
echo "Test agents/demo/tools.$lang:"
|
||||
if [[ "$cmd" == "sh" ]]; then
|
||||
"$(argc --argc-shell-path)" ./scripts/run-agent.sh demo get_sysinfo '{}'
|
||||
elif command -v "$cmd" &> /dev/null; then
|
||||
$cmd ./scripts/run-agent.$lang demo get_sysinfo '{}'
|
||||
fi
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
# @cmd Clean tools
|
||||
@@ -475,7 +463,7 @@ clean@agent() {
|
||||
_choice_agent | xargs -I{} rm -rf agents/{}/functions.json
|
||||
}
|
||||
|
||||
# @cmd Symlink web_search tool
|
||||
# @cmd Link a tool as web_search tool
|
||||
#
|
||||
# Example:
|
||||
# argc link-web-search search_bing.sh
|
||||
@@ -484,7 +472,7 @@ link-web-search() {
|
||||
_link_tool $1 web_search
|
||||
}
|
||||
|
||||
# @cmd Symlink code_interpreter tool
|
||||
# @cmd Link a tool as code_interpreter tool
|
||||
#
|
||||
# Example:
|
||||
# argc link-code-interpreter execute_py_code.py
|
||||
@@ -550,6 +538,7 @@ _get_agent_tools_path() {
|
||||
entry_file="agents/$name/tools.$lang"
|
||||
if [[ -f "agents/$name/tools.$lang" ]]; then
|
||||
echo "$entry_file"
|
||||
break
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ The agent definition file (`index.yaml`) defines crucial aspects of your agent:
|
||||
```yaml
|
||||
name: TestAgent
|
||||
description: This is test agent
|
||||
version: v0.1.0
|
||||
version: 0.1.0
|
||||
instructions: You are a test ai agent to ...
|
||||
conversation_starters:
|
||||
- What can you do?
|
||||
|
||||
@@ -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
|
||||
```
|
||||
@@ -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
|
||||
@@ -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"]}`
|
||||
}
|
||||
@@ -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')}"
|
||||
])
|
||||
Executable
+12
@@ -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" "$@")"
|
||||
@@ -0,0 +1 @@
|
||||
get_current_time.sh
|
||||
Reference in New Issue
Block a user