I create human-centered digital products and engaging graphic designs that strengthen brand image.
import { z } from "zod";
import { Agent, AgentInputItem, Runner } from "@openai/agents";
const BriefAgentSchema = z.object({ classification: z.enum(["project_ux/ui", "project_dev"]) });
const briefAgent = new Agent({
name: "Brief Agent",
instructions: `You are a helpful assistant who helps gather information from my clients regarding the project to be implemented.
Projects primarily involve UX/UI Design and DEV implementation.
Guide the client through a quick brief, which will help us determine the project's scope and details.
For example, the website structure or the number of application screens, as well as the content of individual subpages/screens and functionalities.
Additionally, contextualize information that may be crucial to project implementation and pricing options.`,
model: "gpt-5",
outputType: BriefAgentSchema,
modelSettings: {
reasoning: {
effort: "low"
},
store: true
}
});
const uxUiAgent = new Agent({
name: "UX/UI Agent",
instructions: "You are a Lead UX/UI Designer. You gather information from potential clients regarding UX/UI collaboration, which will help prepare a project proposal. It's important that the information collected allows you to assess the amount of work and the overall goal of the project.",
model: "gpt-5",
modelSettings: {
reasoning: {
effort: "low"
},
store: true
}
});
const devAgent = new Agent({
name: "Dev Agent",
instructions: "You're a DEV specialist. You gather information from clients regarding development projects to determine the project to be implemented and its details. You guide the client through the brief, using the information gathered to develop a proposal for the client.",
model: "gpt-5",
modelSettings: {
reasoning: {
effort: "low"
},
store: true
}
});
type WorkflowInput = { input_as_text: string };
// Main code entrypoint
export const runWorkflow = async (workflow: WorkflowInput) => {
const conversationHistory: AgentInputItem[] = [
{
role: "user",
content: [
{
type: "input_text",
text: workflow.input_as_text
}
]
}
];
const runner = new Runner({
traceMetadata: {
__trace_source__: "agent-builder",
workflow_id: "wf_68e4104fa4d481909f40426b373687980ec5325f70795d7d"
}
});
const briefAgentResultTemp = await runner.run(
briefAgent,
[
...conversationHistory
]
);
conversationHistory.push(...briefAgentResultTemp.newItems.map((item) => item.rawItem));
if (!briefAgentResultTemp.finalOutput) {
throw new Error("Agent result is undefined");
}
const briefAgentResult = {
output_text: JSON.stringify(briefAgentResultTemp.finalOutput),
output_parsed: briefAgentResultTemp.finalOutput
};
if (briefAgentResult.output_parsed.classification == "project_ux/ui") {
const uxUiAgentResultTemp = await runner.run(
uxUiAgent,
[
...conversationHistory
]
);
conversationHistory.push(...uxUiAgentResultTemp.newItems.map((item) => item.rawItem));
if (!uxUiAgentResultTemp.finalOutput) {
throw new Error("Agent result is undefined");
}
const uxUiAgentResult = {
output_text: uxUiAgentResultTemp.finalOutput ?? ""
};
} else {
const devAgentResultTemp = await runner.run(
devAgent,
[
...conversationHistory
]
);
conversationHistory.push(...devAgentResultTemp.newItems.map((item) => item.rawItem));
if (!devAgentResultTemp.finalOutput) {
throw new Error("Agent result is undefined");
}
const devAgentResult = {
output_text: devAgentResultTemp.finalOutput ?? ""
};
}
}