Skip to content

Commit 0aa6d68

Browse files
authored
fix: move voice prompt from agents to python repo (#1463)
1 parent 62c8196 commit 0aa6d68

7 files changed

Lines changed: 105 additions & 10 deletions

File tree

packages/uipath/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath"
3-
version = "2.10.23"
3+
version = "2.10.24"
44
description = "Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools."
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"

packages/uipath/src/uipath/agent/react/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
PromptUserSettings,
88
get_chat_system_prompt,
99
)
10+
from .conversational_voice_prompts import get_voice_system_prompt
1011
from .prompts import AGENT_SYSTEM_PROMPT_TEMPLATE
1112
from .tools import (
1213
END_EXECUTION_TOOL,
@@ -25,4 +26,5 @@
2526
"RaiseErrorToolSchemaModel",
2627
"PromptUserSettings",
2728
"get_chat_system_prompt",
29+
"get_voice_system_prompt",
2830
]

packages/uipath/src/uipath/agent/react/conversational_prompts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,13 @@ def get_chat_system_prompt(
175175
)
176176
prompt = prompt.replace(
177177
"{{CONVERSATIONAL_AGENT_SERVICE_PREFIX_userSettingsPrompt}}",
178-
_get_user_settings_template(user_settings),
178+
get_user_settings_template(user_settings),
179179
)
180180

181181
return prompt
182182

183183

184-
def _get_user_settings_template(
184+
def get_user_settings_template(
185185
user_settings: PromptUserSettings | None,
186186
) -> str:
187187
"""Get the user settings template section.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""Conversational voice agent prompt generation logic."""
2+
3+
from datetime import datetime, timezone
4+
5+
from .conversational_prompts import PromptUserSettings, get_user_settings_template
6+
7+
_VOICE_SYSTEM_PROMPT_TEMPLATE = """You are {{VOICE_AGENT_PREFIX_agentName}}.
8+
The current date is: {{VOICE_AGENT_PREFIX_currentDate}}.
9+
10+
=====================================================================
11+
AGENT SYSTEM PROMPT
12+
=====================================================================
13+
{{VOICE_AGENT_PREFIX_systemPrompt}}
14+
15+
{{VOICE_AGENT_PREFIX_userSettingsPrompt}}
16+
17+
=====================================================================
18+
TOOL USAGE RULES
19+
=====================================================================
20+
Use the end call tool to end the call when:
21+
- The primary objective of the call has been fulfilled and the user confirms they have no further questions
22+
- The user explicitly asks to end the call or says goodbye
23+
24+
"""
25+
26+
27+
def get_voice_system_prompt(
28+
system_message: str,
29+
agent_name: str | None,
30+
user_settings: PromptUserSettings | None = None,
31+
) -> str:
32+
"""Build the full voice system prompt with agent name, date, and optional user context."""
33+
formatted_date = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%MZ")
34+
35+
prompt = _VOICE_SYSTEM_PROMPT_TEMPLATE
36+
prompt = prompt.replace(
37+
"{{VOICE_AGENT_PREFIX_agentName}}",
38+
agent_name or "Voice Assistant",
39+
)
40+
prompt = prompt.replace(
41+
"{{VOICE_AGENT_PREFIX_currentDate}}",
42+
formatted_date,
43+
)
44+
prompt = prompt.replace(
45+
"{{VOICE_AGENT_PREFIX_systemPrompt}}",
46+
system_message,
47+
)
48+
prompt = prompt.replace(
49+
"{{VOICE_AGENT_PREFIX_userSettingsPrompt}}",
50+
get_user_settings_template(user_settings),
51+
)
52+
53+
return prompt

packages/uipath/tests/agent/react/test_conversational_prompts.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
from uipath.agent.react.conversational_prompts import (
99
PromptUserSettings,
10-
_get_user_settings_template,
1110
get_chat_system_prompt,
11+
get_user_settings_template,
1212
)
1313

1414
SYSTEM_MESSAGE = "You are a helpful assistant."
@@ -235,23 +235,23 @@ def test_default_none_values(self):
235235

236236

237237
class TestGetUserSettingsTemplate:
238-
"""Tests for _get_user_settings_template helper."""
238+
"""Tests for get_user_settings_template helper."""
239239

240240
def test_none_returns_empty(self):
241241
"""Returns empty string when user_settings is None."""
242-
result = _get_user_settings_template(None)
242+
result = get_user_settings_template(None)
243243
assert result == ""
244244

245245
def test_empty_settings_returns_empty(self):
246246
"""Returns empty string when all fields are None."""
247247
settings = PromptUserSettings()
248-
result = _get_user_settings_template(settings)
248+
result = get_user_settings_template(settings)
249249
assert result == ""
250250

251251
def test_partial_settings_includes_non_none_only(self):
252252
"""Only includes non-None fields in JSON."""
253253
settings = PromptUserSettings(name="Test", email="test@example.com")
254-
result = _get_user_settings_template(settings)
254+
result = get_user_settings_template(settings)
255255

256256
assert "USER CONTEXT" in result
257257
assert '"name": "Test"' in result or '"name":"Test"' in result
@@ -271,7 +271,7 @@ def test_full_settings_json_format(self):
271271
country="UK",
272272
timezone="Europe/London",
273273
)
274-
result = _get_user_settings_template(settings)
274+
result = get_user_settings_template(settings)
275275

276276
# Extract JSON from the result
277277
json_match = re.search(r"```json\s*(\{[^`]+\})\s*```", result)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Tests for voice agent prompt generation."""
2+
3+
from uipath.agent.react import PromptUserSettings, get_voice_system_prompt
4+
5+
6+
class TestGetVoiceSystemPrompt:
7+
"""Test get_voice_system_prompt with various user settings."""
8+
9+
def test_no_user_settings(self) -> None:
10+
result = get_voice_system_prompt("Be helpful.", "Agent")
11+
assert "USER CONTEXT" not in result
12+
assert "Be helpful." in result
13+
14+
def test_with_user_settings(self) -> None:
15+
settings = PromptUserSettings(name="Alice", email="alice@test.com")
16+
result = get_voice_system_prompt("Be helpful.", "Agent", user_settings=settings)
17+
assert "USER CONTEXT" in result
18+
assert '"name": "Alice"' in result
19+
assert '"email": "alice@test.com"' in result
20+
21+
def test_user_settings_none_values_excluded(self) -> None:
22+
settings = PromptUserSettings(name="Bob")
23+
result = get_voice_system_prompt("Be helpful.", "Agent", user_settings=settings)
24+
assert '"name": "Bob"' in result
25+
assert "email" not in result
26+
27+
def test_user_settings_all_none_skipped(self) -> None:
28+
settings = PromptUserSettings()
29+
result = get_voice_system_prompt("Be helpful.", "Agent", user_settings=settings)
30+
assert "USER CONTEXT" not in result
31+
32+
def test_default_agent_name(self) -> None:
33+
result = get_voice_system_prompt("Hello.", None)
34+
assert "You are Voice Assistant." in result
35+
36+
def test_includes_date_and_system_message(self) -> None:
37+
result = get_voice_system_prompt("Do things.", "MyAgent")
38+
assert "You are MyAgent." in result
39+
assert "The current date is:" in result
40+
assert "Do things." in result

packages/uipath/uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)