Skip to content

Commit

Permalink
Find and replace ToolkitTask -> PromptTask
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed Dec 20, 2024
1 parent 9523429 commit b2fddde
Show file tree
Hide file tree
Showing 36 changed files with 166 additions and 178 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ agent.run("https://griptape.ai", "griptape.txt")
And here is the output:

```
[08/12/24 14:48:15] INFO ToolkitTask c90d263ec69046e8b30323c131ae4ba0
[08/12/24 14:48:15] INFO PromptTask c90d263ec69046e8b30323c131ae4ba0
Input: Load https://griptape.ai, summarize it, and store it in a file called griptape.txt.
[08/12/24 14:48:16] INFO Subtask ebe23832cbe2464fb9ecde9fcee7c30f
Actions: [
Expand Down Expand Up @@ -166,7 +166,7 @@ And here is the output:
]
INFO Subtask c233853450fb4fd6a3e9c04c52b33bf6
Response: Successfully saved memory artifacts to disk
[08/12/24 14:48:23] INFO ToolkitTask c90d263ec69046e8b30323c131ae4ba0
[08/12/24 14:48:23] INFO PromptTask c90d263ec69046e8b30323c131ae4ba0
Output: The content from https://griptape.ai has been summarized and stored in a file called `griptape.txt`.
```

Expand All @@ -177,8 +177,8 @@ The important thing to note here is that no matter how big the webpage is it can
In the above example, we set [off_prompt](https://docs.griptape.ai/stable/griptape-framework/structures/task-memory.md#off-prompt) to `True`, which means that the LLM can never see the data it manipulates, but can send it to other Tools.

> [!IMPORTANT]
> This example uses Griptape's [ToolkitTask](https://docs.griptape.ai/stable/griptape-framework/structures/tasks/#toolkit-task), which requires a highly capable LLM to function correctly. By default, Griptape uses the [OpenAiChatPromptDriver](https://docs.griptape.ai/stable/griptape-framework/drivers/prompt-drivers/#openai-chat); for another powerful LLM try swapping to the [AnthropicPromptDriver](https://docs.griptape.ai/stable/griptape-framework/drivers/prompt-drivers/#anthropic)!
> If you're using a less powerful LLM, consider using the [ToolTask](https://docs.griptape.ai/stable/griptape-framework/structures/tasks/#tool-task) instead, as the `ToolkitTask` might not work properly or at all.
> This example uses Griptape's [PromptTask](https://docs.griptape.ai/stable/griptape-framework/structures/tasks/#prompt-task) with `tools`, which requires a highly capable LLM to function correctly. By default, Griptape uses the [OpenAiChatPromptDriver](https://docs.griptape.ai/stable/griptape-framework/drivers/prompt-drivers/#openai-chat); for another powerful LLM try swapping to the [AnthropicPromptDriver](https://docs.griptape.ai/stable/griptape-framework/drivers/prompt-drivers/#anthropic)!
> If you're using a less powerful LLM, consider using the [ToolTask](https://docs.griptape.ai/stable/griptape-framework/structures/tasks/#tool-task) instead, as the `PromptTask` with `tools` might not work properly or at all.
[Check out our docs](https://docs.griptape.ai/stable/griptape-framework/drivers/prompt-drivers/) to learn more about how to use Griptape with other LLM providers like Anthropic, Claude, Hugging Face, and Azure.

Expand Down
2 changes: 1 addition & 1 deletion docs/griptape-framework/drivers/web-search-drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You can use Web Search Drivers with [Structures](../structures/agents.md):
```

```
ToolkitTask 45a53f1024494baab41a1f10a67017b1
PromptTask 45a53f1024494baab41a1f10a67017b1
Output: Here are some websites with information about AI
frameworks:
Expand Down
8 changes: 4 additions & 4 deletions docs/griptape-framework/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Agents on their own are fun, but let's add some capabilities to them using Gript
Here is the chain of thought from the Agent. Notice where it realizes it can use the tool you just injected to do the calculation.[^1]

```
[07/23/24 10:47:38] INFO ToolkitTask 6a51060d1fb74e57840a91aa319f26dc
[07/23/24 10:47:38] INFO PromptTask 6a51060d1fb74e57840a91aa319f26dc
Input: what is 7^12
[07/23/24 10:47:39] INFO Subtask 0c984616fd2345a7b48a0b0d692daa3c
Actions: [
Expand All @@ -123,7 +123,7 @@ Here is the chain of thought from the Agent. Notice where it realizes it can use
]
INFO Subtask 0c984616fd2345a7b48a0b0d692daa3c
Response: 13841287201
[07/23/24 10:47:40] INFO ToolkitTask 6a51060d1fb74e57840a91aa319f26dc
[07/23/24 10:47:40] INFO PromptTask 6a51060d1fb74e57840a91aa319f26dc
Output: 13,841,287,201
Answer: 13,841,287,201
```
Expand All @@ -137,7 +137,7 @@ Agents are great for getting started, but they are intentionally limited to a si
```

```
[08/12/24 14:50:28] INFO ToolkitTask 19dcf6020968468a91aa8a93c2a3f645
[08/12/24 14:50:28] INFO PromptTask 19dcf6020968468a91aa8a93c2a3f645
Input: Load https://www.griptape.ai, summarize it, and store it in griptape.txt
[08/12/24 14:50:30] INFO Subtask a685799379c5421b91768353fc219939
Actions: [
Expand Down Expand Up @@ -202,7 +202,7 @@ Agents are great for getting started, but they are intentionally limited to a si
]
INFO Subtask aaaeca1a089844d4915d065deb3c00cf
Response: Successfully saved file
[08/12/24 14:50:39] INFO ToolkitTask 19dcf6020968468a91aa8a93c2a3f645
[08/12/24 14:50:39] INFO PromptTask 19dcf6020968468a91aa8a93c2a3f645
Output: The content from https://www.griptape.ai has been summarized and stored in griptape.txt.
INFO PromptTask dbbb38f144f445db896dc12854f17ad3
Input: Say the following in spanish: The content from https://www.griptape.ai has been summarized and stored in griptape.txt.
Expand Down
4 changes: 2 additions & 2 deletions docs/griptape-framework/misc/src/events_3.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from griptape.drivers import OpenAiChatPromptDriver
from griptape.events import BaseChunkEvent, EventBus, EventListener
from griptape.structures import Pipeline
from griptape.tasks import ToolkitTask
from griptape.tasks import PromptTask
from griptape.tools import PromptSummaryTool, WebScraperTool

EventBus.add_event_listeners(
Expand All @@ -15,7 +15,7 @@

pipeline = Pipeline()
pipeline.add_tasks(
ToolkitTask(
PromptTask(
"Based on https://griptape.ai, tell me what griptape is.",
prompt_driver=OpenAiChatPromptDriver(model="gpt-4o", stream=True),
tools=[WebScraperTool(off_prompt=True), PromptSummaryTool(off_prompt=False)],
Expand Down
4 changes: 2 additions & 2 deletions docs/griptape-framework/misc/src/events_chunk_stream.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from griptape.drivers import OpenAiChatPromptDriver
from griptape.events import ActionChunkEvent, EventBus, EventListener, TextChunkEvent
from griptape.structures import Pipeline
from griptape.tasks import ToolkitTask
from griptape.tasks import PromptTask
from griptape.tools import PromptSummaryTool, WebScraperTool

EventBus.add_event_listeners(
Expand All @@ -19,7 +19,7 @@

pipeline = Pipeline()
pipeline.add_tasks(
ToolkitTask(
PromptTask(
"Based on https://griptape.ai, tell me what griptape is.",
prompt_driver=OpenAiChatPromptDriver(model="gpt-4o", stream=True),
tools=[WebScraperTool(off_prompt=True), PromptSummaryTool(off_prompt=False)],
Expand Down
4 changes: 2 additions & 2 deletions docs/griptape-framework/src/index_4.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from griptape.memory.structure import ConversationMemory
from griptape.structures import Pipeline
from griptape.tasks import PromptTask, ToolkitTask
from griptape.tasks import PromptTask
from griptape.tools import FileManagerTool, PromptSummaryTool, WebScraperTool

# Pipelines represent sequences of tasks.
pipeline = Pipeline(conversation_memory=ConversationMemory())

pipeline.add_tasks(
# Load up the first argument from `pipeline.run`.
ToolkitTask(
PromptTask(
"{{ args[0] }}",
# Add tools for web scraping, and file management
tools=[WebScraperTool(off_prompt=True), FileManagerTool(off_prompt=True), PromptSummaryTool(off_prompt=False)],
Expand Down
41 changes: 19 additions & 22 deletions docs/griptape-framework/structures/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,33 @@ search:

An [Agent](../../reference/griptape/structures/agent.md) is the quickest way to get started with Griptape.
Agents take in [tools](../../reference/griptape/structures/agent.md#griptape.structures.agent.Agent.tools) and [input](../../reference/griptape/structures/agent.md#griptape.structures.agent.Agent.input)
directly, which the agent uses to dynamically determine whether to use a [Prompt Task](./tasks.md#prompt-task) or [Toolkit Task](./tasks.md#toolkit-task).

If [tools](../../reference/griptape/structures/agent.md#griptape.structures.agent.Agent.tools) are passed provided to the Agent, a [Toolkit Task](./tasks.md#toolkit-task) will be used. If no [tools](../../reference/griptape/structures/agent.md#griptape.structures.agent.Agent.tools)
are provided, a [Prompt Task](./tasks.md#prompt-task) will be used.
directly, which the agent uses to add a [Prompt Task](./tasks.md#prompt-task).

You can access the final output of the Agent by using the [output](../../reference/griptape/structures/structure.md#griptape.structures.structure.Structure.output) attribute.

## Toolkit Task Agent
### Agent Input

```python
--8<-- "docs/griptape-framework/structures/src/agents_2.py"
```

```
[09/08/23 10:10:24] INFO PromptTask e70fb08090b24b91a9307fa83479e851
Input: Write me a haiku about Skateboards and Programming
[09/08/23 10:10:28] INFO PromptTask e70fb08090b24b91a9307fa83479e851
Output: Code on wheels in flight,
Skateboards meet algorithms bright,
In binary, we ignite.
```

### Agent Tools

```python
--8<-- "docs/griptape-framework/structures/src/agents_1.py"
```

```
[07/23/24 10:53:41] INFO ToolkitTask 487db777bc014193ba90b061451b69a6
[07/23/24 10:53:41] INFO PromptTask 487db777bc014193ba90b061451b69a6
Input: Calculate the following: what's 13^7?
[07/23/24 10:53:42] INFO Subtask 126cefa3ac5347b88495e25af52f3268
Actions: [
Expand All @@ -38,22 +50,7 @@ You can access the final output of the Agent by using the [output](../../referen
]
INFO Subtask 126cefa3ac5347b88495e25af52f3268
Response: 62748517
[07/23/24 10:53:43] INFO ToolkitTask 487db777bc014193ba90b061451b69a6
[07/23/24 10:53:43] INFO PromptTask 487db777bc014193ba90b061451b69a6
Output: 62,748,517
Answer: 62,748,517
```

## Prompt Task Agent

```python
--8<-- "docs/griptape-framework/structures/src/agents_2.py"
```

```
[09/08/23 10:10:24] INFO PromptTask e70fb08090b24b91a9307fa83479e851
Input: Write me a haiku about Skateboards and Programming
[09/08/23 10:10:28] INFO PromptTask e70fb08090b24b91a9307fa83479e851
Output: Code on wheels in flight,
Skateboards meet algorithms bright,
In binary, we ignite.
```
8 changes: 4 additions & 4 deletions docs/griptape-framework/structures/src/agents_1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from griptape.structures import Agent
from griptape.tools import CalculatorTool

agent = Agent(input="Calculate the following: {{ args[0] }}", tools=[CalculatorTool()])
agent = Agent(
input="Write me a {{ args[0] }} about {{ args[1] }} and {{ args[2] }}",
)

agent.run("what's 13^7?")
print("Answer:", agent.output)
agent.run("Haiku", "Skateboards", "Programming")
12 changes: 4 additions & 8 deletions docs/griptape-framework/structures/src/agents_2.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from griptape.structures import Agent
from griptape.tasks import PromptTask
from griptape.tools import CalculatorTool

agent = Agent()
agent.add_task(
PromptTask(
"Write me a {{ creative_medium }} about {{ args[0] }} and {{ args[1] }}", context={"creative_medium": "haiku"}
)
)
agent = Agent(input="Calculate the following: {{ args[0] }}", tools=[CalculatorTool()])

agent.run("Skateboards", "Programming")
agent.run("what's 13^7?")
print("Answer:", agent.output)
4 changes: 2 additions & 2 deletions docs/griptape-framework/structures/src/tasks_4.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from griptape.structures import Agent
from griptape.tasks import ToolkitTask
from griptape.tasks import PromptTask
from griptape.tools import FileManagerTool, PromptSummaryTool, WebScraperTool

agent = Agent()
agent.add_task(
ToolkitTask(
PromptTask(
"Load https://www.griptape.ai, summarize it, and store it in a file called griptape.txt",
tools=[WebScraperTool(off_prompt=True), FileManagerTool(off_prompt=True), PromptSummaryTool(off_prompt=True)],
),
Expand Down
20 changes: 10 additions & 10 deletions docs/griptape-framework/structures/task-memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ Lets look at a simple example where `off_prompt` is set to `False`:
```

```
[04/26/24 13:06:42] INFO ToolkitTask 36b9dea13b9d479fb752014f41dca54c
[04/26/24 13:06:42] INFO PromptTask 36b9dea13b9d479fb752014f41dca54c
Input: What is the square root of 12345?
[04/26/24 13:06:48] INFO Subtask a88c0feeaef6493796a9148ed68c9caf
Thought: To find the square root of 12345, I can use the CalculatorTool action with the expression "12345 ** 0.5".
Actions: [{"name": "CalculatorTool", "path": "calculate", "input": {"values": {"expression": "12345 ** 0.5"}}, "tag": "sqrt_12345"}]
INFO Subtask a88c0feeaef6493796a9148ed68c9caf
Response: 111.1080555135405
[04/26/24 13:06:49] INFO ToolkitTask 36b9dea13b9d479fb752014f41dca54c
[04/26/24 13:06:49] INFO PromptTask 36b9dea13b9d479fb752014f41dca54c
Output: The square root of 12345 is approximately 111.108.
```

Expand All @@ -46,7 +46,7 @@ Let's explore what happens when `off_prompt` is set to `True`:
```

```
[04/26/24 13:07:02] INFO ToolkitTask ecbb788d9830491ab72a8a2bbef5fb0a
[04/26/24 13:07:02] INFO PromptTask ecbb788d9830491ab72a8a2bbef5fb0a
Input: What is the square root of 12345?
[04/26/24 13:07:10] INFO Subtask 4700dc0c2e934d1a9af60a28bd770bc6
Thought: To find the square root of a number, we can use the CalculatorTool action with the expression "sqrt(12345)". However, the CalculatorTool
Expand Down Expand Up @@ -85,7 +85,7 @@ If we had kept it as `True`, the results would have been stored back Task Memory
```

```
[08/12/24 14:54:04] INFO ToolkitTask f7ebd8acc3d64e3ca9db82ef9ec4e65f
[08/12/24 14:54:04] INFO PromptTask f7ebd8acc3d64e3ca9db82ef9ec4e65f
Input: What is the square root of 12345?
[08/12/24 14:54:05] INFO Subtask 777693d039e74ed288f663742fdde2ea
Actions: [
Expand Down Expand Up @@ -121,7 +121,7 @@ If we had kept it as `True`, the results would have been stored back Task Memory
]
[08/12/24 14:54:07] INFO Subtask c8394ca51f1f4ae1b715618a2c5c8120
Response: The text contains a single numerical value: 111.1080555135405.
[08/12/24 14:54:08] INFO ToolkitTask f7ebd8acc3d64e3ca9db82ef9ec4e65f
[08/12/24 14:54:08] INFO PromptTask f7ebd8acc3d64e3ca9db82ef9ec4e65f
Output: The square root of 12345 is approximately 111.108.
```

Expand All @@ -139,7 +139,7 @@ Let's say we want to query the contents of a very large webpage.
When running this example, we get the following error:

```
[04/26/24 13:20:02] ERROR ToolkitTask 67e2f907f95d4850ae79f9da67df54c1
[04/26/24 13:20:02] ERROR PromptTask 67e2f907f95d4850ae79f9da67df54c1
Error code: 400 - {'error': {'message': "This model's maximum context length is 8192 tokens. However, your messages resulted in 73874 tokens.
Please reduce the length of the messages.", 'type': 'invalid_request_error', 'param': 'messages', 'code': 'context_length_exceeded'}}
```
Expand All @@ -154,7 +154,7 @@ Note that we're setting `off_prompt` to `False` on the `QueryTool` so that the _
And now we get the expected output:

```
[08/12/24 14:56:18] INFO ToolkitTask d3ce58587dc944b0a30a205631b82944
[08/12/24 14:56:18] INFO PromptTask d3ce58587dc944b0a30a205631b82944
Input: According to this page https://en.wikipedia.org/wiki/Elden_Ring, how many copies of Elden Ring have been sold?
[08/12/24 14:56:20] INFO Subtask 494850ec40fe474c83d48b5620c5dcbb
Actions: [
Expand Down Expand Up @@ -192,7 +192,7 @@ And now we get the expected output:
[08/12/24 14:56:29] INFO Subtask 8669ee523bb64550850566011bcd14e2
Response: "Elden Ring" sold 13.4 million copies worldwide by the end of March 2022 and 25 million by June 2024. The downloadable content (DLC)
"Shadow of the Erdtree" sold five million copies within three days of its release.
[08/12/24 14:56:30] INFO ToolkitTask d3ce58587dc944b0a30a205631b82944
[08/12/24 14:56:30] INFO PromptTask d3ce58587dc944b0a30a205631b82944
Output: Elden Ring sold 13.4 million copies worldwide by the end of March 2022 and 25 million by June 2024.
```

Expand All @@ -208,7 +208,7 @@ In this example, GPT-4 _never_ sees the contents of the page, only that it was s
```

```
[08/12/24 14:55:21] INFO ToolkitTask 329b1abc760e4d30bbf23e349451d930
[08/12/24 14:55:21] INFO PromptTask 329b1abc760e4d30bbf23e349451d930
Input: Use this page https://en.wikipedia.org/wiki/Elden_Ring to find how many copies of Elden Ring have been sold, and then save the result to
a file.
[08/12/24 14:55:23] INFO Subtask 26205b5623174424b618abafd886c4d8
Expand Down Expand Up @@ -265,7 +265,7 @@ In this example, GPT-4 _never_ sees the contents of the page, only that it was s
]
INFO Subtask 7aafcb3fb0d845858e2fcf9b8dc8a7ec
Response: Successfully saved memory artifacts to disk
[08/12/24 14:55:40] INFO ToolkitTask 329b1abc760e4d30bbf23e349451d930
[08/12/24 14:55:40] INFO PromptTask 329b1abc760e4d30bbf23e349451d930
Output: Successfully saved the number of copies sold of Elden Ring to a file named "elden_ring_sales.txt" in the "results" directory.
```

Expand Down
Loading

0 comments on commit b2fddde

Please sign in to comment.