Skip to content

docs(custom-tools): improve docs for creating custom tools #1791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2025

Conversation

collindutter
Copy link
Member

@collindutter collindutter commented Mar 3, 2025

Describe your changes

Improves docs for creating custom tools. In particular, explains the nuances of the various ways to declare activity parameters.

Issue ticket number and link

Closes #1566


📚 Documentation preview 📚: https://griptape--1791.org.readthedocs.build//1791/

@collindutter collindutter requested review from a team March 3, 2025 19:52
@collindutter collindutter self-assigned this Mar 3, 2025
@collindutter collindutter added the docs Related to documentation. label Mar 3, 2025
@collindutter collindutter added this to the 1.5 milestone Mar 3, 2025
Each activity takes a `config` keyword argument that contains the configuration for the activity. The configuration can contain:

- `description` (str): A plain text description of the activity. Ensure that the description is clear and concise as it will help inform the LLM of when to pick this activity.
- `schema` (optional): An optional instance of `Schema` that defines the input values to the activity. This field can be omitted if the activity does not require any input values.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does not require or does not take? afaik you can have a tool with all optional params but still have a schema

"This field should be omitted if the activity does not accept any input values"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I will more clearly distinguish between an optional schema and a schema with optional values.

@activity(
config={
"description": "Can be used to generate random numbers",
"schema": Schema(
{Optional(Literal("decimals", description="Number of decimals to round the random number to")): int}
{
"start": int,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does @activity have magic that will apply the documentation description (L28-29) to the schema? If not, should we document how to provide description in the schema?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, will add back an example of Literal.

@@ -21,7 +21,28 @@ Here is a simple random number generator Tool:
--8<-- "docs/griptape-framework/tools/custom-tools/logs/index_2.txt"
```

Check out other [Griptape Tools](https://github.com/griptape-ai/griptape/tree/main/griptape/tools) to learn more about tool implementation details.
### Tool Activities

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to explain what an "activity" is to an Agent. Not just a method with the activity decorator - but that it is a thing the agent can do.

For example:

Tool Activities

Activities are actions an Agent can perform with a various tool. They are described in natural language and are passed to the Agent when the tool is given to it. Some examples:

  • "Can be used to create a random number"
  • "Can be used to select a random item from a list"

Technically, each activity is a method in the tool class that's decorated with the activity decorator.

...


I know it's described down below that each activity contains a `config` keyword with a `description` and `schema` - but we jump straight to the technical without explaining the natural language first.

@@ -32,3 +53,5 @@ To start, create a directory for your Tool inside your project. The directory mu
- `requirements.txt` file with tool Python dependencies.

That's it! Import and use your Tool in your project as you would with any other Griptape Tool.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we include an example directory structure? that would be helpful for users.

tool/
  __init__.py
  tool.py
  requirements.txt
app.py

Copy link
Contributor

@shhlife shhlife left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool - just a couple of minor notes!

@collindutter collindutter disabled auto-merge March 3, 2025 21:53

## Tool Dependencies

Each Tool can also have its own dependencies. You can specify them in a `requirements.txt` file in the tool directory and Griptape will install them during Tool execution.
To start, create a directory for your Tool inside your project. The directory must have the following structure:

- `tool.py` file with a tool Python class.
- `requirements.txt` file with tool Python dependencies.
griptape/tools/calculator/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this all needs to be wrapped in ```

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Contributor

@shhlife shhlife left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work!

@collindutter collindutter added this pull request to the merge queue Mar 3, 2025
Merged via the queue into main with commit 25b1276 Mar 3, 2025
16 checks passed
@collindutter collindutter deleted the docs/tool-args branch March 3, 2025 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Related to documentation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update griptape tool docs for how to pass parameters
3 participants