Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

Create Input Node Custom UI Node (#8016)

Swifty6c001bd595e8
diff --git a/rnd/autogpt_builder/src/components/CustomNode.tsx b/rnd/autogpt_builder/src/components/CustomNode.tsx
index 22cfaef952..e9f74709fd 100644
--- a/rnd/autogpt_builder/src/components/CustomNode.tsx
+++ b/rnd/autogpt_builder/src/components/CustomNode.tsx
@@ -12,8 +12,10 @@ import InputModalComponent from "./InputModalComponent";
import OutputModalComponent from "./OutputModalComponent";
import {
BlockIORootSchema,
+ BlockIOStringSubSchema,
Category,
NodeExecutionResult,
+ BlockUIType,
} from "@/lib/autogpt-server-api/types";
import { beautifyString, cn, setNestedProperty } from "@/lib/utils";
import { Button } from "@/components/ui/button";
@@ -21,7 +23,10 @@ import { Switch } from "@/components/ui/switch";
import { Copy, Trash2 } from "lucide-react";
import { history } from "./history";
import NodeHandle from "./NodeHandle";
-import { NodeGenericInputField } from "./node-input-components";
+import {
+ NodeGenericInputField,
+ NodeTextBoxInput,
+} from "./node-input-components";
import SchemaTooltip from "./SchemaTooltip";
import { getPrimaryCategoryColor } from "@/lib/utils";
import { FlowContext } from "./Flow";
@@ -59,6 +64,7 @@ export type CustomNodeData = {
backend_id?: string;
errors?: { [key: string]: string };
isOutputStatic?: boolean;
+ uiType: BlockUIType;
};
export type CustomNode = Node<CustomNodeData, "custom">;
@@ -118,8 +124,16 @@ export function CustomNode({ data, id, width, height }: NodeProps<CustomNode>) {
setIsAdvancedOpen(checked);
};
- const generateOutputHandles = (schema: BlockIORootSchema) => {
- if (!schema?.properties) return null;
+ const generateOutputHandles = (
+ schema: BlockIORootSchema,
+ nodeType: BlockUIType,
+ ) => {
+ if (
+ !schema?.properties ||
+ nodeType === BlockUIType.OUTPUT ||
+ nodeType === BlockUIType.NOTE
+ )
+ return null;
const keys = Object.keys(schema.properties);
return keys.map((key) => (
<div key={key}>
@@ -133,6 +147,137 @@ export function CustomNode({ data, id, width, height }: NodeProps<CustomNode>) {
));
};
+ const generateInputHandles = (
+ schema: BlockIORootSchema,
+ nodeType: BlockUIType,
+ ) => {
+ if (!schema?.properties) return null;
+ let keys = Object.entries(schema.properties);
+ switch (nodeType) {
+ case BlockUIType.INPUT:
+ // For INPUT blocks, dont include connection handles
+ return keys.map(([propKey, propSchema]) => {
+ const isRequired = data.inputSchema.required?.includes(propKey);
+ const isConnected = isHandleConnected(propKey);
+ const isAdvanced = propSchema.advanced;
+ return (
+ (isRequired || isAdvancedOpen || !isAdvanced) && (
+ <div key={propKey}>
+ <span className="text-m green -mb-1 text-gray-900">
+ {propSchema.title || beautifyString(propKey)}
+ </span>
+ <div key={propKey} onMouseOver={() => {}}>
+ {!isConnected && (
+ <NodeGenericInputField
+ className="mb-2 mt-1"
+ propKey={propKey}
+ propSchema={propSchema}
+ currentValue={getValue(propKey)}
+ connections={data.connections}
+ handleInputChange={handleInputChange}
+ handleInputClick={handleInputClick}
+ errors={data.errors ?? {}}
+ displayName={propSchema.title || beautifyString(propKey)}
+ />
+ )}
+ </div>
+ </div>
+ )
+ );
+ });
+
+ case BlockUIType.NOTE:
+ // For NOTE blocks, don't render any input handles
+ const [noteKey, noteSchema] = keys[0];
+ return (
+ <div key={noteKey}>
+ <NodeTextBoxInput
+ className=""
+ selfKey={noteKey}
+ schema={noteSchema as BlockIOStringSubSchema}
+ value={getValue(noteKey)}
+ handleInputChange={handleInputChange}
+ handleInputClick={handleInputClick}
+ error={data.errors?.[noteKey] ?? ""}
+ displayName={noteSchema.title || beautifyString(noteKey)}
+ />
+ </div>
+ );
+
+ case BlockUIType.OUTPUT:
+ // For OUTPUT blocks, only show the 'value' property
+ return keys.map(([propKey, propSchema]) => {
+ const isRequired = data.inputSchema.required?.includes(propKey);
+ const isConnected = isHandleConnected(propKey);
+ const isAdvanced = propSchema.advanced;
+ return (
+ (isRequired || isAdvancedOpen || !isAdvanced) && (
+ <div key={propKey} onMouseOver={() => {}}>
+ {propKey !== "value" ? (
+ <span className="text-m green -mb-1 text-gray-900">
+ {propSchema.title || beautifyString(propKey)}
+ </span>
+ ) : (
+ <NodeHandle
+ keyName={propKey}
+ isConnected={isConnected}
+ isRequired={isRequired}
+ schema={propSchema}
+ side="left"
+ />
+ )}
+ {!isConnected && (
+ <NodeGenericInputField
+ className="mb-2 mt-1"
+ propKey={propKey}
+ propSchema={propSchema}
+ currentValue={getValue(propKey)}
+ connections={data.connections}
+ handleInputChange={handleInputChange}
+ handleInputClick={handleInputClick}
+ errors={data.errors ?? {}}
+ displayName={propSchema.title || beautifyString(propKey)}
+ />
+ )}
+ </div>
+ )
+ );
+ });
+
+ default:
+ return keys.map(([propKey, propSchema]) => {
+ const isRequired = data.inputSchema.required?.includes(propKey);
+ const isConnected = isHandleConnected(propKey);
+ const isAdvanced = propSchema.advanced;
+ return (
+ (isRequired || isAdvancedOpen || isConnected || !isAdvanced) && (
+ <div key={propKey} onMouseOver={() => {}}>
+ <NodeHandle
+ keyName={propKey}
+ isConnected={isConnected}
+ isRequired={isRequired}
+ schema={propSchema}
+ side="left"
+ />
+ {!isConnected && (
+ <NodeGenericInputField
+ className="mb-2 mt-1"
+ propKey={propKey}
+ propSchema={propSchema}
+ currentValue={getValue(propKey)}
+ connections={data.connections}
+ handleInputChange={handleInputChange}
+ handleInputClick={handleInputClick}
+ errors={data.errors ?? {}}
+ displayName={propSchema.title || beautifyString(propKey)}
+ />
+ )}
+ </div>
+ )
+ );
+ });
+ }
+ };
const handleInputChange = (path: string, value: any) => {
const keys = parseKeys(path);
const newValues = JSON.parse(JSON.stringify(data.hardcodedValues));
@@ -378,13 +523,13 @@ export function CustomNode({ data, id, width, height }: NodeProps<CustomNode>) {
return (
<div
- className={`${blockClasses} ${errorClass} ${statusClass}`}
+ className={`${data.uiType === BlockUIType.NOTE ? "w-[300px]" : "w-[500px]"} ${blockClasses} ${errorClass} ${statusClass} ${data.uiType === BlockUIType.NOTE ? "bg-yellow-100" : "bg-white"}`}
onMouseEnter={handleHovered}
onMouseLeave={handleMouseLeave}
data-id={`custom-node-${id}`}
>
<div
- className={`mb-2 p-3 ${getPrimaryCategoryColor(data.categories)} rounded-t-xl`}
+ className={`mb-2 p-3 ${data.uiType === BlockUIType.NOTE ? "bg-yellow-100" : getPrimaryCategoryColor(data.categories)} rounded-t-xl`}
>
<div className="flex items-center justify-between">
<div className="font-roboto p-3 text-lg font-semibold">
@@ -417,53 +562,24 @@ export function CustomNode({ data, id, width, height }: NodeProps<CustomNode>) {
)}
</div>
</div>
- <div className="flex items-start justify-between gap-2 p-3">
+ {data.uiType !== BlockUIType.NOTE ? (
+ <div className="flex items-start justify-between p-3">
+ <div>
+ {data.inputSchema &&
+ generateInputHandles(data.inputSchema, data.uiType)}
+ </div>
+ <div className="flex-none">
+ {data.outputSchema &&
+ generateOutputHandles(data.outputSchema, data.uiType)}
+ </div>
+ </div>
+ ) : (
<div>
{data.inputSchema &&
- Object.entries(data.inputSchema.properties).map(
- ([propKey, propSchema]) => {
- const isRequired = data.inputSchema.required?.includes(propKey);
- const isConnected = isHandleConnected(propKey);
- const isAdvanced = propSchema.advanced;
- return (
- (isRequired ||
- isAdvancedOpen ||
- isConnected ||
- !isAdvanced) && (
- <div key={propKey} onMouseOver={() => {}}>
- <NodeHandle
- keyName={propKey}
- isConnected={isConnected}
- isRequired={isRequired}
- schema={propSchema}
- side="left"
- />
- {!isConnected && (
- <NodeGenericInputField
- className="mb-2 mt-1"
- propKey={propKey}
- propSchema={propSchema}
- currentValue={getValue(propKey)}
- connections={data.connections}
- handleInputChange={handleInputChange}
- handleInputClick={handleInputClick}
- errors={data.errors ?? {}}
- displayName={
- propSchema.title || beautifyString(propKey)
- }
- />
- )}
- </div>
- )
- );
- },
- )}
+ generateInputHandles(data.inputSchema, data.uiType)}
</div>
- <div className="flex-none">
- {data.outputSchema && generateOutputHandles(data.outputSchema)}
- </div>
- </div>
- {isOutputOpen && (
+ )}
+ {isOutputOpen && data.uiType !== BlockUIType.NOTE && (
<div
data-id="latest-output"
className="nodrag m-3 break-words rounded-md border-[1.5px] p-2"
@@ -486,25 +602,27 @@ export function CustomNode({ data, id, width, height }: NodeProps<CustomNode>) {
)}
</div>
)}
- <div className="mt-2.5 flex items-center pb-4 pl-4">
- <Switch checked={isOutputOpen} onCheckedChange={toggleOutput} />
- <span className="m-1 mr-4">Output</span>
- {hasAdvancedFields && (
- <>
- <Switch onCheckedChange={toggleAdvancedSettings} />
- <span className="m-1">Advanced</span>
- </>
- )}
- {data.status && (
- <Badge
- variant="outline"
- data-id={`badge-${id}-${data.status}`}
- className={cn(data.status.toLowerCase(), "ml-auto mr-5")}
- >
- {data.status}
- </Badge>
- )}
- </div>
+ {data.uiType !== BlockUIType.NOTE && (
+ <div className="mt-2.5 flex items-center pb-4 pl-4">
+ <Switch checked={isOutputOpen} onCheckedChange={toggleOutput} />
+ <span className="m-1 mr-4">Output</span>
+ {hasAdvancedFields && (
+ <>
+ <Switch onCheckedChange={toggleAdvancedSettings} />
+ <span className="m-1">Advanced</span>
+ </>
+ )}
+ {data.status && (
+ <Badge
+ variant="outline"
+ data-id={`badge-${id}-${data.status}`}
+ className={cn(data.status.toLowerCase(), "ml-auto mr-5")}
+ >
+ {data.status}
+ </Badge>
+ )}
+ </div>
+ )}
<InputModalComponent
title={activeKey ? `Enter ${beautifyString(activeKey)}` : undefined}
isOpen={isModalOpen}
diff --git a/rnd/autogpt_builder/src/components/Flow.tsx b/rnd/autogpt_builder/src/components/Flow.tsx
index 16e3fd7049..92e384eb40 100644
--- a/rnd/autogpt_builder/src/components/Flow.tsx
+++ b/rnd/autogpt_builder/src/components/Flow.tsx
@@ -417,6 +417,7 @@ const FlowEditor: React.FC<{
isOutputOpen: false,
block_id: blockId,
isOutputStatic: nodeSchema.staticOutput,
+ uiType: nodeSchema.uiType,
},
};
diff --git a/rnd/autogpt_builder/src/components/customnode.css b/rnd/autogpt_builder/src/components/customnode.css
index 90efecdd2e..840fd31a94 100644
--- a/rnd/autogpt_builder/src/components/customnode.css
+++ b/rnd/autogpt_builder/src/components/customnode.css
@@ -1,6 +1,5 @@
.custom-node {
color: #000000;
- width: 500px;
box-sizing: border-box;
transition: border-color 0.3s ease-in-out;
}
diff --git a/rnd/autogpt_builder/src/components/node-input-components.tsx b/rnd/autogpt_builder/src/components/node-input-components.tsx
index 394abc5213..f0a2bf85f4 100644
--- a/rnd/autogpt_builder/src/components/node-input-components.tsx
+++ b/rnd/autogpt_builder/src/components/node-input-components.tsx
@@ -10,7 +10,7 @@ import {
BlockIONumberSubSchema,
BlockIOBooleanSubSchema,
} from "@/lib/autogpt-server-api/types";
-import { FC, useCallback, useEffect, useState } from "react";
+import React, { FC, useCallback, useEffect, useState } from "react";
import { Button } from "./ui/button";
import { Switch } from "./ui/switch";
import {
@@ -587,6 +587,52 @@ const NodeStringInput: FC<{
);
};
+export const NodeTextBoxInput: FC<{
+ selfKey: string;
+ schema: BlockIOStringSubSchema;
+ value?: string;
+ error?: string;
+ handleInputChange: NodeObjectInputTreeProps["handleInputChange"];
+ handleInputClick: NodeObjectInputTreeProps["handleInputClick"];
+ className?: string;
+ displayName: string;
+}> = ({
+ selfKey,
+ schema,
+ value = "",
+ error,
+ handleInputChange,
+ handleInputClick,
+ className,
+ displayName,
+}) => {
+ return (
+ <div className={className}>
+ <div
+ className="nodrag relative m-0 h-[200px] w-full bg-yellow-100 p-4"
+ onClick={schema.secret ? () => handleInputClick(selfKey) : undefined}
+ >
+ <textarea
+ id={selfKey}
+ value={schema.secret && value ? "********" : value}
+ readOnly={schema.secret}
+ placeholder={
+ schema?.placeholder || `Enter ${beautifyString(displayName)}`
+ }
+ onChange={(e) => handleInputChange(selfKey, e.target.value)}
+ onBlur={(e) => handleInputChange(selfKey, e.target.value)}
+ className="h-full w-full resize-none overflow-hidden border-none bg-transparent text-lg text-black outline-none"
+ style={{
+ fontSize: "min(1em, 16px)",
+ lineHeight: "1.2",
+ }}
+ />
+ </div>
+ {error && <span className="error-message">{error}</span>}
+ </div>
+ );
+};
+
const NodeNumberInput: FC<{
selfKey: string;
schema: BlockIONumberSubSchema;
diff --git a/rnd/autogpt_builder/src/lib/autogpt-server-api/types.ts b/rnd/autogpt_builder/src/lib/autogpt-server-api/types.ts
index 20948f4870..876180f1c9 100644
--- a/rnd/autogpt_builder/src/lib/autogpt-server-api/types.ts
+++ b/rnd/autogpt_builder/src/lib/autogpt-server-api/types.ts
@@ -13,6 +13,7 @@ export type Block = {
inputSchema: BlockIORootSchema;
outputSchema: BlockIORootSchema;
staticOutput: boolean;
+ uiType: BlockUIType;
};
export type BlockIORootSchema = {
@@ -182,3 +183,10 @@ export type User = {
id: string;
email: string;
};
+
+export enum BlockUIType {
+ STANDARD = "Standard",
+ INPUT = "Input",
+ OUTPUT = "Output",
+ NOTE = "Note",
+}
diff --git a/rnd/autogpt_server/autogpt_server/blocks/__init__.py b/rnd/autogpt_server/autogpt_server/blocks/__init__.py
index 789fd6aa29..2f3c568c62 100644
--- a/rnd/autogpt_server/autogpt_server/blocks/__init__.py
+++ b/rnd/autogpt_server/autogpt_server/blocks/__init__.py
@@ -55,15 +55,15 @@ for cls in all_subclasses(Block):
raise ValueError(f"Block ID {block.name} error: {block.id} is already in use")
# Prevent duplicate field name in input_schema and output_schema
- duplicate_field_names = set(block.input_schema.__fields__.keys()) & set(
- block.output_schema.__fields__.keys()
+ duplicate_field_names = set(block.input_schema.model_fields.keys()) & set(
+ block.output_schema.model_fields.keys()
)
if duplicate_field_names:
raise ValueError(
f"{block.name} has duplicate field names in input_schema and output_schema: {duplicate_field_names}"
)
- for field in block.input_schema.__fields__.values():
+ for field in block.input_schema.model_fields.values():
if field.annotation is bool and field.default not in (True, False):
raise ValueError(f"{block.name} has a boolean field with no default value")
diff --git a/rnd/autogpt_server/autogpt_server/blocks/basic.py b/rnd/autogpt_server/autogpt_server/blocks/basic.py
index 0fc960be96..51cf69479a 100644
--- a/rnd/autogpt_server/autogpt_server/blocks/basic.py
+++ b/rnd/autogpt_server/autogpt_server/blocks/basic.py
@@ -1,5 +1,7 @@
+import re
from typing import Any, List
+from jinja2 import BaseLoader, Environment
from pydantic import Field
from autogpt_server.data.block import (
@@ -12,6 +14,8 @@ from autogpt_server.data.block import (
from autogpt_server.data.model import SchemaField
from autogpt_server.util.mock import MockObject
+jinja = Environment(loader=BaseLoader())
+
class StoreValueBlock(Block):
"""
@@ -136,7 +140,7 @@ class FindInDictionaryBlock(Block):
yield "missing", input_data.input
-class InputBlock(Block):
+class AgentInputBlock(Block):
"""
This block is used to provide input to the graph.
@@ -148,13 +152,20 @@ class InputBlock(Block):
class Input(BlockSchema):
value: Any = SchemaField(description="The value to be passed as input.")
name: str = SchemaField(description="The name of the input.")
- description: str = SchemaField(description="The description of the input.")
+ description: str = SchemaField(
+ description="The description of the input.",
+ default="",
+ advanced=True,
+ )
placeholder_values: List[Any] = SchemaField(
- description="The placeholder values to be passed as input."
+ description="The placeholder values to be passed as input.",
+ default=[],
+ advanced=True,
)
limit_to_placeholder_values: bool = SchemaField(
description="Whether to limit the selection to placeholder values.",
default=False,
+ advanced=True,
)
class Output(BlockSchema):
@@ -164,8 +175,8 @@ class InputBlock(Block):
super().__init__(
id="c0a8e994-ebf1-4a9c-a4d8-89d09c86741b",
description="This block is used to provide input to the graph.",
- input_schema=InputBlock.Input,
- output_schema=InputBlock.Output,
+ input_schema=AgentInputBlock.Input,
+ output_schema=AgentInputBlock.Output,
test_input=[
{
"value": "Hello, World!",
@@ -194,7 +205,7 @@ class InputBlock(Block):
yield "result", input_data.value
-class OutputBlock(Block):
+class AgentOutputBlock(Block):
"""
Records the output of the graph for users to see.
@@ -215,13 +226,17 @@ class OutputBlock(Block):
"""
class Input(BlockSchema):
- recorded_value: Any = SchemaField(
- description="The value to be recorded as output."
- )
+ value: Any = SchemaField(description="The value to be recorded as output.")
name: str = SchemaField(description="The name of the output.")
- description: str = SchemaField(description="The description of the output.")
- fmt_string: str = SchemaField(
- description="The format string to be used to format the recorded_value."
+ description: str = SchemaField(
+ description="The description of the output.",
+ default="",
+ advanced=True,
+ )
+ format: str = SchemaField(
+ description="The format string to be used to format the recorded_value.",
+ default="",
+ advanced=True,
)
class Output(BlockSchema):
@@ -238,31 +253,31 @@ class OutputBlock(Block):
"This block is key for capturing and presenting final results or "
"important intermediate outputs of the graph execution."
),
- input_schema=OutputBlock.Input,
- output_schema=OutputBlock.Output,
+ input_schema=AgentOutputBlock.Input,
+ output_schema=AgentOutputBlock.Output,
test_input=[
{
- "recorded_value": "Hello, World!",
+ "value": "Hello, World!",
"name": "output_1",
"description": "This is a test output.",
- "fmt_string": "{value}",
+ "format": "{{ output_1 }}!!",
},
{
- "recorded_value": 42,
+ "value": "42",
"name": "output_2",
"description": "This is another test output.",
- "fmt_string": "{value}",
+ "format": "{{ output_2 }}",
},
{
- "recorded_value": MockObject(value="!!", key="key"),
+ "value": MockObject(value="!!", key="key"),
"name": "output_3",
"description": "This is a test output with a mock object.",
- "fmt_string": "{value}",
+ "format": "{{ output_3 }}",
},
],
test_output=[
- ("output", "Hello, World!"),
- ("output", 42),
+ ("output", "Hello, World!!!"),
+ ("output", "42"),
("output", MockObject(value="!!", key="key")),
],
categories={BlockCategory.OUTPUT, BlockCategory.BASIC},
@@ -274,13 +289,15 @@ class OutputBlock(Block):
Attempts to format the recorded_value using the fmt_string if provided.
If formatting fails or no fmt_string is given, returns the original recorded_value.
"""
- if input_data.fmt_string:
+ if input_data.format:
try:
- yield "output", input_data.fmt_string.format(input_data.recorded_value)
- except Exception:
- yield "output", input_data.recorded_value
+ fmt = re.sub(r"(?<!{){[ a-zA-Z0-9_]+}", r"{\g<0>}", input_data.format)
+ template = jinja.from_string(fmt)
+ yield "output", template.render({input_data.name: input_data.value})
+ except Exception as e:
+ yield "output", f"Error: {e}, {input_data.value}"
else:
- yield "output", input_data.recorded_value
+ yield "output", input_data.value
class AddToDictionaryBlock(Block):
@@ -422,7 +439,8 @@ class NoteBlock(Block):
class Input(BlockSchema):
text: str = SchemaField(description="The text to display in the sticky note.")
- class Output(BlockSchema): ...
+ class Output(BlockSchema):
+ output: str = SchemaField(description="The text to display in the sticky note.")
def __init__(self):
super().__init__(
@@ -432,8 +450,11 @@ class NoteBlock(Block):
input_schema=NoteBlock.Input,
output_schema=NoteBlock.Output,
test_input={"text": "Hello, World!"},
- test_output=None,
+ test_output=[
+ ("output", "Hello, World!"),
+ ],
ui_type=BlockUIType.NOTE,
)
- def run(self, input_data: Input) -> BlockOutput: ...
+ def run(self, input_data: Input) -> BlockOutput:
+ yield "output", input_data.text
diff --git a/rnd/autogpt_server/autogpt_server/blocks/llm.py b/rnd/autogpt_server/autogpt_server/blocks/llm.py
index edfc8f7064..81574f89f8 100644
--- a/rnd/autogpt_server/autogpt_server/blocks/llm.py
+++ b/rnd/autogpt_server/autogpt_server/blocks/llm.py
@@ -438,7 +438,7 @@ class Message(BlockSchema):
class AIConversationBlock(Block):
class Input(BlockSchema):
messages: List[Message] = SchemaField(
- description="List of messages in the conversation.", min_items=1
+ description="List of messages in the conversation.", min_length=1
)
model: LlmModel = SchemaField(
default=LlmModel.GPT4_TURBO,
diff --git a/rnd/autogpt_server/autogpt_server/data/graph.py b/rnd/autogpt_server/autogpt_server/data/graph.py
index 9f9da51fab..984e051920 100644
--- a/rnd/autogpt_server/autogpt_server/data/graph.py
+++ b/rnd/autogpt_server/autogpt_server/data/graph.py
@@ -9,7 +9,7 @@ from prisma.models import AgentGraph, AgentNode, AgentNodeLink
from pydantic import BaseModel, PrivateAttr
from pydantic_core import PydanticUndefinedType
-from autogpt_server.blocks.basic import InputBlock, OutputBlock
+from autogpt_server.blocks.basic import AgentInputBlock, AgentOutputBlock
from autogpt_server.data.block import BlockInput, get_block, get_blocks
from autogpt_server.data.db import BaseDbModel, transaction
from autogpt_server.data.user import DEFAULT_USER_ID
@@ -106,7 +106,9 @@ class Graph(GraphMeta):
def starting_nodes(self) -> list[Node]:
outbound_nodes = {link.sink_id for link in self.links}
input_nodes = {
- v.id for v in self.nodes if isinstance(get_block(v.block_id), InputBlock)
+ v.id
+ for v in self.nodes
+ if isinstance(get_block(v.block_id), AgentInputBlock)
}
return [
node
@@ -116,7 +118,9 @@ class Graph(GraphMeta):
@property
def ending_nodes(self) -> list[Node]:
- return [v for v in self.nodes if isinstance(get_block(v.block_id), OutputBlock)]
+ return [
+ v for v in self.nodes if isinstance(get_block(v.block_id), AgentOutputBlock)
+ ]
@property
def subgraph_map(self) -> dict[str, str]:
@@ -179,7 +183,9 @@ class Graph(GraphMeta):
+ [sanitize(link.sink_name) for link in node.input_links]
)
for name in block.input_schema.get_required_fields():
- if name not in provided_inputs and not isinstance(block, InputBlock):
+ if name not in provided_inputs and not isinstance(
+ block, AgentInputBlock
+ ):
raise ValueError(
f"Node {block.name} #{node.id} required input missing: `{name}`"
)
@@ -193,7 +199,7 @@ class Graph(GraphMeta):
def is_input_output_block(nid: str) -> bool:
bid = node_map[nid].block_id
b = get_block(bid)
- return isinstance(b, InputBlock) or isinstance(b, OutputBlock)
+ return isinstance(b, AgentInputBlock) or isinstance(b, AgentOutputBlock)
# subgraphs: all nodes in subgraph must be present in the graph.
for subgraph_id, node_ids in self.subgraphs.items():
diff --git a/rnd/autogpt_server/autogpt_server/executor/manager.py b/rnd/autogpt_server/autogpt_server/executor/manager.py
index 42ca2be57b..865ee2d9e3 100644
--- a/rnd/autogpt_server/autogpt_server/executor/manager.py
+++ b/rnd/autogpt_server/autogpt_server/executor/manager.py
@@ -14,7 +14,7 @@ from typing import TYPE_CHECKING, Any, Coroutine, Generator, TypeVar
if TYPE_CHECKING:
from autogpt_server.server.rest_api import AgentServer
-from autogpt_server.blocks.basic import InputBlock
+from autogpt_server.blocks.basic import AgentInputBlock
from autogpt_server.data import db
from autogpt_server.data.block import Block, BlockData, BlockInput, get_block
from autogpt_server.data.execution import (
@@ -699,7 +699,7 @@ class ExecutionManager(AppService):
nodes_input = []
for node in graph.starting_nodes:
input_data = {}
- if isinstance(get_block(node.block_id), InputBlock):
+ if isinstance(get_block(node.block_id), AgentInputBlock):
name = node.input_default.get("name")
if name and name in data:
input_data = {"value": data[name]}
diff --git a/rnd/autogpt_server/autogpt_server/usecases/sample.py b/rnd/autogpt_server/autogpt_server/usecases/sample.py
index 6935e3fbc2..49f0e4f853 100644
--- a/rnd/autogpt_server/autogpt_server/usecases/sample.py
+++ b/rnd/autogpt_server/autogpt_server/usecases/sample.py
@@ -1,6 +1,6 @@
from prisma.models import User
-from autogpt_server.blocks.basic import InputBlock, PrintToConsoleBlock
+from autogpt_server.blocks.basic import AgentInputBlock, PrintToConsoleBlock
from autogpt_server.blocks.text import FillTextTemplateBlock
from autogpt_server.data import graph
from autogpt_server.data.graph import create_graph
@@ -28,22 +28,12 @@ def create_test_graph() -> graph.Graph:
"""
nodes = [
graph.Node(
- block_id=InputBlock().id,
- input_default={
- "name": "input_1",
- "description": "First input value",
- "placeholder_values": [],
- "limit_to_placeholder_values": False,
- },
+ block_id=AgentInputBlock().id,
+ input_default={"name": "input_1"},
),
graph.Node(
- block_id=InputBlock().id,
- input_default={
- "name": "input_2",
- "description": "Second input value",
- "placeholder_values": [],
- "limit_to_placeholder_values": False,
- },
+ block_id=AgentInputBlock().id,
+ input_default={"name": "input_2"},
),
graph.Node(
block_id=FillTextTemplateBlock().id,
diff --git a/rnd/autogpt_server/test/data/test_graph.py b/rnd/autogpt_server/test/data/test_graph.py
index 777f6b23a1..c103cc44e9 100644
--- a/rnd/autogpt_server/test/data/test_graph.py
+++ b/rnd/autogpt_server/test/data/test_graph.py
@@ -2,7 +2,7 @@ from uuid import UUID
import pytest
-from autogpt_server.blocks.basic import InputBlock, StoreValueBlock
+from autogpt_server.blocks.basic import AgentInputBlock, StoreValueBlock
from autogpt_server.data.graph import Graph, Link, Node
from autogpt_server.data.user import DEFAULT_USER_ID, create_default_user
from autogpt_server.server.model import CreateGraph
@@ -25,7 +25,7 @@ async def test_graph_creation(server: SpinTestServer):
await create_default_user("false")
value_block = StoreValueBlock().id
- input_block = InputBlock().id
+ input_block = AgentInputBlock().id
graph = Graph(
id="test_graph",
diff --git a/rnd/autogpt_server/test/executor/test_manager.py b/rnd/autogpt_server/test/executor/test_manager.py
index 40ba11c450..21618c94d8 100644
--- a/rnd/autogpt_server/test/executor/test_manager.py
+++ b/rnd/autogpt_server/test/executor/test_manager.py
@@ -36,23 +36,19 @@ async def assert_sample_graph_executions(
graph_exec_id: str,
):
executions = await agent_server.get_graph_run_node_execution_results(
- test_graph.id, graph_exec_id, test_user.id
+ test_graph.id,
+ graph_exec_id,
+ test_user.id,
)
output_list = [{"result": ["Hello"]}, {"result": ["World"]}]
input_list = [
{
"name": "input_1",
- "description": "First input value",
- "placeholder_values": [],
- "limit_to_placeholder_values": False,
"value": "Hello",
},
{
"name": "input_2",
- "description": "Second input value",
- "placeholder_values": [],
- "limit_to_placeholder_values": False,
"value": "World",
},
]
@@ -61,16 +57,24 @@ async def assert_sample_graph_executions(
exec = executions[0]
assert exec.status == execution.ExecutionStatus.COMPLETED
assert exec.graph_exec_id == graph_exec_id
- assert exec.output_data in output_list
- assert exec.input_data in input_list
+ assert (
+ exec.output_data in output_list
+ ), f"Output data: {exec.output_data} and {output_list}"
+ assert (
+ exec.input_data in input_list
+ ), f"Input data: {exec.input_data} and {input_list}"
assert exec.node_id in [test_graph.nodes[0].id, test_graph.nodes[1].id]
# Executing StoreValueBlock
exec = executions[1]
assert exec.status == execution.ExecutionStatus.COMPLETED
assert exec.graph_exec_id == graph_exec_id
- assert exec.output_data in output_list
- assert exec.input_data in input_list
+ assert (
+ exec.output_data in output_list
+ ), f"Output data: {exec.output_data} and {output_list}"
+ assert (
+ exec.input_data in input_list
+ ), f"Input data: {exec.input_data} and {input_list}"
assert exec.node_id in [test_graph.nodes[0].id, test_graph.nodes[1].id]
# Executing FillTextTemplateBlock