Client setup
The Inngest client is created once and re-used across the application. It includes therealtimeMiddleware to enable the publish helper inside function handlers.
inngest/client.ts
Function: code-agent
The function is triggered by the code-agent/codeAgent.run event and processes one project at a time.
inngest/functions.ts
Event payload
Concurrency
Theconcurrency configuration ensures that at most one run of code-agent executes for a given projectId at any time. Additional triggers for the same project queue behind the active run.
Function steps
Eachstep.run call is a durable checkpoint. If the function is interrupted, Inngest replays from the last completed step.
get-or-create-sandbox
Looks up the project’s stored
sandboxId. Reconnects to the existing E2B sandbox or creates a new forgeai-v1 sandbox and persists the ID to the database.get-prev-messages
Loads the 6 most recent messages for the project from the database and converts them to
@inngest/agent-kit Message objects. These seed the agent’s conversation history.get-prev-code-files
Fetches the file map from the most recent code fragment for this project. This gives the agent the current state of the codebase without reading every file from the sandbox.
build-agent-input
If an
imageUrl is present in the event payload, calls extractDesignSpecFromImage (GPT-4o) to produce a structured design spec and prepends it to the user’s message. Otherwise passes the message through unchanged.run network
Runs the
@inngest/agent-kit network. The coding agent iterates up to 20 times, calling sandbox tools until it emits a <task_summary> in its response.get-sandbox-url
Retrieves the public HTTPS URL for port 3000 on the E2B sandbox via
sandbox.getHost(3000).generate-metadata
Runs the naming agent (GPT-5.2) to generate a short project title and saves it to the project record in the database.
Real-time status updates
The function publishes status strings to a per-project Inngest Realtime channel throughout execution. The UI subscribes to this channel to show live progress.inngest/functions.ts
| Step | Status string |
|---|---|
terminal tool | "Installing packages..." |
createOrUpdateFiles tool | "Generating project files..." |
readFiles tool | "Reading project files..." |
unsplashImage tool | "Downloading images..." |
get-sandbox-url | "Generating sandbox url..." |
generate-metadata | "Generating project name..." |
save-to-db | "Saving to db..." |
| Function complete | "Demo is ready" |
Related pages
AI models
The agent network and models that run inside the Inngest function.
E2B sandbox
The isolated execution environment the function provisions and uses.