genkit icon indicating copy to clipboard operation
genkit copied to clipboard

Store arbitrary values in ALS/Context

Open mbleigh opened this issue 1 year ago • 0 comments

Within a flow there are a variety of reasons I might need to store out-of-band context. An example is let's say I have state stored according to a session id. I want tools to be used in the context of this session id, but I don't want the LLM to be forced to forward the session id through.

There should be an easy mechanism to do something like:

defineFlow({
  name: 'doThing',
  inputSchema: z.object({sessionId: z.string()}),
}, async input => {
  storeContext('sessionId', input.sessionId); // saved into ALS
  await generate({
    prompt: 'do stuff with tools',
    tools: ['getSessionHistory'],
  });
});

defineTool({
  name: 'getSessionHistory',
}, async () => {
  const sessionId = loadContext('sessionId');
  return await doSomeServerThing(sessionId);
});

In Go we may not need to do this because ctx.Context already gives people ways to do this for themselves, but I don't think folks are familiar enough with ALS to do this for themselves.

mbleigh avatar Jul 31 '24 20:07 mbleigh