Skip to content

Store arbitrary values in ALS/Context #727

@mbleigh

Description

@mbleigh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions