Repository navigation
Array find first exists agent - #1182
Conversation
WalkthroughAdds 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
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)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (5)
agents/vanilla_agents/package.json (1)
3-3: Package version bump to 2.0.9Version 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 behaviorIf no element passes,
findreturnsundefined. Decide whether returningundefinedis acceptable or normalize tonullfor 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 descriptionShort and clear phrasing.
- description: "The array to be find", + description: "The array to search",
28-44: Samples are solid and cover falsy valuesGood 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 purposeCurrent 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
📒 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
nullas 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
paramsbut does not use it; that is a harmless unused argument but is a separate, optional cleanup.[actions]
- Recommendation: Do NOT change the generic from
nulltounknown.- Optional: remove the unused
paramsdestructuring in the function signature for cleanliness.-->
Do not change the params generic fromnull→ keepAgentFunction<null, ...>for consistencyShort reason: the repo convention is to use
nullfor 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 tounknownwould 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
nullwithunknown.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
paramsbinding; 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 correctNew agent is imported and exported consistently with existing pattern (default export info objects). No issues.
| output: { | ||
| type: "object", | ||
| }, |
There was a problem hiding this comment.
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.
| 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", |
There was a problem hiding this comment.
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.
| 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).
Summary by CodeRabbit
New Features
Chores