Commit 3ff12bb
committed
Replace private pydantic-ai access with public Agent.toolsets surface
The _get_function_tools helper reached into agent._function_tools (0.2.x)
and agent._function_toolset (1.x) — both private dataclass fields. The
tool-dispatch and requires-approval lookup paths additionally probed
speculative private attributes (_wrapped_function, callable_function,
_core_tool, wrapped_tool) on Tool objects that do not exist on the
public Tool dataclass.
Refactor to walk the public Agent.toolsets property (documented to
include the auto-built function toolset for tools registered directly
on the agent), pick FunctionToolset instances, and read the public
FunctionToolset.tools dict. Use the public Tool.function and
Tool.requires_approval fields for callable extraction and fallback
approval checks. Verified against pydantic-ai 1.87.0 source (our
minimum pin).
Update test mocks in test_pydantic_ai_agents.py and
test_nested_approval_gates.py to set inst.toolsets via a
MagicMock(spec=FunctionToolset) helper so isinstance() recognises the
fake. The integration test
test_check_tool_requires_approval_with_real_pydantic_ai_agent
exercises the helper end-to-end against a real Agent instance.1 parent 9d8226e commit 3ff12bb
3 files changed
Lines changed: 74 additions & 76 deletions
File tree
- opencontractserver
- llms/agents
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
148 | 149 | | |
149 | 150 | | |
150 | 151 | | |
151 | | - | |
152 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
153 | 156 | | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
163 | 162 | | |
164 | 163 | | |
165 | 164 | | |
| |||
1605 | 1604 | | |
1606 | 1605 | | |
1607 | 1606 | | |
1608 | | - | |
| 1607 | + | |
1609 | 1608 | | |
1610 | 1609 | | |
1611 | 1610 | | |
1612 | 1611 | | |
1613 | 1612 | | |
1614 | 1613 | | |
1615 | | - | |
1616 | | - | |
1617 | | - | |
1618 | | - | |
1619 | | - | |
1620 | | - | |
1621 | | - | |
1622 | | - | |
1623 | | - | |
1624 | | - | |
1625 | | - | |
1626 | | - | |
| 1614 | + | |
| 1615 | + | |
1627 | 1616 | | |
1628 | | - | |
| 1617 | + | |
1629 | 1618 | | |
1630 | 1619 | | |
1631 | 1620 | | |
| |||
1933 | 1922 | | |
1934 | 1923 | | |
1935 | 1924 | | |
1936 | | - | |
| 1925 | + | |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
1937 | 1930 | | |
1938 | 1931 | | |
1939 | 1932 | | |
1940 | | - | |
1941 | | - | |
1942 | | - | |
1943 | | - | |
1944 | | - | |
1945 | | - | |
1946 | | - | |
1947 | | - | |
1948 | | - | |
1949 | | - | |
1950 | | - | |
1951 | | - | |
1952 | | - | |
1953 | | - | |
1954 | | - | |
1955 | | - | |
1956 | | - | |
1957 | | - | |
1958 | | - | |
1959 | | - | |
1960 | | - | |
1961 | | - | |
1962 | | - | |
1963 | | - | |
1964 | | - | |
1965 | | - | |
| 1933 | + | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
| 1937 | + | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
1966 | 1943 | | |
1967 | 1944 | | |
1968 | 1945 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
90 | 102 | | |
91 | 103 | | |
92 | 104 | | |
| |||
180 | 192 | | |
181 | 193 | | |
182 | 194 | | |
183 | | - | |
| 195 | + | |
184 | 196 | | |
185 | 197 | | |
186 | 198 | | |
| |||
413 | 425 | | |
414 | 426 | | |
415 | 427 | | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
421 | 436 | | |
422 | 437 | | |
423 | 438 | | |
| |||
499 | 514 | | |
500 | 515 | | |
501 | 516 | | |
502 | | - | |
503 | | - | |
504 | | - | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
505 | 522 | | |
506 | 523 | | |
507 | 524 | | |
| |||
569 | 586 | | |
570 | 587 | | |
571 | 588 | | |
572 | | - | |
573 | | - | |
574 | | - | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
575 | 594 | | |
576 | 595 | | |
577 | 596 | | |
| |||
615 | 634 | | |
616 | 635 | | |
617 | 636 | | |
618 | | - | |
| 637 | + | |
619 | 638 | | |
620 | 639 | | |
621 | 640 | | |
| |||
640 | 659 | | |
641 | 660 | | |
642 | 661 | | |
643 | | - | |
644 | | - | |
645 | | - | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
646 | 665 | | |
647 | 666 | | |
648 | 667 | | |
| |||
683 | 702 | | |
684 | 703 | | |
685 | 704 | | |
686 | | - | |
| 705 | + | |
687 | 706 | | |
688 | 707 | | |
689 | 708 | | |
| |||
712 | 731 | | |
713 | 732 | | |
714 | 733 | | |
715 | | - | |
716 | | - | |
717 | | - | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
718 | 739 | | |
719 | 740 | | |
720 | 741 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
859 | 859 | | |
860 | 860 | | |
861 | 861 | | |
862 | | - | |
| 862 | + | |
863 | 863 | | |
864 | 864 | | |
865 | 865 | | |
| |||
885 | 885 | | |
886 | 886 | | |
887 | 887 | | |
888 | | - | |
| 888 | + | |
889 | 889 | | |
890 | 890 | | |
891 | 891 | | |
| |||
1048 | 1048 | | |
1049 | 1049 | | |
1050 | 1050 | | |
1051 | | - | |
| 1051 | + | |
1052 | 1052 | | |
1053 | 1053 | | |
1054 | 1054 | | |
| |||
1203 | 1203 | | |
1204 | 1204 | | |
1205 | 1205 | | |
1206 | | - | |
| 1206 | + | |
1207 | 1207 | | |
1208 | 1208 | | |
1209 | 1209 | | |
| |||
0 commit comments