Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add deep research use case (Python) #482

Merged
merged 27 commits into from
Jan 22, 2025
Merged

Conversation

leehuwuj
Copy link
Collaborator

@leehuwuj leehuwuj commented Jan 17, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced deep research workflow for analyzing personal documents
    • Added support for conducting in-depth research using multi-agent system
    • Enhanced chat interface with new deep research event visualization
  • Improvements

    • Updated dependency versions for better compatibility
    • Expanded template use cases and application types
    • Improved event streaming and background task handling
  • Documentation

    • Added README template for deep research project setup
    • Included detailed workflow and configuration instructions

Copy link

changeset-bot bot commented Jan 17, 2025

🦋 Changeset detected

Latest commit: c2136e5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
create-llama Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

coderabbitai bot commented Jan 17, 2025

Warning

Rate limit exceeded

@leehuwuj has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 22 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between dd7e79d and c2136e5.

📒 Files selected for processing (1)
  • templates/components/agents/python/deep_research/app/workflows/deep_research.py (1 hunks)

Walkthrough

This pull request introduces a comprehensive enhancement for deep research functionality across multiple components. The changes span various files and technologies, adding a new "deep_research" application type with support for multi-agent document analysis workflows. The implementation includes Python backend components for research planning, frontend React components for displaying research progress, and updated type definitions to support the new use case.

Changes

File Change Summary
helpers/datasources.ts Added AI_REPORTS constant for PDF data source
package.json Updated @types/prompts dependency version
questions/simple.ts Added "deep_research" application type with new prompt options
helpers/types.ts Added "deep_research" to TemplateUseCase type
templates/components/multiagent/python/app/api/routers/chat.py Updated chat function to include background tasks
templates/components/multiagent/python/app/workflows/events.py Added SourceNodesEvent class
templates/types/streaming/nextjs/... Added DeepResearchCard component for chat UI

Sequence Diagram

sequenceDiagram
    participant User
    participant ChatUI
    participant WorkflowEngine
    participant ResearchAgents
    participant DocumentIndex

    User->>ChatUI: Initiate Deep Research
    ChatUI->>WorkflowEngine: Start Workflow
    WorkflowEngine->>DocumentIndex: Retrieve Relevant Documents
    DocumentIndex-->>WorkflowEngine: Return Context Nodes
    WorkflowEngine->>ResearchAgents: Plan Research
    ResearchAgents-->>WorkflowEngine: Generate Research Questions
    WorkflowEngine->>ResearchAgents: Execute Research
    ResearchAgents->>DocumentIndex: Answer Questions
    ResearchAgents-->>WorkflowEngine: Compile Answers
    WorkflowEngine->>ChatUI: Stream Research Progress
    WorkflowEngine->>ChatUI: Generate Final Report
Loading

Possibly related PRs

Suggested reviewers

  • marcusschiesser

Poem

🐰 A Rabbit's Research Rhyme 🔍

Through documents deep and wide I hop,
Gathering knowledge, I never stop!
Agents dancing, questions bright,
Insights gleaming with pure delight!
Research magic, now complete! 📚✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

helpers/python.ts Outdated Show resolved Hide resolved
@leehuwuj leehuwuj marked this pull request as ready for review January 21, 2025 04:31
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (8)
templates/components/agents/python/blog/app/workflows/agents.py (1)

34-57: Adjust Indentation in Multi-Line Prompt String

The prompt string in analyze_prompt has inconsistent indentation, which may lead to formatting issues in the generated prompt. Consider adjusting the indentation to ensure the prompt is correctly formatted.

Apply this diff to fix the indentation:

 analyze_prompt = PromptTemplate(
-    """
-      You are a professor who is guiding a researcher to research a specific request/problem.
-      Your task is to decide on a research plan for the researcher.
-      The possible actions are:
-      + Provide a list of questions for the researcher to investigate, with the purpose of clarifying the request.
-      + Write a report if the researcher has already gathered enough research on the topic and can resolve the initial request.
-      + Cancel the research if most of the answers from researchers indicate there is insufficient information to research the request. Do not attempt more than 3 research iterations or too many questions.
-      The workflow should be:
-      + Always begin by providing some initial questions for the researcher to investigate.
-      + Analyze the provided answers against the initial topic/request. If the answers are insufficient to resolve the initial request, provide additional questions for the researcher to investigate.
-      + If the answers are sufficient to resolve the initial request, instruct the researcher to write a report.
-      <User request>
-      {user_request}
-      </User request>
-
-      <Collected information>
-      {context_str}
-      </Collected information>
-
-      <Conversation context>
-      {conversation_context}
-      </Conversation context>
-      """
+    """
+You are a professor who is guiding a researcher to research a specific request/problem.
+Your task is to decide on a research plan for the researcher.
+The possible actions are:
+  - Provide a list of questions for the researcher to investigate, with the purpose of clarifying the request.
+  - Write a report if the researcher has already gathered enough research on the topic and can resolve the initial request.
+  - Cancel the research if most of the answers from researchers indicate there is insufficient information to research the request. Do not attempt more than 3 research iterations or too many questions.
+The workflow should be:
+  - Always begin by providing some initial questions for the researcher to investigate.
+  - Analyze the provided answers against the initial topic/request. If the answers are insufficient to resolve the initial request, provide additional questions for the researcher to investigate.
+  - If the answers are sufficient to resolve the initial request, instruct the researcher to write a report.
+
+<User request>
+{user_request}
+</User request>
+
+<Collected information>
+{context_str}
+</Collected information>
+
+<Conversation context>
+{conversation_context}
+</Conversation context>
+"""
 )
