From ae323af2d90ef714608145dd3c7a23d59ccf10a2 Mon Sep 17 00:00:00 2001 From: Kyo Lee Date: Thu, 21 Nov 2024 00:30:11 +0000 Subject: [PATCH] [Docs Agent] Docs Agent release version 0.4.1 What's changed: - **New how-to guide**: Publish a new how-to guide on creating a new task. - **Add response type flag**: Add a new flag that allows users to specify the response type of `agent runtask`. --- .../docs-agent/docs/create-a-new-task.md | 248 ++++++++++++++++++ .../docs-agent/docs_agent/utilities/tasks.py | 9 + .../gemini/python/docs-agent/pyproject.toml | 2 +- 3 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 examples/gemini/python/docs-agent/docs/create-a-new-task.md diff --git a/examples/gemini/python/docs-agent/docs/create-a-new-task.md b/examples/gemini/python/docs-agent/docs/create-a-new-task.md new file mode 100644 index 000000000..48a8f5be0 --- /dev/null +++ b/examples/gemini/python/docs-agent/docs/create-a-new-task.md @@ -0,0 +1,248 @@ +# Create a new Docs Agent task + +This guide provides instructions on how to create a new Docs Agent +task file (`.yaml`) for automating a workflow. + +## Create a new task + +To create a new task in your Docs Agent setup, follow these steps: + +1. Go to your Docs Agent directory, for example: + + ``` + cd ~/docs_agent + ``` + +2. Go to the `tasks` directory: + + ``` + cd tasks + ``` + +3. Open a text editor and create a new `yaml` file, for example: + + ``` + nano my-new-task.yaml + ``` + +4. Copy and paste the following task template: + + ``` + tasks: + - name: "" + model: "models/gemini-1.5-flash" + description: "" + preamble: <”PREAMBLE>” + steps: + - prompt: "" + - prompt: "" + - prompt: "" + ``` + +5. Update the task name (``). +6. (**Optional**) Update the model (see this + [Gemini model code][model-code]). +7. Update the task description (``). +8. (**Optional**) Update the preamble (``). + + **Note**: The `preamble` field is not required. If it's not used, + remove the `preamble` field. + +9. Update the prompts (``). +10. (**Optional**) Add more prompts under the `steps` section. +11. Save the file and exit the text editor. +12. To verify that your new task is available, run the following command: + + ``` + agent runtask + ``` + +13. Run the new task using the task name: + + ``` + agent runtask --task + ``` + + For example: + + ``` + agent runtask --task MyNewExampleTask + ``` + + If your task accepts custom input, you can run it with the + `--custom_input` field, for example: + + ``` + agent runtask --task MyNewExampleTask --custom_input ~/my_project/my_example_doc.md + ``` + +## A minimum task file + +The example task below is created using only the **required fields**: + +``` +tasks: + - name: "MyExampleTask" + model: "models/gemini-1.5-flash" + description: "An agent example that is created using only the required fields for a task." + steps: + - prompt: "This is my first prompt." + - prompt: "This is my second prompt." + - prompt: "This is my third prompt." +``` + +A task can have one `prompt` step at a minimum. + +For more examples, see the [`tasks`][tasks-dir] directory. + +## More examples for steps + +This section contains more `prompt` examples and optional fields. + +### A standard prompt step + +A step that runs the `helpme` command: + +``` + steps: + - prompt: "Revise the PSA email draft above to be more concise and better structured." +``` + +### A POSIX command step + +A step that runs a POSIX command: + +``` + steps: + - prompt: "git --no-pager log --since=2024-10-15" + function: "posix" +``` + +**Important**: To run a POSIX command, the `function` field +must be set to `posix`. + +### A step that reads a file + +The `file` flag reads the specified file and added its content +to the prompt's context. + +A step that runs the `helpme` command with the `file` flag: + +``` + steps: + - prompt: "Analyze this file to understand the overall structure and key concepts." + flags: + file: "/home/user/docs_agent/README.md" +``` + +A step that runs the `helpme` command with the `file` flag and accepts custom input: + +``` + steps: + - prompt: "Analyze this file to understand the overall structure and key concepts." + flags: + file: "" + default_input: "/home/user/docs_agent/README.md" +``` + +When this step is run, the `` string will be replaced with +the value provided in the `--custom_input` field at runtime. + +### A step that reads all files in a directory + +The `allfiles` flag reads all the files in the specified directory +and added their content to the prompt's context. + +A step that runs the `helpme` command with the `allfiles` flag: + +``` + steps: + - prompt: "Analyze the files in this directory to understand the overall structure and key concepts." + flags: + allfiles: "/home/user/docs_agent/docs" +``` + +A step that runs the `helpme` command with the `allfiles` flag +and accepts custom input: + +``` + steps: + - prompt: "Analyze the files in this directory to understand the overall structure and key concepts." + flags: + allfiles: "" + default_input: "/home/user/docs_agent/docs" +``` + +When this step is run, the `` string will be replaced with +the value provided in the `--custom_input` field at runtime. + +### A step that reads each file in a directory + +Similar to a `foreach` loop, the `perfile` flag reads each file in +the specified directory and added the file's content to the prompt's +context. For instance, if there are 5 files in the input directory, +the same prompt will run 5 times using each file's content as context. + +A step that runs the `helpme` command with the `perfile` flag: + +``` + steps: + - prompt: "Analyze this file to understand the overall structure and key concepts." + flags: + perfile: "/home/user/docs_agent/docs" +``` + +A step that runs the `helpme` command with the `perfile` flag +and accepts custom input: + +``` + steps: + - prompt: "Analyze this file to understand the overall structure and key concepts." + flags: + perfile: "" + default_input: "/home/user/docs_agent/docs" +``` + +When this step is run, the `` string will be replaced with +the value provided in the `--custom_input` field at runtime. + +### A step with the name field + +A step that runs the `helpme` command and the `name` field +(which is for display only) is provided: + +``` + steps: + - name: "Revise the PSA email" + prompt: "Revise the PSA email draft above to be more concise and better structured." +``` + +### A step with the function field + +A step that runs the `helpme` command that explicitly mentions +which `function` to use: + +``` + steps: + - prompt: "Revise the PSA email draft above to be more concise and better structured." + function: "helpme" +``` + +Without the `function` field, the prompt is set to use the `helpme` command by default. + +### A question step + +A step that runs the `tellme` command: + +``` + steps: + - prompt: "Does Flutter support Material Design 3?" + function: "tellme" +``` + +Using the `tellme` command requires **a vector database setup**. + + + +[model-code]: https://ai.google.dev/gemini-api/docs/models/gemini +[tasks-dir]: ../tasks diff --git a/examples/gemini/python/docs-agent/docs_agent/utilities/tasks.py b/examples/gemini/python/docs-agent/docs_agent/utilities/tasks.py index 5b846bd80..95b4e2391 100644 --- a/examples/gemini/python/docs-agent/docs_agent/utilities/tasks.py +++ b/examples/gemini/python/docs-agent/docs_agent/utilities/tasks.py @@ -40,6 +40,7 @@ def __init__( cont: typing.Optional[str] = None, terminal: typing.Optional[str] = None, default_input: typing.Optional[str] = None, + response_type: typing.Optional[str] = None, ): self.model = model self.file = file @@ -53,6 +54,7 @@ def __init__( self.cont = cont self.terminal = terminal self.default_input = default_input + self.response_type = response_type def __str__(self): help_str = "" @@ -72,6 +74,8 @@ def __str__(self): help_str += f"RAG: {str(self.rag)}\n" if self.yaml is not None and self.yaml != "": help_str += f"YAML: {self.yaml}\n" + if self.response_type is not None and self.response_type != "": + help_str += f"Response type: {self.response_type}\n" if self.out is not None and self.out != "": help_str += f"Out: {self.out}\n" if self.new is not None and self.new != False: @@ -132,6 +136,10 @@ def dictionaryToFlags(flags: dict) -> Flags: default_input = str(flags["default_input"]) else: default_input = "" + if "response_type" in flags: + response_type = str(flags["response_type"]) + else: + response_type = "" flags = Flags( model=model, file=file, @@ -145,6 +153,7 @@ def dictionaryToFlags(flags: dict) -> Flags: cont=cont, terminal=terminal, default_input=default_input, + response_type=response_type, ) return flags diff --git a/examples/gemini/python/docs-agent/pyproject.toml b/examples/gemini/python/docs-agent/pyproject.toml index 3923b9b54..8b9786099 100644 --- a/examples/gemini/python/docs-agent/pyproject.toml +++ b/examples/gemini/python/docs-agent/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "docs-agent" -version = "0.4.0" +version = "0.4.1" description = "" authors = ["Docs Agent contributors"] readme = "README.md"