Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store arbitrary context in Flow AsyncLocalStorage #880

Open
mbleigh opened this issue Sep 9, 2024 · 0 comments
Open

Store arbitrary context in Flow AsyncLocalStorage #880

mbleigh opened this issue Sep 9, 2024 · 0 comments

Comments

@mbleigh
Copy link
Collaborator

mbleigh commented Sep 9, 2024

Because tools and flows are defined independently but are often interrelated in practice, it would be great to be able to set and retrieve arbitrary values from ALS. Something like:

import { setFlowContext, getFlowContext, defineFlow, defineTool, generate } from "genkit";

const findRestaurant = defineTool({
  name: 'findRestaurant',
  inputSchema: z.object({query: z.string()}),
  async ({query}) => {
    const userInfo = getFlowContext('userInfo');
    return searchRestaurants(query, zipcode: userInfo.zipcode);
  }
});

defineFlow({
  name: 'chatbotFlow',
  inputSchema: z.object({userInfo: UserInfoSchema}),
}, ({userInfo}) => {
  setFlowContext('userInfo', userInfo);
  generate({
    // ...
    tools: [findRestaurant],
  });
});
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

No branches or pull requests

1 participant