Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/uipath/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath"
version = "2.15.15"
version = "2.15.16"
description = "Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools."
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
Expand Down
46 changes: 46 additions & 0 deletions packages/uipath/src/uipath/agent/models/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,25 @@ def _drop_malformed_tools(cls, value: Any) -> Any:
return tools


class AdvancedSubagent(BaseCfg):
"""A subagent of an advanced-mode agent (``settings.subagents[]``).

``model`` absent means the parent agent's model; ``tools`` absent means every
parent tool, while an explicit list names parent tool resource ids. An entry
that doesn't parse is logged and dropped by ``AgentSettings``, so it never
fails parsing of the agent definition.
"""

id: str | None = None
name: str
description: str
system_prompt: str | None = Field(None, alias="systemPrompt")
model: str | None = None
byom_properties: AgentByomProperties | None = Field(None, alias="byomProperties")
mode: Literal["isolated", "fork"] = "isolated"
tools: list[str] | None = None


class AgentSettings(BaseCfg):
"""Agent settings model."""

Expand All @@ -1789,8 +1808,35 @@ class AgentSettings(BaseCfg):
max_iterations: Optional[int] = Field(None, alias="maxIterations")
persona: Optional[str] = Field(None, alias="persona")
model_settings: Optional[ModelSettings] = Field(None, alias="modelSettings")
mode: str | None = None
subagents: list[AdvancedSubagent] | None = None
advanced_agent: Optional[AdvancedAgentSettings] = Field(None, alias="advancedAgent")

@field_validator("subagents", mode="before")
@classmethod
def _drop_malformed_subagents(cls, value: Any) -> Any:
if value is None:
return None
if not isinstance(value, list):
logger.warning(
"Ignoring settings.subagents: expected a list, got %s",
type(value).__name__,
)
return None
subagents: List[AdvancedSubagent] = []
for index, entry in enumerate(value):
try:
subagents.append(AdvancedSubagent.model_validate(entry))
except ValidationError as exc:
name = entry.get("name") if isinstance(entry, dict) else None
logger.warning(
"Ignoring subagent %r at settings.subagents[%d]: %s",
name,
index,
exc.errors(include_url=False),
)
return subagents

@field_validator("advanced_agent", mode="before")
@classmethod
def _ignore_malformed_advanced_agent(cls, value: Any) -> Any:
Expand Down
7 changes: 7 additions & 0 deletions packages/uipath/src/uipath/agent/utils/text_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def build_string_from_tokens(
tool_names: list[str] | None = None,
escalation_names: list[str] | None = None,
context_names: list[str] | None = None,
subagent_names: list[str] | None = None,
) -> str:
"""Build a string from text tokens with variable replacement.

Expand All @@ -21,6 +22,7 @@ def build_string_from_tokens(
tool_names: Optional list of tool names for tool.* variable resolution
escalation_names: Optional list of escalation names for escalation.* variable resolution
context_names: Optional list of context names for context.* variable resolution
subagent_names: Optional list of subagent names for subagents.* variable resolution
"""
parts: list[str] = []

