Skip to content

Conversation

@pavelgj
Copy link
Collaborator

@pavelgj pavelgj commented Jun 26, 2025

ai.defineResource({
  uri: 'my://resource/{param}',
  description: 'provides my resource',
}, async ({uri}) => {
  return [{ text: `resource ${uri}` }]
});

await ai.generate({
  prompt: [{text: 'analyze this: '}, { resource: { uri: 'my://resource/value' } }]
})

Checklist (if applicable):

@pavelgj pavelgj requested a review from mbleigh June 26, 2025 03:07
Copy link
Collaborator

@mbleigh mbleigh left a comment

Choose a reason for hiding this comment

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

Looking good, few comments and higher-level questions:

  1. Will resource resolution show up in traces?
  2. Should we put this in beta or go straight to stable?
  3. At the moment the action name is the URI but the metadata gets annotated with both the name and the URI - should we either allow an (optional?) name for a resource template or have metadata just be {resource: {uri: "..."}}
  4. Should we consider the part type being {resource: {uri: "..."}} instead of {resource: string}? I'm torn, because I like the simplicity a lot but worry if we might add something later...maybe better to keep it simple.
pavelgj and others added 3 commits June 26, 2025 17:05
Co-authored-by: Michael Bleigh <bleigh@google.com>
This commit introduces support for both resource templates (using RFC6570) and static URIs in the `defineResource` function.

- Added a `template` option to `ResourceOptions` for specifying URI templates.
- Updated the resource matching logic to handle both static URIs and templates.
- Updated tests to reflect the new functionality.
- Added resource metadata to parts.
@pavelgj
Copy link
Collaborator Author

pavelgj commented Jun 26, 2025

Looking good, few comments and higher-level questions:

  1. Will resource resolution show up in traces?

Yes:
image

  1. Should we put this in beta or go straight to stable?

I'm fine with stable if you're happy with the API.

  1. At the moment the action name is the URI but the metadata gets annotated with both the name and the URI - should we either allow an (optional?) name for a resource template or have metadata just be {resource: {uri: "..."}}

you're talking about generate message metadata (on the part)?
right now it's:

        metadata: {
          resource: {
            name: 'test://resource/{param}',
            uri: 'test://resource/value',
          },
        },

name referring the action name. Action name is derived from either uri or template (whichever one is provided).
The uri in metadata might be misleading... I'm thinking value instead.

        metadata: {
          resource: {
            name: 'test://resource/{param}',
            value: 'test://resource/value',
          },
        },
  1. Should we consider the part type being {resource: {uri: "..."}} instead of {resource: string}? I'm torn, because I like the simplicity a lot but worry if we might add something later...maybe better to keep it simple.

yeah... judgement call. It's conceivable that some other options might get added....

pavelgj and others added 3 commits June 26, 2025 20:31
Co-authored-by: Michael Bleigh <bleigh@google.com>
This commit refactors the resource API to return a content object instead of an array of parts. This change provides a more structured way to return resource content and allows for future expansion of the resource API.

The following changes were made:

- Updated the `ResourceFn` type to return a `ResourceOutput` object with a `content` property.
- Updated the `defineResource` function to return a `ResourceOutput` object.
- Updated the `applyResources` function to extract the `content` property from the `ResourceOutput` object.
- Updated tests to reflect the new API.
…void circular deps.

This commit refactors the `js/ai/src/model.ts` file by:

- Moving all type definitions to a new file `js/ai/src/model-types.ts` to improve code organization and readability.
- Exporting all types from `js/ai/src/model.ts` to maintain API compatibility.
- Updating imports and exports in `js/ai/src/model.ts` to reflect the changes.
@pavelgj pavelgj enabled auto-merge (squash) June 27, 2025 01:31
@pavelgj pavelgj merged commit 022ab9c into main Jun 27, 2025
5 checks passed
@pavelgj pavelgj deleted the pj/js-resources branch June 27, 2025 01:32
cabljac pushed a commit to invertase/genkit that referenced this pull request Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants