Skip to content

Instantly share code, notes, and snippets.

@ruvnet
Last active May 3, 2025 16:21
Show Gist options
  • Save ruvnet/88c61ee4e38191b0be65f498792d5017 to your computer and use it in GitHub Desktop.
Save ruvnet/88c61ee4e38191b0be65f498792d5017 to your computer and use it in GitHub Desktop.
a specialized research assistant that leverages Perplexity AI to conduct deep, comprehensive research on any topic, creating structured documentation and reports through a recursive self-learning approach.
{
"slug": "deep-research",
"name": "🔍 Deep Research Mode",
"roleDefinition": "You are a specialized research assistant that leverages Perplexity AI to conduct deep, comprehensive research on any topic, creating structured documentation and reports through a recursive self-learning approach.",
"customInstructions": "You use Perplexity AI's advanced search capabilities to retrieve detailed, accurate information and organize it into a comprehensive research documentation system writing to a research sub folder and final report sub folder with ToC and multiple md files. You:\n\n• Craft precise queries to extract domain-specific information\n• Provide structured, actionable research with proper citations\n• Validate information across multiple sources\n• Create a hierarchical documentation structure\n• Implement recursive self-learning to refine and expand research\n\n## Research Documentation Structure\n\nFor each research project, create the following folder structure:\n\n```\nresearch/\n├── 01_initial_queries/\n│ ├── 01_scope_definition.md\n│ ├── 02_key_questions.md\n│ └── 03_information_sources.md\n├── 02_data_collection/\n│ ├── 01_primary_findings.md\n│ ├── 02_secondary_findings.md\n│ └── 03_expert_insights.md\n├── 03_analysis/\n│ ├── 01_patterns_identified.md\n│ ├── 02_contradictions.md\n│ └── 03_knowledge_gaps.md\n├── 04_synthesis/\n│ ├── 01_integrated_model.md\n│ ├── 02_key_insights.md\n│ └── 03_practical_applications.md\n└── 05_final_report/\n ├── 00_table_of_contents.md\n ├── 01_executive_summary.md\n ├── 02_methodology.md\n ├── 03_findings.md\n ├── 04_analysis.md\n ├── 05_recommendations.md\n └── 06_references.md\n```\n\n## Recursive Self-Learning Approach\n\n1. **Initial Research Phase**: Begin with broad queries to establish baseline knowledge\n2. **Knowledge Gap Identification**: Document unanswered questions and areas needing deeper exploration\n3. **Targeted Research Cycles**: Use findings from each cycle to inform more specific queries\n4. **Cross-Validation**: Compare information across sources to identify consensus and contradictions\n5. **Synthesis & Integration**: Combine findings into cohesive models and actionable insights\n6. **Documentation**: Update all relevant markdown files with new findings at each stage\n7. **Refinement**: Continuously improve research based on accumulated knowledge\n\nWhen using the Perplexity MCP tool:\n• Set appropriate system prompts to guide the AI's response format\n• Structure queries to build on previous findings\n• Request citations to verify information sources\n• Adjust temperature settings based on the research phase (lower for factual queries, higher for exploratory)\n• Use findings from each query to inform subsequent research directions\n\nExample usage:\n```\n<use_mcp_tool>\n <server_name>perplexityai</server_name>\n <tool_name>PERPLEXITYAI_PERPLEXITY_AI_SEARCH</tool_name>\n <arguments>\n {\n \"systemContent\": \"You are a specialized research assistant. Provide detailed, actionable information with citations. Structure your response with clear headings and bullet points.\",\n \"userContent\": \"Based on our previous findings about [topic], what are the key considerations for [specific aspect]?\",\n \"temperature\": 0.3,\n \"return_citations\": true\n }\n </arguments>\n</use_mcp_tool>\n```",
"groups": [
"mcp",
"edit"
],
"source": "project"
}
{
"mcpServers": {
"perplexityai": {
"url": "https://mcp.composio.dev/composio/server/replace_with_your_composio_server_id",
"alwaysAllow": [
"PERPLEXITYAI_PERPLEXITY_AI_SEARCH"
]
}
}
}

Perplexity AI MCP Integration

introduction: This document outlines the integration of Perplexity AI's MCP with Roo Code's Deep Research Mode. The goal is to create an autonomous research-build-optimize workflow that leverages advanced AI capabilities for efficient and effective software development.

Implementing Autonomous Deep Research with Roo Code + Perplexity MCP

The Deep Research Mode in Roo Code combined with Perplexity MCP enables a powerful autonomous research-build-optimize workflow that can transform complex research tasks into actionable insights and functional implementations.

Overview

Autonomous Deep Research is a methodology that combines:

  1. Structured Research Process: A hierarchical approach to information gathering and analysis
  2. Recursive Self-Learning: Continuous refinement of knowledge through iterative research cycles
  3. Code Implementation: Automatic translation of research findings into functional code
  4. Optimization Loops: Continuous improvement based on new discoveries and feedback

This integration allows for end-to-end automation of the research-to-implementation pipeline, significantly reducing the time and effort required to transform domain knowledge into working solutions.

Architecture

┌─────────────────────────┐     ┌─────────────────────────┐     ┌─────────────────────────┐
│                         │     │                         │     │                         │
│  Perplexity MCP Server  │────▶│    Deep Research Mode   │────▶│     Code Generation     │
│                         │     │                         │     │                         │
└─────────────────────────┘     └─────────────────────────┘     └─────────────────────────┘
          ▲                               │                               │
          │                               │                               │
          └───────────────────────────────┼───────────────────────────────┘
                                          │
                                          ▼
                              ┌─────────────────────────┐
                              │                         │
                              │  Structured Knowledge   │
                              │       Repository        │
                              │                         │
                              └─────────────────────────┘

PERPLEXITYAI_PERPLEXITY_AI_SEARCH

Perplexity AI search interfaces with Perplexity AI to perform search queries and return responses from a range of models. This action manages requests to Perplexity AI and processes the resulting completions, which may include text, citations, and images based on selected models and settings. Key features include: autoprompting to enhance and refine queries, choice of AI models for various content and performance requirements, temperature settings to manage response randomness, top k and top p filters to fine-tune response generation. Beta features include citations and images in results, and response streaming for dynamic interaction. Note: the parameters 'presence penalty' and 'frequency penalty' are mutually exclusive and cannot be used simultaneously.

Parameters

Parameter Description Example Values
frequency_penalty Multiplicative penalty for new tokens based on their frequency in the text to avoid repetition. Mutually exclusive with the 'presence_penalty' parameter. 0.5, 1.0, 1.5
max_tokens The maximum number of tokens to generate. Sum of max_tokens and prompt tokens should not exceed the model's context window limit. Unspecified leads to generation until stop token or context window end. 100, 150, 200
model The name of the model to use for generating completions. Choose a model based on the desired balance between performance and resource usage. For more information check https://docs.perplexity.ai/guides/model-cards -
presence_penalty Penalty for new tokens based on their current presence in the text, encouraging topic variety. Mutually exclusive with the 'frequency_penalty' parameter. -2.0, 0.0, 2.0
return_citations Whether to include citations in the model's response. Citations feature is in closed beta. True, False
return_images Whether to include images in the model's response. Image generation feature is in closed beta. True, False
stream Whether to stream the response incrementally using server-sent events. True, False
systemContent* The system's Content for specifying instructions. "Be precise and concise.", "Be elaborate and descriptive"
temperature Controls generation randomness, with 0 being deterministic and values approaching 2 being more random. 0.0, 0.7, 1.5
top_k Limits the number of high-probability tokens to consider for generation. Set to 0 to disable. 0, 40, 80
top_p Nucleus sampling threshold, controlling the token selection pool based on cumulative probability. 0.1, 0.9, 1.0
userContent* The user's Content for asking questions or providing input. "How many stars are there in our galaxy?"

*Required parameters

Implementation Workflow

1. Research Phase

The Deep Research Mode uses Perplexity MCP to gather information through a structured process:

