In this guide, we will walk through the process of creating custom nodes for Vellum Workflows using the Workflows SDK. Custom nodes allow you to extend the functionality of your Workflows by implementing specific logic tailored to your needs.
In this tutorial, we will create a simple workflow that:
UniversalBaseModelworkflow.pyThis file defines the main workflow. The workflow consists of a graph that connects a CustomNode (our data fetcher) to a SummarizeResultsNode. The Outputs class specifies the expected output of the workflow.
custom_node.pyIn custom_node.py we define a CustomNode that extends BaseNode. The run method fetches fake social media posts from an API and, depending on the include_user_details input, fetches user details from a separate API and returns the results. This node demonstrates how you can use the run method to define custom runtime logic based on the node’s inputs.
In types.py we define response types using UniversalBaseModel (which inherits from Pydantic) to achieve static type checking & type inference throughout our Workflow. We also use pydash to coerce our response types from camel case to snake case, to achieve consistency with the code conventions we prefer (and simultaneously, make our linter happy).
summarize_results_node.pyThis file defines a SummarizeResultsNode that extends InlinePromptNode. It uses GPT-4o-mini to summarize the posts data fetched by the CustomNode. The node is configured with prompt blocks that define how the input data should be processed.
To execute the workflow, create a script.py like the one below, and run it via python script.py. The workflow will fetch the social media posts, process them through the SummarizeResultsNode, and log the summary.
Output:
By following this guide, you have learned how to extend BaseNode to create custom nodes in Vellum Workflows. This approach allows you to tailor workflows to your specific requirements, integrating external data sources and processing them with advanced language models.