templates/components/agents/python/blog/app/workflows/writer.py (2)

114-149: Consider Streaming the Report Generation for Better User Experience

In the write_report function, you have an option to stream the response based on the stream flag. Streaming the report generation can enhance the user experience by allowing the user to receive the content incrementally.


214-249: Limit the Number of Concurrent Workers in answer Step

In the answer step, you have set num_workers=2. Ensure that this limit is appropriate for your application's performance and resource constraints. Increasing the number may improve throughput but could also lead to resource exhaustion.

helpers/datasources.ts (1)

45-53: Consider making the AI reports data source more maintainable.

The hardcoded URL and verbose filename could be improved:

  1. Consider moving the URL to a configuration file for easier updates.
  2. Simplify the filename to something more readable.
 export const AI_REPORTS: TemplateDataSource = {
   type: "file",
   config: {
     url: new URL(
       "https://www.europarl.europa.eu/RegData/etudes/ATAG/2024/760392/EPRS_ATA(2024)760392_EN.pdf",
     ),
-    filename: "EPRS_ATA_2024_760392_EN.pdf",
+    filename: "ai_report_2024.pdf",
   },
 };
templates/types/streaming/nextjs/app/components/ui/chat/custom/writer-card.tsx (1)

59-112: Enhance error handling in state transformation.

The state transformation function could benefit from better error handling:

  1. Add validation for required fields.
  2. Handle potential edge cases.
 const transformState = (
   state: WriterState,
   event: WriterEvent,
 ): WriterState => {
+  if (!event?.data) {
+    return state;
+  }
+
   switch (event.data.event) {
     case "answer": {
       const { id, question, answer } = event.data;
       if (!id || !question) return state;
questions/simple.ts (2)

230-236: Consider adding document generation tools for blog use case.

The blog use case might benefit from document generation tools for creating well-formatted blog posts.

     blog: {
       template: "multiagent",
       useCase: "blog",
-      tools: [],
+      tools: getTools(["document_generator"]),
       frontend: true,
       dataSources: [AI_REPORTS],
     },

98-102: Simplify language selection logic.

Consider using an array or Set for excluded app types to make the code more maintainable.

+const FASTAPI_ONLY_APPS = new Set(["extractor", "contract_review", "blog"]);
+
-  if (
-    appType !== "extractor" &&
-    appType !== "contract_review" &&
-    appType !== "blog"
-  ) {
+  if (!FASTAPI_ONLY_APPS.has(appType)) {
templates/components/agents/python/blog/README-template.md (1)

28-28: Add missing article for better readability.

Add "the" before "generate script" to improve grammar.

-or add your own documents and run generate script again.
+or add your own documents and run the generate script again.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~28-~28: You might be missing the article “the” here.
Context: ...2024, or add your own documents and run generate script again. After starting the serve...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 860b9d4 and df66f07.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (23)
  • helpers/datasources.ts (1 hunks)
  • helpers/types.ts (1 hunks)
  • package.json (1 hunks)
  • questions/simple.ts (5 hunks)
  • templates/components/agents/python/blog/README-template.md (2 hunks)
  • templates/components/agents/python/blog/app/agents/choreography.py (0 hunks)
  • templates/components/agents/python/blog/app/agents/orchestrator.py (0 hunks)
  • templates/components/agents/python/blog/app/agents/publisher.py (0 hunks)
  • templates/components/agents/python/blog/app/agents/researcher.py (0 hunks)
  • templates/components/agents/python/blog/app/agents/workflow.py (0 hunks)
  • templates/components/agents/python/blog/app/workflows/__init__.py (1 hunks)
  • templates/components/agents/python/blog/app/workflows/agents.py (1 hunks)
  • templates/components/agents/python/blog/app/workflows/blog.py (0 hunks)
  • templates/components/agents/python/blog/app/workflows/models.py (1 hunks)
  • templates/components/agents/python/blog/app/workflows/multi.py (0 hunks)
  • templates/components/agents/python/blog/app/workflows/planner.py (0 hunks)
  • templates/components/agents/python/blog/app/workflows/single.py (0 hunks)
  • templates/components/agents/python/blog/app/workflows/writer.py (1 hunks)
  • templates/components/multiagent/python/app/api/routers/chat.py (1 hunks)
  • templates/components/multiagent/python/app/api/routers/vercel_response.py (4 hunks)
  • templates/components/multiagent/python/app/workflows/events.py (2 hunks)
  • templates/types/streaming/nextjs/app/components/ui/chat/chat-message-content.tsx (2 hunks)
  • templates/types/streaming/nextjs/app/components/ui/chat/custom/writer-card.tsx (1 hunks)
💤 Files with no reviewable changes (9)
  • templates/components/agents/python/blog/app/workflows/blog.py
  • templates/components/agents/python/blog/app/agents/orchestrator.py
  • templates/components/agents/python/blog/app/agents/choreography.py
  • templates/components/agents/python/blog/app/agents/researcher.py
  • templates/components/agents/python/blog/app/workflows/multi.py
  • templates/components/agents/python/blog/app/agents/publisher.py
  • templates/components/agents/python/blog/app/workflows/planner.py
  • templates/components/agents/python/blog/app/workflows/single.py
  • templates/components/agents/python/blog/app/agents/workflow.py
✅ Files skipped from review due to trivial changes (1)
  • templates/components/agents/python/blog/app/workflows/init.py
🧰 Additional context used
📓 Path-based instructions (9)
templates/types/streaming/nextjs/app/components/ui/chat/chat-message-content.tsx (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/components/multiagent/python/app/api/routers/chat.py (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/components/multiagent/python/app/workflows/events.py (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/components/agents/python/blog/README-template.md (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/types/streaming/nextjs/app/components/ui/chat/custom/writer-card.tsx (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/components/agents/python/blog/app/workflows/models.py (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/components/multiagent/python/app/api/routers/vercel_response.py (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/components/agents/python/blog/app/workflows/agents.py (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/components/agents/python/blog/app/workflows/writer.py (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

🪛 LanguageTool
templates/components/agents/python/blog/README-template.md

[uncategorized] ~28-~28: You might be missing the article “the” here.
Context: ...2024, or add your own documents and run generate script again. After starting the serve...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)

⏰ Context from checks skipped due to timeout of 90000ms (41)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, express, --llamacloud)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, express, --example-file)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, express, --no-files)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --llamacloud)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --example-file)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --no-files)
  • GitHub Check: typescript (20, 3.11, windows-latest, express, --llamacloud)
  • GitHub Check: typescript (20, 3.11, windows-latest, express, --example-file)
  • GitHub Check: typescript (20, 3.11, windows-latest, express, --no-files)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --llamacloud)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --example-file)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --no-files)
  • GitHub Check: typescript (20, 3.11, macos-latest, express, --llamacloud)
  • GitHub Check: typescript (20, 3.11, macos-latest, express, --example-file)
  • GitHub Check: typescript (20, 3.11, macos-latest, express, --no-files)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --llamacloud)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --example-file)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --no-files)
  • GitHub Check: typescript (18, 3.11, ubuntu-22.04, express, --llamacloud)
  • GitHub Check: typescript (18, 3.11, ubuntu-22.04, express, --example-file)
  • GitHub Check: typescript (18, 3.11, ubuntu-22.04, express, --no-files)
  • GitHub Check: typescript (18, 3.11, ubuntu-22.04, nextjs, --llamacloud)
  • GitHub Check: typescript (18, 3.11, ubuntu-22.04, nextjs, --example-file)
  • GitHub Check: typescript (18, 3.11, ubuntu-22.04, nextjs, --no-files)
  • GitHub Check: typescript (18, 3.11, windows-latest, express, --llamacloud)
  • GitHub Check: typescript (18, 3.11, windows-latest, express, --example-file)
  • GitHub Check: typescript (18, 3.11, windows-latest, express, --no-files)
  • GitHub Check: typescript (18, 3.11, windows-latest, nextjs, --llamacloud)
  • GitHub Check: typescript (18, 3.11, windows-latest, nextjs, --example-file)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --llamacloud)
  • GitHub Check: typescript (18, 3.11, windows-latest, nextjs, --no-files)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --example-file)
  • GitHub Check: typescript (18, 3.11, macos-latest, express, --example-file)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --llamacloud)
  • GitHub Check: typescript (18, 3.11, macos-latest, express, --no-files)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --example-file)
  • GitHub Check: typescript (18, 3.11, macos-latest, nextjs, --llamacloud)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --no-files)
  • GitHub Check: typescript (18, 3.11, macos-latest, nextjs, --example-file)
  • GitHub Check: typescript (18, 3.11, macos-latest, nextjs, --no-files)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --example-file)
🔇 Additional comments (17)
templates/components/multiagent/python/app/api/routers/vercel_response.py (1)

91-93: Handle Unexpected Result Types in _chat_response_generator

Make sure that the variable result is always converted to a string before concatenation to final_response and yielding. Verify that result is of an expected type to prevent potential runtime errors.

templates/components/agents/python/blog/app/workflows/agents.py (1)

156-158: Sanitize Node IDs to Prevent Injection Attacks

When constructing content with node IDs in _get_text_node_content_for_citation, ensure node IDs are properly escaped or sanitized to prevent potential injection attacks if node IDs contain special characters.

[security_issue]

Consider applying input sanitization:

import html

node_id = html.escape(node.node.node_id)
templates/components/agents/python/blog/app/workflows/writer.py (2)

264-270: Verify Correctness of Event Collection in collect_answers

In the collect_answers method, you use ctx.collect_events with an expected list of events based on num_questions. Ensure that num_questions correctly reflects the number of CollectAnswersEvent instances to be collected.


73-90: Initialize Memory with Correct Chat History

In the __init__ method of WriterWorkflow, ensure that the chat history is correctly initialized in the ChatMemoryBuffer. This will help maintain conversation context throughout the workflow.

templates/components/agents/python/blog/app/workflows/models.py (6)

9-10: LGTM! Simple marker event for planning research phase.

The empty event class is appropriate for signaling the start of research planning.


13-16: LGTM! Well-structured research event with proper metadata.

The event captures all necessary data for research tracking:

  • Question ID for referencing
  • Actual question text for readability
  • Context nodes with relevance scores

19-22: LGTM! Consistent answer collection event.

The event maintains symmetry with ResearchEvent for question tracking while adding the answer field.


25-26: LGTM! Simple marker event for report writing phase.

The empty event class is appropriate for signaling the start of report writing.


30-35: LGTM! Well-defined event data model with type safety.

Good use of:

  • Literal types for event and state enums
  • Optional fields for flexible data structure
  • Clear state progression (pending → inprogress → done/error)

38-43: LGTM! Clean event class with proper serialization.

The event properly encapsulates writer card data with a clean serialization method.

templates/components/multiagent/python/app/workflows/events.py (1)

33-45: LGTM! Well-structured source nodes event with clean serialization.

The event properly:

  • Handles source nodes with relevance scores
  • Transforms nodes to a consistent format
  • Provides a clean response structure
templates/types/streaming/nextjs/app/components/ui/chat/chat-message-content.tsx (1)

26-30: LGTM! Clean integration of WriterCard component.

Based on the previous discussion in PR comments, this is a reasonable approach to integrate the writer-specific component while maintaining extensibility for future custom components.

templates/components/multiagent/python/app/api/routers/chat.py (1)

41-41: LGTM! Clean addition of background tasks support.

The background tasks parameter is properly integrated into the endpoint and passed to the response handler.

templates/types/streaming/nextjs/app/components/ui/chat/custom/writer-card.tsx (1)

1-1: Add 'use client' directive.

The component needs the 'use client' directive at the top of the file for Next.js client-side rendering.

+// @ts-expect-error - 'use client' directive
+'use client';
 import { Message } from "@llamaindex/chat-ui";
templates/components/agents/python/blog/README-template.md (2)

1-1: LGTM! Clear and concise introduction.

The introduction effectively communicates that this is a LlamaIndex multi-agents project using Workflows.


26-31: LGTM! Clear usage instructions and example.

The section effectively explains the blog writer use case with a practical example.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~28-~28: You might be missing the article “the” here.
Context: ...2024, or add your own documents and run generate script again. After starting the serve...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)

package.json (1)

46-46: LGTM! Type definitions version update.

The update to @types/prompts version 2.4.2 aligns with the new blog-related type definitions.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
templates/components/agents/python/blog/README-template.md (3)

Line range hint 3-24: Add more details about required environment variables.

While the setup instructions are clear, consider adding a list of required environment variables and their descriptions to help users configure their .env file correctly.

Add a section like this after the dev-container note:

Required environment variables in `.env`:
- `OPENAI_API_KEY`: Your OpenAI API key (required if using OpenAI models)
- Add other required variables here...

