|
11 | 11 | ) |
12 | 12 |
|
13 | 13 | from uipath_langchain.agent.tools.static_args import ( |
| 14 | + ArgumentPropertiesMixin, |
14 | 15 | StaticArgsHandler, |
15 | 16 | apply_static_args, |
| 17 | + resolve_static_args, |
16 | 18 | ) |
17 | 19 | from uipath_langchain.agent.tools.structured_tool_with_argument_properties import ( |
18 | 20 | StructuredToolWithArgumentProperties, |
@@ -461,3 +463,119 @@ def test_apply_static_args_replace_entire_array(self): |
461 | 463 | "enabled": True, |
462 | 464 | } |
463 | 465 | assert result == expected |
| 466 | + |
| 467 | + |
| 468 | +class TestResolveStaticArgs: |
| 469 | + """Test cases for resolve_static_args function.""" |
| 470 | + |
| 471 | + def test_resolve_static_args_with_argument_properties(self): |
| 472 | + """Test resolve_static_args with an object that has argument_properties.""" |
| 473 | + |
| 474 | + class ResourceWithProps(ArgumentPropertiesMixin): |
| 475 | + argument_properties = { |
| 476 | + "$['host']": AgentToolStaticArgumentProperties( |
| 477 | + is_sensitive=False, value="api.example.com" |
| 478 | + ), |
| 479 | + } |
| 480 | + |
| 481 | + result = resolve_static_args(ResourceWithProps(), {"unused": "input"}) |
| 482 | + |
| 483 | + assert result == {"$['host']": "api.example.com"} |
| 484 | + |
| 485 | + def test_resolve_static_args_with_static_values_of_different_types(self): |
| 486 | + """Test resolve_static_args resolves string, integer, and object static values.""" |
| 487 | + |
| 488 | + class ResourceWithProps(ArgumentPropertiesMixin): |
| 489 | + argument_properties = { |
| 490 | + "$['connection_id']": AgentToolStaticArgumentProperties( |
| 491 | + is_sensitive=False, value="12345" |
| 492 | + ), |
| 493 | + "$['timeout']": AgentToolStaticArgumentProperties( |
| 494 | + is_sensitive=False, value=30 |
| 495 | + ), |
| 496 | + "$['config']": AgentToolStaticArgumentProperties( |
| 497 | + is_sensitive=False, value={"enabled": True, "retries": 3} |
| 498 | + ), |
| 499 | + } |
| 500 | + |
| 501 | + result = resolve_static_args(ResourceWithProps(), {"unused": "input"}) |
| 502 | + |
| 503 | + assert result == { |
| 504 | + "$['connection_id']": "12345", |
| 505 | + "$['timeout']": 30, |
| 506 | + "$['config']": {"enabled": True, "retries": 3}, |
| 507 | + } |
| 508 | + |
| 509 | + def test_resolve_static_args_with_argument_properties_extracts_from_agent_input( |
| 510 | + self, |
| 511 | + ): |
| 512 | + """Test resolve_static_args resolves AgentToolArgumentArgumentProperties from agent_input.""" |
| 513 | + |
| 514 | + class ResourceWithProps(ArgumentPropertiesMixin): |
| 515 | + argument_properties = { |
| 516 | + "$['user_id']": AgentToolArgumentArgumentProperties( |
| 517 | + is_sensitive=False, argument_path="userId" |
| 518 | + ), |
| 519 | + "$['query']": AgentToolArgumentArgumentProperties( |
| 520 | + is_sensitive=False, argument_path="searchQuery" |
| 521 | + ), |
| 522 | + } |
| 523 | + |
| 524 | + agent_input = { |
| 525 | + "userId": "user123", |
| 526 | + "searchQuery": "test search", |
| 527 | + "unused_arg": "not_used", |
| 528 | + } |
| 529 | + |
| 530 | + result = resolve_static_args(ResourceWithProps(), agent_input) |
| 531 | + |
| 532 | + assert result == { |
| 533 | + "$['user_id']": "user123", |
| 534 | + "$['query']": "test search", |
| 535 | + } |
| 536 | + |
| 537 | + def test_resolve_static_args_with_mixed_static_and_argument_properties(self): |
| 538 | + """Test resolve_static_args with both static and argument properties.""" |
| 539 | + |
| 540 | + class ResourceWithProps(ArgumentPropertiesMixin): |
| 541 | + argument_properties = { |
| 542 | + "$['api_key']": AgentToolStaticArgumentProperties( |
| 543 | + is_sensitive=False, value="secret_key" |
| 544 | + ), |
| 545 | + "$['user_id']": AgentToolArgumentArgumentProperties( |
| 546 | + is_sensitive=False, argument_path="userId" |
| 547 | + ), |
| 548 | + "$['version']": AgentToolStaticArgumentProperties( |
| 549 | + is_sensitive=False, value="v1" |
| 550 | + ), |
| 551 | + } |
| 552 | + |
| 553 | + agent_input = {"userId": "user456"} |
| 554 | + |
| 555 | + result = resolve_static_args(ResourceWithProps(), agent_input) |
| 556 | + |
| 557 | + assert result == { |
| 558 | + "$['api_key']": "secret_key", |
| 559 | + "$['user_id']": "user456", |
| 560 | + "$['version']": "v1", |
| 561 | + } |
| 562 | + |
| 563 | + def test_resolve_static_args_skips_missing_argument_values(self): |
| 564 | + """Test that argument properties referencing missing agent_input keys are skipped.""" |
| 565 | + |
| 566 | + class ResourceWithProps(ArgumentPropertiesMixin): |
| 567 | + argument_properties = { |
| 568 | + "$['existing_param']": AgentToolArgumentArgumentProperties( |
| 569 | + is_sensitive=False, argument_path="existingArg" |
| 570 | + ), |
| 571 | + "$['missing_param']": AgentToolArgumentArgumentProperties( |
| 572 | + is_sensitive=False, argument_path="missingArg" |
| 573 | + ), |
| 574 | + } |
| 575 | + |
| 576 | + agent_input = {"existingArg": "exists"} |
| 577 | + |
| 578 | + result = resolve_static_args(ResourceWithProps(), agent_input) |
| 579 | + |
| 580 | + assert result == {"$['existing_param']": "exists"} |
| 581 | + assert "$['missing_param']" not in result |
0 commit comments