added max_subtasks to agent.

This commit is contained in:
Jason Schleifer
2025-01-18 05:50:01 +13:00
parent a7db2acc9d
commit dd3e16082e
5 changed files with 109 additions and 215 deletions
+6
View File
@@ -14,6 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
### Security -->
## [2.1.13] - 2025-18-01
### Added
- The `Create Agent` node now has a `max_subtasks` parameter that will try and help make sure the agent doesn't get caught in an infinite loop of tool use. This is especially useful when you have agents using other agents as tools, and sometimes they get "chatty". If they go back and forth too many times, the run will abort and return the reason why & what the last output was in the thread. This should give you some more control over ensuring you don't have agents running forever.
### Changed
- The [Photographer-Workflow-Comparison-Example](examples/Photographer-Workflow-Comparison-Example.json) has some new rules to try and keep exchanges brief, and also takes advantage of the new `max_subtasks` parameter.
## [2.1.12] - 2025-15-01
### Changed
- Added a list of models for `Griptape Prompt Driver: Groq` based on the Supported Models page: https://console.groq.com/docs/models
@@ -1,6 +1,6 @@
{
"last_node_id": 43,
"last_link_id": 53,
"last_link_id": 54,
"nodes": [
{
"id": 1,
@@ -11,10 +11,10 @@
],
"size": [
300,
156
180
],
"flags": {},
"order": 15,
"order": 13,
"mode": 0,
"inputs": [
{
@@ -73,7 +73,8 @@
},
"widgets_values": [
"",
""
"",
2
],
"color": "#323",
"bgcolor": "#535"
@@ -90,7 +91,7 @@
200
],
"flags": {},
"order": 9,
"order": 3,
"mode": 0,
"inputs": [],
"outputs": [
@@ -115,7 +116,7 @@
},
"widgets_values": [
"Cinematographer Ruleset",
"You identify as a cinematographer\nThe main subject of the image should be well framed\nIf no environment is specified, set the image in a location that will evoke a deep and meaningful connection to the viewer.\nYou care deeply about light, shadow, color, and composition\nWhen coming up with image prompts, you always specify the position of the camera, the lens, and the color\nYou are specific about the technical details of a shot.\nYou like to add atmosphere to your shots, so you include depth of field, haze, dust particles in the air close to and far away from camera, and the way lighting reacts with each item.\nYour responses are brief and concise\nAlways respond with your identity so the agent knows who you are."
"You identify as a cinematographer\nThe main subject of the image should be well framed\nIf no environment is specified, set the image in a location that will evoke a deep and meaningful connection to the viewer.\nYou care deeply about light, shadow, color, and composition\nWhen coming up with image prompts, you always specify the position of the camera, the lens, and the color\nYou are specific about the technical details of a shot.\nYou like to add atmosphere to your shots, so you include depth of field, haze, dust particles in the air close to and far away from camera, and the way lighting reacts with each item.\nYour responses are brief and concise\nAlways respond with your identity so the agent knows who you are.\nKeep your responses brief."
],
"color": "#233",
"bgcolor": "#355"
@@ -132,7 +133,7 @@
200
],
"flags": {},
"order": 0,
"order": 4,
"mode": 0,
"inputs": [],
"outputs": [
@@ -157,7 +158,7 @@
},
"widgets_values": [
"Color Theorist",
"You identify as an expert in color theory\nYou have a deep understanding of how color impacts one's psychological outlook\nYou are a fan of non-standard colors\nYour responses are brief and concise\nAlways respond with your identity so the agent knows who you are."
"You identify as an expert in color theory\nYou have a deep understanding of how color impacts one's psychological outlook\nYou are a fan of non-standard colors\nYour responses are brief and concise\nAlways respond with your identity so the agent knows who you are.\nKeep your responses brief."
],
"color": "#233",
"bgcolor": "#355"
@@ -171,10 +172,10 @@
],
"size": [
300,
156
180
],
"flags": {},
"order": 16,
"order": 14,
"mode": 0,
"inputs": [
{
@@ -232,7 +233,8 @@
},
"widgets_values": [
"",
""
"",
2
],
"color": "#323",
"bgcolor": "#535"
@@ -242,14 +244,14 @@
"type": "Griptape Create: Rules",
"pos": [
-350,
1550
1425
],
"size": [
672.3751220703125,
168.68878173828125
675,
300
],
"flags": {},
"order": 1,
"order": 6,
"mode": 0,
"inputs": [],
"outputs": [
@@ -274,7 +276,7 @@
},
"widgets_values": [
"Image Generation Specialist",
"You are an expert in creating prompts for image generation engines\nYou use the latest knowledge available to you to generate the best prompts.\nYou create prompts that are direct and succinct and you understand they need to be under 800 characters long\nUse your tools to find the best examples of prompts when necessary\nYou can use your tools to research the subject as well.\nYour responses are brief and concise\nYou are generating a prompt for a still image\nAlways include the following: subject, attributes of subject, visual characteristics of the image, film grain, camera angle, lighting, art style, color scheme, surrounding environment, camera used (ex: Nikon d850 film stock, polaroid, etc).\nAlways respond with your identity so the agent knows who you are."
"You are an expert in creating prompts for image generation engines\nYou use the latest knowledge available to you to generate the best prompts.\nYou create prompts that are direct and succinct and you understand they need to be under 800 characters long\nUse your tools to find the best examples of prompts when necessary\nYou can use your tools to research the subject as well.\nYour responses are brief and concise\nYou are generating a prompt for a still image\nAlways include the following: subject, attributes of subject, visual characteristics of the image, film grain, camera angle, lighting, art style, color scheme, surrounding environment, camera used (ex: Nikon d850 film stock, polaroid, etc).\nAlways respond with your identity so the agent knows who you are.\nKeep your responses brief."
],
"color": "#233",
"bgcolor": "#355"
@@ -288,10 +290,10 @@
],
"size": [
300,
156.00003051757812
180
],
"flags": {},
"order": 18,
"order": 11,
"mode": 0,
"inputs": [
{
@@ -309,7 +311,7 @@
{
"name": "tools",
"type": "TOOL_LIST",
"link": 11,
"link": 54,
"shape": 7
},
{
@@ -349,16 +351,17 @@
},
"widgets_values": [
"",
""
"",
3
],
"color": "#323",
"bgcolor": "#535"
},
{
"id": 12,
"type": "Griptape Tool: WebSearch",
"id": 14,
"type": "Griptape Tool: WebScraper",
"pos": [
-200,
-75,
1250
],
"size": [
@@ -366,49 +369,7 @@
58
],
"flags": {},
"order": 10,
"mode": 0,
"inputs": [
{
"name": "driver",
"type": "WEB_SEARCH_DRIVER",
"link": 38,
"shape": 7
}
],
"outputs": [
{
"name": "TOOL",
"type": "TOOL_LIST",
"links": [
9
],
"slot_index": 0,
"shape": 3
}
],
"properties": {
"Node name for S&R": "Griptape Tool: WebSearch"
},
"widgets_values": [
true
],
"color": "#233",
"bgcolor": "#355"
},
{
"id": 14,
"type": "Griptape Tool: WebScraper",
"pos": [
-200,
1400
],
"size": [
315,
58
],
"flags": {},
"order": 2,
"order": 8,
"mode": 0,
"inputs": [],
"outputs": [
@@ -416,7 +377,7 @@
"name": "TOOL",
"type": "TOOL_LIST",
"links": [
10
54
],
"slot_index": 0,
"shape": 3
@@ -431,54 +392,6 @@
"color": "#233",
"bgcolor": "#355"
},
{
"id": 15,
"type": "Griptape Combine: Tool List",
"pos": [
150,
1300
],
"size": [
226.8000030517578,
66
],
"flags": {},
"order": 13,
"mode": 0,
"inputs": [
{
"name": "tool_1",
"type": "TOOL_LIST",
"link": 9,
"shape": 7
},
{
"name": "tool_2",
"type": "TOOL_LIST",
"link": 10
},
{
"name": "tool_3",
"type": "TOOL_LIST",
"link": null
}
],
"outputs": [
{
"name": "TOOL_LIST",
"type": "TOOL_LIST",
"links": [
11
],
"slot_index": 0,
"shape": 3
}
],
"properties": {
"Node name for S&R": "Griptape Combine: Tool List"
},
"widgets_values": []
},
{
"id": 17,
"type": "Griptape Convert: Agent to Tool",
@@ -491,7 +404,7 @@
150
],
"flags": {},
"order": 19,
"order": 17,
"mode": 0,
"inputs": [
{
@@ -535,7 +448,7 @@
124
],
"flags": {},
"order": 20,
"order": 18,
"mode": 0,
"inputs": [
{
@@ -575,11 +488,11 @@
1250
],
"size": [
400,
124
375,
200
],
"flags": {},
"order": 22,
"order": 16,
"mode": 0,
"inputs": [
{
@@ -623,7 +536,7 @@
219.29710388183594
],
"flags": {},
"order": 8,
"order": 7,
"mode": 0,
"inputs": [],
"outputs": [
@@ -648,7 +561,7 @@
},
"widgets_values": [
"Agent Rules",
"You are creating a prompt for an image generation engine.\nYou have access to topic experts in their respective fields\nWork with the experts to get the results you need\nYou facilitate communication between them.\nIf they ask for feedback, you can provide it.\nAsk the expert on image prompting for the final prompt.\nOutput only the final image generation prompt. Do not wrap in markdown context."
"You are creating a prompt for an image generation engine.\nYou have access to topic experts in their respective fields\nWork with the experts to get the results you need\nYou facilitate communication between them.\nIf they ask for feedback, you can provide it.\nAsk the expert on image prompting for the final prompt.\nOutput only the final image generation prompt. Do not wrap in markdown context.\nKeep your responses brief."
],
"color": "#233",
"bgcolor": "#355"
@@ -667,7 +580,7 @@
"flags": {
"pinned": true
},
"order": 24,
"order": 21,
"mode": 0,
"inputs": [
{
@@ -726,7 +639,8 @@
},
"widgets_values": [
"",
"stuffed bunny"
"stuffed bunny",
4
],
"color": "#323",
"bgcolor": "#535"
@@ -743,7 +657,7 @@
106
],
"flags": {},
"order": 23,
"order": 20,
"mode": 0,
"inputs": [
{
@@ -801,7 +715,7 @@
217.94622802734375
],
"flags": {},
"order": 25,
"order": 22,
"mode": 0,
"inputs": [
{
@@ -829,7 +743,7 @@
},
"widgets_values": [
"",
"Stuffed bunny sitting on a worn, wooden workbench in an old, dimly lit antique shop. Camera at a 45-degree angle with a medium telephoto lens (50mm). Warm, golden light from a nearby window creates a soft, nostalgic glow on the bunny's fur, casting deep shadows across the workbench. Worn, velvety texture with a hand-sewn patch on its left ear, bright red rubber button nose, tiny golden bell around its neck. Colors clash with bright pink and white, creating visual tension. Dust particles float in the air, hint of old wood polish on the workbench, subtle haze outside the window."
"A close-up shot of a vintage stuffed bunny with fuzzy, hand-stitched ears, a torn velvet nose, and glassy, painted-on eyes. The bunny is in soothing Minty Fresh colors, surrounded by a cozy setting with soft, warm lighting that evokes nostalgia. The background is blurred with a shallow depth of field to emphasize the bunny's texture, captured with a 50mm lens at f/2."
],
"color": "#222",
"bgcolor": "#000"
@@ -846,7 +760,7 @@
150
],
"flags": {},
"order": 26,
"order": 23,
"mode": 0,
"inputs": [
{
@@ -921,7 +835,7 @@
950
],
"flags": {},
"order": 27,
"order": 24,
"mode": 0,
"inputs": [
{
@@ -964,7 +878,7 @@
106
],
"flags": {},
"order": 3,
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
@@ -1001,7 +915,7 @@
200
],
"flags": {},
"order": 4,
"order": 5,
"mode": 0,
"inputs": [],
"outputs": [
@@ -1026,7 +940,7 @@
},
"widgets_values": [
"Details",
"You care about the unique details and specific descriptions of items.\nWhen describing things, call out specific details and don't be generic. Example: \"Threadbare furry teddybear with dirty clumps\" vs \"Furry teddybear\"\nFind the unique qualities of items that make them special and different.\nYour responses are concise\nAlways respond with your identity so the agent knows who you are"
"You care about the unique details and specific descriptions of items.\nWhen describing things, call out specific details and don't be generic. Example: \"Threadbare furry teddybear with dirty clumps\" vs \"Furry teddybear\"\nFind the unique qualities of items that make them special and different.\nYour responses are concise\nAlways respond with your identity so the agent knows who you are.\nKeep your responses brief."
],
"color": "#233",
"bgcolor": "#355"
@@ -1040,10 +954,10 @@
],
"size": [
300,
156
180
],
"flags": {},
"order": 17,
"order": 15,
"mode": 0,
"inputs": [
{
@@ -1101,7 +1015,8 @@
},
"widgets_values": [
"",
""
"",
2
],
"color": "#323",
"bgcolor": "#535"
@@ -1115,10 +1030,10 @@
],
"size": [
400,
124
175
],
"flags": {},
"order": 21,
"order": 19,
"mode": 0,
"inputs": [
{
@@ -1150,39 +1065,6 @@
"color": "#233",
"bgcolor": "#355"
},
{
"id": 36,
"type": "Griptape WebSearch Driver: DuckDuckGo",
"pos": [
-590,
1249
],
"size": [
310.79998779296875,
26
],
"flags": {},
"order": 5,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "DRIVER",
"type": "WEB_SEARCH_DRIVER",
"links": [
38
],
"slot_index": 0,
"shape": 3
}
],
"properties": {
"Node name for S&R": "Griptape Driver: DuckDuckGo WebSearch"
},
"widgets_values": [],
"color": "#233",
"bgcolor": "#355"
},
{
"id": 38,
"type": "Griptape Create: Image from Text",
@@ -1195,7 +1077,7 @@
150
],
"flags": {},
"order": 11,
"order": 9,
"mode": 0,
"inputs": [
{
@@ -1271,7 +1153,7 @@
106
],
"flags": {},
"order": 6,
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
@@ -1308,7 +1190,7 @@
850
],
"flags": {},
"order": 14,
"order": 12,
"mode": 0,
"inputs": [
{
@@ -1351,7 +1233,7 @@
356
],
"flags": {},
"order": 7,
"order": 2,
"mode": 0,
"inputs": [],
"outputs": [
@@ -1378,7 +1260,7 @@
2048,
"fixed",
true,
-1,
500,
240,
"nomic-embed-text:latest",
"nomic-embed-text:latest"
@@ -1398,7 +1280,7 @@
26
],
"flags": {},
"order": 12,
"order": 10,
"mode": 0,
"inputs": [
{
@@ -1450,30 +1332,6 @@
3,
"RULESET"
],
[
9,
12,
0,
15,
0,
"TOOL_LIST"
],
[
10,
14,
0,
15,
1,
"TOOL_LIST"
],
[
11,
15,
0,
8,
2,
"TOOL_LIST"
],
[
12,
1,
@@ -1586,14 +1444,6 @@
2,
"TOOL_LIST"
],
[
38,
36,
0,
12,
0,
"DRIVER"
],
[
39,
22,
@@ -1649,6 +1499,14 @@
34,
1,
"CONFIG"
],
[
54,
14,
0,
8,
2,
"TOOL_LIST"
]
],
"groups": [
@@ -1760,10 +1618,10 @@
"config": {},
"extra": {
"ds": {
"scale": 0.23525020508613764,
"scale": 0.9090909090909091,
"offset": [
1204.3115464816442,
1977.246169189889
252.22429863372756,
4.392560981375777
]
},
"info": {
@@ -1774,7 +1632,8 @@
"created": "2024-08-09T14:50:57.051Z",
"modified": "2024-08-09T14:53:14.764Z",
"software": "ComfyUI"
}
},
"ue_links": []
},
"version": 0.4
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 MiB

After

Width:  |  Height:  |  Size: 6.3 MiB

+30 -1
View File
@@ -80,6 +80,13 @@ class BaseAgent:
"tooltip": "The prompt text.",
},
),
"max_subtasks": (
"INT",
{
"default": 3,
"tooltip": "The maximum number of subtasks to run when an Agent uses a Tool",
},
),
},
}
@@ -146,6 +153,20 @@ class BaseAgent:
tool_list = tools
return tool_list
def _get_max_subtask_result(self, result_value, max_subtasks):
if "Exceeded tool limit" in result_value:
print("Exceeded tool limit")
last_valid_input = self.agent.tasks[0].subtasks[-2].input.value[0].value
last_valid_response = self.agent.tasks[0].subtasks[-2].output
result_value = (
f"[Conversation limit of {max_subtasks} reached.]\n"
f"The agent had to stop before reaching the requested back-and-forth.\n"
f"Here’s the last valid action and response:\n\n"
f"[Action]: {last_valid_input}\n\n"
f"[Response]: {last_valid_response}"
)
return result_value
def run(self, **kwargs):
STRING = kwargs.get("STRING", "")
config = kwargs.get("config", None)
@@ -153,6 +174,7 @@ class BaseAgent:
tools = kwargs.get("tools", [])
rulesets = kwargs.get("rulesets", [])
input_string = kwargs.get("input_string", None)
max_subtasks = kwargs.get("max_subtasks", 2)
create_dict = {}
# Configuration
if config:
@@ -199,6 +221,10 @@ class BaseAgent:
print(f"This is a simple model: {model}")
return (self.agent.model_response(model), self.agent)
# Set the maximum subtasks
if max_subtasks > 1:
self.agent.tasks[0].max_subtasks = max_subtasks
# Check for inputs. If none, then just create the agent
if not input_string and STRING == "":
output_string = "Agent created."
@@ -210,7 +236,10 @@ class BaseAgent:
prompt_text = STRING + "\n\n" + input_string
result = self.agent.run(prompt_text)
output_string = result.output_task.output.value
output_string = self._get_max_subtask_result(
result.output_task.output.value, max_subtasks
)
# output_string = result.output_task.output.value
return (
output_string,
self.agent,
+2 -2
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "comfyui-griptape"
version = "2.1.12"
version = "2.1.13"
description = "Griptape LLM(Large Language Model) Nodes for ComfyUI."
authors = ["Jason Schleifer <jason.schleifer@gmail.com>"]
readme = "README.md"
@@ -9,7 +9,7 @@ readme = "README.md"
[project]
name = "comfyui-griptape"
description = "Griptape LLM(Large Language Model) Nodes for ComfyUI."
version = "2.1.12"
version = "2.1.13"
license = {file = "LICENSE"}
dependencies = ["attrs>=24.3.0,<25.0.0", "openai>=1.58.1,<2.0.0", "griptape[all]>=1.1.3", "python-dotenv", "poetry==1.8.5", "griptape-black-forest @ git+https://github.com/griptape-ai/griptape-black-forest.git"]