26-31: Consider adding more diverse examples.

While the AI investment example is good, providing additional example prompts would help users better understand the range of blog topics they can generate.

Add more examples like:

Example prompts:
- "Write a post about AI investment in 2024"
- "Create a blog post summarizing the key trends in [topic from your documents]"
- "Generate an article analyzing [specific aspect] from the provided documents"

33-33: Add more details about the workflow structure.

Consider expanding this section to help users understand how to customize the workflow. Include information about the WriterWorkflow class and its components.

Add details like:

The `writer.py` file contains the `WriterWorkflow` class that orchestrates:
- Information retrieval from documents
- Content analysis
- Blog post generation

To customize the workflow, you can modify:
- Research parameters
- Analysis criteria
- Output format
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between df66f07 and 8e83568.

📒 Files selected for processing (1)
  • templates/components/agents/python/blog/README-template.md (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
templates/components/agents/python/blog/README-template.md (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

⏰ Context from checks skipped due to timeout of 90000ms (45)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, express, --llamacloud)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, express, --example-file)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, express, --no-files)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --llamacloud)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --example-file)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --no-files)
  • GitHub Check: typescript (20, 3.11, windows-latest, express, --llamacloud)
  • GitHub Check: typescript (20, 3.11, windows-latest, express, --example-file)
  • GitHub Check: typescript (20, 3.11, windows-latest, express, --no-files)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --llamacloud)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --example-file)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --no-files)
  • GitHub Check: typescript (20, 3.11, macos-latest, express, --llamacloud)
  • GitHub Check: typescript (20, 3.11, macos-latest, express, --example-file)
  • GitHub Check: typescript (20, 3.11, macos-latest, express, --no-files)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --llamacloud)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --example-file)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --no-files)
  • GitHub Check: typescript (18, 3.11, ubuntu-22.04, express, --llamacloud)
  • GitHub Check: typescript (18, 3.11, ubuntu-22.04, express, --example-file)
  • GitHub Check: typescript (18, 3.11, ubuntu-22.04, express, --no-files)
  • GitHub Check: typescript (18, 3.11, ubuntu-22.04, nextjs, --llamacloud)
  • GitHub Check: typescript (18, 3.11, ubuntu-22.04, nextjs, --example-file)
  • GitHub Check: typescript (18, 3.11, ubuntu-22.04, nextjs, --no-files)
  • GitHub Check: typescript (18, 3.11, windows-latest, express, --llamacloud)
  • GitHub Check: typescript (18, 3.11, windows-latest, express, --example-file)
  • GitHub Check: typescript (18, 3.11, windows-latest, express, --no-files)
  • GitHub Check: typescript (18, 3.11, windows-latest, nextjs, --llamacloud)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --llamacloud)
  • GitHub Check: typescript (18, 3.11, windows-latest, nextjs, --example-file)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --example-file)
  • GitHub Check: typescript (18, 3.11, windows-latest, nextjs, --no-files)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --no-files)
  • GitHub Check: typescript (18, 3.11, macos-latest, express, --llamacloud)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --llamacloud)
  • GitHub Check: typescript (18, 3.11, macos-latest, express, --example-file)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --example-file)
  • GitHub Check: typescript (18, 3.11, macos-latest, express, --no-files)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --no-files)
  • GitHub Check: typescript (18, 3.11, macos-latest, nextjs, --llamacloud)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --llamacloud)
  • GitHub Check: typescript (18, 3.11, macos-latest, nextjs, --example-file)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --example-file)
  • GitHub Check: typescript (18, 3.11, macos-latest, nextjs, --no-files)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --no-files)
🔇 Additional comments (3)
templates/components/agents/python/blog/README-template.md (3)

1-1: LGTM! Clear and concise introduction.

The introduction effectively communicates the project's purpose and core technologies with proper documentation links.


33-33: File path reference is now correct.

The text and link now consistently refer to writer.py.


Line range hint 35-47: LGTM! Comprehensive resource links.

The deployment reference and learning resources are well-organized and provide valuable links to documentation.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
templates/types/streaming/nextjs/app/components/ui/chat/custom/writer-card.tsx (1)

142-152: ⚠️ Potential issue

Add type safety and error handling for annotations.

The type casting of annotations could lead to runtime errors.

