Welcome to the first chapter of the components project tutorial! We are going to start with a very exciting feature: building the tool that allows users to create new AI Agents.
The Use Case: Imagine you want to create a helper bot called "Chef Bot." To make Chef Bot work, you need to define many things:
The Problem: If we put all these settings on one giant form, it would look like a tax return documentβscary, confusing, and overwhelming!
The Solution: We use a Wizard.
Think of a Wizard like a friendly tour guide. Instead of asking you 20 questions at once, the guide asks, "First, what is the name?" followed by "Great! Now, what tools should it use?" This component, CreateAgentWizard.tsx, is the master blueprint for that tour.
Before we look at code, let's understand the pieces involved.
Imagine CreateAgentWizard is the manager of a sandwich shop.
Using this component is actually very simple because it is a self-contained "smart" component. It brings its own logic with it.
If you were building the page that lets users create agents, you would simply drop this component into your layout.
import React from 'react';
// We import the Wizard component
import CreateAgentWizard from './agents/new-agent-creation/CreateAgentWizard';
const CreatePage = () => {
// We simply place the Wizard in our page
return (
<div className="page-container">
<CreateAgentWizard />
</div>
);
};
What happens here?
By simply rendering <CreateAgentWizard />, the application starts the multi-step process. The user will immediately see the first step of the creation flow.
Now, let's look inside CreateAgentWizard.tsx to see how it organizes the assembly line.
When this component loads, it does two main things:
Here is a sequence diagram of how the Wizard interacts with the user and the internal logic:
Let's look at how the code is structured inside. We'll break it down into small pieces.
First, the component needs a list of all the stops on our tour. This is usually an array of objects, where each object represents a screen.
// Inside CreateAgentWizard.tsx
const steps = [
{ id: 'location', label: 'Location', component: <LocationStep /> },
{ id: 'method', label: 'Method', component: <MethodStep /> },
{ id: 'identity', label: 'Identity', component: <AgentIdentityStep /> },
{ id: 'tools', label: 'Tools', component: <ToolsStep /> },
// ... and so on for Model, Memory, etc.
];
Explanation: We create a list called steps. Each item has an id and the actual component (the React code) that should show up on the screen for that step.
Finally, the component returns the JSX (UI). It wraps the steps in the WizardProvider.
// The component output
return (
<WizardProvider steps={steps} initialStep={0}>
<div className="wizard-layout">
{/* Components here display the current step and buttons */}
<WizardStepDisplay />
<WizardNavigationButtons />
</div>
</WizardProvider>
);
Explanation:
<WizardProvider>: This is the "brain." We feed it the steps list we created above. It handles the logic of "Next," "Back," and saving data.<WizardStepDisplay />: This is a placeholder for the part of the code that asks the Provider, "Which component should I show right now?"<WizardNavigationButtons />: These are your "Next" and "Previous" buttons.WizardProvider to keep track of the form data (like the agent's name) so it doesn't get lost when you switch to the "Tools" screen.LocationStep or ColorStep) into one cohesive flow.
In this chapter, we explored agents/new-agent-creation/CreateAgentWizard.tsx.
We learned that:
You now understand the high-level entry point for creating agents!
Generated by Code IQ