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: deep researcher with ai sdk added #1264

Merged
merged 1 commit into from
Feb 9, 2025

Conversation

Prat011
Copy link
Collaborator

@Prat011 Prat011 commented Feb 9, 2025

Important

Adds a Deep Researcher Agent example using AI SDKs with demo script, package configuration, and README.

  • New Feature:
    • Adds demo.mjs for a Deep Researcher Agent using @ai-sdk/openai and composio-core.
    • Implements functions for displaying logos, frames, and loading animations.
    • Uses generateText to perform research and summarize findings.
  • Dependencies:
    • Adds dependencies in package.json including @ai-sdk/openai, ai, chalk, composio-core, dotenv, figlet, gradient-string, ora, and zod.
  • Documentation:
    • Adds readme.md with installation and usage instructions for the Deep Researcher Agent.

This description was created by Ellipsis for 014262e. It will automatically update as commits are pushed.

Copy link

vercel bot commented Feb 9, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
composio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 9, 2025 2:32pm

Comment on lines +50 to +91
const appName = "serpapi";

async function setupUserConnectionIfNotExists(entityId) {
const spinner = displayLoadingAnimation('Checking connection status...');
spinner.start();

try {
const entity = await toolset.client.getEntity(entityId);
const connection = await entity.getConnection({app:appName});

if (!connection) {
spinner.text = 'Initiating new connection...';
const newConnection = await entity.initiateConnection(appName);
console.log(chalk.green("\n🔗 Log in via: "), chalk.blue.underline(newConnection.redirectUrl));
spinner.text = 'Waiting for connection...';
return await newConnection.waitUntilActive(60);
}

spinner.succeed(chalk.green('Connection established!'));
return connection;
} catch (error) {
spinner.fail(chalk.red('Connection failed!'));
throw error;
}
}

async function executeAgent(entityName) {
displayLogo();

displayFrame('Initializing Deep Research Protocol...');

// Setup entity and ensure connection
const entity = await toolset.client.getEntity(entityName);
await setupUserConnectionIfNotExists(entity.id);

const spinner = displayLoadingAnimation('Retrieving tools...');
spinner.start();

// Retrieve tools for the specified app
const tools = await toolset.getTools({
apps: ["serpapi", "tavily"]
}, entity.id);

Choose a reason for hiding this comment

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

The appName constant is hardcoded to serpapi but tools are retrieved for both serpapi and tavily. Connection setup should handle both apps or be aligned with tool retrieval.

Copy link

github-actions bot commented Feb 9, 2025

This comment was generated by github-actions[bot]!

JS SDK Coverage Report

📊 Coverage report for JS SDK can be found at the following URL:
https://pub-92e668239ab84bfd80ee07d61e9d2f40.r2.dev/coverage-13226669862/coverage/index.html

📁 Test report folder can be found at the following URL:
https://pub-92e668239ab84bfd80ee07d61e9d2f40.r2.dev/html-report-13226669862/html-report/report.html

}

// Setup toolset
const toolset = new VercelAIToolSet({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider adding error handling for missing API key:

if (!process.env.COMPOSIO_API_KEY) {
  throw new Error('COMPOSIO_API_KEY environment variable is required')
}


displayFrame('Enter Research Topic');

const topic = await new Promise((resolve) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider adding input validation for the research topic:

if (!topic || topic.trim().length === 0) {
  throw new Error('Research topic cannot be empty')
}


Conduct comprehensive research covering these perspectives. Focus on finding factual, verifiable information from credible sources, cite your sources.
`,
maxToolRoundtrips: 5,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider adding retry logic for API calls:

const maxRetries = 3;
let attempt = 0;
while (attempt < maxRetries) {
  try {
    const output = await generateText({...});
    break;
  } catch (error) {
    attempt++;
    if (attempt === maxRetries) throw error;
    await new Promise(resolve => setTimeout(resolve, 1000 * attempt));
  }
}

@@ -0,0 +1,23 @@
{
"name": "lead-generator-agent",
Copy link
Collaborator

Choose a reason for hiding this comment

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

The package name lead-generator-agent seems incorrect for this project. Consider renaming it to deep-researcher-agent to match the actual functionality.

@shreysingla11
Copy link
Collaborator

Code Review Summary

Overall Quality: 7/10

Strengths:

  • Well-structured code organization
  • Good separation of concerns
  • Clear UI/UX with progress indicators
  • Comprehensive research approach with multiple perspectives

Areas for Improvement:

  1. Error Handling

    • Add validation for environment variables
    • Add input validation
    • Implement retry logic for API calls
  2. Documentation

    • Add JSDoc comments for functions
    • Document error scenarios
    • Add examples in README
  3. Package Configuration

    • Fix package name to match project purpose
    • Add proper description and author fields
    • Add engine constraints
  4. Testing

    • Add unit tests
    • Add integration tests
    • Add error scenario tests

The implementation provides a solid foundation but would benefit from improved error handling, documentation, and testing to make it more robust and maintainable.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Reviewed everything up to 014262e in 3 minutes and 8 seconds

More details
  • Looked at 264 lines of code in 3 files
  • Skipped 1 files when reviewing.
  • Skipped posting 9 drafted comments based on config settings.
1. js/examples/deep_researcher/demo.mjs:52
  • Draft comment:
    This implements the same connection setup logic. Consider enhancing the existing implementation with the spinner UI improvements instead of duplicating the core functionality.

  • function setupUserConnectionIfNotExists (sample.mjs)

  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50%
    The comment suggests merging the implementations, but this seems backwards - the new implementation is actually better with its UI improvements. The old implementation is simpler and less featured. We wouldn't want to remove the improvements to match the old version. And since these are in different example files that serve different purposes, some duplication may be acceptable.
    The comment raises a valid point about code duplication. Perhaps there could be a shared utility function that both examples could use.
    While sharing code could reduce duplication, these are separate example files that demonstrate different things - one is a simple example, one is a full featured demo. Some duplication may be acceptable for clarity and independence of the examples.
    The comment should be deleted since it suggests going backwards in functionality, and example files often intentionally contain some duplication for clarity.

2. js/examples/deep_researcher/demo.mjs:118
  • Draft comment:
    Potential model ID typo: 'gpt-4o' is used here while 'o1' is passed later. Confirm intended model identifiers.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50%
    The different model IDs could be intentional - the first call is for deep research which might need a more powerful model (gpt-4o), while the second call is just for summarization which could use a simpler model (o1). The third call uses gpt-4o again for extracting highlights. Without knowing the capabilities and intended use of these models, we can't assume this is a mistake.
    I might be wrong about the model capabilities - maybe o1 is actually the more powerful model. Or maybe these are indeed typos that could cause runtime errors.
    However, the consistent pattern (gpt-4o for analysis, o1 for summarization, gpt-4o for highlights) suggests this is intentional architecture. Making assumptions about model IDs without understanding the system would be dangerous.
    We should delete this comment. The different model IDs appear to be an intentional design choice, and without strong evidence that this is a mistake, we shouldn't suggest changes.
3. js/examples/deep_researcher/demo.mjs:28
  • Draft comment:
    Consider validating process.stdout.columns to avoid potential undefined width in non-standard terminals.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 30% vs. threshold = 50%
    This is a new file, so the code is changed. The suggestion is technically correct - process.stdout.columns could be undefined in some environments. However, this is a demo/example file, and the fallback is more of a defensive programming nice-to-have than a critical issue. The current code would likely work fine in most normal terminal environments.
    I might be underestimating the frequency of non-standard terminals. The code could actually break in some real-world scenarios.
    While true, this is clearly marked as a demo file and the fix is more of an optimization than a critical issue. The current code would work in standard environments.
    While technically correct, this comment suggests an optimization that isn't critical enough to warrant keeping in a demo file review.
4. js/examples/deep_researcher/demo.mjs:187
  • Draft comment:
    Add a newline at the end of the file to follow best practices.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50%
    While having a newline at the end of files is indeed a best practice, this kind of comment is very minor and could be handled by automated tooling like EditorConfig or Prettier. It doesn't affect functionality and is more of a style/formatting issue. According to our rules, we should avoid making purely informative comments or obvious/unimportant suggestions.
    The suggestion is technically correct and follows a widely accepted best practice. Not having a final newline could cause issues with some tools.
    While correct, this is exactly the kind of minor formatting issue that should be handled by automated tooling rather than manual code review comments. It doesn't impact functionality or code quality significantly.
    Delete this comment as it's too minor for a code review comment and would be better handled by automated tooling.
5. js/examples/deep_researcher/package.json:2
  • Draft comment:
    Package name 'lead-generator-agent' does not match the Deep Researcher context. Consider renaming for consistency.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 30% vs. threshold = 50%
    The package name is indeed inconsistent with the directory name, which could be confusing. However, package names are often different from directory names for various reasons. Without more context about the project's purpose or naming conventions, we can't be certain this is actually an issue. The comment is making assumptions about intended naming patterns.
    The package name could be intentionally different from the directory name - maybe this is a lead generator that does deep research? We don't have enough context to know if this is truly an issue.
    While the name could be intentional, having consistent naming between directory and package does improve code maintainability and reduces confusion.
    Given the uncertainty about naming intentions and lack of established conventions, this comment should be removed as it's making assumptions without strong evidence.
6. js/examples/deep_researcher/demo.mjs:46
  • Draft comment:
    Check if COMPOSIO_API_KEY is defined to avoid runtime errors.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50%
    While checking environment variables is generally good practice, we need to consider: 1) This is a demo file 2) The error handling may already be handled by VercelAIToolSet 3) There's already error handling in the executeAgent function 4) The suggestion adds complexity with an IIFE that may be overkill
    I may be underestimating the importance of fail-fast validation. An undefined API key could lead to confusing errors later.
    The code already has error handling in place, and VercelAIToolSet likely has its own validation. Adding another check adds complexity without clear benefit.
    The comment should be deleted as it suggests adding unnecessary complexity when there's already error handling in place.
7. js/examples/deep_researcher/demo.mjs:118
  • Draft comment:
    Clarify or document the custom model names (gpt-4o and o1) to ensure they are valid and intended.
  • Reason this comment was not posted:
    Marked as duplicate.
8. js/examples/deep_researcher/package.json:2
  • Draft comment:
    Project name 'lead-generator-agent' does not match the Deep Researcher Agent context; consider renaming for consistency.
  • Reason this comment was not posted:
    Marked as duplicate.
9. js/examples/deep_researcher/package.json:5
  • Draft comment:
    The 'main' field ('index.js') is inconsistent with the demo (demo.mjs); update if needed.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50%
    Since this is a new file, the author deliberately set it to index.js. Without seeing the demo.mjs file or having more context about the project structure, we can't be certain there's an actual inconsistency. The comment is making assumptions about files we can't see. Following our rules, we should delete comments that require more context to verify.
    The demo.mjs file might actually exist in the repository, and there could be a real inconsistency that needs fixing.
    Even if demo.mjs exists, we can't verify this without more context. The author might have intentionally set index.js as the main entry point for good reasons we can't see.
    Delete the comment as it requires more context to verify and makes assumptions about files outside the current diff.

Workflow ID: wflow_oGrOMfVEddeHNqsQ


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.


displayFrame('Enter Research Topic');

const topic = await new Promise((resolve) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider validating the research topic input to avoid empty queries.


## Installation

To get started with the Lead Generator Agent, you need to install the following dependencies:
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure consistent naming; replace 'Lead Generator Agent' with 'Deep Researcher Agent' in installation instructions.

Suggested change
To get started with the Lead Generator Agent, you need to install the following dependencies:
To get started with the Deep Researcher Agent, you need to install the following dependencies:

@Karthikeya-Meesala Karthikeya-Meesala merged commit 71066d9 into master Feb 9, 2025
13 of 14 checks passed
@Karthikeya-Meesala Karthikeya-Meesala deleted the feat/deepresearcher-js-example branch February 9, 2025 16:53
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