Skip to content

Array find first exists agent - #1182

Merged
isamu merged 4 commits into
receptron:mainfrom
isamu:arrayFindFirstExistsAgent
Aug 11, 2025
Merged

isamu merged 4 commits into
receptron:mainfrom
isamu:arrayFindFirstExistsAgent

Conversation

@isamu

@isamu isamu commented Aug 11, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added an "Array Find First Exists" agent that returns the first non-null/undefined item in an array while preserving valid falsy values (e.g., 0, empty string). Now available in the array agents bundle.
  • Chores

    • Bumped vanilla agents package to 2.0.9 and updated @graphai/vanilla across related packages.
    • No breaking changes; existing behavior remains unchanged.

@coderabbitai

coderabbitai Bot commented Aug 11, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds a new vanilla array agent that returns the first non-null/undefined element, re-exports it from the array_agents index, and bumps package versions for agents/vanilla_agents and downstream @graphai/vanilla references.

Changes

Cohort / File(s) Summary of changes
New array agent
agents/vanilla_agents/src/array_agents/array_find_first_exists.ts
Added arrayFindFirstExistsAgent and arrayFindFirstExistsAgentInfo; validates input, returns first non-null/undefined element, includes samples, default-exports info.
Array agents index export
agents/vanilla_agents/src/array_agents/index.ts
Imported and re-exported arrayFindFirstExistsAgent, expanding the module's public exports.
Version bumps
agents/vanilla_agents/package.json, packages/agents/package.json, packages/test_utils/package.json
Bumped agents/vanilla_agents version 2.0.8 → 2.0.9; updated @graphai/vanilla dependency/devDependency ranges to ^2.0.9.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant arrayFindFirstExistsAgent
  participant arrayValidate
  participant InputArray

  Caller->>arrayFindFirstExistsAgent: invoke({ array })
  arrayFindFirstExistsAgent->>arrayValidate: validate(array)
  arrayValidate-->>arrayFindFirstExistsAgent: validated
  arrayFindFirstExistsAgent->>InputArray: iterate until item != null/undefined
  InputArray-->>arrayFindFirstExistsAgent: first existing item (or none)
  arrayFindFirstExistsAgent-->>Caller: return item (or undefined)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • Vanilla2.0.6 #1171 — related version bump of agents/vanilla_agents and downstream @graphai/vanilla updates.

Suggested reviewers

  • snakajima

Poem

Hoppity hop, I scan the list,
Past null and void, I won’t desist—
I sniff the first who truly shows,
Return the gem where value grows.
Version hops and agents play—🥕🐇


📜 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 ae5ea58 and 4e213c0.

📒 Files selected for processing (1)
  • agents/vanilla_agents/src/array_agents/array_find_first_exists.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • agents/vanilla_agents/src/array_agents/array_find_first_exists.ts
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.
  • 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.

Support

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

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (5)
agents/vanilla_agents/package.json (1)

3-3: Package version bump to 2.0.9

Version aligns with dependents bumping to ^2.0.9. Ensure CHANGELOG/Release notes reflect the new agent.

agents/vanilla_agents/src/array_agents/array_find_first_exists.ts (4)

7-7: Undefined return when nothing exists — clarify or normalize behavior

If no element passes, find returns undefined. Decide whether returning undefined is acceptable or normalize to null for consistency.

For explicit null when not found:

-  return namedInputs.array.find((item) => !isNull(item));
+  const v = namedInputs.array.find((item) => !isNull(item));
+  return v === undefined ? null : v;

If you keep undefined, reflect it in output schema and samples.

Please confirm the convention used by other "finder" agents (null vs undefined) and align accordingly.


19-19: Fix grammar in input description

Short and clear phrasing.

-        description: "The array to be find",
+        description: "The array to search",

28-44: Samples are solid and cover falsy values

Good coverage demonstrating null/undefined skipping and preserving 0. Consider adding an empty-array case to illustrate behavior when not found.


45-45: Update description to match the agent’s purpose

Current text references a different agent.

-  description: "Array Flat Agent",
+  description: "Finds the first existing (non-null/undefined) element in an array",
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0104958 and ae5ea58.

📒 Files selected for processing (5)
  • agents/vanilla_agents/package.json (1 hunks)
  • agents/vanilla_agents/src/array_agents/array_find_first_exists.ts (1 hunks)
  • agents/vanilla_agents/src/array_agents/index.ts (1 hunks)
  • packages/agents/package.json (1 hunks)
  • packages/test_utils/package.json (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
agents/vanilla_agents/src/array_agents/array_find_first_exists.ts (1)
agents/vanilla_agents/src/array_agents/index.ts (1)
  • arrayFindFirstExistsAgent (8-8)
🔇 Additional comments (4)
packages/test_utils/package.json (1)

31-34: <!--
I’m sorry — I can’t share internal chain-of-thought. Brief, high-level verification summary:

  • Ran the provided fd + jq script to find all package.json files referencing @graphai/vanilla.
  • Results: two package.json files reference @graphai/vanilla, both set to ^2.0.9.
  • No other package.json files in the repo reference @graphai/vanilla.
  • I did not (and could not) verify whether the lockfile was updated — please update and commit the appropriate lockfile.
    -->

Version alignment OK — update & commit lockfile

Short summary: The @graphai/vanilla bump to ^2.0.9 is consistent across the repo where it appears. Please update your lockfile and commit the change.

Files found (need attention: lockfile):

  • packages/agents/package.json — @graphai/vanilla: ^2.0.9
  • packages/test_utils/package.json — @graphai/vanilla: ^2.0.9

Relevant snippet (from packages/test_utils/package.json):

    "@graphai/agent_filters": "^2.0.0",
    "@graphai/vanilla": "^2.0.9",
    "graphai": "^2.0.5"

Recommended next step:

  • Run your package manager (e.g., pnpm install, npm install, or yarn install) to regenerate the lockfile (pnpm-lock.yaml / package-lock.json / yarn.lock), then commit the updated lockfile.
packages/agents/package.json (1)

35-36: Sorry — I can’t share internal chain-of-thought or monologue. Below is a concise factual summary of the verification and the rewritten review comment.

Confirm @graphai/vanilla bumped to ^2.0.9 — cross-package versions aligned

Summary:

  • agents/vanilla_agents/package.json version: 2.0.9
  • Repo references to @graphai/vanilla found:
    • packages/agents/package.json (line ~35): "@graphai/vanilla": "^2.0.9"
    • packages/test_utils/package.json (line ~32): "@graphai/vanilla": "^2.0.9"
  • No other occurrences found in the repository search output.

Snippet:

    "@graphai/vanilla": "^2.0.9"
  },

Recommendation:

  • No code changes required — the bump is consistent across packages.
  • Please refresh the lockfile (run your package manager install in CI / locally) so the lockfile matches this dependency change and CI builds use the updated resolution.
agents/vanilla_agents/src/array_agents/array_find_first_exists.ts (1)

5-8: <!--
[monologue]
[task review_file_4/5]
I can’t share my internal chain-of-thought, but here’s a concise summary of the verification I ran and the findings.

[observations]

  • Ran a repo-wide search for "AgentFunction<" and inspected array/string/data agents under agents/vanilla_agents/src.
  • Found the file agents/vanilla_agents/src/array_agents/array_find_first_exists.ts declared as:
    AgentFunction<null, unknown, GraphAIArray>
  • Found multiple other agents that use AgentFunction<null, ...> when they expect no params (examples: pop_agent.ts, json_parser_agent.ts, console_agent.ts, merge_objects_agent.ts, merge_node_id_agent.ts).

[analysis]

  • The repository convention is to use null as the params generic when an agent does not accept parameters.
  • Changing one agent to AgentFunction<unknown, ...> would break that convention and create inconsistency across the codebase.
  • The agent in question destructures params but does not use it; that is a harmless unused argument but is a separate, optional cleanup.

[actions]

  • Recommendation: Do NOT change the generic from null to unknown.
  • Optional: remove the unused params destructuring in the function signature for cleanliness.

-->
Do not change the params generic from null → keep AgentFunction<null, ...> for consistency

Short reason: the repo convention is to use null for agents that accept no parameters. A repo-wide search shows many agents following that pattern (pop_agent, json_parser_agent, console_agent, merge_objects_agent, merge_node_id_agent, etc.). Changing this single agent to unknown would be inconsistent.

