Skip to content

Open sourcing#33

Merged
joel13samuel merged 3 commits intomainfrom
open-sourcing
Jul 28, 2025
Merged

Open sourcing#33
joel13samuel merged 3 commits intomainfrom
open-sourcing

Conversation

@joel13samuel
Copy link
Copy Markdown
Contributor

@joel13samuel joel13samuel commented Jul 28, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved startup checks to ensure all required environment variables are present, with clear error messages and immediate exit if any are missing.
  • Refactor

    • Enhanced initialization and configuration handling for external services, improved logging, and tightened error handling for tool execution and webhook processing.
  • Style

    • Reformatted and improved the readability of prompts and instructions for SmartLead email webhook handling.
  • Chores

    • Removed unused helper and tool files related to organization and SmartLead API management.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 28, 2025

Caution

Review failed

The pull request is closed.

"""

Walkthrough

This change introduces stricter environment variable checks at startup, refactors agent initialization and tool execution logic, deletes custom tool and SmartLead helper modules, and applies formatting corrections to prompt text. The code now enforces configuration requirements, centralizes error handling and logging, and removes previously defined custom tools and API helpers.

Changes

Cohort / File(s) Change Summary
Environment Variable Checks
index.ts
Added checks for multiple required environment variables at startup, logging errors and exiting if any are missing.
Agent Initialization & Tool Execution Refactor
lib/agent.ts
Refactored Anthropic and Composio client initialization to module scope, updated model selection, improved error handling and logging, enforced environment config, and revised tool execution logic to use environment variables and logging.
Custom Clerk Tools Removal
src/agents/clerk-agent/tools.ts
Deleted file containing custom tools and executors for managing organization data in company records.
Prompt Formatting Adjustments
src/agents/smartlead-agent/index.ts
Reformatted and re-indented JSON input examples and comments in the prompt text for clarity; no functional changes.
SmartLead Helpers Removal
src/agents/smartlead-agent/smartlead-helpers.ts
Deleted file containing SmartLead API helper functions and related type definitions.

Sequence Diagram(s)

sequenceDiagram
    participant Startup
    participant EnvVars
    participant Logger
    participant Process

    Startup->>EnvVars: Check required variables (AGENTUITY_PROJECT_KEY, ATTIO_AUTH_TOKEN, etc.)
    alt Variable missing
        EnvVars->>Logger: Log error (red)
        EnvVars->>Process: Exit with failure code
    else All present
        EnvVars->>Startup: Continue startup
    end
Loading
sequenceDiagram
    participant Request
    participant Agent
    participant Anthropic
    participant Composio
    participant Logger

    Request->>Agent: Incoming request
    Agent->>Anthropic: Generate message (main model)
    Agent->>Composio: Execute tool calls (using env user ID)
    Agent->>Logger: Log events/errors
    Agent->>Request: Return response
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~35 minutes

Possibly related PRs

  • Open sourcing #33: Shares identical environment variable checks and similar refactorings in lib/agent.ts, indicating direct relation.
  • Smartlead2 #15: Previously added the SmartLead helper functions now deleted; both affect SmartLead API integration and environment configuration.
  • Orgs is now a string that can contain orgs per company #10: Added custom Clerk tools for organization handling that are now removed; both PRs impact the same tooling and data management.

Poem

In the warren of code, checks now abound,
If your env is missing, red errors resound!
Old helpers and tools have hopped far away,
While logging and models keep bugs at bay.
With carrots of caution and logs in delight,
This bunny reviews—your code feels just right! 🥕✨
"""

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2136da7 and 1c603a4.

📒 Files selected for processing (2)
  • lib/agent.ts (8 hunks)
  • src/agents/smartlead-agent/index.ts (3 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch open-sourcing

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@joel13samuel joel13samuel merged commit af5171b into main Jul 28, 2025
Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
index.ts (1)

27-98: Consider making some environment variables optional based on feature usage.

All environment variables are enforced as mandatory at startup. This approach requires all services to be configured even if some features might not be used. Consider implementing conditional checks based on enabled features or documenting which variables are truly required vs optional.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c5e2236 and 2136da7.

📒 Files selected for processing (5)
  • index.ts (2 hunks)
  • lib/agent.ts (9 hunks)
  • src/agents/clerk-agent/tools.ts (0 hunks)
  • src/agents/smartlead-agent/index.ts (2 hunks)
  • src/agents/smartlead-agent/smartlead-helpers.ts (0 hunks)
💤 Files with no reviewable changes (2)
  • src/agents/smartlead-agent/smartlead-helpers.ts
  • src/agents/clerk-agent/tools.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/src/agents/**/index.ts

📄 CodeRabbit Inference Engine (.cursor/rules/agent.mdc)

**/src/agents/**/index.ts: Prefer loading types from the node modules package @agentuity/sdk in the node_modules folder
The file should export a default function
Prefer naming the default function Agent or the name of the Agent based on the context of the Agent description
All code should be in Typescript format
Use the provided logger from the AgentContext interface such as ctx.logger.info("my message: %s", "hello")

Files:

  • src/agents/smartlead-agent/index.ts
src/agents/**/*.ts

📄 CodeRabbit Inference Engine (.cursor/rules/sdk.mdc)

src/agents/**/*.ts: Use TypeScript for better type safety and IDE support
Import types from @agentuity/sdk
Use structured error handling with try/catch blocks
Leverage the provided logger for consistent logging
Use the storage APIs for persisting data

Files:

  • src/agents/smartlead-agent/index.ts
🧠 Learnings (4)
📓 Common learnings
Learnt from: mcongrove
PR: agentuity/app#544
File: web/src/components/screens/deploy/ProjectSetupScreen.tsx:232-242
Timestamp: 2025-06-09T22:56:13.989Z
Learning: Environment variable secret detection logic should be centralized in utility functions rather than duplicated across components for better maintainability and consistency.
Learnt from: CR
PR: agentuity/examples#0
File: agents/Startup_News_Scraper/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:38:58.657Z
Learning: Applies to agents/Startup_News_Scraper/**/src/agents/**/index.ts : Prefer naming the default function Agent or the name of the Agent based on the context of the Agent description
Learnt from: CR
PR: agentuity/examples#0
File: agents/tavily_agent/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-07-17T13:40:30.298Z
Learning: Applies to agents/tavily_agent/agents/**/*.py : Use the AgentContext class and its properties (logger, kv, vector, get_agent, tracer, sdkVersion, devmode, orgId, projectId) to access agent context and capabilities
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/pydantic/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:16:30.899Z
Learning: When writing agent code in 'agents/**/*.py', prefer importing types such as AgentRequest, AgentResponse, and AgentContext from the 'agentuity' package to ensure compatibility and consistency.
index.ts (19)

Learnt from: CR
PR: agentuity/examples#0
File: agents/Startup_News_Scraper/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:38:58.657Z
Learning: Applies to agents/Startup_News_Scraper//src/agents//index.ts : All code should be in Typescript format

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/mastra/basic/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:15:21.314Z
Learning: For best practices in Agentuity SDK projects, use TypeScript for type safety, import types from @agentuity/sdk, use structured error handling with try/catch, leverage the provided logger, use storage APIs for data persistence, and consider agent communication for complex workflows.

Learnt from: CR
PR: agentuity/examples#0
File: agentuity/sdk-js/streaming/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:40:37.445Z
Learning: Applies to agentuity/sdk-js/streaming//src/agents//index.ts : All code should be in Typescript format

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/mastra/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:15:12.561Z
Learning: In Agentuity AI Agent files (**/src/agents/**/index.ts), import types such as AgentRequest, AgentResponse, and AgentContext from the @agentuity/sdk package to ensure type safety and consistency.

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/langgraph/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:14:39.393Z
Learning: In Agentuity AI Agent files (**/src/agents/**/index.ts), import types such as AgentRequest, AgentResponse, and AgentContext from the @agentuity/sdk package to ensure type safety and consistency.

Learnt from: CR
PR: agentuity/examples#0
File: agents/Startup_News_Scraper/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-07-17T13:39:11.850Z
Learning: Applies to agents/Startup_News_Scraper/src/agents/**/*.ts : Import types from @agentuity/sdk

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/mastra/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:15:12.561Z
Learning: In Agentuity AI Agent files (**/src/agents/**/index.ts), always use the provided logger from the AgentContext interface (e.g., ctx.logger.info(...)) for logging, rather than custom or external logging solutions.

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/langgraph/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:14:39.393Z
Learning: In Agentuity AI Agent files (**/src/agents/**/index.ts), always use the provided logger from the AgentContext interface (e.g., ctx.logger.info(...)) for logging, rather than custom or external logging solutions.

Learnt from: CR
PR: agentuity/examples#0
File: agents/composio/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:39:37.133Z
Learning: Applies to agents/composio//src/agents//index.ts : All code should be in Typescript format

Learnt from: CR
PR: agentuity/examples#0
File: agents/Startup_News_Scraper/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:38:58.657Z
Learning: Applies to agents/Startup_News_Scraper//src/agents//index.ts : Prefer loading types from the node modules package @agentuity/sdk in the node_modules folder

Learnt from: CR
PR: agentuity/collider#0
File: projects/collider-node/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-24T15:42:21.297Z
Learning: Agent files for Agentuity should export a default async function, typically named Agent or contextually named after the Agent, which receives AgentRequest, AgentResponse, and AgentContext as parameters.

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/vercel/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:16:49.315Z
Learning: When writing an Agent in TypeScript for Agentuity, always use the types provided by the @agentuity/sdk package for AgentRequest, AgentResponse, and AgentContext to ensure type safety and compatibility.

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/openai/from-oai-typescript/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:15:59.829Z
Learning: In Agent files for Agentuity, always export a default function, preferably named 'Agent' or contextually after the Agent, to ensure consistency and clarity.

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/vercel/basic/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:16:58.079Z
Learning: Import types from @agentuity/sdk to ensure consistency and leverage type definitions.

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/openai/from-oai/.cursor/rules/agentuity.mdc:0-0
Timestamp: 2025-06-23T17:16:16.519Z
Learning: The Agentuity configuration file (agentuity.yaml) is reserved for configuring the AI Agent project and should not be edited or suggested for edits during code review.

Learnt from: CR
PR: agentuity/examples#0
File: agentuity/sdk-js/streaming/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:40:37.445Z
Learning: Applies to agentuity/sdk-js/streaming//src/agents//index.ts : Prefer naming the default function Agent or the name of the Agent based on the context of the Agent description

Learnt from: jhaynie
PR: agentuity/cli#313
File: cmd/cloud.go:852-853
Timestamp: 2025-05-22T18:27:10.386Z
Learning: In the agentuity CLI codebase, there's a specific error handling pattern: errsystem is used exclusively for unexpected system errors, while expected error conditions use tui.ShowWarning() and direct os.Exit(1) calls.

Learnt from: CR
PR: agentuity/collider#0
File: projects/collider-node/.cursor/rules/agentuity.mdc:0-0
Timestamp: 2025-06-24T15:42:23.807Z
Learning: The file 'agentuity.yaml' is used to configure the Agentuity AI Agent project and should not be edited or suggested for edits.

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/langchain/basic/.cursor/rules/agentuity.mdc:0-0
Timestamp: 2025-06-23T17:14:18.092Z
Learning: The file 'agentuity.yaml' is used to configure the Agentuity AI Agent project and should not be edited or suggested for edits.

src/agents/smartlead-agent/index.ts (10)

Learnt from: CR
PR: agentuity/docs#0
File: agent-docs/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-07-23T12:40:34.834Z
Learning: Applies to agent-docs/src/agents/**/*.ts : Consider agent communication for complex workflows

Learnt from: CR
PR: agentuity/examples#0
File: agents/deep-research-js/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-07-17T13:40:05.817Z
Learning: Applies to agents/deep-research-js/src/agents/**/*.ts : Consider agent communication for complex workflows

Learnt from: CR
PR: agentuity/examples#0
File: agentuity/sdk-js/streaming/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:40:37.445Z
Learning: Applies to agentuity/sdk-js/streaming//src/agents//index.ts : All code should be in Typescript format

Learnt from: CR
PR: agentuity/examples#0
File: agents/agent-riza/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-07-17T13:39:31.143Z
Learning: Applies to agents/agent-riza/src/agents/**/*.ts : Consider agent communication (e.g., response.handoff, context.getAgent) for complex workflows

Learnt from: CR
PR: agentuity/docs#0
File: agent-docs/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-23T12:40:22.412Z
Learning: Applies to agent-docs//src/agents//index.ts : All code should be in Typescript format

Learnt from: CR
PR: agentuity/examples#0
File: agents/deep-research-js/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:39:55.775Z
Learning: Applies to agents/deep-research-js//src/agents//index.ts : All code should be in Typescript format

Learnt from: CR
PR: agentuity/examples#0
File: agents/composio/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:39:37.133Z
Learning: Applies to agents/composio//src/agents//index.ts : All code should be in Typescript format

Learnt from: CR
PR: agentuity/examples#0
File: agents/Startup_News_Scraper/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:38:58.657Z
Learning: Applies to agents/Startup_News_Scraper//src/agents//index.ts : All code should be in Typescript format

Learnt from: CR
PR: agentuity/fuse-infra#0
File: .cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-08T16:50:51.612Z
Learning: Applies to /src/agents//index.ts : All code should be in Typescript format

Learnt from: CR
PR: agentuity/agent-crm#0
File: .cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-18T15:32:21.381Z
Learning: Applies to /src/agents//index.ts : All code should be in Typescript format

lib/agent.ts (23)

Learnt from: CR
PR: agentuity/examples#0
File: agents/agent-riza/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-07-17T13:39:31.143Z
Learning: Applies to agents/agent-riza/src/agents/**/*.ts : Consider agent communication (e.g., response.handoff, context.getAgent) for complex workflows

Learnt from: CR
PR: agentuity/examples#0
File: agents/composio/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:39:37.133Z
Learning: Applies to agents/composio//src/agents//index.ts : Prefer naming the default function Agent or the name of the Agent based on the context of the Agent description

Learnt from: CR
PR: agentuity/examples#0
File: agents/deep-research-js/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-07-17T13:40:05.817Z
Learning: Applies to agents/deep-research-js/src/agents/**/*.ts : Consider agent communication for complex workflows

Learnt from: CR
PR: agentuity/docs#0
File: agent-docs/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-07-23T12:40:34.834Z
Learning: Applies to agent-docs/src/agents/**/*.ts : Consider agent communication for complex workflows

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/vercel/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:16:49.315Z
Learning: When writing an Agent in TypeScript for Agentuity, always use the types provided by the @agentuity/sdk package for AgentRequest, AgentResponse, and AgentContext to ensure type safety and compatibility.

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/mastra/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:15:12.561Z
Learning: In Agentuity AI Agent files (**/src/agents/**/index.ts), always use the provided logger from the AgentContext interface (e.g., ctx.logger.info(...)) for logging, rather than custom or external logging solutions.

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/langgraph/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:14:39.393Z
Learning: In Agentuity AI Agent files (**/src/agents/**/index.ts), always use the provided logger from the AgentContext interface (e.g., ctx.logger.info(...)) for logging, rather than custom or external logging solutions.

Learnt from: CR
PR: agentuity/examples#0
File: agentuity/sdk-js/streaming/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:40:37.445Z
Learning: Applies to agentuity/sdk-js/streaming//src/agents//index.ts : Prefer naming the default function Agent or the name of the Agent based on the context of the Agent description

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/langgraph/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:14:39.393Z
Learning: In Agentuity AI Agent files (**/src/agents/**/index.ts), import types such as AgentRequest, AgentResponse, and AgentContext from the @agentuity/sdk package to ensure type safety and consistency.

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/mastra/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:15:12.561Z
Learning: In Agentuity AI Agent files (**/src/agents/**/index.ts), import types such as AgentRequest, AgentResponse, and AgentContext from the @agentuity/sdk package to ensure type safety and consistency.

Learnt from: CR
PR: agentuity/collider#0
File: projects/collider-node/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-24T15:42:32.504Z
Learning: The Agentuity JavaScript SDK provides core interfaces such as AgentHandler, AgentRequest, AgentResponse, and AgentContext for building AI agents in TypeScript/JavaScript.

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/langgraph/basic/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:14:46.802Z
Learning: The Agentuity JavaScript SDK provides core interfaces such as AgentHandler, AgentRequest, AgentResponse, and AgentContext for building AI agents in TypeScript or JavaScript.

Learnt from: CR
PR: agentuity/examples#0
File: agents/composio/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-07-17T13:39:44.988Z
Learning: Applies to agents/composio/src/agents/**/*.ts : Import types from @agentuity/sdk

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/vercel/basic/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:16:58.079Z
Learning: Import types from @agentuity/sdk to ensure consistency and leverage type definitions.

Learnt from: CR
PR: agentuity/collider#0
File: projects/collider-node/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-24T15:42:21.297Z
Learning: Agent files for Agentuity should export a default async function, typically named Agent or contextually named after the Agent, which receives AgentRequest, AgentResponse, and AgentContext as parameters.

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/mastra/basic/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:15:21.314Z
Learning: For best practices in Agentuity SDK projects, use TypeScript for type safety, import types from @agentuity/sdk, use structured error handling with try/catch, leverage the provided logger, use storage APIs for data persistence, and consider agent communication for complex workflows.

Learnt from: CR
PR: agentuity/examples#0
File: patterns/llmAsJury/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:17:19.027Z
Learning: Import types from @agentuity/sdk to ensure consistency and type safety.

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/vercel/basic/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:16:58.079Z
Learning: In the Agentuity JavaScript SDK, the main handler for an agent should implement the AgentHandler type: (request: AgentRequest, response: AgentResponse, context: AgentContext) => Promise.

Learnt from: CR
PR: agentuity/examples#0
File: patterns/llmAsJury/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:17:19.027Z
Learning: In the Agentuity JavaScript SDK, the main handler for an agent should implement the AgentHandler type: (request: AgentRequest, response: AgentResponse, context: AgentContext) => Promise.

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/openai/from-oai-typescript/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:16:08.480Z
Learning: In the Agentuity JavaScript SDK, the main handler for an agent should implement the AgentHandler type: (request: AgentRequest, response: AgentResponse, context: AgentContext) => Promise.

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/mastra/basic/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:15:21.314Z
Learning: In the Agentuity JavaScript SDK, the main handler for an agent should implement the AgentHandler type: a function that takes (request: AgentRequest, response: AgentResponse, context: AgentContext) and returns a Promise of AgentResponseType.

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/mastra/basic/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:15:21.314Z
Learning: The AgentRequest interface in the Agentuity SDK provides methods for accessing trigger type, metadata, and request payload in various formats (JSON, text, ArrayBuffer, typed object).

Learnt from: CR
PR: agentuity/examples#0
File: frameworks/langgraph/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:14:39.393Z
Learning: In Agentuity AI Agent files (**/src/agents/**/index.ts), the default export should be an async function that handles the agent logic, typically accepting parameters (req: AgentRequest, resp: AgentResponse, ctx: AgentContext).

🔇 Additional comments (4)
src/agents/smartlead-agent/index.ts (1)

31-37: LGTM! Formatting improvements enhance readability.

The JSON structure formatting corrections improve the clarity of the tool call examples in the prompt, making them properly nested and easier to understand.

Also applies to: 51-57, 59-65, 68-72, 74-85, 87-94, 97-100, 104-106, 118-121

lib/agent.ts (3)

6-11: Excellent refactoring improvements!

The changes improve the code quality:

  • Module-level client initialization avoids repeated instantiation
  • Explicit environment variable validation with clear error messages
  • Specific tool list instead of filtering improves clarity and potentially performance

Also applies to: 40-44, 45-54


125-125: Great improvement in logging and observability!

Replacing console.log with context logger ensures proper log aggregation and follows the Agentuity SDK best practices.

Also applies to: 173-177, 182-185, 193-193, 216-216, 257-257


203-290: Well-structured separation of custom and composio tool execution!

The refactored logic clearly separates custom tool execution from composio tools, with proper error handling for each. The merging strategy for mixed tool results is clean and maintainable.

Comment thread lib/agent.ts
Comment on lines +29 to +33
const payload = await req.data.json();
if (
verifyWebhook &&
!verifyWebhook(JSON.stringify(payload), req, resp, ctx)
) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify webhook signature validation compatibility.

The change from raw body to parsed JSON might break webhook signature validation if the verifier expects the exact raw body bytes for HMAC verification. Many webhook providers (like Stripe) require the raw body for signature validation.


🏁 Script executed:

#!/bin/bash
# Check if any webhook verifiers in the codebase use signature validation
rg -A 10 "verifyWebhook|signature|hmac" --type ts

Length of output: 2057


Ensure webhook signature verifiers receive the unaltered raw body

The handler currently parses the JSON and then re-serializes it for verifyWebhook, which will break HMAC checks (e.g. Stripe’s constructEvent) that require the exact raw payload bytes. Update the code to read the raw text first, pass it directly into verifyWebhook, then parse it for further processing.

Example diff:

-    const payload = await req.data.json();
-    if (
-      verifyWebhook &&
-      !verifyWebhook(JSON.stringify(payload), req, resp, ctx)
-    ) {
+    const rawBody = await req.data.text();
+    const payload = JSON.parse(rawBody);
+    if (
+      verifyWebhook &&
+      !verifyWebhook(rawBody, req, resp, ctx)
+    ) {
       return resp.json({
         success: false,
         error: "Webhook verification failed.",
       });

Areas to address:

  • lib/agent.ts (lines 29–33): switch from json() / stringify to text() / JSON.parse
  • src/agents/stripe-agent/index.ts: ensure your verifyWebhook implementation (currently commented out) accepts and uses the raw body for HMAC verification
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const payload = await req.data.json();
if (
verifyWebhook &&
!verifyWebhook(JSON.stringify(payload), req, resp, ctx)
) {
// Read the raw body for signature verification
const rawBody = await req.data.text();
const payload = JSON.parse(rawBody);
if (
verifyWebhook &&
!verifyWebhook(rawBody, req, resp, ctx)
) {
return resp.json({
success: false,
error: "Webhook verification failed.",
});
}
🤖 Prompt for AI Agents
In lib/agent.ts around lines 29 to 33, the code currently parses the request
body as JSON and then re-serializes it for verifyWebhook, which breaks HMAC
verification. Change the code to first read the raw request body as text, pass
this raw text directly to verifyWebhook, and then parse the text with JSON.parse
for further processing. This ensures the webhook signature verifier receives the
exact unaltered payload it requires.

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.

2 participants