Expand All @@ -36,6 +38,7 @@ def build_string_from_tokens(
tool_names,
escalation_names,
context_names,
subagent_names,
)
parts.append(resolved_value)
else:
Expand All @@ -50,6 +53,7 @@ def _process_variable_token(
tool_names: list[str] | None = None,
escalation_names: list[str] | None = None,
context_names: list[str] | None = None,
subagent_names: list[str] | None = None,
) -> str:
"""Process a variable token and return its resolved value.

Expand Down Expand Up @@ -83,6 +87,9 @@ def _process_variable_token(
elif prefix == "contexts":
found_name = _find_resource_name(path, context_names)
return found_name if found_name else raw_string
elif prefix == "subagents":
found_name = _find_resource_name(path, subagent_names)
return found_name if found_name else raw_string

return raw_string

Expand Down
98 changes: 98 additions & 0 deletions packages/uipath/tests/agent/models/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from uipath.agent.models.agent import (
AdvancedAgentSettings,
AdvancedSubagent,
AgentA2aResourceConfig,
AgentBooleanOperator,
AgentBooleanRule,
Expand Down Expand Up @@ -5375,3 +5376,100 @@ def test_round_trip_by_alias_keeps_conversation_mode(self):
(reparsed,) = AgentDefinition.model_validate(dumped).resources
assert isinstance(reparsed, AgentConversationalAgentToolResourceConfig)
assert reparsed.settings.conversation_mode == "multiple"


class TestAdvancedSubagents:
"""``settings.mode`` and ``settings.subagents`` as written by Agent Builder."""

base = {"engine": "basic-v1", "model": "gpt-4o", "maxTokens": 100, "temperature": 0}

def test_absent_mode_and_subagents_are_none(self):
settings = AgentSettings.model_validate(self.base)
assert settings.mode is None
assert settings.subagents is None

def test_empty_list_is_kept_distinct_from_absent(self):
settings = AgentSettings.model_validate(
{**self.base, "mode": "advanced", "subagents": []}
)
assert settings.mode == "advanced"
assert settings.subagents == []

def test_parses_a_subagent_by_alias_with_defaults(self):
settings = AgentSettings.model_validate(
{
**self.base,
"mode": "advanced",
"subagents": [
{"id": "s1", "name": "general-purpose", "description": "Anything"}
],
}
)
assert settings.subagents is not None
(subagent,) = settings.subagents
assert isinstance(subagent, AdvancedSubagent)
assert subagent.mode == "isolated"
assert subagent.tools is None
assert subagent.model is None
assert subagent.system_prompt is None
assert subagent.byom_properties is None

def test_parses_a_fully_configured_subagent(self):
subagent = AdvancedSubagent.model_validate(
{
"id": "s2",
"name": "researcher",
"description": "Reads files",
"systemPrompt": "Be brief",
"model": "gpt-4o-mini",
"byomProperties": {
"connectionId": "c1",
"connectorKey": "uipath-openai",
},
"mode": "fork",
"tools": ["tool-1"],
}
)
assert subagent.system_prompt == "Be brief"
assert subagent.mode == "fork"
assert subagent.tools == ["tool-1"]
assert subagent.byom_properties is not None
assert subagent.byom_properties.connection_id == "c1"

def test_malformed_subagent_entry_is_dropped_and_others_kept(
self, caplog: pytest.LogCaptureFixture
):
with caplog.at_level(logging.WARNING):
settings = AgentSettings.model_validate(
{
**self.base,
"mode": "advanced",
"subagents": [
{"name": "no-description"},
{"name": "future", "description": "d", "mode": "async"},
{"name": "kept", "description": "d"},
"not-an-object",
],
}
)
assert settings.subagents is not None
assert [subagent.name for subagent in settings.subagents] == ["kept"]
assert "no-description" in caplog.text
assert "future" in caplog.text

@pytest.mark.parametrize("subagents", ["x", {"name": "x"}, 5])
def test_malformed_subagents_is_ignored(
self, subagents: Any, caplog: pytest.LogCaptureFixture
):
with caplog.at_level(logging.WARNING):
settings = AgentSettings.model_validate(
{**self.base, "mode": "advanced", "subagents": subagents}
)
assert settings.subagents is None
assert "subagents" in caplog.text

def test_rejects_an_unknown_mode(self):
with pytest.raises(ValidationError):
AdvancedSubagent.model_validate(
{"name": "x", "description": "y", "mode": "handoff"}
)
22 changes: 22 additions & 0 deletions packages/uipath/tests/agent/utils/test_text_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,25 @@ def test_boolean(self):
def test_string_enum_uses_underlying_value(self):
"""Test string enums serialize to their values for prompt interpolation."""
assert serialize_argument(self.RiskTolerance.LOW) == "low"


class TestSubagentTokens:
"""``subagents.*`` variables resolve like the other resource categories."""

def test_resolves_to_the_configured_subagent_name(self):
tokens = [
TextToken(type=TextTokenType.SIMPLE_TEXT, raw_string="Delegate to "),
TextToken(type=TextTokenType.VARIABLE, raw_string="subagents.Researcher"),
]
result = build_string_from_tokens(
tokens, {}, subagent_names=["researcher", "general-purpose"]
)
assert result == "Delegate to researcher"

def test_keeps_the_raw_string_when_unknown(self):
tokens = [TextToken(type=TextTokenType.VARIABLE, raw_string="subagents.ghost")]
assert (
build_string_from_tokens(tokens, {}, subagent_names=["researcher"])
== "subagents.ghost"
)
assert build_string_from_tokens(tokens, {}) == "subagents.ghost"
2 changes: 1 addition & 1 deletion packages/uipath/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading