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.
chore(platform):Refactor GraphExecution naming clash and remove unused Graph Execution functions (#8939)
Zamil Majdy6490b4e188dc
diff --git a/autogpt_platform/backend/backend/data/execution.py b/autogpt_platform/backend/backend/data/execution.pyindex dc28b48837..4775d94553 100644--- a/autogpt_platform/backend/backend/data/execution.py+++ b/autogpt_platform/backend/backend/data/execution.py@@ -9,7 +9,6 @@ from prisma.models import (AgentNodeExecution,AgentNodeExecutionInputOutput,)-from prisma.types import AgentGraphExecutionWhereInputfrom pydantic import BaseModelfrom backend.data.block import BlockData, BlockInput, CompletedBlockOutput@@ -19,14 +18,14 @@ from backend.util import json, mockfrom backend.util.settings import Config-class GraphExecution(BaseModel):+class GraphExecutionEntry(BaseModel):user_id: strgraph_exec_id: strgraph_id: str- start_node_execs: list["NodeExecution"]+ start_node_execs: list["NodeExecutionEntry"]-class NodeExecution(BaseModel):+class NodeExecutionEntry(BaseModel):user_id: strgraph_exec_id: strgraph_id: str@@ -325,34 +324,6 @@ async def update_execution_status(return ExecutionResult.from_db(res)-async def get_graph_execution(- graph_exec_id: str, user_id: str-) -> AgentGraphExecution | None:- """- Retrieve a specific graph execution by its ID.-- Args:- graph_exec_id (str): The ID of the graph execution to retrieve.- user_id (str): The ID of the user to whom the graph (execution) belongs.-- Returns:- AgentGraphExecution | None: The graph execution if found, None otherwise.- """- execution = await AgentGraphExecution.prisma().find_first(- where={"id": graph_exec_id, "userId": user_id},- include=GRAPH_EXECUTION_INCLUDE,- )- return execution---async def list_executions(graph_id: str, graph_version: int | None = None) -> list[str]:- where: AgentGraphExecutionWhereInput = {"agentGraphId": graph_id}- if graph_version is not None:- where["agentGraphVersion"] = graph_version- executions = await AgentGraphExecution.prisma().find_many(where=where)- return [execution.id for execution in executions]--async def get_execution_results(graph_exec_id: str) -> list[ExecutionResult]:executions = await AgentNodeExecution.prisma().find_many(where={"agentGraphExecutionId": graph_exec_id},diff --git a/autogpt_platform/backend/backend/data/graph.py b/autogpt_platform/backend/backend/data/graph.pyindex ad53f0b9d2..cbf65ae268 100644--- a/autogpt_platform/backend/backend/data/graph.py+++ b/autogpt_platform/backend/backend/data/graph.py@@ -7,7 +7,7 @@ from typing import Any, Literal, Optional, Typeimport prismafrom prisma.models import AgentGraph, AgentGraphExecution, AgentNode, AgentNodeLink-from prisma.types import AgentGraphExecutionWhereInput, AgentGraphWhereInput+from prisma.types import AgentGraphWhereInputfrom pydantic.fields import computed_fieldfrom backend.blocks.agent import AgentExecutorBlock@@ -143,7 +143,6 @@ class Graph(BaseDbModel):is_template: bool = Falsename: strdescription: str- executions: list[GraphExecution] = []nodes: list[Node] = []links: list[Link] = []@@ -329,11 +328,6 @@ class GraphModel(Graph):@staticmethoddef from_db(graph: AgentGraph, hide_credentials: bool = False):- executions = [- GraphExecution.from_db(execution)- for execution in graph.AgentGraphExecution or []- ]-return GraphModel(id=graph.id,user_id=graph.userId,@@ -342,7 +336,6 @@ class GraphModel(Graph):is_template=graph.isTemplate,name=graph.name or "",description=graph.description or "",- executions=executions,nodes=[GraphModel._process_node(node, hide_credentials)for node in graph.AgentNodes or []@@ -412,7 +405,6 @@ async def set_node_webhook(node_id: str, webhook_id: str | None) -> NodeModel:async def get_graphs(user_id: str,- include_executions: bool = False,filter_by: Literal["active", "template"] | None = "active",) -> list[GraphModel]:"""@@ -420,7 +412,6 @@ async def get_graphs(Default behaviour is to get all currently active graphs.Args:- include_executions: Whether to include executions in the graph metadata.filter_by: An optional filter to either select templates or active graphs.user_id: The ID of the user that owns the graph.@@ -434,30 +425,31 @@ async def get_graphs(elif filter_by == "template":where_clause["isTemplate"] = True- graph_include = AGENT_GRAPH_INCLUDE- graph_include["AgentGraphExecution"] = include_executions-graphs = await AgentGraph.prisma().find_many(where=where_clause,distinct=["id"],order={"version": "desc"},- include=graph_include,+ include=AGENT_GRAPH_INCLUDE,)return [GraphModel.from_db(graph) for graph in graphs]async def get_executions(user_id: str) -> list[GraphExecution]:- where_clause: AgentGraphExecutionWhereInput = {"userId": user_id}-executions = await AgentGraphExecution.prisma().find_many(- where=where_clause,+ where={"userId": user_id},order={"createdAt": "desc"},)-return [GraphExecution.from_db(execution) for execution in executions]+async def get_execution(user_id: str, execution_id: str) -> GraphExecution | None:+ execution = await AgentGraphExecution.prisma().find_first(+ where={"id": execution_id, "userId": user_id}+ )+ return GraphExecution.from_db(execution) if execution else None++async def get_graph(graph_id: str,version: int | None = None,diff --git a/autogpt_platform/backend/backend/executor/manager.py b/autogpt_platform/backend/backend/executor/manager.pyindex c6db354049..0d6ed816f1 100644--- a/autogpt_platform/backend/backend/executor/manager.py+++ b/autogpt_platform/backend/backend/executor/manager.py@@ -25,8 +25,8 @@ from backend.data.execution import (ExecutionQueue,ExecutionResult,ExecutionStatus,- GraphExecution,- NodeExecution,+ GraphExecutionEntry,+ NodeExecutionEntry,merge_execution_input,parse_execution_output,)@@ -96,13 +96,13 @@ class LogMetadata:T = TypeVar("T")-ExecutionStream = Generator[NodeExecution, None, None]+ExecutionStream = Generator[NodeExecutionEntry, None, None]def execute_node(db_client: "DatabaseManager",creds_manager: IntegrationCredentialsManager,- data: NodeExecution,+ data: NodeExecutionEntry,execution_stats: dict[str, Any] | None = None,) -> ExecutionStream:"""@@ -252,15 +252,15 @@ def _enqueue_next_nodes(graph_exec_id: str,graph_id: str,log_metadata: LogMetadata,-) -> list[NodeExecution]:+) -> list[NodeExecutionEntry]:def add_enqueued_execution(node_exec_id: str, node_id: str, data: BlockInput- ) -> NodeExecution:+ ) -> NodeExecutionEntry:exec_update = db_client.update_execution_status(node_exec_id, ExecutionStatus.QUEUED, data)db_client.send_execution_update(exec_update)- return NodeExecution(+ return NodeExecutionEntry(user_id=user_id,graph_exec_id=graph_exec_id,graph_id=graph_id,@@ -269,7 +269,7 @@ def _enqueue_next_nodes(data=data,)- def register_next_executions(node_link: Link) -> list[NodeExecution]:+ def register_next_executions(node_link: Link) -> list[NodeExecutionEntry]:enqueued_executions = []next_output_name = node_link.source_namenext_input_name = node_link.sink_name@@ -501,8 +501,8 @@ class Executor:@error_loggeddef on_node_execution(cls,- q: ExecutionQueue[NodeExecution],- node_exec: NodeExecution,+ q: ExecutionQueue[NodeExecutionEntry],+ node_exec: NodeExecutionEntry,) -> dict[str, Any]:log_metadata = LogMetadata(user_id=node_exec.user_id,@@ -529,8 +529,8 @@ class Executor:@time_measureddef _on_node_execution(cls,- q: ExecutionQueue[NodeExecution],- node_exec: NodeExecution,+ q: ExecutionQueue[NodeExecutionEntry],+ node_exec: NodeExecutionEntry,log_metadata: LogMetadata,stats: dict[str, Any] | None = None,):@@ -580,7 +580,9 @@ class Executor:@classmethod@error_logged- def on_graph_execution(cls, graph_exec: GraphExecution, cancel: threading.Event):+ def on_graph_execution(+ cls, graph_exec: GraphExecutionEntry, cancel: threading.Event+ ):log_metadata = LogMetadata(user_id=graph_exec.user_id,graph_eid=graph_exec.graph_exec_id,@@ -605,7 +607,7 @@ class Executor:@time_measureddef _on_graph_execution(cls,- graph_exec: GraphExecution,+ graph_exec: GraphExecutionEntry,cancel: threading.Event,log_metadata: LogMetadata,) -> tuple[dict[str, Any], Exception | None]:@@ -636,13 +638,13 @@ class Executor:cancel_thread.start()try:- queue = ExecutionQueue[NodeExecution]()+ queue = ExecutionQueue[NodeExecutionEntry]()for node_exec in graph_exec.start_node_execs:queue.add(node_exec)running_executions: dict[str, AsyncResult] = {}- def make_exec_callback(exec_data: NodeExecution):+ def make_exec_callback(exec_data: NodeExecutionEntry):node_id = exec_data.node_iddef callback(result: object):@@ -717,7 +719,7 @@ class ExecutionManager(AppService):self.use_redis = Trueself.use_supabase = Trueself.pool_size = settings.config.num_graph_workers- self.queue = ExecutionQueue[GraphExecution]()+ self.queue = ExecutionQueue[GraphExecutionEntry]()self.active_graph_runs: dict[str, tuple[Future, threading.Event]] = {}@classmethod@@ -768,7 +770,7 @@ class ExecutionManager(AppService):data: BlockInput,user_id: str,graph_version: int | None = None,- ) -> GraphExecution:+ ) -> GraphExecutionEntry:graph: GraphModel | None = self.db_client.get_graph(graph_id=graph_id, user_id=user_id, version=graph_version)@@ -818,7 +820,7 @@ class ExecutionManager(AppService):starting_node_execs = []for node_exec in node_execs:starting_node_execs.append(- NodeExecution(+ NodeExecutionEntry(user_id=user_id,graph_exec_id=node_exec.graph_exec_id,graph_id=node_exec.graph_id,@@ -832,7 +834,7 @@ class ExecutionManager(AppService):)self.db_client.send_execution_update(exec_update)- graph_exec = GraphExecution(+ graph_exec = GraphExecutionEntry(user_id=user_id,graph_id=graph_id,graph_exec_id=graph_exec_id,diff --git a/autogpt_platform/backend/backend/server/rest_api.py b/autogpt_platform/backend/backend/server/rest_api.pyindex 0efe68862d..a45824418e 100644--- a/autogpt_platform/backend/backend/server/rest_api.py+++ b/autogpt_platform/backend/backend/server/rest_api.py@@ -117,17 +117,17 @@ class AgentServer(backend.util.service.AppProcess):async def test_create_graph(create_graph: backend.server.routers.v1.CreateGraph,user_id: str,- is_template=False,):return await backend.server.routers.v1.create_new_graph(create_graph, user_id)@staticmethod- async def test_get_graph_run_status(- graph_id: str, graph_exec_id: str, user_id: str- ):- return await backend.server.routers.v1.get_graph_run_status(- graph_id, graph_exec_id, user_id+ async def test_get_graph_run_status(graph_exec_id: str, user_id: str):+ execution = await backend.data.graph.get_execution(+ user_id=user_id, execution_id=graph_exec_id)+ if not execution:+ raise ValueError(f"Execution {graph_exec_id} not found")+ return execution.status@staticmethodasync def test_get_graph_run_node_execution_results(diff --git a/autogpt_platform/backend/backend/server/routers/v1.py b/autogpt_platform/backend/backend/server/routers/v1.pyindex 1139d59981..beb56e4c9c 100644--- a/autogpt_platform/backend/backend/server/routers/v1.py+++ b/autogpt_platform/backend/backend/server/routers/v1.py@@ -149,12 +149,9 @@ class DeleteGraphResponse(TypedDict):@v1_router.get(path="/graphs", tags=["graphs"], dependencies=[Depends(auth_middleware)])async def get_graphs(- user_id: Annotated[str, Depends(get_user_id)],- with_runs: bool = False,+ user_id: Annotated[str, Depends(get_user_id)]) -> Sequence[graph_db.Graph]:- return await graph_db.get_graphs(- include_executions=with_runs, filter_by="active", user_id=user_id- )+ return await graph_db.get_graphs(filter_by="active", user_id=user_id)@v1_router.get(@@ -386,7 +383,7 @@ def execute_graph(async def stop_graph_run(graph_exec_id: str, user_id: Annotated[str, Depends(get_user_id)]) -> Sequence[execution_db.ExecutionResult]:- if not await execution_db.get_graph_execution(graph_exec_id, user_id):+ if not await graph_db.get_execution(user_id=user_id, execution_id=graph_exec_id):raise HTTPException(404, detail=f"Agent execution #{graph_exec_id} not found")await asyncio.to_thread(@@ -408,26 +405,6 @@ async def get_executions(return await graph_db.get_executions(user_id=user_id)-@v1_router.get(- path="/graphs/{graph_id}/executions",- tags=["graphs"],- dependencies=[Depends(auth_middleware)],-)-async def list_graph_runs(- graph_id: str,- user_id: Annotated[str, Depends(get_user_id)],- graph_version: int | None = None,-) -> Sequence[str]:- graph = await graph_db.get_graph(graph_id, graph_version, user_id=user_id)- if not graph:- rev = "" if graph_version is None else f" v{graph_version}"- raise HTTPException(- status_code=404, detail=f"Agent #{graph_id}{rev} not found."- )-- return await execution_db.list_executions(graph_id, graph_version)--@v1_router.get(path="/graphs/{graph_id}/executions/{graph_exec_id}",tags=["graphs"],@@ -445,25 +422,6 @@ async def get_graph_run_node_execution_results(return await execution_db.get_execution_results(graph_exec_id)-# NOTE: This is used for testing-async def get_graph_run_status(- graph_id: str,- graph_exec_id: str,- user_id: Annotated[str, Depends(get_user_id)],-) -> execution_db.ExecutionStatus:- graph = await graph_db.get_graph(graph_id, user_id=user_id)- if not graph:- raise HTTPException(status_code=404, detail=f"Graph #{graph_id} not found.")-- execution = await execution_db.get_graph_execution(graph_exec_id, user_id)- if not execution:- raise HTTPException(- status_code=404, detail=f"Execution #{graph_exec_id} not found."- )-- return execution.executionStatus--############################################################################# Templates ################################################################################diff --git a/autogpt_platform/backend/backend/util/test.py b/autogpt_platform/backend/backend/util/test.pyindex 37ab2302da..5433fd9022 100644--- a/autogpt_platform/backend/backend/util/test.py+++ b/autogpt_platform/backend/backend/util/test.py@@ -60,9 +60,7 @@ async def wait_execution(timeout: int = 20,) -> Sequence[ExecutionResult]:async def is_execution_completed():- status = await AgentServer().test_get_graph_run_status(- graph_id, graph_exec_id, user_id- )+ status = await AgentServer().test_get_graph_run_status(graph_exec_id, user_id)log.info(f"Execution status: {status}")if status == ExecutionStatus.FAILED:log.info("Execution failed")diff --git a/autogpt_platform/backend/test/executor/test_scheduler.py b/autogpt_platform/backend/test/executor/test_scheduler.pyindex ed02ec1379..5e9fbc2bc9 100644--- a/autogpt_platform/backend/test/executor/test_scheduler.py+++ b/autogpt_platform/backend/test/executor/test_scheduler.py@@ -14,7 +14,6 @@ async def test_agent_schedule(server: SpinTestServer):test_user = await create_test_user()test_graph = await server.agent_server.test_create_graph(create_graph=CreateGraph(graph=create_test_graph()),- is_template=False,user_id=test_user.id,)diff --git a/autogpt_platform/frontend/src/app/page.tsx b/autogpt_platform/frontend/src/app/page.tsxindex 60cb18f9f3..33842a49fe 100644--- a/autogpt_platform/frontend/src/app/page.tsx+++ b/autogpt_platform/frontend/src/app/page.tsx@@ -87,9 +87,7 @@ const Monitor = () => {selectedFlow={selectedFlow}onSelectFlow={(f) => {setSelectedRun(null);- setSelectedFlow(- f.id == selectedFlow?.id ? null : (f as GraphMetaWithRuns),- );+ setSelectedFlow(f.id == selectedFlow?.id ? null : (f as GraphMeta));}}/><FlowRunsListdiff --git a/autogpt_platform/frontend/src/components/feature-flag/with-feature-flag.tsx b/autogpt_platform/frontend/src/components/feature-flag/with-feature-flag.tsxindex aecfef2f1b..79ed9d92ce 100644--- a/autogpt_platform/frontend/src/components/feature-flag/with-feature-flag.tsx+++ b/autogpt_platform/frontend/src/components/feature-flag/with-feature-flag.tsx@@ -18,13 +18,13 @@ export function withFeatureFlag<P extends object>(if (flags && flagKey in flags) {setHasFlagLoaded(true);}- }, [flags, flagKey]);+ }, [flags]);useEffect(() => {if (hasFlagLoaded && !flags[flagKey]) {router.push("/404");}- }, [hasFlagLoaded, flags, flagKey, router]);+ }, [hasFlagLoaded, flags, router]);// Show loading state until flags loadedif (!hasFlagLoaded) {diff --git a/autogpt_platform/frontend/src/lib/autogpt-server-api/baseClient.ts b/autogpt_platform/frontend/src/lib/autogpt-server-api/baseClient.tsindex dec9ef95ab..00ca4566bf 100644--- a/autogpt_platform/frontend/src/lib/autogpt-server-api/baseClient.ts+++ b/autogpt_platform/frontend/src/lib/autogpt-server-api/baseClient.ts@@ -12,7 +12,6 @@ import {GraphCreatable,GraphExecuteResponse,GraphMeta,- GraphMetaWithRuns,GraphUpdateable,NodeExecutionResult,OAuth2Credentials,@@ -69,11 +68,6 @@ export default class BaseAutoGPTServerAPI {return this._get(`/graphs`);}- async listGraphsWithRuns(): Promise<GraphMetaWithRuns[]> {- let graphs = await this._get(`/graphs?with_runs=true`);- return graphs.map(parseGraphMetaWithRuns);- }-getExecutions(): Promise<GraphExecution[]> {return this._get(`/executions`);}@@ -163,12 +157,6 @@ export default class BaseAutoGPTServerAPI {return this._request("POST", `/graphs/${id}/execute`, inputData);}- listGraphRunIDs(graphID: string, graphVersion?: number): Promise<string[]> {- const query =- graphVersion !== undefined ? `?graph_version=${graphVersion}` : "";- return this._get(`/graphs/${graphID}/executions` + query);- }-async getGraphExecutionInfo(graphID: string,runID: string,@@ -521,20 +509,3 @@ function parseNodeExecutionResultTimestamps(result: any): NodeExecutionResult {end_time: result.end_time ? new Date(result.end_time) : undefined,};}--function parseGraphMetaWithRuns(result: any): GraphMetaWithRuns {- return {- ...result,- executions: result.executions- ? result.executions.map(parseExecutionMetaTimestamps)- : [],- };-}--function parseExecutionMetaTimestamps(result: any): GraphExecution {- return {- ...result,- started_at: new Date(result.started_at).getTime(),- ended_at: result.ended_at ? new Date(result.ended_at).getTime() : undefined,- };-}diff --git a/autogpt_platform/frontend/src/lib/autogpt-server-api/types.ts b/autogpt_platform/frontend/src/lib/autogpt-server-api/types.tsindex 01c40d7805..cf9299be96 100644--- a/autogpt_platform/frontend/src/lib/autogpt-server-api/types.ts+++ b/autogpt_platform/frontend/src/lib/autogpt-server-api/types.ts@@ -200,7 +200,6 @@ export type GraphExecution = {graph_version: number;};-/* backend/data/graph.py:Graph = GraphMeta & GraphMetaWithRuns & Graph */export type GraphMeta = {id: string;version: number;@@ -212,10 +211,7 @@ export type GraphMeta = {output_schema: BlockIOObjectSubSchema;};-export type GraphMetaWithRuns = GraphMeta & {- executions: GraphExecution[];-};-+/* Mirror of backend/data/graph.py:Graph */export type Graph = GraphMeta & {nodes: Array<Node>;links: Array<Link>;