multi-agent-doc-research
Copilot instructions12 starsChanged 12 months agoMITView on GitHub
This is a dual-orchestration multi-agent research system that uses both Microsoft Agent Framework (AFW) and Semantic Kernel (SK) to perform deep document research with specialized AI agents. Critical: Both orchestrators provide identical interfaces but different implementation strategies. AFW is event-driven; SK is function-calli
- Reads credentials
- Installs packages
The file
Show its rules and text
We split this copilot-instructions.md into the rules it gives an agent
26 rules. About 0 are common, 18 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈18
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 5
Write clear and concise comments for each function.
- Distinctive: line 6
Ensure functions have descriptive names and include type hints.
- Very specific: line 8
Use the typing module for type annotations (e.g., List[str], Dict[str, int]).
- Distinctive: line 13
Always prioritize readability and clarity.
- Distinctive: line 15
Write code with good maintainability practices, including comments on why certain design decisions were made.
- Distinctive: line 18
Use consistent naming conventions and follow language-specific best practices.
- Distinctive: line 19
Write concise, efficient, and idiomatic code that is also easily understandable.
- Distinctive: line 20
Write comments in English
- Distinctive: line 21
Write README.md files in English
- Distinctive: line 26
Follow the PEP 8 style guide for Python.
- Distinctive: line 28
Ensure lines do not exceed 79 characters.
- Very specific: line 29
Place function and class docstrings immediately after the def or class keyword.
- Distinctive: line 30
Use blank lines to separate functions, classes, and code blocks where appropriate.
- Distinctive: line 34
Always include test cases for critical paths of the application.
- Distinctive: line 37
Write unit tests for functions and document them with docstrings explaining the test cases.
- Very specific: line 119
SK Plugin: Add @kernel_function methods, use KernelArguments for parameters
- Distinctive: line 123
Use GroupChat: when: Fixed writer-reviewer workflow, speed prioritized, 💰 medium tokens
- Distinctive: line 124
Use Magentic: when: Complex multi-step reasoning needed, quality over speed, 💰💰 high tokens
- Distinctive: line 132
All orchestrators yield base64-encoded messages:
- Very specific: line 146
Search Engines: Use SearchEngine enum from utils/enum.py
- Very specific: line 147
Localization: Check i18n/locale_msg.py for UI text
- Distinctive: line 204
Mixing orchestrators: Don't call AFW executors from SK plugins or vice versa
- Very specific: line 205
Prompt loading: Always use load_prompt() from langchain, not raw file reads
- Distinctive: line 206
Streaming: Must yield string chunks; never return complete responses in streaming mode
- Very specific: line 207
Timezone: Use settings.TIME_ZONE (default: "Asia/Seoul") for timestamps
- Very specific: line 209
File uploads: Use UnifiedFileUploadPlugin which handles semantic/page chunking via PROCESSING_METHOD env var
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Python Coding Conventions
Python Instructions
- Write clear and concise comments for each function.
- Ensure functions have descriptive names and include type hints.
- Provide docstrings following PEP 257 conventions.
- Use the
typingmodule for type annotations (e.g.,List[str],Dict[str, int]). - Break down complex functions into smaller, more manageable functions.
General Instructions
- Always prioritize readability and clarity.
- For algorithm-related code, include explanations of the approach used.
- Write code with good maintainability practices, including comments on why certain design decisions were made.
- Handle edge cases and write clear exception handling.
- For libraries or external dependencies, mention their usage and purpose in comments.
- Use consistent naming conventions and follow language-specific best practices.
- Write concise, efficient, and idiomatic code that is also easily understandable.
- Write comments in English
- Write README.md files in English
- Generate all documentation in English
Code Style and Formatting
- Follow the PEP 8 style guide for Python.
- Maintain proper indentation (use 4 spaces for each level of indentation).
- Ensure lines do not exceed 79 characters.
- Place function and class docstrings immediately after the
deforclasskeyword. - Use blank lines to separate functions, classes, and code blocks where appropriate.
Edge Cases and Testing
- Always include test cases for critical paths of the application.
- Account for common edge cases like empty inputs, invalid data types, and large datasets.
- Include comments for edge cases and the expected behavior in those cases.
- Write unit tests for functions and document them with docstrings explaining the test cases.
Example of Proper Documentation
def calculate_area(radius: float) -> float:
"""
Calculate the area of a circle given the radius.
Parameters:
radius (float): The radius of the circle.
Returns:
float: The area of the circle, calculated as π * radius^2.
"""
import math
return math.pi * radius ** 2Multi-Agent Doc Research - AI Agent Instructions
Architecture Overview
This is a dual-orchestration multi-agent research system that uses both Microsoft Agent Framework (AFW) and Semantic Kernel (SK) to perform deep document research with specialized AI agents.
Core Workflow Pattern
User Query → Intent Analysis → Task Planning → Multi-Source Search → Multi-Agent Collaboration → Response
├─ Web Search (Bing)
├─ AI Search (Azure AI Search)
└─ YouTube Search (MCP Server)Dual Orchestration Architectures
1. Agent Framework (services_afw/) - Production Pattern
- Pattern: Executor-based workflow with
@handlermethods - Key Classes:
IntentAnalyzerExecutor,TaskPlannerExecutor,ResponseGeneratorExecutor - Agent Patterns:
GroupChattingExecutor: Writer ↔ Reviewer approval loop (3-5 rounds)MagenticExecutor: Intelligent orchestration with dynamic agent coordination (Orchestrator → ResearchAnalyst/Writer/Reviewer)
- Workflow: Uses
WorkflowBuilderwithctx.send_message()for inter-executor communication - Entry:
PlanSearchOrchestratorAFW.generate_response()indoc_research_orchestrator_afw.py
2. Semantic Kernel (services_sk/) - Alternative Implementation
- Pattern: Plugin-based with
@kernel_functiondecorators - Key Classes:
IntentPlanPlugin,GroupChattingPlugin,MagenticPlugin - Integration: Uses
Kernelobject withAzureChatCompletionservice - Entry:
PlanSearchOrchestratorSK.generate_response()indoc_research_orchestrator_sk.py
Critical: Both orchestrators provide identical interfaces but different implementation strategies. AFW is event-driven; SK is function-calling based.
Project Structure Conventions
Backend Organization (app/backend/)
services_afw/ # Agent Framework executors (preferred)
services_sk/ # Semantic Kernel plugins (alternative)
prompts/ # YAML prompt templates (shared by both)
config/config.py # Pydantic Settings with .env loading
model/models.py # Pydantic models for API contracts
utils/ # Shared utilities (enum.py, json_control.py, yield_message.py)
tests/ # pytest-based tests
evals/ # Azure AI Evaluation with batch_eval.pyPrompt Management
- All prompts are YAML files in
prompts/directory - Load using:
load_prompt(path, encoding="utf-8") - Naming:
{purpose}_{role}_prompt.yaml(e.g.,research_writer_prompt.yaml) - Bilingual support:
_kr.yamlsuffix for Korean variants
Frontend (app/frontend/)
- Framework: Chainlit 2.8.0 (not Gradio/Streamlit)
- Entry:
src/app.py - Pattern: Async event handlers with
@cl.on_message,@cl.on_chat_start - API Communication: Streaming via
aiohttpwith SSE to backend FastAPI
Critical Development Patterns
Adding New Executors/Plugins
- AFW Executor: Inherit from
Executor, add@handlermethods, usectx.send_message()for workflow - SK Plugin: Add
@kernel_functionmethods, useKernelArgumentsfor parameters - Both must: Accept
settings: Settings, implement async streaming, handle errors gracefully
Multi-Agent Pattern Selection
- Use GroupChat when: Fixed writer-reviewer workflow, speed prioritized, 💰 medium tokens
- Use Magentic when: Complex multi-step reasoning needed, quality over speed, 💰💰 high tokens
- Configuration: Via
multi_agent_typeparameter inPlanSearchRequest"afw_group_chat"→GroupChattingExecutor"afw_magentic"→MagenticExecutor"sk_group_chat"→ SK equivalent"vanilla"→ Direct AOAI SDK without agents
Streaming Response Protocol
All orchestrators yield base64-encoded messages:
yield f"### {step_name}#input#{description}" # Progress update
yield f"### {step_name}#code#{base64_encoded_content}" # Code/markdown content
yield "actual_token_content" # Stream tokensFrontend decodes with decode_step_content() in app_utils.py.
Configuration Management
- Never hardcode: Load from
Settings(backed by.env) - Azure OpenAI: Multiple deployments for different tasks
AZURE_OPENAI_DEPLOYMENT_NAME→ Main chatAZURE_OPENAI_QUERY_DEPLOYMENT_NAME→ Query rewritingAZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME→ Document vectorization
- Search Engines: Use
SearchEngineenum fromutils/enum.py - Localization: Check
i18n/locale_msg.pyfor UI text
Testing & Evaluation
Running Tests
cd app/backend
pytest tests/ -v # All tests
pytest tests/test_file_upload_system.py # File upload onlyBatch Evaluation
cd app/backend/evals
python batch_eval.py --input data/RTF_queries.csv --max_concurrent 3 --temperature 0.5- Uses Azure AI Evaluation SDK:
RelevanceEvaluator,SimilarityEvaluator,RetrievalEvaluator - Results saved to
results/with timestamped JSON/matplotlib plots
Local Development Workflow
Backend Setup
cd app/backend
uv venv .venv --python 3.12 --seed
source .venv/bin/activate
uv pip install -e ".[dev]"
cp .env.example .env # Configure Azure credentials
uv run run.py # Starts on http://localhost:8000Frontend Setup
cd app/frontend
./run_app.sh # Starts Chainlit on http://localhost:7860Environment Variables Required
See .env.example for full list. Critical ones:
AZURE_OPENAI_*(API key, endpoint, deployments)AZURE_AI_SEARCH_*(for document search)AZURE_DOCUMENT_INTELLIGENCE_*(for PDF processing)BING_API_KEY(optional, for web search)
Deployment
Azure Container Apps (Bicep)
cd infra
./deploy.sh # Deploys to Azure Container Apps- Identity: Uses
main_aca_identity_exist.bicepif managed identity exists - Resources: Log Analytics → Container App Environment → Backend + Frontend apps
- Configuration: Edit
main.parameters.jsonbefore deploying
Common Pitfalls
- Mixing orchestrators: Don't call AFW executors from SK plugins or vice versa
- Prompt loading: Always use
load_prompt()from langchain, not raw file reads - Streaming: Must yield string chunks; never return complete responses in streaming mode
- Timezone: Use
settings.TIME_ZONE(default: "Asia/Seoul") for timestamps - Logging: SK agents are noisy; see
main.pyfor logger silencing pattern - File uploads: Use
UnifiedFileUploadPluginwhich handles semantic/page chunking viaPROCESSING_METHODenv var
Key Dependencies
- agent-framework: 1.0.0b251112 (MS Agent Framework)
- semantic-kernel: 1.37.0 (MS Semantic Kernel)
- chainlit: 2.8.0 (Frontend)
- fastapi: 0.103.0+ (Backend API)
- azure-ai-evaluation: 1.11.0 (Evaluation)
- azure-search-documents: 11.5.3 (Document search)
- langchain: 0.3.25 (Prompt management)
When to Use What
| Task | Tool/Pattern |
| Add new search source | Create Executor in services_afw/ with @handler |
| Modify agent behavior | Edit YAML prompts in prompts/ |
| Change orchestration flow | Modify PlanSearchOrchestratorAFW.generate_response() |
| Add evaluation metric | Extend batch_eval.py with new Azure evaluator |
| Debug streaming | Check yield_message.py utilities and base64 encoding |
| Add UI feature | Edit Chainlit handlers in app/frontend/src/app.py |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