Add error boundary and type guards:

 export function WriterCard({ message, className }: WriterCardProps) {
+  if (!message?.annotations) {
+    return null;
+  }
+
   const writerEvents = message.annotations as WriterEvent[] | undefined;
+  
+  // Add type guard
+  const isWriterEvent = (event: any): event is WriterEvent => {
+    return event?.type === "writer_card" && event?.data?.event;
+  };
+
   const hasWriterEvents = writerEvents?.some(
-    (event) => event.type === "writer_card",
+    isWriterEvent
   );
🧹 Nitpick comments (2)
templates/types/streaming/nextjs/app/components/ui/chat/custom/writer-card.tsx (2)

22-58: Consider using discriminated union types for better type safety.

The event types could be more specific using discriminated unions. This would provide better type safety and autocompletion.

Consider this refactor:

-type WriterEvent = {
+type BaseWriterEvent = {
   type: "writer_card";
+};
+
+type RetrieveEvent = BaseWriterEvent & {
+  data: {
+    event: "retrieve";
+    state: EventState;
+  };
+};
+
+type AnalyzeEvent = BaseWriterEvent & {
+  data: {
+    event: "analyze";
+    state: EventState;
+  };
+};
+
+type AnswerEvent = BaseWriterEvent & {
   data: {
-    event: "retrieve" | "analyze" | "answer";
+    event: "answer";
     state: EventState;
     id?: string;
     question?: string;
     answer?: string | null;
   };
-};
+};
+
+type WriterEvent = RetrieveEvent | AnalyzeEvent | AnswerEvent;

154-213: Add loading states and accessibility improvements.

The UI could benefit from better loading indicators and accessibility.

Consider these improvements:

 return (
   <div
     className={cn(
       "rounded-lg border bg-card text-card-foreground shadow-sm p-5 space-y-6 w-full",
       className,
     )}
+    role="region"
+    aria-label="Writer Analysis"
   >
     {state.retrieve.state !== null && (
       <div className="border-t pt-4">
-        <h3 className="text-lg font-semibold flex items-center gap-2">
+        <h3 className="text-lg font-semibold flex items-center gap-2" aria-live="polite">
           <Search className="h-5 w-5" />
           <span>
             {state.retrieve.state === "inprogress"
               ? "Searching..."
               : "Search completed"}
           </span>
+          {state.retrieve.state === "inprogress" && (
+            <span className="sr-only">Loading...</span>
+          )}
         </h3>
       </div>
     )}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e83568 and 7061dc3.

📒 Files selected for processing (2)
  • templates/components/agents/python/blog/app/workflows/models.py (1 hunks)
  • templates/types/streaming/nextjs/app/components/ui/chat/custom/writer-card.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • templates/components/agents/python/blog/app/workflows/models.py
🧰 Additional context used
📓 Path-based instructions (1)
templates/types/streaming/nextjs/app/components/ui/chat/custom/writer-card.tsx (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

⏰ Context from checks skipped due to timeout of 90000ms (44)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, express, --llamacloud)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, express, --example-file)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, express, --no-files)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --llamacloud)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --example-file)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --no-files)
  • GitHub Check: typescript (20, 3.11, windows-latest, express, --llamacloud)
  • GitHub Check: typescript (20, 3.11, windows-latest, express, --example-file)
  • GitHub Check: typescript (20, 3.11, windows-latest, express, --no-files)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --llamacloud)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --no-files)
  • GitHub Check: typescript (20, 3.11, macos-latest, express, --llamacloud)
  • GitHub Check: typescript (20, 3.11, macos-latest, express, --example-file)
  • GitHub Check: typescript (20, 3.11, macos-latest, express, --no-files)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --llamacloud)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --example-file)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --no-files)
  • GitHub Check: typescript (18, 3.11, ubuntu-22.04, express, --llamacloud)
  • GitHub Check: typescript (18, 3.11, ubuntu-22.04, express, --example-file)
  • GitHub Check: typescript (18, 3.11, ubuntu-22.04, express, --no-files)
  • GitHub Check: typescript (18, 3.11, ubuntu-22.04, nextjs, --llamacloud)
  • GitHub Check: typescript (18, 3.11, ubuntu-22.04, nextjs, --example-file)
  • GitHub Check: typescript (18, 3.11, ubuntu-22.04, nextjs, --no-files)
  • GitHub Check: typescript (18, 3.11, windows-latest, express, --llamacloud)
  • GitHub Check: typescript (18, 3.11, windows-latest, express, --example-file)
  • GitHub Check: typescript (18, 3.11, windows-latest, express, --no-files)
  • GitHub Check: typescript (18, 3.11, windows-latest, nextjs, --llamacloud)
  • GitHub Check: typescript (18, 3.11, windows-latest, nextjs, --example-file)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --llamacloud)
  • GitHub Check: typescript (18, 3.11, windows-latest, nextjs, --no-files)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --example-file)
  • GitHub Check: typescript (18, 3.11, macos-latest, express, --llamacloud)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --no-files)
  • GitHub Check: typescript (18, 3.11, macos-latest, express, --example-file)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --llamacloud)
  • GitHub Check: typescript (18, 3.11, macos-latest, express, --no-files)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --example-file)
  • GitHub Check: typescript (18, 3.11, macos-latest, nextjs, --llamacloud)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --no-files)
  • GitHub Check: typescript (18, 3.11, macos-latest, nextjs, --example-file)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --llamacloud)
  • GitHub Check: typescript (18, 3.11, macos-latest, nextjs, --no-files)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --example-file)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --no-files)
