Repository navigation
Commit 082a8ff
committed
Python: refactor(core): one declaration factory, per-call registry
Review of the host-declaration factories asked for two changes. The
helpers had grown to five or six functions that did roughly the same
thing, and the shared helper registered agent_framework.interceptor on
the caller-supplied HostRegistry before validation. HostRegistry.kind()
mutates in place, so a refused document or a raising kind resolver left
the caller's registry holding the kind: the next factory call failed as
already registered, or reused the first call's resolver.
create_agent_hooks_middleware_from_declaration is now the only
declaration factory. It accepts a built HostDeclaration, any Mapping
(copied into a dict for the SDK), or a file path as str or os.PathLike,
read once through HostDeclaration.from_path. JSON text is not accepted
directly; HostDeclaration.from_json covers it. The registry keyword is
replaced by configure_registry, a callback that receives a fresh
HostRegistry built for that call over this framework's surface, after
agent_framework.interceptor is registered when interceptors is given
and before the document is validated. The registry never leaves the
factory and nothing caller-owned is mutated, so a refused document or
a raising callback cannot affect a later call. A callback that
registers agent_framework.interceptor while interceptors is also given
hits the SDK's own "registered twice" ValueError. The callback's return
value is ignored (Callable[[HostRegistry], object]), so a lambda over
the chaining registry methods works. A document with no bindings is
refused at construction with ValueError, the rule
create_agent_hooks_middleware already applies, since an emitter with
zero interceptors fails closed on every emission. This mirrors the .NET
factories, which take Action<HostRegistry> configureRegistry and refuse
zero bindings the same way.
Removed: create_agent_hooks_middleware_from_declaration_path,
create_agent_hooks_middleware_from_declaration_json and
create_agent_hooks_host_registry, with the surface check they needed,
from the module, the lazy export map, the stub and PACKAGE_STATUS.md.
Tests cover reuse of one callback after a refused document and after
the callback itself raised, two factories sharing one callback and one
interceptors mapping, the registered-twice clash, str and os.PathLike
paths, a missing file, JSON text given as a path, a lambda callback, a
document with no bindings, and a kind, identity provider, approval
resolver and redactor registered through the callback. The per-run
reload and the from_emitter single-session tests stay.
Signed-off-by: MohammadHaroonAbuomar <[email protected]>1 parent 38f3e4e commit 082a8ff
5 files changed
Lines changed: 455 additions & 294 deletions
File tree
- python
- packages/core
- agent_framework
- tests/core
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 86 | + | |
| 87 | + | |
91 | 88 | | |
92 | 89 | | |
93 | 90 | | |
94 | 91 | | |
95 | | - | |
| 92 | + | |
96 | 93 | | |
97 | 94 | | |
98 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | 46 | | |
48 | 47 | | |
49 | | - | |
50 | | - | |
51 | 48 | | |
52 | 49 | | |
53 | 50 | | |
| |||
688 | 685 | | |
689 | 686 | | |
690 | 687 | | |
691 | | - | |
692 | 688 | | |
693 | 689 | | |
694 | | - | |
695 | | - | |
696 | 690 | | |
697 | 691 | | |
698 | 692 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | 8 | | |
10 | 9 | | |
11 | | - | |
12 | | - | |
13 | 10 | | |
14 | 11 | | |
15 | 12 | | |
| |||
643 | 640 | | |
644 | 641 | | |
645 | 642 | | |
646 | | - | |
647 | 643 | | |
648 | 644 | | |
649 | | - | |
650 | | - | |
651 | 645 | | |
652 | 646 | | |
653 | 647 | | |
| |||
0 commit comments