genkit
genkit copied to clipboard
Default Context / Context Resolver
When building a complex project that has non-trivial context, it's difficult to make it work with the Dev UI for a few reasons:
- Dev UI does not currently support context well throughout (e.g. tools)
- Even if it did, context is not always representable as JSON
I have a couple ideas to address this:
const ai = genkit({...});
// 1. Have a "default context" that is settable after genkit init
ai.applyContext({foo: 'bar'}); // now context will always be `{foo: 'bar'}` unless explicitly passed
ai.applyContext((actionMeta, input, {context}) => { /* set programmatically */ });
ai.defineTool({..., defaultContext: {...}}); // alternative
// 2. Have a "context resolver" that can translate JSON from Dev UI to context
ai.defineTool({..., resolveContext: (inputContext) => outputContext)});
Needs more noodling, but wanted to record.