@@ -41,14 +41,17 @@ const Page = () => {
41
41
} ) ;
42
42
43
43
const [ agentInfoDisplay , setAgentInfoDisplay ] =
44
- useState < AgentName > ( 'Wikipedia' ) ;
44
+ useState < AgentName | false > ( false ) ;
45
+ const [ currentStep , setCurrentStep ] = useState ( 0 ) ;
45
46
46
47
// form submit handler
47
48
const handleSend = async ( e : FormEvent < HTMLFormElement > ) => {
48
49
e . preventDefault ( ) ;
49
50
let scrolledIntermediate = false ;
51
+ let intermediateLogged = false ;
50
52
51
53
try {
54
+ setCurrentStep ( 1 ) ;
52
55
setLoading ( true ) ;
53
56
setProgress ( null ) ;
54
57
setAgentStates ( {
@@ -90,6 +93,11 @@ const Page = () => {
90
93
91
94
if ( result . progress ) {
92
95
setLoading ( false ) ;
96
+ if ( result . progress === 'Call Agent Manager LLM' ) {
97
+ setCurrentStep ( intermediateLogged ? 3 : 2 ) ;
98
+ } else {
99
+ intermediateLogged = true ;
100
+ }
93
101
}
94
102
95
103
setProgress ( result . progress ) ;
@@ -122,6 +130,7 @@ const Page = () => {
122
130
}
123
131
124
132
if ( result . crossReferenceOutput ) {
133
+ setCurrentStep ( 5 ) ;
125
134
document
126
135
. getElementById ( 'cross-reference-output' )
127
136
?. scrollIntoView ( { behavior : 'smooth' } ) ;
@@ -160,6 +169,14 @@ const Page = () => {
160
169
}
161
170
} ;
162
171
172
+ const resolveStepStatus = ( stepNumber : number ) => {
173
+ return ( currentStep === stepNumber ? "loading" : currentStep > stepNumber ? "done" : "init" ) ;
174
+ }
175
+
176
+ const displayUsedResources = [ ...Object . entries ( agentStates ) ]
177
+ . filter ( ( [ key , value ] ) => value && key !== "Cross Reference" )
178
+ . map ( ( [ key ] ) => key )
179
+
163
180
return (
164
181
< main className = "h-screen" >
165
182
{ progress && (
@@ -171,17 +188,18 @@ const Page = () => {
171
188
< div className = "max-w-screen-sm px-8 pt-16 mx-auto pb-44" >
172
189
{ /* header */ }
173
190
< header >
174
- < div className = "mb-8" >
175
- < WorkflowIcon size = { 40 } />
176
- </ div >
177
-
178
- < h1 className = "text-2xl font-semibold text-balance" >
191
+ < h1 className = "text-2xl font-semibold text-balance mb-8" >
179
192
Cross Reference Agent
180
193
</ h1 >
181
- < h2 className = "text-lg text-balance opacity-60" >
182
- This is a simple example to demonstrate how to use Upstash Workflow
183
- Agents to cross-reference information from different sources.
184
- </ h2 >
194
+ < div className = "text-lg text-balance flex flex-row flex-wrap items-center gap-2" >
195
+ < span className = "text-zinc-500" >
196
+ This is a simple example to demonstrate how to use
197
+ < div className = "inline-block mx-1 align-text-bottom" >
198
+ < WorkflowIcon size = { 22 } />
199
+ </ div >
200
+ Upstash Workflow Agents to cross-reference information from different sources.
201
+ </ span >
202
+ </ div >
185
203
186
204
< div className = "flex flex-wrap items-center gap-2 mt-4" >
187
205
< a
@@ -233,8 +251,8 @@ const Page = () => {
233
251
{ /* step-by-step */ }
234
252
< Step className = "mt-16 md:mt-16" >
235
253
{ /* step-1 */ }
236
- < StepItem >
237
- < StepNumber order = { 1 } />
254
+ < StepItem status = { resolveStepStatus ( 1 ) } >
255
+ < StepNumber order = { 1 } status = { resolveStepStatus ( 1 ) } />
238
256
239
257
< StepTitle > Ask a Question</ StepTitle >
240
258
< StepDesc >
@@ -268,27 +286,36 @@ const Page = () => {
268
286
</ StepItem >
269
287
270
288
{ /* step-2 */ }
271
- < StepItem >
272
- < StepNumber order = { 2 } />
289
+ < StepItem status = { resolveStepStatus ( 2 ) } >
290
+ < StepNumber order = { 2 } status = { resolveStepStatus ( 2 ) } />
273
291
274
292
< StepTitle > View Answers From Various Resources</ StepTitle >
275
293
< StepDesc >
276
294
The cross-reference agent will orchestrate worker agents to get
277
295
answers from different resources.
278
296
</ StepDesc >
279
297
298
+ { currentStep > 1 && (
280
299
< StepContent >
281
300
< div className = "flex flex-col gap-4" >
301
+ { displayUsedResources . length > 0 &&
302
+ < span className = 'opacity-60' >
303
+ Your agent chose to use {
304
+ displayUsedResources
305
+ . join ( ', ' ) } to answer your question.
306
+ </ span >
307
+ }
282
308
< div className = "flex gap-4 w-full" >
283
309
< AgentBlock
284
310
name = "Wikipedia"
285
311
agentInfoDisplay = { agentInfoDisplay }
286
312
setAgentInfoDisplay = { setAgentInfoDisplay }
313
+ isDisabled = { agentStates [ 'Wikipedia' ] === false }
287
314
>
288
315
< Img
289
316
src = "/icons/wikipedia.png"
290
- width = { 68 }
291
- height = { 68 }
317
+ width = { 44 }
318
+ height = { 44 }
292
319
alt = "Wikipedia"
293
320
className = { agentStates [ 'Wikipedia' ] === false ? 'opacity-60' : 'opacity-100' }
294
321
/>
@@ -297,11 +324,12 @@ const Page = () => {
297
324
name = "WolframAlpha"
298
325
agentInfoDisplay = { agentInfoDisplay }
299
326
setAgentInfoDisplay = { setAgentInfoDisplay }
327
+ isDisabled = { agentStates [ 'WolframAlpha' ] === false }
300
328
>
301
329
< Img
302
330
src = "/icons/wolfram-alpha.png"
303
- width = { 72 }
304
- height = { 72 }
331
+ width = { 48 }
332
+ height = { 48 }
305
333
alt = "WolframAlpha"
306
334
className = { agentStates [ 'WolframAlpha' ] === false ? 'opacity-60' : 'opacity-100' }
307
335
/>
@@ -310,57 +338,64 @@ const Page = () => {
310
338
name = "DuckDuckGo"
311
339
agentInfoDisplay = { agentInfoDisplay }
312
340
setAgentInfoDisplay = { setAgentInfoDisplay }
341
+ isDisabled = { agentStates [ 'DuckDuckGo' ] === false }
313
342
>
314
343
< Img
315
344
src = "/icons/duckduckgo.png"
316
- width = { 62 }
317
- height = { 62 }
345
+ width = { 40 }
346
+ height = { 40 }
318
347
alt = "DuckDuckGo"
319
348
className = { agentStates [ 'DuckDuckGo' ] === false ? 'opacity-60' : 'opacity-100' }
320
349
/>
321
350
</ AgentBlock >
322
351
</ div >
352
+ { agentInfoDisplay &&
323
353
< AgentInfo
324
354
name = { agentInfoDisplay }
325
355
code = { CODES [ agentInfoDisplay ] }
326
356
state = { agentStates [ agentInfoDisplay ] }
327
357
/>
358
+ }
328
359
</ div >
329
360
</ StepContent >
361
+ ) }
330
362
</ StepItem >
331
363
332
364
{ /* step-3 */ }
333
- < StepItem >
334
- < StepNumber order = { 3 } />
365
+ < StepItem status = { resolveStepStatus ( 3 ) } >
366
+ < StepNumber order = { 3 } status = { resolveStepStatus ( 3 ) } />
335
367
336
368
< StepTitle > See Final Summary with References</ StepTitle >
337
369
< StepDesc >
338
370
The cross-reference agent will summarize the answers with
339
371
references.
340
372
</ StepDesc >
341
373
374
+ { currentStep > 2 && (
342
375
< StepContent >
343
376
< AgentInfo
344
377
name = "Cross Reference"
345
378
code = { CODES [ 'Cross Reference' ] }
346
379
state = { agentStates [ 'Cross Reference' ] }
347
380
/>
348
381
</ StepContent >
382
+ ) }
349
383
</ StepItem >
350
384
351
385
{ /* step-4 */ }
352
- < StepItem >
353
- < StepNumber order = { 4 } />
386
+ < StepItem status = { resolveStepStatus ( 4 ) } >
387
+ < StepNumber order = { 4 } status = { resolveStepStatus ( 4 ) } />
354
388
355
389
< StepTitle > See Logs in Upstash Console</ StepTitle >
356
390
< StepDesc >
357
391
After running the workflow, navigate to the Upstash Console to see
358
392
the related logs.
359
393
</ StepDesc >
360
394
395
+ { currentStep > 3 && (
361
396
< StepContent >
362
397
< a
363
- className = "inline-flex items-center gap-1 px-3 py-2 bg-gray-100 rounded-md hover:bg-purple-100 "
398
+ className = "inline-flex items-center gap-1 px-3 py-2 rounded-md bg-purple-500 text-white hover:bg-purple-400 "
364
399
href = "https://console.upstash.com/qstash?tab=workflow"
365
400
>
366
401
< svg
@@ -390,6 +425,7 @@ const Page = () => {
390
425
alt = "s"
391
426
/>
392
427
</ StepContent >
428
+ ) }
393
429
</ StepItem >
394
430
</ Step >
395
431
</ div >
0 commit comments