🔇 Additional comments (1)
templates/types/streaming/nextjs/app/components/ui/chat/custom/writer-card.tsx (1)

1-21: LGTM! Well-structured imports and client directive.

The file structure follows Next.js best practices with the "use client" directive correctly placed at the top, and imports are well-organized.

@leehuwuj leehuwuj changed the title feat: Improve blog use case with deep research feat: Add deep research use case (Python) Jan 21, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (6)
templates/components/agents/python/deep_research/app/workflows/models.py (2)

13-16: Consider adding input validation for question attributes.

While the typing is good, consider adding validation to ensure question_id and question are non-empty strings. You can use Pydantic for this:

-class ResearchEvent(Event):
+from pydantic import Field
+
+class ResearchEvent(Event):
     question_id: str = Field(..., min_length=1)
     question: str = Field(..., min_length=1)
     context_nodes: List[NodeWithScore]

19-22: Consider inheritance for common attributes.

ResearchEvent and CollectAnswersEvent share common attributes. Consider creating a base class:

+class BaseQuestionEvent(Event):
+    question_id: str = Field(..., min_length=1)
+    question: str = Field(..., min_length=1)
+
-class ResearchEvent(Event):
+class ResearchEvent(BaseQuestionEvent):
-    question_id: str
-    question: str
     context_nodes: List[NodeWithScore]

-class CollectAnswersEvent(Event):
+class CollectAnswersEvent(BaseQuestionEvent):
-    question_id: str
-    question: str
     answer: str
templates/types/streaming/nextjs/app/components/ui/chat/custom/deep-research-card.tsx (1)

145-225: Consider improving accessibility.

While the implementation is solid, consider these accessibility improvements:

-    <CollapsibleTrigger className="w-full">
+    <CollapsibleTrigger className="w-full" aria-label={`Toggle answer for: ${question.question}`}>

Also consider adding appropriate ARIA labels for the search and analysis sections.

.changeset/yellow-oranges-play.md (1)

1-5: Consider expanding the changeset description.

While the version bump is appropriate, consider adding more details about:

  • Key features of the deep research functionality
  • Any breaking changes or dependencies
  • Migration steps if applicable
🧰 Tools
🪛 LanguageTool

