Make an agent: pick its face, name it, or start from a suggested job.
Suggestions
import{Command,UiSchema}from"@effect/ui"import{Html}from"@effect/ui/html"import*as stylex from"@stylexjs/stylex"import{Effect,Schema}from"effect"import{ accepted,Outcome, pending, refused }from"./ui/uicontext/components/domain/Outcome.ts"import{AgentCreate}from"./ui/uicontext/components/kit/AgentCreate.ts"import{Persona}from"./ui/uicontext/components/kit/Persona.ts"import{ sx }from"./ui/uicontext/components/Sx.ts"import{ color, font }from"./ui/uicontext/components/tokens.stylex.ts"constMessage=UiSchema.TaggedEnum({SubmittedAgent:{name:Schema.String,persona:Persona,job:Schema.optional(Schema.String)},CompletedCreate:{name:Schema.String,taken:Schema.Boolean},})// Stands in for the server making the agent: a moment, then yes, or no when the name is taken.constCreate=Command.make("CreateSampleAgent",{args:{name:Schema.String}},({ name })=>Effect.sleep("600 millis").pipe(Effect.as(Message.CompletedCreate({ name,taken: name.toLowerCase()==="inbox"}))))const styles = stylex.create({made:{margin:0,color: color.muted,fontSize: font.sm,textAlign:"center"}})exportconstMakeAnAgent=Html.component({name:"MakeAnAgent",model:Schema.Struct({outcome:Schema.NullOr(Outcome),made:Schema.NullOr(Schema.String)}),message:Message,}).make({init:()=>({outcome:null,made:null}),update:{SubmittedAgent:($,{ name })=> $.evolve({outcome:pending("create")}).run(Create.make({ name })),CompletedCreate:($,{ name, taken })=> taken? $.evolve({outcome:refused("create",`You already have an agent called ${name}.`)}): $.evolve({outcome:accepted("create"),made: name }),},view:(h, model)=> h.div.children( model.made!==null&& h.p.attrs({role:"status",...sx(styles.made)}).children(`${model.made} is ready. It opens in its conversation.`),AgentCreate(h,{props:{agentId:"agent-create-demo",outcome: model.outcome,suggestions:[{id:"night-shift",name:"Night Shift",job:"Works overnight and preps your morning digest.",persona:{shape:"hexagon",color:"orange"}},{id:"inbox-triage",name:"Inbox Triage",job:"Sorts your email and drafts replies in your voice.",persona:{shape:"cloud",color:"pink"}},],},onEmit:{Submitted:({ name, persona, job })=>Message.SubmittedAgent({ name, persona,...(job ===undefined?{}:{ job })})},}),),})
constMessage=UiSchema.TaggedEnum({SubmittedAgent:{name:Schema.String,persona:Persona,job:Schema.optional(Schema.String)}})// the pane keeps its draft; you make the agent, then pass back how it went as `outcome`exportconstNewAgent=(h:Html.H<typeofMessage.Type>,outcome:Outcome|null)=>AgentCreate(h,{props:{suggestions:[{id:"night-shift",name:"Night Shift",job:"Works overnight and preps your morning digest.",persona:{shape:"hexagon",color:"orange"}}], outcome,},onEmit:{Submitted:({ name, persona, job })=>Message.SubmittedAgent({ name, persona,...(job ===undefined?{}:{ job })})},})
API reference
Props
AgentCreate props
Name
Type
Description
suggestionsrequired
AgentSuggestion[]
—
persona
Persona
The face it starts with
outcome
Outcome | null
—
agentId
string
—
Events
AgentCreate events
Event
Payload
Description
Submitted
{ name: string; persona: Persona; job?: string }
—
Agent actions
What agents can do with AgentCreate
Action
Description
RequestedCreateasks first
Create an agent with a name, optionally a color and shape, and its job as its first message