From 4a2daf42eaf34d3833166bcb98e7629930f295f8 Mon Sep 17 00:00:00 2001 From: Maxwell Du <60411452+maxduu@users.noreply.github.com> Date: Fri, 24 Apr 2026 01:20:27 -0400 Subject: [PATCH 1/3] feat: allow conversation id to be part of convo agent prompt --- .../agent/react/conversational_prompts.py | 30 ++++++++++- .../react/test_conversational_prompts.py | 53 +++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/packages/uipath/src/uipath/agent/react/conversational_prompts.py b/packages/uipath/src/uipath/agent/react/conversational_prompts.py index 7732c7f69..0e05ba846 100644 --- a/packages/uipath/src/uipath/agent/react/conversational_prompts.py +++ b/packages/uipath/src/uipath/agent/react/conversational_prompts.py @@ -24,6 +24,7 @@ class PromptUserSettings(BaseModel): _AGENT_SYSTEM_PROMPT_PREFIX_TEMPLATE = """You are {{CONVERSATIONAL_AGENT_SERVICE_PREFIX_agentName}}. The current date is: {{CONVERSATIONAL_AGENT_SERVICE_PREFIX_currentDate}}. Understand user goals through conversation and use appropriate tools to fulfill requests. +{{CONVERSATIONAL_AGENT_SERVICE_PREFIX_conversationIdPrompt}} ===================================================================== PRECEDENCE HIERARCHY @@ -136,18 +137,27 @@ class PromptUserSettings(BaseModel): {user_settings_json} ```""" +_CONVERSATION_ID_TEMPLATE = """ +The current conversation ID is {conversation_id}. +You should generally not discuss this conversation ID with the user, but it may be useful to include as a tool-call argument when relevant." +""" + def get_chat_system_prompt( model: str, system_message: str, agent_name: str | None, user_settings: PromptUserSettings | None = None, + conversation_id: str | None = None, ) -> str: """Generate a system prompt for a conversational agent. Args: agent_definition: Conversational agent definition user_settings: Optional user data that is injected into the system prompt. + conversation_id: Optional conversation identifier. When provided, the + prompt informs the model of the current conversation ID so it can + use it as a tool-call argument without surfacing it to the user. Returns: The complete system prompt string @@ -177,6 +187,10 @@ def get_chat_system_prompt( "{{CONVERSATIONAL_AGENT_SERVICE_PREFIX_userSettingsPrompt}}", get_user_settings_template(user_settings), ) + prompt = prompt.replace( + "{{CONVERSATIONAL_AGENT_SERVICE_PREFIX_conversationIdPrompt}}", + get_conversation_id_template(conversation_id), + ) return prompt @@ -190,7 +204,7 @@ def get_user_settings_template( user_settings: User profile information Returns: - The user context template with JSON or empty string + The filled-in user settings template if user_settings is provided, otherwise an empty string """ if user_settings is None: return "" @@ -205,3 +219,17 @@ def get_user_settings_template( user_settings_json = json.dumps(settings_dict, ensure_ascii=False) return _USER_CONTEXT_TEMPLATE.format(user_settings_json=user_settings_json) + + +def get_conversation_id_template(conversation_id: str | None) -> str: + """Get the conversation-ID prompt section. + + Args: + conversation_id: The ID of the current conversation, if any + + Returns: + The filled-in conversation ID template if conversation_id is provided, otherwise an empty string + """ + if not conversation_id: + return "" + return _CONVERSATION_ID_TEMPLATE.format(conversation_id=conversation_id) diff --git a/packages/uipath/tests/agent/react/test_conversational_prompts.py b/packages/uipath/tests/agent/react/test_conversational_prompts.py index a58a94807..0a3c4231f 100644 --- a/packages/uipath/tests/agent/react/test_conversational_prompts.py +++ b/packages/uipath/tests/agent/react/test_conversational_prompts.py @@ -149,6 +149,59 @@ def test_generate_system_prompt_unnamed_agent_uses_default(self): assert "You are Unnamed Agent." in prompt +class TestConversationIdInPrompt: + """Tests for conversation_id in generated prompts.""" + + def test_prompt_includes_conversation_id_when_provided(self): + prompt = get_chat_system_prompt( + model="claude-3-sonnet", + system_message=SYSTEM_MESSAGE, + agent_name="Test Agent", + user_settings=None, + conversation_id="conv-abc-123", + ) + + assert "The current conversation ID is conv-abc-123" in prompt + assert "You should generally not discuss this conversation ID with the user, but it may be useful to include as a tool-call argument when relevant." in prompt + assert "{{CONVERSATIONAL_AGENT_SERVICE_PREFIX_conversationIdPrompt}}" not in prompt + + def test_prompt_omits_conversation_id_section_when_none(self): + prompt = get_chat_system_prompt( + model="claude-3-sonnet", + system_message=SYSTEM_MESSAGE, + agent_name="Test Agent", + user_settings=None, + conversation_id=None, + ) + + assert "conversation ID" not in prompt + assert "{{CONVERSATIONAL_AGENT_SERVICE_PREFIX_conversationIdPrompt}}" not in prompt + + def test_prompt_omits_conversation_id_section_when_empty_string(self): + prompt = get_chat_system_prompt( + model="claude-3-sonnet", + system_message=SYSTEM_MESSAGE, + agent_name="Test Agent", + user_settings=None, + conversation_id="", + ) + + assert "conversation ID" not in prompt + + def test_prompt_defaults_to_no_conversation_id(self): + """conversation_id parameter defaults to None — call sites that don't + pass it must not get a dangling placeholder.""" + prompt = get_chat_system_prompt( + model="claude-3-sonnet", + system_message=SYSTEM_MESSAGE, + agent_name="Test Agent", + user_settings=None, + ) + + assert "{{CONVERSATIONAL_AGENT_SERVICE_PREFIX_conversationIdPrompt}}" not in prompt + assert "conversation ID" not in prompt + + class TestCitationFormat: """Tests for citation format in generated prompts.""" From 98cb9f6e3276624a22452b8a20061f24872a3815 Mon Sep 17 00:00:00 2001 From: Maxwell Du <60411452+maxduu@users.noreply.github.com> Date: Fri, 24 Apr 2026 01:20:52 -0400 Subject: [PATCH 2/3] fix: formatting --- .../agent/react/test_conversational_prompts.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/uipath/tests/agent/react/test_conversational_prompts.py b/packages/uipath/tests/agent/react/test_conversational_prompts.py index 0a3c4231f..5ec556d22 100644 --- a/packages/uipath/tests/agent/react/test_conversational_prompts.py +++ b/packages/uipath/tests/agent/react/test_conversational_prompts.py @@ -162,8 +162,13 @@ def test_prompt_includes_conversation_id_when_provided(self): ) assert "The current conversation ID is conv-abc-123" in prompt - assert "You should generally not discuss this conversation ID with the user, but it may be useful to include as a tool-call argument when relevant." in prompt - assert "{{CONVERSATIONAL_AGENT_SERVICE_PREFIX_conversationIdPrompt}}" not in prompt + assert ( + "You should generally not discuss this conversation ID with the user, but it may be useful to include as a tool-call argument when relevant." + in prompt + ) + assert ( + "{{CONVERSATIONAL_AGENT_SERVICE_PREFIX_conversationIdPrompt}}" not in prompt + ) def test_prompt_omits_conversation_id_section_when_none(self): prompt = get_chat_system_prompt( @@ -175,7 +180,9 @@ def test_prompt_omits_conversation_id_section_when_none(self): ) assert "conversation ID" not in prompt - assert "{{CONVERSATIONAL_AGENT_SERVICE_PREFIX_conversationIdPrompt}}" not in prompt + assert ( + "{{CONVERSATIONAL_AGENT_SERVICE_PREFIX_conversationIdPrompt}}" not in prompt + ) def test_prompt_omits_conversation_id_section_when_empty_string(self): prompt = get_chat_system_prompt( @@ -198,7 +205,9 @@ def test_prompt_defaults_to_no_conversation_id(self): user_settings=None, ) - assert "{{CONVERSATIONAL_AGENT_SERVICE_PREFIX_conversationIdPrompt}}" not in prompt + assert ( + "{{CONVERSATIONAL_AGENT_SERVICE_PREFIX_conversationIdPrompt}}" not in prompt + ) assert "conversation ID" not in prompt From faef72a0cb02f7649579270ad26d47fd8b0eabc1 Mon Sep 17 00:00:00 2001 From: Maxwell Du <60411452+maxduu@users.noreply.github.com> Date: Fri, 24 Apr 2026 01:46:24 -0400 Subject: [PATCH 3/3] chore: update comment --- .../uipath/src/uipath/agent/react/conversational_prompts.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/uipath/src/uipath/agent/react/conversational_prompts.py b/packages/uipath/src/uipath/agent/react/conversational_prompts.py index 0e05ba846..8066f436d 100644 --- a/packages/uipath/src/uipath/agent/react/conversational_prompts.py +++ b/packages/uipath/src/uipath/agent/react/conversational_prompts.py @@ -155,9 +155,7 @@ def get_chat_system_prompt( Args: agent_definition: Conversational agent definition user_settings: Optional user data that is injected into the system prompt. - conversation_id: Optional conversation identifier. When provided, the - prompt informs the model of the current conversation ID so it can - use it as a tool-call argument without surfacing it to the user. + conversation_id: Optional conversation identifier that is injected into the system prompt. Returns: The complete system prompt string