[style] ~5-~5: Consider an alternative adjective to strengthen your wording.
Context: --- "create-llama": patch --- Add deep research over own documents use case (P...

(DEEP_PROFOUND)

templates/components/agents/python/deep_research/README-template.md (2)

5-11: Enhance setup instructions with environment requirements.

The setup instructions should specify:

  • Required Python version
  • Link to dev container setup documentation
  • Platform-specific requirements (if any)

26-35: Enhance technical documentation for usage section.

Please add:

  • List of supported file formats
  • Default value of TOP_K
  • Performance implications of different TOP_K values
  • Memory requirements for document processing
🧰 Tools
🪛 LanguageTool

[style] ~26-~26: Consider an alternative adjective to strengthen your wording.
Context: ...`shell poetry run dev ``` ## Use Case: Deep Research over own documents The workfl...

(DEEP_PROFOUND)


[style] ~28-~28: Consider an alternative adjective to strengthen your wording.
Context: ...er own documents The workflow performs deep research by retrieving and analyzing do...

(DEEP_PROFOUND)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7061dc3 and dd7e79d.

📒 Files selected for processing (11)
  • .changeset/yellow-oranges-play.md (1 hunks)
  • helpers/types.ts (1 hunks)
  • questions/simple.ts (5 hunks)
  • templates/components/agents/python/deep_research/README-template.md (1 hunks)
  • templates/components/agents/python/deep_research/app/workflows/__init__.py (1 hunks)
  • templates/components/agents/python/deep_research/app/workflows/agents.py (1 hunks)
  • templates/components/agents/python/deep_research/app/workflows/deep_research.py (1 hunks)
  • templates/components/agents/python/deep_research/app/workflows/models.py (1 hunks)
  • templates/types/streaming/nextjs/app/components/ui/chat/chat-message-content.tsx (2 hunks)
  • templates/types/streaming/nextjs/app/components/ui/chat/custom/deep-research-card.tsx (1 hunks)
  • templates/types/streaming/nextjs/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • templates/types/streaming/nextjs/package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • templates/types/streaming/nextjs/app/components/ui/chat/chat-message-content.tsx
🧰 Additional context used
📓 Path-based instructions (6)
templates/components/agents/python/deep_research/README-template.md (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/components/agents/python/deep_research/app/workflows/__init__.py (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/components/agents/python/deep_research/app/workflows/models.py (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/types/streaming/nextjs/app/components/ui/chat/custom/deep-research-card.tsx (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/components/agents/python/deep_research/app/workflows/agents.py (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/components/agents/python/deep_research/app/workflows/deep_research.py (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

🪛 LanguageTool
.changeset/yellow-oranges-play.md

[style] ~5-~5: Consider an alternative adjective to strengthen your wording.
Context: --- "create-llama": patch --- Add deep research over own documents use case (P...

(DEEP_PROFOUND)

templates/components/agents/python/deep_research/README-template.md

[style] ~26-~26: Consider an alternative adjective to strengthen your wording.
Context: ...`shell poetry run dev ``` ## Use Case: Deep Research over own documents The workfl...

(DEEP_PROFOUND)


[style] ~28-~28: Consider an alternative adjective to strengthen your wording.
Context: ...er own documents The workflow performs deep research by retrieving and analyzing do...

(DEEP_PROFOUND)

🔇 Additional comments (14)
templates/components/agents/python/deep_research/app/workflows/agents.py (1)

14-25: AnalysisDecision class implementation is correct and well-structured.

The class correctly leverages Pydantic's BaseModel to define the data model with appropriate fields, types, and default values. This facilitates structured data handling and validation.

templates/components/agents/python/deep_research/app/workflows/__init__.py (1)

1-3: Public API exposure is correctly implemented.

The create_workflow function is properly imported and included in the __all__ list, making it accessible as part of the module's public interface.

templates/components/agents/python/deep_research/app/workflows/models.py (4)

9-10: LGTM! Simple marker event class.

The empty class extending Event is appropriate for signaling the start of research planning.


25-26: LGTM! Consistent with PlanResearchEvent pattern.

The empty class extending Event is appropriate for signaling the completion of research.


30-35: LGTM! Well-structured event data model.

Good use of:

  • Literal types for type safety
  • Optional fields for flexibility
  • Comprehensive state enumeration

38-43: LGTM! Clean event serialization.

The implementation correctly handles event type safety and serialization.

helpers/types.ts (1)

55-55: LGTM! Valid addition to template use cases.

The new "deep_research" use case is consistently added to the union type.

templates/types/streaming/nextjs/app/components/ui/chat/custom/deep-research-card.tsx (3)

23-58: LGTM! Well-structured type definitions.

Clear separation of concerns between event types and UI state types with comprehensive type safety.


68-120: LGTM! Clean and immutable state transformation.

The implementation:

  • Maintains immutability
  • Handles edge cases
  • Clearly separates different event types

123-143: LGTM! Clean state initialization.

Good use of functional programming patterns with proper null handling.

questions/simple.ts (4)

21-22: LGTM! Type definition changes are clean and well-integrated.

The addition of the "deep_research" type maintains consistency with existing patterns.


39-39: Great UI/UX improvements with clear categorization!

The emoji prefixes and detailed descriptions help users understand the differences between agents and workflows.

Also applies to: 42-87


98-102: Verify language selection exclusion for deep research.

The exclusion of language selection for deep_research seems appropriate, but please confirm this is intentional and aligns with the implementation.

✅ Verification successful

Language selection exclusion for deep_research is correct

The exclusion is appropriate as deep_research is implemented exclusively as a Python-based multiagent template with no alternative language implementations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if deep_research implementation has language-specific code
rg -l "deep_research.*\.(py|ts|js)" 

Length of output: 105


Script:

#!/bin/bash
# Search for deep_research related files
echo "=== Deep Research Files ==="
fd "deep_research"

echo -e "\n=== Deep Research Implementation References ==="
rg -i "deep_research" -g "!*.md" -A 3

echo -e "\n=== Language Configuration Patterns ==="
rg "language.*selection.*deep_research|deep_research.*language" -g "!*.md"

Length of output: 7002


230-236: Review tools configuration for deep research.

Other multiagent templates (like financial_report_agent) include tools such as document_generator and interpreter. Consider if deep_research would benefit from similar tools.

@marcusschiesser marcusschiesser merged commit b4e41aa into main Jan 22, 2025
47 checks passed
@marcusschiesser marcusschiesser deleted the lee/deep-research branch January 22, 2025 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants