Building an Agent

Now that you have seems some of our nodes, and the general anatomy of an agent. Let's attempt to build an Agent.

First define the following fields:

id: "movie-agent",
name: "Movie Script agent",
description: "An Agent that generates a movie script",
variables: {},
fields: [],
workflow: []

id
the unique identifier for your agent. This will be used by our api system to execute and run your agent from the database. Spaces and special characters are not allowed

name
the display name for your agent.

description
the long descriptions for your agent.

variables
the key-value pair runtime memory and context for your agent

fields
the playground input form descriptor for the agent.

workflow
the main nodes and procedures of your agents


Variables

The variables are key-value pair dictionary that is used as a context window for executing your agent. Its data will be read and used to substitude important fields for all the chain nodes when the workflow prompt chain is being executed.

Its data is available globally across all nodes in the chain.

variables: {
    replicateAPIKey: "apikey",
    genre: ""
}

Nodes and workflow

Let's declare your first prompt node. In a prompt node, the following fields are declared:

workflow: [
    {
        "type": "prompt",
        "name": "Sypnosis",

        "system": "You are a story development expert creating a synopsis for a {genre} film according to the user's request",
        "user": "{prompt}",
        "apikey": "{replicateAPI}",
        "llm": "replicate",
        "model": "google-deepmind/gemma-3-27b-it",
        "temperature": 1,
        "maxTokens": 2000,
        "output": "context",
    },
]

Notice how the system and user uses a special {key} syntax. This syntax is used to allow substitution of values from the shared variables object when the node is being executed.

As an example, when running your agent, if you set the variables.genre:

variables: {
    genre: "scifi"
}

The engine will substitute it into the system prompt, or whichever field that has the templating syntax:

// system becomes:
You are a story development expert creating a synopsis for a scifi film according to the user's request

Notice settings like temperature, maxTokens, are numbers type. and thus it cannot be used for substitution.

Each node also denotes an output. This is used to store the output (ai response) to the variables key-value context storage. If the key doesnt exist, a new one will be created instead and its data stored accordingly.


In a subsequent node, we can use the sypnosis generated from the previous node and expand on it, since the previous node uses context key to store the data,

We can reference it + the original user's prompt

Node 2: PromptNode

systemPrompt: "You are a helpful assistant for writing the character development for the movie sypnosis and user's request"
userPrompt: "Movie sypnosis {context} \n\nRequests: {prompt}"

output: "summary"

Here, we generate the list of characters, but, we are also passing along the generated summary from the previous stage

I think 2 prompt nodes seems like a great start for now. Let's add a return node to specify which fields within our context to return as part of the agent's output body:

workflow: [
    ...
    {
        "type": "return",
        "name": "Returning summary",

        "output": ["summary"],
    },
]

With these fields, your basic agent is completed


Adding dynamic forms to agents

Have you notice the default agents available in Engine is capable of generating a dynamic form for react? This dynamic form is actually part of our ReactJS sdk for running agents.

To make your own agents capable of displaying a dynamically generated Input form, you'll have to declare the Fields property for your agent