Repository navigation
feat(agent): make the conversational loop aware of its output schema - #2003
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified in the output-schema prompt changes.
No open issues 🎉
What changed in this PR
This PR adds output-schema awareness to the UiPath SDK’s conversational prompts, helping agents distinguish user-facing replies from structured fields recorded after each turn. Runtime wiring is handled in companion repositories.
Changes:
- Adds an optional output-schema hint and a schema-independent helper to remove it before extraction.
- Clarifies that structured output extraction applies only to the current turn.
- Exports the new helpers and adds tests for rendering, removal, and prompt preservation.
| File | Description |
|---|---|
packages/uipath/tests/agent/react/test_conversational_prompts.py |
Tests schema hints, stripping behavior, and current-turn instructions. |
packages/uipath/src/uipath/agent/react/conversational_prompts.py |
Adds schema-aware prompts and stripping support; refines extraction instructions. |
packages/uipath/src/uipath/agent/react/__init__.py |
Exports the hint-rendering and stripping helpers. |
Review effort: Balanced
The hard-wrapped section text becomes single lines; content is unchanged, and the strip derives its markers from these same constants so it cannot drift. Also formats the two over-long lines in strip_conversational_output_hint_section that ruff format was already flagging. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
🚨 Heads up:
|
radu-mocanu
left a comment
There was a problem hiding this comment.
looks good!
don t forget to bump the patch version before merging
|



Why
See https://github.com/UiPath/uipath-agents-python/pull/900 for full context and testing.
In summary:
A conversational agent's structured output fields are filled by a separate LLM call after the loop ends. The loop itself never sees the output schema, so a builder who writes "set
statusto resolved in the output" in the system prompt gives the agent an instruction it cannot act on. The agent then either hunts for a tool that does not exist, or narrates the field values to the user.This is the uipath-python half: the prompt itself. Wiring lives in uipath-agents-python, and the extraction-call handling in uipath-langchain-python.
What changes
get_chat_system_promptgains an optionaloutput_schemaparameter. When present, the schema's JSON is appended to the conversational system prompt under aSTRUCTURED OUTPUT FOR THIS TURNsection that tells the model three things: the fields are recorded after its turn by a separate step, there is no tool for them, and the reply the user reads should not mention them.Two supporting pieces:
get_conversational_output_hint_section(output_schema)renders the section; it returns""forNone, so callers that pass nothing behave exactly as before.strip_conversational_output_hint_section(prompt)removes it again. The extraction call replays the exchange including the system message, where "you have no tool for these fields" would directly contradict the instruction telling the model to callset_conversational_output. Today a forced tool choice masks that contradiction; it would stop masking it as soon as models that reject forcing are downgraded toauto.The strip is schema-independent: its markers come from the section constants used to render it, so the two cannot drift. An earlier version re-rendered the section from the schema to find it, which silently did nothing whenever the caller had narrowed the schema differently.
_GENERATE_OUTPUT_INSTRUCTIONis also reworded to scope extraction to the current turn, so a value established in an earlier turn is not reported again when a flow loops back into the same agent.Testing
39 tests in
test_conversational_prompts.py, covering the section's presence and absence, the schema JSON being injected verbatim, andstrip ∘ assemblerestoring the bare prompt byte-for-byte.End-to-end results are in the uipath-agents-python PR: 175 live runs across 7 authoring styles, 4 scenarios and 5 models. Summary — 8 replies leaked raw output JSON to the user without this section and 0 with it; 2 runs crashed inventing a tool and 0 with it; field accuracy unchanged.