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.
feat(rnd): Add staticOutput field on block API (#7802)
Zamil Majdy526364297c9d
diff --git a/rnd/autogpt_server/autogpt_server/blocks/basic.py b/rnd/autogpt_server/autogpt_server/blocks/basic.pyindex 412b3063b1..760fcb47ce 100644--- a/rnd/autogpt_server/autogpt_server/blocks/basic.py+++ b/rnd/autogpt_server/autogpt_server/blocks/basic.py@@ -12,20 +12,7 @@ class ValueBlock(Block):"""This block allows you to provide a constant value as a block, in a stateless manner.The common use-case is simply pass the `input` data, it will `output` the same data.- But this will not retain the state, once it is executed, the output is consumed.-- To retain the state, you can feed the `output` to the `data` input, so that the data- is retained in the block for the next execution. You can then trigger the block by- feeding the `input` pin with any data, and the block will produce value of `data`.-- Ex:- <constant_data> <any_trigger>- || ||- =====> `data` `input`- || \\ //- || ValueBlock- || ||- ========= `output`+ The block output will be static, the output can be consumed multiple times."""class Input(BlockSchema):@@ -46,9 +33,7 @@ class ValueBlock(Block):super().__init__(id="1ff065e9-88e8-4358-9d82-8dc91f622ba9",description="This block forwards the `input` pin to `output` pin. "- "If the `data` is provided, it will prioritize forwarding `data` "- "over `input`. By connecting the `output` pin to `data` pin, "- "you can retain a constant value for the next executions.",+ "This block output will be static, the output can be consumed many times.",categories={BlockCategory.BASIC},input_schema=ValueBlock.Input,output_schema=ValueBlock.Output,@@ -60,6 +45,7 @@ class ValueBlock(Block):("output", "Hello, World!"), # No data provided, so trigger is returned("output", "Existing Data"), # Data is provided, so data is returned.],+ static_output=True,)def run(self, input_data: Input) -> BlockOutput:diff --git a/rnd/autogpt_server/autogpt_server/data/block.py b/rnd/autogpt_server/autogpt_server/data/block.pyindex 12f0113d02..38de9dd351 100644--- a/rnd/autogpt_server/autogpt_server/data/block.py+++ b/rnd/autogpt_server/autogpt_server/data/block.py@@ -127,6 +127,7 @@ class Block(ABC, Generic[BlockSchemaInputType, BlockSchemaOutputType]):test_output: BlockData | list[BlockData] | None = None,test_mock: dict[str, Any] | None = None,disabled: bool = False,+ static_output: bool = False,):"""Initialize the block with the given schema.@@ -143,6 +144,7 @@ class Block(ABC, Generic[BlockSchemaInputType, BlockSchemaOutputType]):test_output: The list or single expected output if the test_input is run.test_mock: function names on the block implementation to mock on test run.disabled: If the block is disabled, it will not be available for execution.+ static_output: Whether the output links of the block are static by default."""self.id = idself.input_schema = input_schema@@ -154,6 +156,7 @@ class Block(ABC, Generic[BlockSchemaInputType, BlockSchemaOutputType]):self.categories = categories or set()self.contributors = contributors or set()self.disabled = disabled+ self.static_output = static_output@abstractmethoddef run(self, input_data: BlockSchemaInputType) -> BlockOutput:@@ -180,7 +183,10 @@ class Block(ABC, Generic[BlockSchemaInputType, BlockSchemaOutputType]):"outputSchema": self.output_schema.jsonschema(),"description": self.description,"categories": [category.dict() for category in self.categories],- "contributors": [contributor.dict() for contributor in self.contributors],+ "contributors": [+ contributor.model_dump() for contributor in self.contributors+ ],+ "staticOutput": self.static_output,}def execute(self, input_data: BlockInput) -> BlockOutput:diff --git a/rnd/autogpt_server/autogpt_server/data/graph.py b/rnd/autogpt_server/autogpt_server/data/graph.pyindex f3d6a90c82..060793a2e0 100644--- a/rnd/autogpt_server/autogpt_server/data/graph.py+++ b/rnd/autogpt_server/autogpt_server/data/graph.py@@ -7,7 +7,7 @@ import prisma.typesfrom prisma.models import AgentGraph, AgentNode, AgentNodeLinkfrom pydantic import PrivateAttr-from autogpt_server.blocks.basic import InputBlock, OutputBlock, ValueBlock+from autogpt_server.blocks.basic import InputBlock, OutputBlockfrom autogpt_server.data.block import BlockInput, get_block, get_blocksfrom autogpt_server.data.db import BaseDbModel, transactionfrom autogpt_server.data.user import DEFAULT_USER_ID@@ -175,10 +175,10 @@ class Graph(GraphMeta):)node_map = {v.id: v for v in self.nodes}- def is_value_block(nid: str) -> bool:+ def is_static_output_block(nid: str) -> bool:bid = node_map[nid].block_idb = get_block(bid)- return isinstance(b, ValueBlock)+ return b.static_output if b else Falsedef is_input_output_block(nid: str) -> bool:bid = node_map[nid].block_id@@ -227,7 +227,7 @@ class Graph(GraphMeta):):raise ValueError(f"{suffix}, Connecting nodes from different subgraph.")- if is_value_block(link.source_id):+ if is_static_output_block(link.source_id):link.is_static = True # Each value block output should be static.# TODO: Add type compatibility check here.