Skip to content

Commit bc6bec1

Browse files
Refine prompt and fix badcases (#13079)
1 parent 9c42b11 commit bc6bec1

File tree

23 files changed

+581
-395
lines changed

23 files changed

+581
-395
lines changed

tools/sdk-ai-bots/azure-sdk-qa-bot-backend/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Release History
22

3+
## 0.3.0 (2025-11-27)
4+
5+
### Bugs Fixed
6+
7+
* Ehhance intent recognition for non-technical and technical message
8+
9+
### Features Added
10+
11+
* Add TypeSpec Validation category for intention prompt
12+
13+
### Other Changes
14+
15+
* Restructured prompt templates to enhance clarity and maintainability
16+
317
## 0.2.0 (2025-11-13)
418

519
### Features Added

tools/sdk-ai-bots/azure-sdk-qa-bot-backend/config/tenant.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var typespecSources = []model.Source{
2626

2727
var SourceTopK = map[model.Source]int{
2828
model.Source_TypeSpecMigration: 3,
29+
model.Source_TypeSpecQA: 3,
2930
}
3031

3132
var tenantConfigMap = map[model.TenantID]TenantConfig{
@@ -34,30 +35,30 @@ var tenantConfigMap = map[model.TenantID]TenantConfig{
3435
SourceFilter: map[model.Source]string{
3536
model.Source_AzureSDKGuidelines: "search.ismatch('python_*', 'title')",
3637
},
37-
PromptTemplate: "qa_prompt_python.md",
38-
IntentionPromptTemplate: "intention_prompt_python.md",
39-
AgenticSearchPrompt: "You are an Azure SDK for Python expert query analyzer. Your task is to decompose complex user questions into specific, searchable sub-queries that can be processed in parallel to retrieve comprehensive information from Azure SDK documentation, Python-specific guides, and TypeSpec resources.\n\n## Query Analysis Guidelines:\n1. **Identify Core Concepts**: Extract the main technical topics, SDK services, Python patterns, and TypeSpec elements\n2. **Separate Concerns**: Split questions about installation, configuration, implementation, troubleshooting, and best practices\n3. **Consider Context**: Include both Python-specific and general Azure SDK aspects\n4. **Target Sources**: Create queries that align with different knowledge sources (Python SDK docs, wikis, TypeSpec specs)\n\n## Sub-Query Generation Strategy:\n- **Installation/Setup**: How to install, configure, or initialize specific components\n- **API Usage**: Method signatures, parameters, return types, and usage patterns\n- **Authentication**: Authentication methods, credential management, and security patterns\n- **Error Handling**: Common errors, troubleshooting steps, and exception handling\n- **Best Practices**: Recommended patterns, performance optimization, and code examples\n- **Integration**: How components work together, dependencies, and compatibility\n\n## Search Optimization:\n- Use specific technical terms and SDK method names\n- Include both conceptual and implementation-focused queries\n- Add context about Python version compatibility when relevant\n- Consider async/sync patterns for Python-specific searches\n\nGenerate 3-7 focused sub-queries that together will provide comprehensive coverage of the user's question, ensuring parallel search efficiency and minimal overlap.",
38+
PromptTemplate: "language_python/qa.md",
39+
IntentionPromptTemplate: "language_python/intention.md",
40+
AgenticSearchPrompt: "language_python/agentic_search.md",
4041
},
4142
model.TenantID_GolangChannelQaBot: {
4243
Sources: append([]model.Source{model.Source_AzureSDKForGo, model.Source_AzureSDKGuidelines}, typespecSources...),
4344
SourceFilter: map[model.Source]string{
4445
model.Source_AzureSDKGuidelines: "search.ismatch('golang_*', 'title')",
4546
},
46-
PromptTemplate: "language_channel.md",
47-
IntentionPromptTemplate: "intention.md",
48-
AgenticSearchPrompt: "You are an Azure SDK for Golang expert query analyzer. Your task is to decompose complex user questions into specific, searchable sub-queries that can be processed in parallel to retrieve comprehensive information from Azure SDK documentation, Golang-specific guides, and TypeSpec resources.\n\n## Query Analysis Guidelines:\n1. **Identify Core Concepts**: Extract the main technical topics, SDK services, Golang patterns, and TypeSpec elements\n2. **Separate Concerns**: Split questions about installation, configuration, implementation, troubleshooting, and best practices\n3. **Consider Context**: Include both Golang-specific and general Azure SDK aspects\n4. **Target Sources**: Create queries that align with different knowledge sources (Golang SDK docs, wikis, TypeSpec specs)\n\n## Sub-Query Generation Strategy:\n- **Installation/Setup**: How to install, configure, or initialize specific components\n- **API Usage**: Method signatures, parameters, return types, and usage patterns\n- **Authentication**: Authentication methods, credential management, and security patterns\n- **Error Handling**: Common errors, troubleshooting steps, and exception handling\n- **Best Practices**: Recommended patterns, performance optimization, and code examples\n- **Integration**: How components work together, dependencies, and compatibility\n\n## Search Optimization:\n- Use specific technical terms and SDK method names\n- Include both conceptual and implementation-focused queries\n- Add context about Golang version compatibility when relevant\n- Consider async/sync patterns for Golang-specific searches\n\nGenerate 3-7 focused sub-queries that together will provide comprehensive coverage of the user's question, ensuring parallel search efficiency and minimal overlap.",
47+
PromptTemplate: "common/language_channel.md",
48+
IntentionPromptTemplate: "prompt_template/intention.md",
49+
AgenticSearchPrompt: "common/agentic_search.md",
4950
},
5051
model.TenantID_AzureSDKQaBot: {
51-
PromptTemplate: "typespec.md",
52+
PromptTemplate: "typespec/qa.md",
5253
Sources: typespecSources,
53-
IntentionPromptTemplate: "intention.md",
54-
AgenticSearchPrompt: "You are a TypeSpec and Azure API expert query analyzer. Your role is to intelligently decompose complex user questions into targeted sub-queries that can be searched in parallel across TypeSpec documentation, Azure REST API specifications, and Azure API guidelines.\n\n## Query Decomposition Strategy:\n1. **Syntax & Language**: TypeSpec syntax, decorators, built-in types, and language constructs\n2. **Azure Integration**: Azure-specific decorators, patterns, and service integration\n3. **API Design**: REST API modeling, resource definitions, and operation patterns\n4. **Code Generation**: Emitter behavior, target language specifics, and generated artifacts\n5. **Migration & Adoption**: Moving from OpenAPI/Swagger to TypeSpec, conversion patterns\n6. **Compliance & Guidelines**: Azure API guidelines adherence, ARM requirements, naming conventions\n\n## Sub-Query Optimization:\n- **Specific Technical Terms**: Use exact decorator names (@route, @doc, @example), built-in types (string, int32, etc.)\n- **Context-Aware**: Include Azure service context (ARM, data-plane, management operations)\n- **Progressive Complexity**: Start with basic concepts, then dive into advanced patterns\n- **Cross-Reference**: Link TypeSpec syntax with resulting OpenAPI/ARM template patterns\n- **Practical Examples**: Focus on real-world usage scenarios and common implementation patterns\n\n## Search Targeting:\n- **TypeSpec Core**: Language fundamentals, syntax, and basic patterns\n- **Azure TypeSpec**: Azure-specific decorators, templates, and service patterns\n- **API Guidelines**: Compliance requirements, naming conventions, and best practices\n- **ARM/RPC**: Resource provider contracts, management plane requirements\n- **Migration Guidance**: Conversion patterns, tooling, and adoption strategies\n\nGenerate 4-8 precise sub-queries that comprehensively cover the user's question while enabling efficient parallel search across different knowledge domains.",
54+
IntentionPromptTemplate: "typespec/intention.md",
55+
AgenticSearchPrompt: "typespec/agentic_search.md",
5556
},
5657
model.TenantID_AzureSDKOnboarding: {
57-
PromptTemplate: "azure_sdk_onboarding.md",
58+
PromptTemplate: "azure_sdk_onboarding/qa.md",
5859
Sources: []model.Source{model.Source_AzureSDKDocsEng},
59-
AgenticSearchPrompt: "You are an Azure SDK onboarding query analyzer specializing in identifying basic onboarding phase documentation. Your goal is to decompose user questions into targeted searches that efficiently locate foundational guidance, prerequisites, and phase-specific documentation.\n\nNote: The user query already contains category information that should be leveraged for targeted search.\n\n## Core Onboarding Phases (Search Priority):\n1. **Service Onboarding**: Service registration, prerequisites, readiness criteria, initial setup\n2. **API Design**: REST API specifications, TypeSpec vs OpenAPI workflows, design guidelines\n3. **SDK Development**: Multi-language SDK generation, client library patterns, coding standards\n4. **SDK Release**: Release planning, versioning, GA criteria, publication workflows\n\n## Required Sub-Query Types (MUST include at least one from each):\n1. **Category Guidelines**: ALWAYS generate at least one sub-query specifically targeting category-specific guidelines, standards, and best practices based on the category information in the user query\n2. **Phase-Specific Documentation**: Target the specific onboarding phase mentioned or implied in the query\n3. **Process Documentation**: Search for workflows, procedures, and step-by-step guidance\n\n## Basic Documentation Search Strategy:\n- **Category Guidelines**: Extract the category from user query and search for \"[category] guidelines\", \"[category] standards\", \"[category] best practices\", \"[category] requirements\"\n- **Prerequisites & Getting Started**: Focus on 'what do I need before', 'requirements', 'setup'\n- **Phase-Specific Guides**: Target 'how to start', 'basic steps', 'introduction to'\n- **Common Workflows**: Search for 'typical process', 'standard workflow', 'basic procedure'\n- **Foundational Concepts**: Look for 'overview', 'fundamentals', 'key concepts'\n- **Phase Transitions**: Find 'next steps', 'moving from X to Y', 'when to proceed'\n\n## Query Optimization for Basic Guidance:\n- **Category-First Approach**: Always include the category information from the user query in at least one sub-query\n- **Beginner-Friendly Terms**: Use simple, clear terminology over advanced jargon\n- **Process-Oriented**: Focus on 'how to', 'steps to', 'process for'\n- **Phase Identification**: Include specific phase names in queries\n- **Sequential Learning**: Structure searches from basic to intermediate concepts\n- **Common Questions**: Target frequent onboarding pain points and basic uncertainties\n\n## Search Query Structure:\n- Start with a category-specific guideline query based on the user's query category\n- Include both conceptual ('what is') and procedural ('how to') searches\n- Target documentation that explains fundamentals before diving into details\n- Focus on getting started guides, overviews, and introductory materials\n- Search for phase-specific checklists, requirements, and basic workflows\n\nGenerate 4-6 focused sub-queries that efficiently locate basic phase documentation and foundational guidance relevant to the user's onboarding question. ENSURE that at least one sub-query specifically targets category guidelines based on the category information present in the user query.",
60-
IntentionPromptTemplate: "azure_sdk_onboarding_intention.md",
60+
AgenticSearchPrompt: "azure_sdk_onboarding/agentic_search.md",
61+
IntentionPromptTemplate: "azure_sdk_onboarding/intention.md",
6162
},
6263
}
6364

tools/sdk-ai-bots/azure-sdk-qa-bot-backend/service/agent/service.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (s *CompletionService) ChatCompletion(ctx context.Context, req *model.Compl
9292
// Skip RAG workflow for non-technical messages
9393
log.Printf("Skipping RAG workflow - non-technical message detected")
9494
chunks = []string{}
95-
promptTemplate = "non_technical_question_prompt.md"
95+
promptTemplate = "common/non_technical_question.md"
9696
} else {
9797
// Run agentic search and knowledge search in parallel, then merge results
9898
chunks, err = s.runParallelSearchAndMergeResults(ctx, req, query)
@@ -110,7 +110,9 @@ func (s *CompletionService) ChatCompletion(ctx context.Context, req *model.Compl
110110
}
111111

112112
// 5. Get answer from LLM
113-
llmMessages = append(llmMessages, &azopenai.ChatRequestSystemMessage{Content: azopenai.NewChatRequestSystemMessageContent(prompt)})
113+
llmMessages = append([]azopenai.ChatRequestMessageClassification{
114+
&azopenai.ChatRequestSystemMessage{Content: azopenai.NewChatRequestSystemMessageContent(prompt)},
115+
}, llmMessages...)
114116
result, err := s.getLLMResult(llmMessages, tenantConfig.PromptTemplate)
115117
if err != nil {
116118
log.Printf("LLM request failed: %v", err)
@@ -136,7 +138,9 @@ func (s *CompletionService) RecognizeIntention(promptTemplate string, messages [
136138
return nil, err
137139
}
138140

139-
messages = append(messages, &azopenai.ChatRequestSystemMessage{Content: azopenai.NewChatRequestSystemMessageContent(promptStr)})
141+
messages = append([]azopenai.ChatRequestMessageClassification{
142+
&azopenai.ChatRequestSystemMessage{Content: azopenai.NewChatRequestSystemMessageContent(promptStr)},
143+
}, messages...)
140144

141145
resp, err := config.OpenAIClient.GetChatCompletions(context.TODO(), azopenai.ChatCompletionsOptions{
142146
Messages: messages,
@@ -474,7 +478,11 @@ func (s *CompletionService) agenticSearch(ctx context.Context, query string, req
474478
log.Printf("ERROR: %s", err)
475479
return nil, err
476480
}
477-
log.Printf("Agentic search sub queries: %+v", resp.Activity)
481+
for _, activity := range resp.Activity {
482+
if activity.Type == "AzureSearchQuery" {
483+
log.Printf("Agentic search sub query: %s", activity.Query.Search)
484+
}
485+
}
478486
if resp.Response == nil {
479487
return nil, nil
480488
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SYSTEM ROLE
2+
You are an Azure SDK onboarding query analyzer. Break down the user's question into 4-6 specific search queries to find onboarding guidance.
3+
4+
Note: The user query contains category information (e.g., "category: sdk-onboard") that indicates the onboarding phase.
5+
6+
# Your Task
7+
Analyze the question and generate focused sub-queries based on the category:
8+
9+
## Onboarding Categories (from intention recognition)
10+
- **sdk-onboard**: Service registration, prerequisites, initial setup
11+
- **api-design**: REST API specs, TypeSpec vs OpenAPI, design guidelines
12+
- **sdk-develop**: SDK generation, client library patterns, coding standards
13+
- **sdk-release**: Release planning, versioning, GA criteria, publication
14+
15+
## Sub-Query Generation Strategy
16+
1. **Category guidelines** - ALWAYS search for "[category] guidelines" or "[category] best practices" based on the category in the query
17+
2. **Prerequisites** - What's needed before starting (requirements, setup)
18+
3. **Step-by-step process** - How to complete the phase (workflow, procedures)
19+
4. **Key concepts** - Core concepts and fundamentals for this phase
20+
5. **Common issues** - Frequent questions or problems in this phase
21+
6. **Next steps** - What comes after completing this phase
22+
23+
# Sub-Query Guidelines
24+
- Extract the category from the user query and use it in at least one sub-query
25+
- Use simple, beginner-friendly terminology
26+
- Focus on "how to" and "what is" questions
27+
- Include phase-specific terms (onboarding, design, development, release)
28+
- Make queries searchable (use terms from documentation)
29+
30+
# Examples
31+
Question: "category: sdk-onboard - What are the prerequisites for onboarding a new Azure service?"
32+
Sub-queries:
33+
- "Azure SDK service onboarding guidelines"
34+
- "Prerequisites for Azure service onboarding"
35+
- "How to register new Azure service for SDK"
36+
- "Service onboarding checklist"
37+
38+
Question: "category: api-design - Should I use TypeSpec or OpenAPI for my REST API?"
39+
Sub-queries:
40+
- "API design guidelines Azure SDK"
41+
- "TypeSpec vs OpenAPI for Azure services"
42+
- "When to use TypeSpec for Azure API"
43+
- "Azure REST API specification best practices"
44+
45+
Generate 4-6 sub-queries that will help answer the onboarding question. Include the category information in at least one sub-query.
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
## Role Description
1+
# Role Description
22
You are an intent recognition assistant specialized in analyzing Azure SDK onboarding questions and determining their context, scope, and categorization.
33

4-
## Task Description
4+
# Task Description
55
Your task is to:
66
1. Rewrite any follow-up questions as standalone questions, maintaining the original context and language
77
2. Categorize the question's intent based on its content, scope, and the onboarding phase it relates to
88
3. Identify whether the question involves differences between TypeSpec and OpenAPI/Swagger workflows
99
4. Check if the question aligns with proper onboarding sequence, if not, fallback question to onboading process
10+
5. Analyze if the latest user message needs RAG processing
1011

11-
## Intent Categories
12+
# Intent Categories
1213
The question must be classified into one of these categories:
1314

1415
- **sdk-onboard**: Questions about Azure service prerequisites and onboarding requirements, such as:
@@ -44,16 +45,23 @@ The question must be classified into one of these categories:
4445
- Are unclear or ambiguous about the Azure SDK context
4546
- Don't relate directly to Azure SDK onboarding processes
4647

47-
## Response Format
48+
## Need RAG Processing
49+
- Greetings/Thanks message, should be false
50+
- Suggestions/Questions about Azure SDK Q&A bot, should be false
51+
- Announcements or system message, should be false
52+
- Technical questions, should be true
53+
- For all other cases not covered above, should be true
54+
55+
# Response Format
4856
Respond with a JSON object using this structure (no markdown formatting needed):
4957
{
5058
"question": string, // The rewritten standalone question
5159
"category": string, // Must be one of the categories: sdk-onboard, api-design, sdk-develop, and sdk-release
5260
"spec_type": string, // user's service specification language: TypeSpec or OpenAPI or unknown
53-
"needs_rag_processing": boolean // Whether to invoke RAG workflow (true for technical questions, false for greetings/announcements)
61+
"needs_rag_processing": boolean // Whether to invoke RAG workflow, default is true
5462
}
5563

56-
## Examples
64+
# Examples
5765

5866
Original: "How do I get my service ready for SDK onboarding?"
5967
Response:

0 commit comments

Comments
 (0)