Ai Automators could need more Events before asking AI
## Summary Ai Automators seem to have no dedicated event which is fired, when all token are replaced with data and before the request will be send to the AI, which makes it hard to "preprocess" the prompt and alter the context. ## Problem This may sound vague, but I'll describe the problem I ran into. To make our website more AI generated content friendly, we may have to get rid of a lot of Drupal Paragraphs, because AI (in the current state) will have problems to understand the JSON:API workflow to create references. Therefore I use one HTML text field, which AI can fill with content. (Which works fine). But, in order to write something via AI (this is our specific case) I added a field to the content-type where I have to put in something like a holiday ID from a website. My AI Automator has this field_holiday_id as base field and also has a prompt which will say how the body field needs to be filled with {{ context }}. Well not exactly. I asked AI, were in the ai_automator code I possibly can highjack the information flow and modify the prompt to add additional data, which in my case I get from an REST API as JSON. Which I simply wanted to add in the prompt via HOLIDAY ---- {{ API response }} ----. So AI can read the JSON and has then enough data to fullfill the actual prompt. This works find. AI found the AutomatorConfigEvent which works for that scenario. But, this event has at least two problems. 1st it is called a bunch of times and would every time result in an API call, which is bad. And 2nd when I want to use more human filled fields and I use the Token system (which I tried), then these tokens are not processed when this event is triggered. I looked for another event which will fix one or the other problem, but after the tokens are replaced it goes straight into the ai provider. I experimented also with the ProcessFieldEvent and the PreGenerateResponseEvent (which has not the config object available) but these are also wrong. I think in times like this (fast moving AI) not everything has to be solved via UI. Therefore having a module, which hooks into some events to alter the prompt before it will be send to the ai provider would be beneficial. As a side note, I also wanted to add on-the-fly skill like markdown files also to the prompt. There is an ai_context module I believe, but something was off to use it. I just want to have skill.md files which I can setup per content-type which then will be added automatically to the prompt. That was not possible. And btw. modifying the context inside ai_automators was not supported iirc. One last thing: base mode should support (just like views) all other text fields from the entity. Why have only one field as source available in base mode when either a "+" could add more or the replacements placeholder could be {{ context_field_a }} {{ context_body }} {{ context_field_links }}. ## Proposed solution *(optional)* For ai_automators an event would be nice which is dedicated for enriching the prompt before it gets send AND which is only fired once. This event should fire AFTER the tokens are rendered. Another event which fires once per ai request to add skills to an context would be nice as well. I myself would then write an ai_skills module, which will have a hook (or similar) system so that each module can have a /skills/*.md directory, in which markdown files could sit and wait to be added to a context (via some condition). ## Workaround *(optional)* Avoid the token system and just use the AutomatorConfigEvent and get the input you need via $this->getEntity(); Find a way to only execute your expensive data gathering calls once. ## Affected modules / components *(optional)* ai_automators
issue