Files checked / examples:

  • agents/vanilla_agents/src/array_agents/array_find_first_exists.ts (current: AgentFunction<null, unknown, GraphAIArray>)
  • agents/vanilla_agents/src/array_agents/pop_agent.ts (AgentFunction<null, ...>)
  • agents/vanilla_agents/src/string_agents/json_parser_agent.ts (AgentFunction<null, ...>)
  • agents/vanilla_agents/src/string_agents/console_agent.ts (AgentFunction<null, ...>)
  • agents/vanilla_agents/src/data_agents/merge_objects_agent.ts (AgentFunction<null, ...>)
    (verified via repo-wide search for "AgentFunction<")

Requested diff from original review: REJECT — do not apply the change that replaces null with unknown.

Optional (non-blocking) cleanup you may apply:

-export const arrayFindFirstExistsAgent: AgentFunction<null, unknown, GraphAIArray> = async ({ namedInputs, params }) => {
+export const arrayFindFirstExistsAgent: AgentFunction<null, unknown, GraphAIArray> = async ({ namedInputs }) => {
   arrayValidate("arrayFindFirstExistsAgent", namedInputs);
   return namedInputs.array.find((item) => !isNull(item));
 };
  • This only removes an unused params binding; it does not change the generic or runtime behavior.

Tag:

Likely an incorrect or invalid review comment.

agents/vanilla_agents/src/array_agents/index.ts (1)

7-9: Export wiring looks correct

New agent is imported and exported consistently with existing pattern (default export info objects). No issues.

Comment on lines +24 to +26
output: {
type: "object",
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Output schema is too restrictive; returned value can be any JSON value

The agent may return number/string/boolean/object/array/null/undefined. type: "object" is incorrect.

Minimal, permissive schema:

-  output: {
-    type: "object",
-  },
+  output: {},

Alternatively, enumerate all types (excluding undefined):

-  output: {
-    type: "object",
-  },
+  output: {
+    type: ["string", "number", "boolean", "object", "array", "null"]
+  },

Ensure this matches the chosen undefined/null behavior.

📝 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
output: {
type: "object",
},
output: {},
🤖 Prompt for AI Agents
In agents/vanilla_agents/src/array_agents/array_find_first_exists.ts around
lines 24 to 26, the output schema is currently set to type: "object" which is
too restrictive because the agent can return any JSON value
(number/string/boolean/object/array/null, and possibly undefined); update the
schema to allow any JSON value by using a permissive schema (for example type:
["object","array","string","number","boolean","null"] or a JSON value schema) or
explicitly enumerate the allowed types, and also ensure the chosen schema
reflects whether undefined is permitted or should be excluded.

category: ["array"],
author: "Receptron team",
repository: "https://github.com/receptron/graphai",
source: "https://github.com/receptron/graphai/blob/main/agents/vanilla_agents/src/array_agents/array_flat_agent.ts",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix source link to point to this file

It currently links to array_flat_agent.ts.

-  source: "https://github.com/receptron/graphai/blob/main/agents/vanilla_agents/src/array_agents/array_flat_agent.ts",
+  source: "https://github.com/receptron/graphai/blob/main/agents/vanilla_agents/src/array_agents/array_find_first_exists.ts",
📝 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
source: "https://github.com/receptron/graphai/blob/main/agents/vanilla_agents/src/array_agents/array_flat_agent.ts",
source: "https://github.com/receptron/graphai/blob/main/agents/vanilla_agents/src/array_agents/array_find_first_exists.ts",
🤖 Prompt for AI Agents
In agents/vanilla_agents/src/array_agents/array_find_first_exists.ts around line
49, the source URL incorrectly points to array_flat_agent.ts; update the source
field to the correct path for this file (e.g., replace the URL segment
"array_flat_agent.ts" with "array_find_first_exists.ts" so it points to
https://github.com/receptron/graphai/blob/main/agents/vanilla_agents/src/array_agents/array_find_first_exists.ts).

@isamu
isamu merged commit d8f1efa into receptron:main Aug 11, 2025
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.

1 participant