Skip to content
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

fix(platform): Fix timer & step-through block #8421

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions autogpt_platform/backend/backend/blocks/iteration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@

from backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema
from backend.data.model import SchemaField
from backend.util.json import json


class StepThroughItemsBlock(Block):
class Input(BlockSchema):
items: list | dict = SchemaField(
items: list = SchemaField(
advanced=False,
description="The list or dictionary of items to iterate over",
placeholder="[1, 2, 3, 4, 5] or {'key1': 'value1', 'key2': 'value2'}",
default=[],
)
items_object: dict = SchemaField(
advanced=False,
description="The list or dictionary of items to iterate over",
placeholder="[1, 2, 3, 4, 5] or {'key1': 'value1', 'key2': 'value2'}",
default={},
)
items_str: str = SchemaField(
advanced=False,
description="The list or dictionary of items to iterate over",
placeholder="[1, 2, 3, 4, 5] or {'key1': 'value1', 'key2': 'value2'}",
default="",
)

class Output(BlockSchema):
Expand Down Expand Up @@ -39,14 +54,20 @@ def __init__(self):
)

def run(self, input_data: Input, **kwargs) -> BlockOutput:
items = input_data.items
if isinstance(items, dict):
# If items is a dictionary, iterate over its values
for item in items.values():
yield "item", item
yield "key", item
else:
# If items is a list, iterate over the list
for index, item in enumerate(items):
yield "item", item
yield "key", index
for data in [input_data.items, input_data.items_object, input_data.items_str]:
if not data:
continue
if isinstance(data, str):
items = json.loads(data)
else:
items = data
if isinstance(items, dict):
# If items is a dictionary, iterate over its values
for item in items.values():
yield "item", item
yield "key", item
else:
# If items is a list, iterate over the list
for index, item in enumerate(items):
yield "item", item
yield "key", index
27 changes: 15 additions & 12 deletions autogpt_platform/backend/backend/blocks/time_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,26 @@ def run(self, input_data: Input, **kwargs) -> BlockOutput:

class CountdownTimerBlock(Block):
class Input(BlockSchema):
input_message: Any = SchemaField(
input_data: Any = SchemaField(
advanced=False,
description="Message to output after the timer finishes",
default="timer finished",
)
seconds: Union[int, str] = SchemaField(
description="Duration in seconds", default=0
advanced=False, description="Duration in seconds", default=0
)
minutes: Union[int, str] = SchemaField(
description="Duration in minutes", default=0
advanced=False, description="Duration in minutes", default=0
)
hours: Union[int, str] = SchemaField(
advanced=False, description="Duration in hours", default=0
)
days: Union[int, str] = SchemaField(
advanced=False, description="Duration in days", default=0
)
hours: Union[int, str] = SchemaField(description="Duration in hours", default=0)
days: Union[int, str] = SchemaField(description="Duration in days", default=0)

class Output(BlockSchema):
output_message: str = SchemaField(
description="Message after the timer finishes"
)
output_data: Any = SchemaField(description="Message after the timer finishes")

def __init__(self):
super().__init__(
Expand All @@ -166,11 +169,11 @@ def __init__(self):
output_schema=CountdownTimerBlock.Output,
test_input=[
{"seconds": 1},
{"input_message": "Custom message"},
{"input_data": "Custom message"},
],
test_output=[
("output_message", "timer finished"),
("output_message", "Custom message"),
("output_data", "timer finished"),
("output_data", "Custom message"),
],
)

Expand All @@ -183,4 +186,4 @@ def run(self, input_data: Input, **kwargs) -> BlockOutput:
total_seconds = seconds + minutes * 60 + hours * 3600 + days * 86400

time.sleep(total_seconds)
yield "output_message", input_data.input_message
yield "output_data", input_data.input_data
4 changes: 3 additions & 1 deletion autogpt_platform/backend/backend/executor/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def update_execution(status: ExecutionStatus) -> ExecutionResult:
input_data_str = json.dumps(input_data)
input_size = len(input_data_str)
log_metadata.info("Executed node with input", input=input_data_str)
update_execution(ExecutionStatus.RUNNING)
exec_res = update_execution(ExecutionStatus.RUNNING)

extra_exec_kwargs = {}
# Last-minute fetch credentials + acquire a system-wide read-write lock to prevent
Expand All @@ -173,6 +173,8 @@ def update_execution(status: ExecutionStatus) -> ExecutionResult:
output_size += len(json.dumps(output_data))
log_metadata.info("Node produced output", output_name=output_data)
db_client.upsert_execution_output(node_exec_id, output_name, output_data)
exec_res.output_data.setdefault(output_name, []).append(output_data)
db_client.send_execution_update(exec_res.model_dump())

for execution in _enqueue_next_nodes(
db_client=db_client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ const NodeArrayInput: FC<{
typeof errors[selfKey] === "string" ? errors[selfKey] : undefined;
return (
<div className={cn(className, "flex flex-col")}>
{displayName && <strong>{displayName}</strong>}
{entries.map((entry: any, index: number) => {
const entryKey = `${selfKey}_$_${index}`;
const isConnected =
Expand Down
2 changes: 1 addition & 1 deletion autogpt_platform/frontend/src/hooks/useAgentGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default function useAgentGraph(
if (!outputSchema) return "unknown";

const outputHandle = outputSchema.properties[handleId];
if (!("type" in outputHandle)) return "unknown";
if (!outputHandle || !("type" in outputHandle)) return "unknown";
return outputHandle.type;
},
[],
Expand Down
Loading