docs: document writing dialogue state from a custom action (#306) - #2362
Open
chethanuk wants to merge 1 commit into
Open
docs: document writing dialogue state from a custom action (#306)#2362chethanuk wants to merge 1 commit into
chethanuk wants to merge 1 commit into
Conversation
…Mo#306) ActionResult(context_updates=...) is the supported way to write a slot back into the conversation context, but no page named it. NVIDIA-NeMo#306 asks how an action sets a dialogue-state variable that a later flow can read. Adds an "ActionResult and Context Updates" section to Creating Actions with a Colang 2.0 and a Colang 1.0 tab, a cross-turn section to Extract User-provided Values, and pointers from Action Parameters and the Colang 2.0 Python actions reference. The Colang 2.0 text records that a ContextUpdate event placed in ActionResult.events is attached to the ActionFinished event and never applied, so context_updates is the only path that works there. The Colang 1.0 tab warns about returning a module-level mutable object, which silently drops every slot after the first. Covered by two tests that pin the published snippets: the Colang 2.0 test asserts the slot survives a second turn, the Colang 1.0 test asserts the value renders in a bot message. Dropping context_updates= from the 2.0 action fails with 'Hello None'. Closes NVIDIA-NeMo#306 Signed-off-by: ChethanUK <chethanuk@outlook.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
#306 asks how to manage dialogue state from a custom action. The capability exists and works in both Colang versions, but it is not documented anywhere.
ActionResultis the mechanism: Colang 1.0 turnscontext_updatesinto aContextUpdateevent, and Colang 2.0 merges the same field intostate.context. The page that owns return values, Creating Actions, covers Simple, Dictionary and Boolean returns and never mentionsActionResult.Four files, no new pages,
docs/index.ymluntouched.ActionResult and Context Updatessection under Return Values: a field table, and a Colang 2.0 / Colang 1.0 tab pair.eventsis marked Colang 1.0 only, since Colang 2.0 attaches those events to the action'sActionFinishedevent and never applies them.Store Extracted Values Across Turnssection. Extraction only puts the value in a flow variable; this is the missing half. Per-tab notes on how far the state actually carries: Colang 1.0 rebuilds context from the cached event history, Colang 2.0 needsprocess_events()becausegenerate()returnsNonefor the state andoutput_varsraises for a 2.0 config. Neither survives a restart.context"can be updated via ContextUpdate event", true of the event in general but not of the path an action controls.The Colang 1.0 tab warns about returning a module-level mutable object, which is #424. Colang 1.0 stores the action result by reference and re-runs the flow from element 0 on every internal event, so an object mutated in place changes underneath that replay and the
ifguards reading it flip. Colang 2.0 cannot hit this: it updates the context once per action and does not re-slide over the stored result.Related Issue(s)
Closes #306
Issue assignee: none yet — filed under label
question, not assigned to me. Flagging per CONTRIBUTING rather than assigning it myself.Verification
Two new tests, both pinning the snippets the pages publish:
The second turn is load-bearing: it asserts the slot outlives the turn that wrote it. Replacing
ActionResult(context_updates={"user_name": value})with a plainreturn valuefails it withExpected 'Hello Ngoc' and received 'Hello None'.The #424 warning is reproduced, not inferred: running the reporter's shape with a module-level dict returns an empty assistant message with slots stuck at
unknown; returningdict(user_info)instead, one word changed, fills all of them.pre-commitpasses on all six changed files.make docs-fernwas not run locally (needs network); CI'sdocs-build.yamlcoversdocs/**on PRs todevelop.One added snippet does not execute under
TestChat: the Colang 2.0 example in Extract User-provided Values follows theactivate llm continuation+user said "<prefix>"shape the page's six existing 2.0 examples already use, and that shape doesn't run under the harness today (not a regression — the page's own existing snippets fail the same way at this commit).AI Assistance
Checklist
creating-actions.mdx:211typingcontext_updatesasdictinstead ofOptional[dict]; fixed, seepr-review.md)