// Example: Initial research query
const initialResearch = await useMcpTool({
  serverName: "perplexityai",
  toolName: "PERPLEXITYAI_PERPLEXITY_AI_SEARCH",
  arguments: {
    systemContent: "You are a specialized research assistant focusing on [domain]. Provide detailed information with citations.",
    userContent: "What are the key concepts, frameworks, and best practices in [specific topic]?",
    temperature: 0.3,
    return_citations: true
  }
});

// Store findings in structured knowledge repository
await storeResearchFindings({
  phase: "initial_queries",
  topic: "key_concepts",
  content: initialResearch.result,
  citations: initialResearch.citations
});

2. Knowledge Gap Identification

The system automatically identifies areas requiring deeper exploration:

// Example: Identify knowledge gaps
const knowledgeGaps = await analyzeResearchFindings({
  currentKnowledge: researchRepository.getAllFindings(),
  requiredKnowledge: projectRequirements.getKnowledgeDomains()
});

// Generate targeted follow-up queries
for (const gap of knowledgeGaps) {
  const followUpResearch = await useMcpTool({
    serverName: "perplexityai",
    toolName: "PERPLEXITYAI_PERPLEXITY_AI_SEARCH",
    arguments: {
      systemContent: "You are investigating a specific aspect of [domain]. Focus on providing detailed technical information.",
      userContent: `Regarding ${gap.topic}, what are the specific implementation details, challenges, and solutions?`,
      temperature: 0.2,
      return_citations: true
    }
  });
  
  // Update knowledge repository
  await storeResearchFindings({
    phase: "targeted_research",
    topic: gap.topic,
    content: followUpResearch.result,
    citations: followUpResearch.citations
  });
}

3. Implementation Phase

Once sufficient knowledge is gathered, the system transitions to code generation:

// Example: Generate implementation based on research
const implementationPlan = await synthesizeResearchFindings({
  findings: researchRepository.getAllFindings(),
  targetFramework: projectRequirements.framework,
  architecturalPattern: projectRequirements.architecture
});

// Generate code implementation
const codeImplementation = await generateCode({
  plan: implementationPlan,
  language: projectRequirements.language,
  testDriven: true
});

// Write implementation to files
await writeImplementation(codeImplementation);

4. Optimization Loop

The system continuously improves the implementation through further research:

// Example: Identify optimization opportunities
const optimizationOpportunities = await analyzeImplementation({
  code: codeImplementation,
  metrics: ["performance", "maintainability", "security"]
});

// Research optimization techniques
for (const opportunity of optimizationOpportunities) {
  const optimizationResearch = await useMcpTool({
    serverName: "perplexityai",
    toolName: "PERPLEXITYAI_PERPLEXITY_AI_SEARCH",
    arguments: {
      systemContent: "You are an optimization specialist. Provide specific techniques to improve code.",
      userContent: `What are the best practices for optimizing ${opportunity.aspect} in ${projectRequirements.language}?`,
      temperature: 0.3,
      return_citations: true
    }
  });
  
  // Apply optimizations
  const optimizedCode = await applyOptimizations({
    code: codeImplementation,
    optimizationTechniques: optimizationResearch.result,
    aspect: opportunity.aspect
  });
  
  // Update implementation
  await updateImplementation(optimizedCode);
}

Folder Structure

The Autonomous Deep Research workflow creates a comprehensive documentation and implementation structure:

project/
├── research/
│   ├── 01_initial_queries/
│   │   ├── 01_scope_definition.md
│   │   ├── 02_key_questions.md
│   │   └── 03_information_sources.md
│   ├── 02_data_collection/
│   │   ├── 01_primary_findings.md
│   │   ├── 02_secondary_findings.md
│   │   └── 03_expert_insights.md
│   ├── 03_analysis/
│   │   ├── 01_patterns_identified.md
│   │   ├── 02_contradictions.md
│   │   └── 03_knowledge_gaps.md
│   ├── 04_synthesis/
│   │   ├── 01_integrated_model.md
│   │   ├── 02_key_insights.md
│   │   └── 03_practical_applications.md
│   └── 05_final_report/
│       ├── 00_table_of_contents.md
│       ├── 01_executive_summary.md
│       ├── 02_methodology.md
│       ├── 03_findings.md
│       ├── 04_analysis.md
│       ├── 05_recommendations.md
│       └── 06_references.md
├── implementation/
│   ├── src/
│   │   ├── core/
│   │   ├── modules/
│   │   └── utils/
│   ├── tests/
│   │   ├── unit/
│   │   └── integration/
│   └── docs/
│       ├── api/
│       └── usage/
└── optimization/
    ├── benchmarks/
    ├── profiles/
    └── improvements/

Best Practices

  1. Start with Clear Scope Definition: Define the research boundaries and specific questions to investigate.

  2. Use Appropriate Temperature Settings:

    • Lower temperatures (0.1-0.3) for factual research and technical details
    • Medium temperatures (0.4-0.7) for synthesis and analysis
    • Higher temperatures (0.8+) for creative problem-solving and ideation
  3. Implement Progressive Research Cycles:

    • Begin with broad queries to establish baseline knowledge
    • Follow with increasingly specific queries based on findings
    • Cross-validate information across multiple research cycles
  4. Maintain Traceability:

    • Document the source of each insight and implementation decision
    • Link code implementations back to research findings
    • Create clear documentation of the reasoning behind design choices
  5. Leverage Recursive Self-Learning:

    • Use findings from each research cycle to inform subsequent queries
    • Continuously refine the research focus based on emerging patterns
    • Identify and resolve contradictions through targeted investigation

Example: Implementing a Domain-Specific Solution

// Step 1: Initial domain research
const domainResearch = await useMcpTool({
  serverName: "perplexityai",
  toolName: "PERPLEXITYAI_PERPLEXITY_AI_SEARCH",
  arguments: {
    systemContent: "You are a domain expert in [field]. Provide comprehensive information about core concepts.",
    userContent: "What are the fundamental principles, algorithms, and data structures used in [domain]?",
    temperature: 0.3,
    return_citations: true
  }
});

// Step 2: Identify implementation approaches
const implementationApproaches = await useMcpTool({
  serverName: "perplexityai",
  toolName: "PERPLEXITYAI_PERPLEXITY_AI_SEARCH",
  arguments: {
    systemContent: "You are a technical architect specializing in [domain] implementations.",
    userContent: "What are the most efficient ways to implement [specific algorithm] in [language]? Compare approaches in terms of performance, maintainability, and scalability.",
    temperature: 0.4,
    return_citations: true
  }
});

// Step 3: Generate implementation
const implementation = generateImplementation({
  domain: domainResearch.result,
  approaches: implementationApproaches.result,
  language: projectConfig.language,
  framework: projectConfig.framework
});

// Step 4: Test and optimize
const optimizationResearch = await useMcpTool({
  serverName: "perplexityai",
  toolName: "PERPLEXITYAI_PERPLEXITY_AI_SEARCH",
  arguments: {
    systemContent: "You are a performance optimization expert for [language/framework].",
    userContent: "What specific optimizations can be applied to improve the performance of [implementation approach] in [specific context]?",
    temperature: 0.3,
    return_citations: true
  }
});

// Apply optimizations and finalize
const optimizedImplementation = applyOptimizations({
  code: implementation,
  optimizations: optimizationResearch.result
});

// Document the entire process
generateDocumentation({
  research: [domainResearch, implementationApproaches, optimizationResearch],
  implementation: optimizedImplementation,
  decisionPoints: implementationDecisions,
  performanceMetrics: benchmarkResults
});

Conclusion

The integration of Roo Code's Deep Research Mode with Perplexity MCP creates a powerful autonomous research and implementation system. This approach enables:

  1. Comprehensive Research: Thorough exploration of domains with proper citation and validation
  2. Knowledge-Driven Implementation: Code that directly reflects the latest research findings
  3. Continuous Optimization: Ongoing improvement based on emerging best practices
  4. Complete Documentation: Detailed records of the entire research-to-implementation process

By leveraging this integration, developers can rapidly transform complex domain knowledge into optimized, well-documented implementations while maintaining a clear trace from research insights to code decisions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment