simplify workflow history and add page tracking #354
+550
−42
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Short Description
Supports merging workflow and job code chats OpenFn/lightning#4109
Adds page navigation tracking to both
job_chatandworkflow_chatservices to improve context awareness and auto-refresh documentation when users navigate between different jobs or workflows. When users switch pages (different job, workflow, or adaptor), the conversation history shows page context via prefixes like[pg:job_code/Transform data/language-common], andjob_chatautomatically refreshes RAG documentation to ensure relevant adaptor docs are retrieved.Fixes #350
Implementation Details
Page Context Construction
contextpayload:job_chat: Extracts currentpage_nameandadaptorfromcontext.page_nameandcontext.adaptor, sets type to"job_code"workflow_chat: Extracts currentpage_namefromcontext.page_name, sets type to"workflow"last_pagein responsemeta(populated with current page info). This is then received in the next conversation turn, along with an updated currentcontext.page_nameHistory Prefixing
add_page_prefix()helper function prefixes user messages in history with format:[pg:type/name/adaptor]or[pg:type/name][pg:job_code/Get FHIR data/language-fhir](job_chat with adaptor)[pg:workflow/fridge-statistics-processing](workflow_chat)Simplified History Format
"I'll add error handling..."instead of{"text": "I'll add error handling...", "yaml": "..."}Navigation Detection & RAG Auto-refresh
has_navigated()helper tojob_chatto detect page changescurrent_page(constructed from context) withlast_page(received from meta)type,name, ORadaptorchangesjob_chatautomatically setsrefresh_rag=trueto fetch fresh documentation for the new page/adaptorBackward Compatibility
job_chatalways includesmetakey withragdata (maintains existing behaviour)workflow_chatconditionally includesmetaonly when page data is present (no breaking change asmetawas never returned before)contextfield toworkflow_chatPayload (previously only injob_chat)Prompt Changes
Tests Added
Anthropic's structured outputs NOT used
Summary of changes relevant to Lightning
last_pagefrom Lightning viametakey (or None on first turn).metais already passed unchanged between Lightning and Apollo forjob_chat, so no change needed.current_pagein thecontextkey.Requests for Lightning:
contextkey in workflow_chat calls, with acurrent_pagekey. This should just be the name of the workflow/step, like 'fetch-fhir-data'.current_pagekey to thecontextkeymetakey, it should be passed back unchanged in the next conversation turn. (It would be ok to add an emptymetakey at the beginning of a conversation too)AI Usage
Please disclose how you've used AI in this work (it's cool, we just want to know!):
You can read more details in our Responsible AI Policy