Skip to content

Add isArray and isMap to tree-agent context#25725

Merged
noencke merged 1 commit intomicrosoft:mainfrom
noencke:isArray-isMap
Oct 21, 2025
Merged

Add isArray and isMap to tree-agent context#25725
noencke merged 1 commit intomicrosoft:mainfrom
noencke:isArray-isMap

Conversation

@noencke
Copy link
Copy Markdown
Contributor

@noencke noencke commented Oct 21, 2025

This gives the LLM an alternative to Array.isArray and instanceof Map that will work on our node types, since Array.isArray does not work with our non-pojo array classes.

The provided functions also work for JS arrays and Maps, so the LLM doesn't have to distinguish between when to use the built-in Array.isArray vs. when to use our provided isArray helper - it can always use the latter. This also gives us the option in the future to force it to use ours by making Array.isArray error within the boundaries of the eval.

This also adds some explicit tests in SharedTree for Array.isArray support.

@noencke noencke requested a review from a team as a code owner October 21, 2025 17:36
@noencke noencke requested review from Copilot and taylorsw04 October 21, 2025 17:36
@github-actions github-actions bot added area: dds Issues related to distributed data structures area: dds: tree area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct base: main PRs targeted against main branch labels Oct 21, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds isArray and isMap helper functions to the tree-agent context, providing LLM-friendly alternatives to Array.isArray and instanceof Map that work correctly with Fluid Framework's custom node types. These helpers also support native JavaScript arrays and Maps, allowing consistent usage patterns in LLM-generated code.

Key changes:

  • Added isArray and isMap helper functions to the Context interface and implementation
  • Updated prompt generation to include documentation for these new helpers
  • Added comprehensive test coverage for both helpers

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/framework/tree-agent/src/api.ts Adds isArray and isMap method signatures to the Context interface
packages/framework/tree-agent/src/agent.ts Implements isArray and isMap helpers using NodeKind checks for TreeNode instances
packages/framework/tree-agent/src/prompt.ts Updates prompt generation to document the new helpers and improves example type name extraction
packages/framework/tree-agent/src/test/agent.spec.ts Adds test coverage for isArray and isMap helpers, removes obsolete test and eslint directives
packages/framework/tree-agent/src/test/__snapshots__/prompt.md Updates snapshot to reflect new helper documentation and improved examples
packages/dds/tree/src/test/simple-tree/node-kinds/arrayNode.spec.ts Documents that custom array nodes don't pass Array.isArray

editToolName,
async query({ edit }) {
const result = await edit(
`if (!context.isArray([]) ||!context.isArray(context.root)) { throw new Error('Expected array root'); } context.root.insertAt(0, 99);`,
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

Missing space after || operator. Should be || !context.isArray for consistency with coding standards.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown
Contributor

🔗 Found some broken links! 💔

Run a link check locally to find them. See
https://github.com/microsoft/FluidFramework/wiki/Checking-for-broken-links-in-the-documentation for more information.

linkcheck output


> fluid-framework-docs-site@0.0.0 ci:check-links /home/runner/work/FluidFramework/FluidFramework/docs
> start-server-and-test "npm run serve -- --no-open" 3000 check-links

1: starting server using command "npm run serve -- --no-open"
and when url "[ 'http://127.0.0.1:3000' ]" is responding with HTTP status code 200
running tests using command "npm run check-links"


> fluid-framework-docs-site@0.0.0 serve
> docusaurus serve --no-open

[SUCCESS] Serving "build" directory at: http://localhost:3000/

> fluid-framework-docs-site@0.0.0 check-links
> linkcheck http://localhost:3000 --skip-file skipped-urls.txt

 ELIFECYCLE  Command failed with exit code 1.

@noencke noencke merged commit accd36a into microsoft:main Oct 21, 2025
39 checks passed
@noencke noencke deleted the isArray-isMap branch October 21, 2025 20:33
anthony-murphy-agent pushed a commit to anthony-murphy-agent/FluidFramework that referenced this pull request Jan 14, 2026
This gives the LLM an alternative to `Array.isArray` and `instanceof
Map` that will work on our node types, since `Array.isArray` does not
work with our non-pojo array classes.

The provided functions also work for JS arrays and Maps, so the LLM
doesn't have to distinguish between when to use the built-in
Array.isArray vs. when to use our provided `isArray` helper - it can
always use the latter. This also gives us the option in the future to
force it to use ours by making `Array.isArray` error within the
boundaries of the eval.

This also adds some explicit tests in SharedTree for `Array.isArray`
support.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: dds: tree area: dds Issues related to distributed data structures area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct base: main PRs targeted against main branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants