@hef2024/llmasaservice-ui 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,815 @@
1
+ # Conversation Starting Guide
2
+
3
+ This guide covers the two ways to automatically start conversations with prompts in AIAgentPanel: the **declarative `initialPrompt` prop** and the **imperative `startNewConversation` API**.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Overview](#overview)
8
+ - [Method 1: initialPrompt (Declarative)](#method-1-initialprompt-declarative)
9
+ - [Method 2: startNewConversation (Imperative)](#method-2-startnewconversation-imperative)
10
+ - [Comparison](#comparison)
11
+ - [Common Use Cases](#common-use-cases)
12
+ - [API Reference](#api-reference)
13
+ - [Examples](#examples)
14
+
15
+ ---
16
+
17
+ ## Overview
18
+
19
+ AIAgentPanel provides two complementary approaches for starting conversations with pre-filled prompts:
20
+
21
+ | Feature | Type | When to Use |
22
+ |---------|------|-------------|
23
+ | **initialPrompt** | Declarative (prop) | Global default for all new conversations |
24
+ | **startNewConversation** | Imperative (method) | Programmatic, conversation-specific prompts |
25
+
26
+ ### Key Differences
27
+
28
+ ```typescript
29
+ // initialPrompt: Applies to ALL new conversations
30
+ <AIAgentPanel initialPrompt="Hello!" {...props} />
31
+
32
+ // startNewConversation: Specific to ONE conversation
33
+ panelRef.current?.startNewConversation("Hello from code!");
34
+ ```
35
+
36
+ ---
37
+
38
+ ## Method 1: initialPrompt (Declarative)
39
+
40
+ The `initialPrompt` prop sets a **global default prompt** that applies to all new conversations created through the UI.
41
+
42
+ ### Basic Usage
43
+
44
+ ```typescript
45
+ import AIAgentPanel from '@hef2024/llmasaservice-ui';
46
+
47
+ function App() {
48
+ return (
49
+ <AIAgentPanel
50
+ initialPrompt="Introduce yourself and explain what you can help with"
51
+ hideInitialPrompt={false}
52
+ agents={['agent-1', 'agent-2']}
53
+ customerId="user-123"
54
+ />
55
+ );
56
+ }
57
+ ```
58
+
59
+ ### How It Works
60
+
61
+ 1. **Set Once**: You pass `initialPrompt` as a prop to AIAgentPanel
62
+ 2. **Applies Globally**: Every time a user clicks "New Conversation" (+ button), this prompt is automatically sent
63
+ 3. **User Can Override**: The prompt is sent via the existing AIChatPanel effect
64
+ 4. **Persistent**: Remains active until you change or remove the prop
65
+
66
+ ### When to Use initialPrompt
67
+
68
+ ✅ **Good for:**
69
+ - Onboarding prompts for new users
70
+ - Context-aware welcomes based on the current page
71
+ - Setting a consistent starting experience
72
+ - Guiding users on what the agent can do
73
+
74
+ ❌ **Not ideal for:**
75
+ - One-time programmatic actions
76
+ - Different prompts for different scenarios
77
+ - Button-triggered specific queries
78
+ - Dynamic conversation starting
79
+
80
+ ### Example: Context-Aware Welcome
81
+
82
+ ```typescript
83
+ function App() {
84
+ const [currentPage, setCurrentPage] = useState('dashboard');
85
+
86
+ // Different welcome message based on page
87
+ const contextPrompt = useMemo(() => {
88
+ switch (currentPage) {
89
+ case 'dashboard':
90
+ return 'Give me an overview of my dashboard metrics';
91
+ case 'analytics':
92
+ return 'What insights can you show me from my data?';
93
+ case 'settings':
94
+ return 'Help me understand my available settings';
95
+ default:
96
+ return 'What can you help me with?';
97
+ }
98
+ }, [currentPage]);
99
+
100
+ return (
101
+ <AIAgentPanel
102
+ initialPrompt={contextPrompt}
103
+ hideInitialPrompt={false}
104
+ // ... other props
105
+ />
106
+ );
107
+ }
108
+ ```
109
+
110
+ ### Props Related to initialPrompt
111
+
112
+ ```typescript
113
+ interface AIAgentPanelProps {
114
+ initialPrompt?: string; // The prompt to send automatically
115
+ hideInitialPrompt?: boolean; // Show/hide the prompt in chat (default: true)
116
+ initialMessage?: string; // Non-sent message (just displayed)
117
+ }
118
+ ```
119
+
120
+ ---
121
+
122
+ ## Method 2: startNewConversation (Imperative)
123
+
124
+ The `startNewConversation` API allows you to **programmatically create conversations** with specific prompts via a ref.
125
+
126
+ ### Basic Usage
127
+
128
+ ```typescript
129
+ import { useRef } from 'react';
130
+ import AIAgentPanel, { AIAgentPanelHandle } from '@hef2024/llmasaservice-ui';
131
+
132
+ function App() {
133
+ const panelRef = useRef<AIAgentPanelHandle>(null);
134
+
135
+ const handleQuickStart = () => {
136
+ panelRef.current?.startNewConversation(
137
+ "What's my progress this week?",
138
+ "fitness-agent" // optional: specific agent
139
+ );
140
+ };
141
+
142
+ return (
143
+ <>
144
+ <button onClick={handleQuickStart}>Quick Start</button>
145
+
146
+ <AIAgentPanel
147
+ ref={panelRef}
148
+ agents={['fitness-agent', 'nutrition-agent']}
149
+ customerId="user-123"
150
+ />
151
+ </>
152
+ );
153
+ }
154
+ ```
155
+
156
+ ### How It Works
157
+
158
+ 1. **Create Ref**: Use `useRef<AIAgentPanelHandle>(null)` to create a ref
159
+ 2. **Pass Ref**: Attach the ref to AIAgentPanel with `ref={panelRef}`
160
+ 3. **Call Method**: Invoke `panelRef.current?.startNewConversation(prompt, agent?)`
161
+ 4. **Auto-Send**: The prompt is automatically sent in the new conversation
162
+
163
+ ### API Signature
164
+
165
+ ```typescript
166
+ interface AIAgentPanelHandle {
167
+ startNewConversation: (prompt: string, agent?: string) => void;
168
+ }
169
+ ```
170
+
171
+ **Parameters:**
172
+ - `prompt` (string, required): The message to send automatically
173
+ - `agent` (string, optional): Specific agent ID. If omitted, uses the currently selected agent
174
+
175
+ **Returns:** `void`
176
+
177
+ ### When to Use startNewConversation
178
+
179
+ ✅ **Good for:**
180
+ - Quick action buttons ("Get my summary", "Ask about X")
181
+ - Programmatic conversation creation from external triggers
182
+ - Different prompts for different UI actions
183
+ - Context-specific queries from buttons/links
184
+ - Integration with other app features
185
+
186
+ ❌ **Not ideal for:**
187
+ - Setting a default welcome message (use `initialPrompt` instead)
188
+ - Prompts that apply to all conversations
189
+ - Non-programmatic scenarios
190
+
191
+ ### Example: Quick Action Buttons
192
+
193
+ ```typescript
194
+ function QuickActions() {
195
+ const panelRef = useRef<AIAgentPanelHandle>(null);
196
+
197
+ return (
198
+ <div>
199
+ <button onClick={() =>
200
+ panelRef.current?.startNewConversation(
201
+ 'Give me a summary of my weekly progress'
202
+ )
203
+ }>
204
+ 📊 Weekly Summary
205
+ </button>
206
+
207
+ <button onClick={() =>
208
+ panelRef.current?.startNewConversation(
209
+ 'What should I focus on today?'
210
+ )
211
+ }>
212
+ 🎯 Today's Focus
213
+ </button>
214
+
215
+ <button onClick={() =>
216
+ panelRef.current?.startNewConversation(
217
+ 'Analyze my nutrition intake for this week',
218
+ 'nutrition-agent' // specific agent
219
+ )
220
+ }>
221
+ 🥗 Nutrition Check
222
+ </button>
223
+
224
+ <AIAgentPanel
225
+ ref={panelRef}
226
+ agents={['fitness-agent', 'nutrition-agent']}
227
+ customerId="user-123"
228
+ />
229
+ </div>
230
+ );
231
+ }
232
+ ```
233
+
234
+ ---
235
+
236
+ ## Comparison
237
+
238
+ ### Feature Comparison Table
239
+
240
+ | Feature | initialPrompt | startNewConversation |
241
+ |---------|---------------|---------------------|
242
+ | **Invocation** | Declarative (prop) | Imperative (method call) |
243
+ | **Scope** | Global (all new conversations) | Per-conversation |
244
+ | **When Applied** | When user clicks "+" button | When method is called |
245
+ | **User Interaction** | Requires user to start conversation | Creates conversation immediately |
246
+ | **Dynamic** | Changes affect future conversations | Each call is independent |
247
+ | **Agent Selection** | Uses current agent | Can specify agent per call |
248
+ | **Best For** | Default welcome prompts | Programmatic actions |
249
+
250
+ ### Side-by-Side Example
251
+
252
+ ```typescript
253
+ function ComparisonExample() {
254
+ const panelRef = useRef<AIAgentPanelHandle>(null);
255
+
256
+ return (
257
+ <div>
258
+ {/* initialPrompt: User must click + button */}
259
+ <AIAgentPanel
260
+ ref={panelRef}
261
+ initialPrompt="Welcome! How can I help you today?"
262
+ hideInitialPrompt={false}
263
+ // This prompt applies when user creates conversation via UI
264
+ />
265
+
266
+ {/* startNewConversation: Immediate, no user action needed */}
267
+ <button onClick={() =>
268
+ panelRef.current?.startNewConversation(
269
+ "Show me my dashboard summary"
270
+ )
271
+ }>
272
+ Get Summary Now
273
+ </button>
274
+ </div>
275
+ );
276
+ }
277
+ ```
278
+
279
+ ### Behavior Differences
280
+
281
+ ```typescript
282
+ // Scenario 1: initialPrompt
283
+ <AIAgentPanel initialPrompt="Hello" />
284
+ // User clicks "+" → New conversation created → "Hello" is sent
285
+
286
+ // Scenario 2: startNewConversation
287
+ panelRef.current?.startNewConversation("Hello");
288
+ // New conversation created immediately → "Hello" is sent → No user action needed
289
+ ```
290
+
291
+ ---
292
+
293
+ ## Common Use Cases
294
+
295
+ ### Use Case 1: Quick Action Dashboard
296
+
297
+ Combine both approaches for maximum flexibility:
298
+
299
+ ```typescript
300
+ function Dashboard() {
301
+ const panelRef = useRef<AIAgentPanelHandle>(null);
302
+ const [currentPage, setCurrentPage] = useState('home');
303
+
304
+ // Global welcome for manually created conversations
305
+ const welcomePrompt = `Welcome to ${currentPage}! What would you like to know?`;
306
+
307
+ return (
308
+ <div>
309
+ {/* Quick action buttons */}
310
+ <div className="quick-actions">
311
+ <button onClick={() =>
312
+ panelRef.current?.startNewConversation(
313
+ 'Summarize my metrics for today'
314
+ )
315
+ }>
316
+ Daily Summary
317
+ </button>
318
+
319
+ <button onClick={() =>
320
+ panelRef.current?.startNewConversation(
321
+ 'What tasks need my attention?'
322
+ )
323
+ }>
324
+ Action Items
325
+ </button>
326
+ </div>
327
+
328
+ <AIAgentPanel
329
+ ref={panelRef}
330
+ initialPrompt={welcomePrompt}
331
+ hideInitialPrompt={false}
332
+ agents={['assistant']}
333
+ customerId="user-123"
334
+ />
335
+ </div>
336
+ );
337
+ }
338
+ ```
339
+
340
+ ### Use Case 2: Contextual Help System
341
+
342
+ ```typescript
343
+ function ContextualHelp({ currentFeature }: { currentFeature: string }) {
344
+ const panelRef = useRef<AIAgentPanelHandle>(null);
345
+
346
+ const getHelpForFeature = () => {
347
+ const helpPrompts = {
348
+ 'charts': 'Explain how to use the charts feature',
349
+ 'export': 'Walk me through the export options',
350
+ 'settings': 'What settings should I configure?',
351
+ };
352
+
353
+ panelRef.current?.startNewConversation(
354
+ helpPrompts[currentFeature] || 'How can you help me?'
355
+ );
356
+ };
357
+
358
+ return (
359
+ <div>
360
+ <button onClick={getHelpForFeature}>
361
+ Get Help with {currentFeature}
362
+ </button>
363
+
364
+ <AIAgentPanel
365
+ ref={panelRef}
366
+ initialPrompt="I'm here to help! What do you need assistance with?"
367
+ agents={['help-agent']}
368
+ customerId="user-123"
369
+ />
370
+ </div>
371
+ );
372
+ }
373
+ ```
374
+
375
+ ### Use Case 3: Onboarding Flow
376
+
377
+ ```typescript
378
+ function OnboardingFlow() {
379
+ const panelRef = useRef<AIAgentPanelHandle>(null);
380
+ const [step, setStep] = useState(1);
381
+
382
+ const startOnboarding = () => {
383
+ const onboardingSteps = [
384
+ "Let's get you started! Tell me about your goals.",
385
+ "Great! Now let's set up your preferences.",
386
+ "Finally, let me show you around the interface.",
387
+ ];
388
+
389
+ panelRef.current?.startNewConversation(onboardingSteps[step - 1]);
390
+ };
391
+
392
+ return (
393
+ <div>
394
+ <button onClick={startOnboarding}>
395
+ Start Onboarding Step {step}
396
+ </button>
397
+
398
+ <AIAgentPanel
399
+ ref={panelRef}
400
+ agents={['onboarding-agent']}
401
+ customerId="user-123"
402
+ />
403
+ </div>
404
+ );
405
+ }
406
+ ```
407
+
408
+ ### Use Case 4: URL-Based Conversation Starter
409
+
410
+ ```typescript
411
+ function URLBasedStarter() {
412
+ const panelRef = useRef<AIAgentPanelHandle>(null);
413
+ const [searchParams] = useSearchParams();
414
+
415
+ useEffect(() => {
416
+ // Start conversation based on URL parameter
417
+ const query = searchParams.get('ask');
418
+ if (query && panelRef.current) {
419
+ panelRef.current.startNewConversation(query);
420
+ }
421
+ }, [searchParams]);
422
+
423
+ return (
424
+ <AIAgentPanel
425
+ ref={panelRef}
426
+ agents={['assistant']}
427
+ customerId="user-123"
428
+ />
429
+ );
430
+ }
431
+
432
+ // Usage: Navigate to /app?ask=What%20is%20my%20status
433
+ ```
434
+
435
+ ---
436
+
437
+ ## API Reference
438
+
439
+ ### AIAgentPanel Props
440
+
441
+ ```typescript
442
+ interface AIAgentPanelProps {
443
+ // ... other props
444
+
445
+ // Initial prompt for all new conversations (global)
446
+ initialPrompt?: string;
447
+
448
+ // Whether to hide the initial prompt in chat UI
449
+ hideInitialPrompt?: boolean;
450
+
451
+ // Initial message (displayed but not sent)
452
+ initialMessage?: string;
453
+ }
454
+ ```
455
+
456
+ ### AIAgentPanelHandle (Ref API)
457
+
458
+ ```typescript
459
+ export interface AIAgentPanelHandle {
460
+ /**
461
+ * Programmatically start a new conversation with an auto-sent prompt
462
+ *
463
+ * @param prompt - The message to send automatically
464
+ * @param agent - (Optional) Specific agent ID. Defaults to current agent.
465
+ *
466
+ * @example
467
+ * // Start conversation with default agent
468
+ * panelRef.current?.startNewConversation('Hello!');
469
+ *
470
+ * @example
471
+ * // Start conversation with specific agent
472
+ * panelRef.current?.startNewConversation('Analyze my data', 'analytics-agent');
473
+ */
474
+ startNewConversation: (prompt: string, agent?: string) => void;
475
+ }
476
+ ```
477
+
478
+ ### TypeScript Usage
479
+
480
+ ```typescript
481
+ import { useRef } from 'react';
482
+ import AIAgentPanel, { AIAgentPanelHandle } from '@hef2024/llmasaservice-ui';
483
+
484
+ function TypedExample() {
485
+ // Properly typed ref
486
+ const panelRef = useRef<AIAgentPanelHandle>(null);
487
+
488
+ const handleAction = () => {
489
+ // TypeScript ensures type safety
490
+ panelRef.current?.startNewConversation(
491
+ 'Your prompt here',
492
+ 'optional-agent-id'
493
+ );
494
+ };
495
+
496
+ return (
497
+ <AIAgentPanel
498
+ ref={panelRef}
499
+ agents={['agent-1']}
500
+ customerId="user-123"
501
+ />
502
+ );
503
+ }
504
+ ```
505
+
506
+ ---
507
+
508
+ ## Examples
509
+
510
+ ### Example 1: Simple Quick Start Button
511
+
512
+ ```typescript
513
+ import { useRef } from 'react';
514
+ import AIAgentPanel, { AIAgentPanelHandle } from '@hef2024/llmasaservice-ui';
515
+
516
+ function SimpleExample() {
517
+ const panelRef = useRef<AIAgentPanelHandle>(null);
518
+
519
+ return (
520
+ <div>
521
+ <button onClick={() =>
522
+ panelRef.current?.startNewConversation('Hello!')
523
+ }>
524
+ Quick Start
525
+ </button>
526
+
527
+ <AIAgentPanel
528
+ ref={panelRef}
529
+ agents={['my-agent']}
530
+ customerId="user-123"
531
+ />
532
+ </div>
533
+ );
534
+ }
535
+ ```
536
+
537
+ ### Example 2: Multiple Quick Actions
538
+
539
+ ```typescript
540
+ function MultipleActions() {
541
+ const panelRef = useRef<AIAgentPanelHandle>(null);
542
+
543
+ const quickActions = [
544
+ { label: 'Daily Summary', prompt: 'Give me my daily summary' },
545
+ { label: 'To-Do List', prompt: 'What tasks do I have today?' },
546
+ { label: 'Recommendations', prompt: 'What should I focus on?' },
547
+ ];
548
+
549
+ return (
550
+ <div>
551
+ {quickActions.map(action => (
552
+ <button
553
+ key={action.label}
554
+ onClick={() => panelRef.current?.startNewConversation(action.prompt)}
555
+ >
556
+ {action.label}
557
+ </button>
558
+ ))}
559
+
560
+ <AIAgentPanel
561
+ ref={panelRef}
562
+ agents={['assistant']}
563
+ customerId="user-123"
564
+ />
565
+ </div>
566
+ );
567
+ }
568
+ ```
569
+
570
+ ### Example 3: Agent-Specific Actions
571
+
572
+ ```typescript
573
+ function AgentSpecificActions() {
574
+ const panelRef = useRef<AIAgentPanelHandle>(null);
575
+
576
+ return (
577
+ <div>
578
+ <button onClick={() =>
579
+ panelRef.current?.startNewConversation(
580
+ 'Analyze my fitness data',
581
+ 'fitness-agent'
582
+ )
583
+ }>
584
+ Fitness Check
585
+ </button>
586
+
587
+ <button onClick={() =>
588
+ panelRef.current?.startNewConversation(
589
+ 'Review my nutrition plan',
590
+ 'nutrition-agent'
591
+ )
592
+ }>
593
+ Nutrition Review
594
+ </button>
595
+
596
+ <AIAgentPanel
597
+ ref={panelRef}
598
+ agents={['fitness-agent', 'nutrition-agent']}
599
+ customerId="user-123"
600
+ />
601
+ </div>
602
+ );
603
+ }
604
+ ```
605
+
606
+ ### Example 4: Combining Both Approaches
607
+
608
+ ```typescript
609
+ function CombinedApproach() {
610
+ const panelRef = useRef<AIAgentPanelHandle>(null);
611
+ const [page, setPage] = useState('dashboard');
612
+
613
+ // Global welcome for UI-created conversations
614
+ const welcomePrompt = `Welcome to the ${page}! How can I help?`;
615
+
616
+ return (
617
+ <div>
618
+ {/* Programmatic quick starts */}
619
+ <div className="quick-actions">
620
+ <button onClick={() =>
621
+ panelRef.current?.startNewConversation('Quick summary please')
622
+ }>
623
+ Quick Summary
624
+ </button>
625
+ </div>
626
+
627
+ {/* Panel with initialPrompt for manual conversations */}
628
+ <AIAgentPanel
629
+ ref={panelRef}
630
+ initialPrompt={welcomePrompt}
631
+ hideInitialPrompt={false}
632
+ agents={['assistant']}
633
+ customerId="user-123"
634
+ />
635
+ </div>
636
+ );
637
+ }
638
+ ```
639
+
640
+ ### Example 5: Dynamic Prompt Based on User Data
641
+
642
+ ```typescript
643
+ function DynamicPromptExample() {
644
+ const panelRef = useRef<AIAgentPanelHandle>(null);
645
+ const { userData } = useUserData(); // Custom hook
646
+
647
+ const getPersonalizedPrompt = () => {
648
+ const { name, lastActivity, goals } = userData;
649
+ return `Hi ${name}! Based on your ${lastActivity} activity and ${goals} goals, what would you like to know?`;
650
+ };
651
+
652
+ return (
653
+ <div>
654
+ <button onClick={() =>
655
+ panelRef.current?.startNewConversation(getPersonalizedPrompt())
656
+ }>
657
+ Personalized Start
658
+ </button>
659
+
660
+ <AIAgentPanel
661
+ ref={panelRef}
662
+ agents={['personal-agent']}
663
+ customerId="user-123"
664
+ />
665
+ </div>
666
+ );
667
+ }
668
+ ```
669
+
670
+ ---
671
+
672
+ ## Best Practices
673
+
674
+ ### ✅ Do's
675
+
676
+ 1. **Use initialPrompt for global defaults**
677
+ ```typescript
678
+ <AIAgentPanel initialPrompt="Welcome! How can I help?" />
679
+ ```
680
+
681
+ 2. **Use startNewConversation for specific actions**
682
+ ```typescript
683
+ <button onClick={() => ref.current?.startNewConversation('Specific query')}>
684
+ ```
685
+
686
+ 3. **Combine both for flexible UX**
687
+ ```typescript
688
+ // Global welcome + programmatic quick actions
689
+ ```
690
+
691
+ 4. **Specify agents when relevant**
692
+ ```typescript
693
+ ref.current?.startNewConversation('Query', 'specific-agent');
694
+ ```
695
+
696
+ 5. **Keep prompts clear and actionable**
697
+ ```typescript
698
+ 'Analyze my weekly progress' // Clear
699
+ vs
700
+ 'Tell me stuff' // Vague
701
+ ```
702
+
703
+ ### ❌ Don'ts
704
+
705
+ 1. **Don't use startNewConversation for global defaults**
706
+ ```typescript
707
+ // ❌ Bad: Repeating for every button
708
+ onClick={() => ref.current?.startNewConversation('Same welcome')}
709
+
710
+ // ✅ Good: Use initialPrompt instead
711
+ <AIAgentPanel initialPrompt="Same welcome" />
712
+ ```
713
+
714
+ 2. **Don't forget to check ref.current**
715
+ ```typescript
716
+ // ❌ Bad: Could crash if ref not ready
717
+ ref.current.startNewConversation('Query');
718
+
719
+ // ✅ Good: Optional chaining
720
+ ref.current?.startNewConversation('Query');
721
+ ```
722
+
723
+ 3. **Don't create excessive conversations**
724
+ ```typescript
725
+ // ❌ Bad: Creates conversation on every render
726
+ useEffect(() => {
727
+ ref.current?.startNewConversation('Query');
728
+ }); // Missing dependency array
729
+
730
+ // ✅ Good: Control when conversations start
731
+ useEffect(() => {
732
+ ref.current?.startNewConversation('Query');
733
+ }, []); // Empty array = once on mount
734
+ ```
735
+
736
+ ---
737
+
738
+ ## Migration Guide
739
+
740
+ ### Upgrading from Earlier Versions
741
+
742
+ If you were using custom solutions to start conversations, here's how to migrate:
743
+
744
+ #### Before (Custom Solution)
745
+
746
+ ```typescript
747
+ // Old way: Managing conversation creation manually
748
+ const [shouldSendPrompt, setShouldSendPrompt] = useState(false);
749
+ const [promptToSend, setPromptToSend] = useState('');
750
+
751
+ useEffect(() => {
752
+ if (shouldSendPrompt) {
753
+ // Custom logic to create conversation and send prompt
754
+ createConversationAndSend(promptToSend);
755
+ setShouldSendPrompt(false);
756
+ }
757
+ }, [shouldSendPrompt]);
758
+
759
+ <button onClick={() => {
760
+ setPromptToSend('My query');
761
+ setShouldSendPrompt(true);
762
+ }}>
763
+ ```
764
+
765
+ #### After (Using startNewConversation)
766
+
767
+ ```typescript
768
+ // New way: Simple and clean
769
+ const panelRef = useRef<AIAgentPanelHandle>(null);
770
+
771
+ <button onClick={() =>
772
+ panelRef.current?.startNewConversation('My query')
773
+ }>
774
+ ```
775
+
776
+ ---
777
+
778
+ ## Troubleshooting
779
+
780
+ ### Issue: startNewConversation not working
781
+
782
+ **Solution:** Ensure you've:
783
+ 1. Created a ref: `const panelRef = useRef<AIAgentPanelHandle>(null)`
784
+ 2. Passed it to AIAgentPanel: `<AIAgentPanel ref={panelRef} />`
785
+ 3. Used optional chaining: `panelRef.current?.startNewConversation(...)`
786
+
787
+ ### Issue: initialPrompt not sending
788
+
789
+ **Solution:** Check that:
790
+ 1. `hideInitialPrompt` is not set to `true` (default behavior)
791
+ 2. The conversation is actually new (not loading existing conversation)
792
+ 3. `initialPrompt` has a value (not empty string)
793
+
794
+ ### Issue: Prompt sent multiple times
795
+
796
+ **Solution:** Ensure you're not:
797
+ 1. Calling `startNewConversation` in a render cycle
798
+ 2. Missing dependency arrays in useEffect
799
+ 3. Creating duplicate event handlers
800
+
801
+ ---
802
+
803
+ ## Version History
804
+
805
+ - **v0.17.0** - Added `startNewConversation` imperative API
806
+ - **v0.16.x** - Initial `initialPrompt` prop support
807
+
808
+ ---
809
+
810
+ ## Related Documentation
811
+
812
+ - [Conversation History Settings](./CONVERSATION-HISTORY.md)
813
+ - [AIAgentPanel API Reference](../local-dev-docs/AIAGENTPANEL.md)
814
+ - [AIChatPanel Documentation](../local-dev-docs/AICHATPANEL.md)
815
+ - [Quick Start Guide](../local-dev-docs/QUICK-START.md)