From 5be8f8fdfc943107b20fc088dc2562cfbc31e646 Mon Sep 17 00:00:00 2001 From: Nathaniel Ramm Date: Sat, 15 Aug 2026 01:14:07 +1000 Subject: [PATCH] pulse-apply apply-format-python-hiivmind-agent-kernel by discreteds@Nathaniels-Mac-mini.local --- examples/spinner.py | 11 +++- src/agent_kernel/core/authority.py | 25 +++------ src/agent_kernel/core/catalog.py | 11 +--- src/agent_kernel/core/commands.py | 4 +- src/agent_kernel/core/continuation.py | 4 +- src/agent_kernel/core/results.py | 4 +- src/agent_kernel/core/specs.py | 53 +++++-------------- src/agent_kernel/integrations/agno/hitl.py | 18 ++----- src/agent_kernel/integrations/agno/hooks.py | 5 +- src/agent_kernel/integrations/agno/runtime.py | 27 +++------- .../integrations/dspy/artifacts.py | 13 ++--- .../integrations/dspy/classifier.py | 23 ++------ tests/agno/test_hitl.py | 16 +++--- tests/core/test_authority.py | 5 +- tests/core/test_commands_catalog.py | 14 ++--- tests/core/test_kernel.py | 40 +++----------- tests/core/test_registry.py | 14 ++--- tests/dspy/test_artifacts.py | 22 ++------ tests/dspy/test_signature.py | 16 ++---- tests/public/test_public_api.py | 4 +- 20 files changed, 82 insertions(+), 247 deletions(-) diff --git a/examples/spinner.py b/examples/spinner.py index 3b5ff36..012cfcd 100644 --- a/examples/spinner.py +++ b/examples/spinner.py @@ -58,7 +58,10 @@ def build_spin(intent: SpinnerIntent, context: BuildContext) -> Briefing: class FakeClassifier: def classify( - self, message: str, *, context: Continuation | None = None, + self, + message: str, + *, + context: Continuation | None = None, ) -> SpinnerIntent: del context action = "spin" if "spin" in message.lower() else "chat" @@ -67,7 +70,11 @@ def classify( class SpinnerRuntime: def execute( - self, message: str, plan: ExecutionPlan, *, context: object | None = None, + self, + message: str, + plan: ExecutionPlan, + *, + context: object | None = None, ) -> Completed: del message, context if "spin_wheel" not in plan.envelope.allowed: diff --git a/src/agent_kernel/core/authority.py b/src/agent_kernel/core/authority.py index bcf2d7e..5106dc7 100644 --- a/src/agent_kernel/core/authority.py +++ b/src/agent_kernel/core/authority.py @@ -29,13 +29,9 @@ def __init__( def _validate_grants(spec: ActionSpec[I], briefing: Briefing) -> None: undeclared = briefing.grants - spec.capabilities if undeclared: - raise ConfigurationError( - f"action {spec.name!r} built undeclared grants: {sorted(undeclared)}" - ) + raise ConfigurationError(f"action {spec.name!r} built undeclared grants: {sorted(undeclared)}") if spec.kind == "toolfree" and briefing.grants: - raise ConfigurationError( - f"toolfree action {spec.name!r} built grants: {sorted(briefing.grants)}" - ) + raise ConfigurationError(f"toolfree action {spec.name!r} built grants: {sorted(briefing.grants)}") def plan(self, intent: I, principal: Principal) -> ExecutionPlan: intent, valid = self.registry.normalize_intent(intent) @@ -46,14 +42,8 @@ def plan(self, intent: I, principal: Principal) -> ExecutionPlan: elif spec is None: reason = f"unknown action: {intent.action}" spec = self.registry.get(self.registry.default) - elif ( - spec.kind == "privileged" - and intent.confidence < self.confidence_threshold - ): - reason = ( - f"confidence {intent.confidence:.2f} " - f"< {self.confidence_threshold:.2f}" - ) + elif spec.kind == "privileged" and intent.confidence < self.confidence_threshold: + reason = f"confidence {intent.confidence:.2f} < {self.confidence_threshold:.2f}" spec = self.registry.get(self.registry.default) elif spec.kind == "privileged" and spec.continuation is not None: for field_name, allowed_values in spec.continuation.authority_fields.items(): @@ -82,8 +72,7 @@ def plan(self, intent: I, principal: Principal) -> ExecutionPlan: if not briefing.grants <= principal.role.capabilities: raise ConfigurationError( - f"final grants exceed principal authority: " - f"{sorted(briefing.grants - principal.role.capabilities)}" + f"final grants exceed principal authority: {sorted(briefing.grants - principal.role.capabilities)}" ) return ExecutionPlan( @@ -92,9 +81,7 @@ def plan(self, intent: I, principal: Principal) -> ExecutionPlan: capabilities=briefing.grants, instructions=briefing.instructions, tool_call_limit=( - briefing.tool_call_limit - if briefing.tool_call_limit is not None - else spec.tool_call_limit + briefing.tool_call_limit if briefing.tool_call_limit is not None else spec.tool_call_limit ), reads_history=spec.reads_history, envelope=AuthorityEnvelope(principal.id, briefing.grants), diff --git a/src/agent_kernel/core/catalog.py b/src/agent_kernel/core/catalog.py index d719f8f..42619f0 100644 --- a/src/agent_kernel/core/catalog.py +++ b/src/agent_kernel/core/catalog.py @@ -18,19 +18,12 @@ def describe( ) -> tuple[dict[str, str | None], ...]: visible: list[CatalogEntry] = [] for spec in planner.registry.specs: - if ( - spec.kind == "privileged" - and not spec.capabilities <= principal.role.capabilities - ): + if spec.kind == "privileged" and not spec.capabilities <= principal.role.capabilities: continue visible.extend(spec.catalog) visible_keys = {entry.key for entry in visible} - current = ( - entry - for entry in visible - if entry.superseded_by is None or entry.superseded_by not in visible_keys - ) + current = (entry for entry in visible if entry.superseded_by is None or entry.superseded_by not in visible_keys) return tuple( { "key": entry.key, diff --git a/src/agent_kernel/core/commands.py b/src/agent_kernel/core/commands.py index 643cc23..e192081 100644 --- a/src/agent_kernel/core/commands.py +++ b/src/agent_kernel/core/commands.py @@ -16,9 +16,7 @@ def parse_command(message: str, registry: Registry[I]) -> I | None: return None matches: list[CommandSpec[I]] = [ - spec.command - for spec in registry.specs - if spec.command is not None and spec.command.name == name + spec.command for spec in registry.specs if spec.command is not None and spec.command.name == name ] if len(matches) != 1: return None diff --git a/src/agent_kernel/core/continuation.py b/src/agent_kernel/core/continuation.py index 7bb5094..e782f60 100644 --- a/src/agent_kernel/core/continuation.py +++ b/src/agent_kernel/core/continuation.py @@ -31,9 +31,7 @@ def from_turn( if continuation_spec is None: return cls(last_action=spec.name) - bounded_awaiting = ( - awaiting if awaiting in continuation_spec.awaiting else None - ) + bounded_awaiting = awaiting if awaiting in continuation_spec.awaiting else None authority_values = [] for field_name, allowed_values in continuation_spec.authority_fields.items(): value = getattr(intent, field_name, None) diff --git a/src/agent_kernel/core/results.py b/src/agent_kernel/core/results.py index 4ce49bb..8c516fb 100644 --- a/src/agent_kernel/core/results.py +++ b/src/agent_kernel/core/results.py @@ -60,9 +60,7 @@ def __post_init__(self) -> None: string_tuple(self.instructions, field="execution plan instructions"), ) if capabilities != self.envelope.allowed: - raise ConfigurationError( - "execution plan capabilities must equal authority envelope allowed" - ) + raise ConfigurationError("execution plan capabilities must equal authority envelope allowed") @dataclass(frozen=True) diff --git a/src/agent_kernel/core/specs.py b/src/agent_kernel/core/specs.py index 15922d0..c3645df 100644 --- a/src/agent_kernel/core/specs.py +++ b/src/agent_kernel/core/specs.py @@ -74,9 +74,7 @@ def __post_init__(self) -> None: snapshot: dict[str, frozenset[str]] = {} for field_name, values in self.authority_fields.items(): if not isinstance(field_name, str) or not field_name.strip(): - raise ConfigurationError( - "continuation authority fields must be non-empty strings" - ) + raise ConfigurationError("continuation authority fields must be non-empty strings") snapshot[field_name] = capability_set( values, field="continuation authority values", @@ -122,33 +120,18 @@ def __init__(self, specs: tuple[ActionSpec[I], ...], *, default: str, denied: st for spec in self._specs.values(): if spec.continuation is None: continue - for field_name, declared_values in ( - spec.continuation.authority_fields.items() - ): + for field_name, declared_values in spec.continuation.authority_fields.items(): model_field = intent_type.model_fields.get(field_name) - if ( - field_name in {"action", "confidence", "brief"} - or model_field is None - or not declared_values - ): - raise ConfigurationError( - f"invalid authority vocabulary for field {field_name!r}" - ) - authority_values.setdefault(field_name, set()).update( - declared_values - ) + if field_name in {"action", "confidence", "brief"} or model_field is None or not declared_values: + raise ConfigurationError(f"invalid authority vocabulary for field {field_name!r}") + authority_values.setdefault(field_name, set()).update(declared_values) authority_fields = tuple(sorted(authority_values)) - authority_options = tuple( - tuple(sorted(authority_values[field_name])) - for field_name in authority_fields - ) + authority_options = tuple(tuple(sorted(authority_values[field_name])) for field_name in authority_fields) candidate_count = 1 for options in authority_options: candidate_count *= len(options) if candidate_count > _MAX_FALLBACK_CANDIDATES: - raise ConfigurationError( - "authority vocabularies produce too many fallback candidates" - ) + raise ConfigurationError("authority vocabularies produce too many fallback candidates") validated_fallback: I | None = None for candidate_values in product(*authority_options): @@ -157,9 +140,7 @@ def __init__(self, specs: tuple[ActionSpec[I], ...], *, default: str, denied: st "confidence": 0.0, "brief": "", } - candidate.update( - zip(authority_fields, candidate_values, strict=True) - ) + candidate.update(zip(authority_fields, candidate_values, strict=True)) try: validated_fallback = intent_type.model_validate(candidate) except ValidationError: @@ -173,12 +154,8 @@ def __init__(self, specs: tuple[ActionSpec[I], ...], *, default: str, denied: st continue break if validated_fallback is None: - raise ConfigurationError( - "authority vocabularies cannot construct a valid fallback intent" - ) - self._fallback_payload = MappingProxyType( - deepcopy(validated_fallback.model_dump(mode="python")) - ) + raise ConfigurationError("authority vocabularies cannot construct a valid fallback intent") + self._fallback_payload = MappingProxyType(deepcopy(validated_fallback.model_dump(mode="python"))) self.default = default self.denied = denied self.intent_type = intent_type @@ -195,14 +172,8 @@ def get(self, action: str) -> ActionSpec[I] | None: return self._specs.get(action) def _check_fallback_invariants(self, intent: I) -> None: - if ( - intent.action != self.default - or not isfinite(intent.confidence) - or intent.confidence != 0.0 - ): - raise ConfigurationError( - "validated fallback intent changed its safety invariants" - ) + if intent.action != self.default or not isfinite(intent.confidence) or intent.confidence != 0.0: + raise ConfigurationError("validated fallback intent changed its safety invariants") def normalize_intent(self, value: object) -> tuple[I, bool]: force_fallback = bool(getattr(value, _FALLBACK_MARKER, False)) diff --git a/src/agent_kernel/integrations/agno/hitl.py b/src/agent_kernel/integrations/agno/hitl.py index 7a4ed93..a292c85 100644 --- a/src/agent_kernel/integrations/agno/hitl.py +++ b/src/agent_kernel/integrations/agno/hitl.py @@ -4,9 +4,7 @@ class UnsupportedRequirement(ValueError): def __init__(self, requirement_type: str): self.requirement_type = requirement_type - super().__init__( - f"Agno requirement type is not supported: {requirement_type}" - ) + super().__init__(f"Agno requirement type is not supported: {requirement_type}") def _active_requirements(response: object) -> tuple[Any, ...]: @@ -62,11 +60,7 @@ def translate_requirements( for field in getattr(requirement, "user_input_schema", None) or (): field_type = getattr(field, "field_type", None) - type_name = ( - getattr(field_type, "__name__", str(field_type)) - if field_type is not None - else None - ) + type_name = getattr(field_type, "__name__", str(field_type)) if field_type is not None else None translated.append( { "field": getattr(field, "name", None), @@ -91,16 +85,12 @@ def apply_user_input( for field in getattr(requirement, "user_input_schema", None) or (): field_name = getattr(field, "name", None) if not isinstance(field_name, str): - raise ValueError( - "Agno user-input requirement has an invalid field name" - ) + raise ValueError("Agno user-input requirement has an invalid field name") field_names.append(field_name) missing = [name for name in field_names if name not in answers] if missing: - raise ValueError( - f"missing answers for Agno user-input fields: {missing}" - ) + raise ValueError(f"missing answers for Agno user-input fields: {missing}") prepared.append( ( requirement, diff --git a/src/agent_kernel/integrations/agno/hooks.py b/src/agent_kernel/integrations/agno/hooks.py index b5a3eef..8f49004 100644 --- a/src/agent_kernel/integrations/agno/hooks.py +++ b/src/agent_kernel/integrations/agno/hooks.py @@ -13,9 +13,6 @@ def authority_hook( ) -> Any: dependencies = getattr(run_context, "dependencies", None) or {} envelope = dependencies.get("agent_kernel_authority") - if ( - not isinstance(envelope, AuthorityEnvelope) - or function_name not in envelope.allowed - ): + if not isinstance(envelope, AuthorityEnvelope) or function_name not in envelope.allowed: raise PermissionError(f"principal may not call {function_name}") return function_call(**args) diff --git a/src/agent_kernel/integrations/agno/runtime.py b/src/agent_kernel/integrations/agno/runtime.py index 9c34484..8b986c9 100644 --- a/src/agent_kernel/integrations/agno/runtime.py +++ b/src/agent_kernel/integrations/agno/runtime.py @@ -87,10 +87,7 @@ def execute( raise ConfigurationError(f"missing Agno tool bindings: {missing}") try: - selected_tools = [ - self.tools[capability] - for capability in sorted(plan.capabilities) - ] + selected_tools = [self.tools[capability] for capability in sorted(plan.capabilities)] agent = self.agent_factory( model=self.model, tools=selected_tools, @@ -137,23 +134,15 @@ def resume( ) -> RuntimeOutcome: record_key = pause.adapter_state if not isinstance(record_key, _PauseToken): - raise ConfigurationError( - "pause state was not created by this Agno runtime" - ) + raise ConfigurationError("pause state was not created by this Agno runtime") record = self._pause_records.get(record_key) if record is None: - raise ConfigurationError( - "pause state was not created by this Agno runtime" - ) + raise ConfigurationError("pause state was not created by this Agno runtime") response = record.response if pause.envelope != record.envelope: - raise ConfigurationError( - "pause authority envelope does not match the original run" - ) + raise ConfigurationError("pause authority envelope does not match the original run") if requirement_state(response) != record.requirement_state: - raise ConfigurationError( - "paused Agno response state does not match the original run" - ) + raise ConfigurationError("paused Agno response state does not match the original run") try: apply_user_input(response, answers) @@ -162,11 +151,7 @@ def resume( dependencies={ "agent_kernel_authority": record.envelope, }, - user_id=( - record.context.user_id - if record.context is not None - else None - ), + user_id=(record.context.user_id if record.context is not None else None), ) if getattr(resumed, "is_paused", False): outcome = self._pause( diff --git a/src/agent_kernel/integrations/dspy/artifacts.py b/src/agent_kernel/integrations/dspy/artifacts.py index 3a2d466..c83d285 100644 --- a/src/agent_kernel/integrations/dspy/artifacts.py +++ b/src/agent_kernel/integrations/dspy/artifacts.py @@ -29,10 +29,7 @@ def _authority_vocabularies( if continuation is None: continue vocabularies[spec.name] = { - field_name: sorted(values) - for field_name, values in sorted( - continuation.authority_fields.items() - ) + field_name: sorted(values) for field_name, values in sorted(continuation.authority_fields.items()) } return dict(sorted(vocabularies.items())) @@ -95,17 +92,13 @@ def load_artifact( expected_fingerprint = registry_fingerprint(registry) artifact_fingerprint = metadata.get("registry_fingerprint") if artifact_fingerprint != expected_fingerprint: - raise ConfigurationError( - "DSPy artifact registry fingerprint does not match the configured registry" - ) + raise ConfigurationError("DSPy artifact registry fingerprint does not match the configured registry") if metadata.get("format_version") != _FORMAT_VERSION: raise ConfigurationError("unsupported DSPy artifact format version") program_name = metadata.get("program_path") if not isinstance(program_name, str) or program_name != path.name: - raise ConfigurationError( - "DSPy artifact metadata program path does not match the requested artifact" - ) + raise ConfigurationError("DSPy artifact metadata program path does not match the requested artifact") module.load(metadata_path.parent / program_name) return module diff --git a/src/agent_kernel/integrations/dspy/classifier.py b/src/agent_kernel/integrations/dspy/classifier.py index 75675f3..e9f02f8 100644 --- a/src/agent_kernel/integrations/dspy/classifier.py +++ b/src/agent_kernel/integrations/dspy/classifier.py @@ -27,10 +27,7 @@ def _authority_vocabularies(registry: Registry[Any]) -> dict[str, tuple[str, ... continue for field_name, values in continuation.authority_fields.items(): vocabularies.setdefault(field_name, set()).update(values) - return { - field_name: tuple(sorted(values)) - for field_name, values in sorted(vocabularies.items()) - } + return {field_name: tuple(sorted(values)) for field_name, values in sorted(vocabularies.items())} def _literal_type(values: tuple[str, ...]) -> Any: @@ -45,15 +42,12 @@ def build_signature( "confidence, brief, and declared authority fields." ), ) -> type[dspy.Signature]: - action_names = tuple( - sorted(action for action in registry.actions if action != registry.denied) - ) + action_names = tuple(sorted(action for action in registry.actions if action != registry.denied)) authority_vocabularies = _authority_vocabularies(registry) collisions = sorted(_RESERVED_FIELDS.intersection(authority_vocabularies)) if collisions: raise ConfigurationError( - "authority fields collide with reserved DSPy projection fields: " - + ", ".join(collisions) + "authority fields collide with reserved DSPy projection fields: " + ", ".join(collisions) ) fields: dict[str, tuple[Any, Any]] = { @@ -70,10 +64,7 @@ def build_signature( fields[field_name] = ( _literal_type(values) | None, dspy.OutputField( - desc=( - "A declared authority value when applicable to the selected " - "action, otherwise null." - ) + desc=("A declared authority value when applicable to the selected action, otherwise null.") ), ) fields["confidence"] = ( @@ -141,11 +132,7 @@ def _normalization_payload(self, prediction: Any) -> Any: if isinstance(prediction, Mapping): if "intent" in prediction: return prediction["intent"] - return { - name: prediction[name] - for name in self.registry.intent_type.model_fields - if name in prediction - } + return {name: prediction[name] for name in self.registry.intent_type.model_fields if name in prediction} structured = getattr(prediction, "intent", _MISSING) if structured is not _MISSING: diff --git a/tests/agno/test_hitl.py b/tests/agno/test_hitl.py index 1398570..b429324 100644 --- a/tests/agno/test_hitl.py +++ b/tests/agno/test_hitl.py @@ -192,9 +192,7 @@ def test_public_requirement_snapshot_cannot_mutate_private_response(plan): requirement = FakeRequirement([FakeField("sides")]) response = paused_response(requirement) finished = completed_response() - runtime = make_runtime( - FakeAgentFactory(response, continue_responses=[finished]) - ) + runtime = make_runtime(FakeAgentFactory(response, continue_responses=[finished])) pause = runtime.execute("spin", plan) pause.requirements[0]["field"] = "delete_world" @@ -415,9 +413,7 @@ def test_resume_can_pause_again_and_then_complete_on_same_agent(plan): assert second_pause.adapter_state is not first_pause.adapter_state assert second_pause.envelope is plan.envelope assert second_pause.runtime_context is context - assert tuple( - item["field"] for item in second_pause.requirements - ) == ("color",) + assert tuple(item["field"] for item in second_pause.requirements) == ("color",) outcome = runtime.resume(second_pause, {"color": "blue"}) @@ -425,7 +421,7 @@ def test_resume_can_pause_again_and_then_complete_on_same_agent(plan): assert len(factory.agents) == 1 assert first_requirement.provided == [{"sides": "d20"}] assert second_requirement.provided == [{"color": "blue"}] - assert [ - call[1]["dependencies"]["agent_kernel_authority"] - for call in factory.agents[0].continue_calls - ] == [plan.envelope, plan.envelope] + assert [call[1]["dependencies"]["agent_kernel_authority"] for call in factory.agents[0].continue_calls] == [ + plan.envelope, + plan.envelope, + ] diff --git a/tests/core/test_authority.py b/tests/core/test_authority.py index 7c6ca89..a9f9df5 100644 --- a/tests/core/test_authority.py +++ b/tests/core/test_authority.py @@ -300,10 +300,7 @@ def build_malicious(intent: ExampleIntent, context) -> Briefing: capabilities=frozenset({"root"}), ) registry = Registry( - tuple( - malicious if spec.name == action else spec - for spec in example.registry.specs - ), + tuple(malicious if spec.name == action else spec for spec in example.registry.specs), default=example.registry.default, denied=example.registry.denied, intent_type=example.intent_type, diff --git a/tests/core/test_commands_catalog.py b/tests/core/test_commands_catalog.py index de586c6..7889bf4 100644 --- a/tests/core/test_commands_catalog.py +++ b/tests/core/test_commands_catalog.py @@ -49,10 +49,7 @@ def test_command_normalizing_to_unknown_action_falls_to_registered_default(examp ), ) registry = Registry( - tuple( - unsafe_spin if spec.name == "spin" else spec - for spec in example.registry.specs - ), + tuple(unsafe_spin if spec.name == "spin" else spec for spec in example.registry.specs), default=example.registry.default, denied=example.registry.denied, intent_type=example.intent_type, @@ -100,10 +97,7 @@ def test_catalog_visibility_uses_conservative_maximum_declared_envelope( build=lambda intent, context: Briefing(instructions=("preview",)), ) registry = Registry( - tuple( - branch_without_grants if spec.name == "spin" else spec - for spec in example.registry.specs - ), + tuple(branch_without_grants if spec.name == "spin" else spec for spec in example.registry.specs), default=example.registry.default, denied=example.registry.denied, intent_type=example.intent_type, @@ -121,9 +115,7 @@ def test_catalog_visibility_uses_conservative_maximum_declared_envelope( def test_core_guide_documents_conservative_catalog_visibility(): - guide = ( - Path(__file__).parents[2] / "docs/core-quickstart.md" - ).read_text(encoding="utf-8") + guide = (Path(__file__).parents[2] / "docs/core-quickstart.md").read_text(encoding="utf-8") assert "catalog visibility is conservative" in guide.lower() assert "maximum declared capabilities" in guide.lower() diff --git a/tests/core/test_kernel.py b/tests/core/test_kernel.py index 08e4df9..00153df 100644 --- a/tests/core/test_kernel.py +++ b/tests/core/test_kernel.py @@ -166,11 +166,7 @@ def build_spin(intent, context): kind="privileged", build=build_spin, capabilities=frozenset({"spin_wheel"}), - continuation=ContinuationSpec( - authority_fields={ - "mode": frozenset({"safe", "fast"}) - } - ), + continuation=ContinuationSpec(authority_fields={"mode": frozenset({"safe", "fast"})}), ), ), default="chat", @@ -224,11 +220,7 @@ def build_chat(intent, context): grants=frozenset({"spin_wheel"}), ), capabilities=frozenset({"spin_wheel"}), - continuation=ContinuationSpec( - authority_fields={ - "mode": frozenset({"fast", "safe"}) - } - ), + continuation=ContinuationSpec(authority_fields={"mode": frozenset({"fast", "safe"})}), ), ), default="chat", @@ -285,9 +277,7 @@ def build_chat(intent, context): grants=frozenset({"spin_wheel"}), ), capabilities=frozenset({"spin_wheel"}), - continuation=ContinuationSpec( - authority_fields={"mode": frozenset({"safe"})} - ), + continuation=ContinuationSpec(authority_fields={"mode": frozenset({"safe"})}), ), ), default="chat", @@ -316,11 +306,7 @@ class PartiallyPromotingIntent(Intent): @model_validator(mode="after") def promote_only_fast(self): - if ( - self.action == "chat" - and self.confidence == 0.0 - and self.mode == "fast" - ): + if self.action == "chat" and self.confidence == 0.0 and self.mode == "fast": object.__setattr__(self, "action", "spin") object.__setattr__(self, "confidence", 1.0) return self @@ -341,11 +327,7 @@ def build_chat(intent, context): grants=frozenset({"spin_wheel"}), ), capabilities=frozenset({"spin_wheel"}), - continuation=ContinuationSpec( - authority_fields={ - "mode": frozenset({"fast", "safe"}) - } - ), + continuation=ContinuationSpec(authority_fields={"mode": frozenset({"fast", "safe"})}), ), ), default="chat", @@ -401,9 +383,7 @@ def build_chat(intent, context): grants=frozenset({"spin_wheel"}), ), capabilities=frozenset({"spin_wheel"}), - continuation=ContinuationSpec( - authority_fields={"mode": frozenset({"safe"})} - ), + continuation=ContinuationSpec(authority_fields={"mode": frozenset({"safe"})}), ), ), default="chat", @@ -487,9 +467,7 @@ def test_run_composes_facade_and_executes_the_original_message(example, member): assert result.plan.action == "spin" assert result.outcome == Completed(content="ran spin", raw=None) assert classifier.calls == [("the original message", context)] - assert runtime.execute_calls == [ - ("the original message", result.plan, runtime_context) - ] + assert runtime.execute_calls == [("the original message", result.plan, runtime_context)] def test_dispatch_normalizes_intent_and_executes_its_brief(example, member): @@ -503,9 +481,7 @@ def test_dispatch_normalizes_intent_and_executes_its_brief(example, member): ) assert result.plan.action == "spin" - assert runtime.execute_calls == [ - ("deterministic request", result.plan, "runtime context") - ] + assert runtime.execute_calls == [("deterministic request", result.plan, "runtime context")] def test_runtime_execution_exception_becomes_failed_outcome(example, member): diff --git a/tests/core/test_registry.py b/tests/core/test_registry.py index 93d3388..6dffc83 100644 --- a/tests/core/test_registry.py +++ b/tests/core/test_registry.py @@ -50,9 +50,7 @@ def test_continuation_snapshots_authority_vocabularies(): modes.add("root") fields["other"] = {"root"} - assert continuation.authority_fields == { - "mode": frozenset({"safe"}) - } + assert continuation.authority_fields == {"mode": frozenset({"safe"})} with pytest.raises(TypeError): continuation.authority_fields["mode"] = frozenset({"root"}) # type: ignore[index] @@ -83,9 +81,7 @@ class ModeIntent(Intent): name="spin", kind="privileged", build=build_chat, - continuation=ContinuationSpec( - authority_fields={field_name: values} - ), + continuation=ContinuationSpec(authority_fields={field_name: values}), ) chat = ActionSpec(name="chat", kind="toolfree", build=build_chat) @@ -113,11 +109,7 @@ def reject_default_action(self): name="spin", kind="privileged", build=build_chat, - continuation=ContinuationSpec( - authority_fields={ - "mode": frozenset({"safe", "fast"}) - } - ), + continuation=ContinuationSpec(authority_fields={"mode": frozenset({"safe", "fast"})}), ) with pytest.raises(ConfigurationError, match="fallback"): diff --git a/tests/dspy/test_artifacts.py b/tests/dspy/test_artifacts.py index 48ca458..aaf9caa 100644 --- a/tests/dspy/test_artifacts.py +++ b/tests/dspy/test_artifacts.py @@ -41,11 +41,7 @@ def load(self, path): def _metadata_path(program_path): - candidates = [ - candidate - for candidate in program_path.parent.iterdir() - if candidate != program_path - ] + candidates = [candidate for candidate in program_path.parent.iterdir() if candidate != program_path] assert len(candidates) == 1 return candidates[0] @@ -110,16 +106,12 @@ def test_load_artifact_rejects_registry_mismatch_before_dspy_load( def test_registry_fingerprint_binds_authority_values_to_each_action(example): spin_safe = replace( SPIN, - continuation=ContinuationSpec( - authority_fields={"mode": frozenset({"safe"})} - ), + continuation=ContinuationSpec(authority_fields={"mode": frozenset({"safe"})}), ) review_fast = replace( SPIN, name="review", - continuation=ContinuationSpec( - authority_fields={"mode": frozenset({"fast"})} - ), + continuation=ContinuationSpec(authority_fields={"mode": frozenset({"fast"})}), ) first = Registry( (CHAT, DENIED, spin_safe, review_fast), @@ -133,15 +125,11 @@ def test_registry_fingerprint_binds_authority_values_to_each_action(example): DENIED, replace( spin_safe, - continuation=ContinuationSpec( - authority_fields={"mode": frozenset({"fast"})} - ), + continuation=ContinuationSpec(authority_fields={"mode": frozenset({"fast"})}), ), replace( review_fast, - continuation=ContinuationSpec( - authority_fields={"mode": frozenset({"safe"})} - ), + continuation=ContinuationSpec(authority_fields={"mode": frozenset({"safe"})}), ), ), default="chat", diff --git a/tests/dspy/test_signature.py b/tests/dspy/test_signature.py index 2da22bf..ee1c79b 100644 --- a/tests/dspy/test_signature.py +++ b/tests/dspy/test_signature.py @@ -82,9 +82,7 @@ def test_projected_signature_rejects_authority_field_colliding_with_reserved_fie def test_registry_fingerprint_is_stable_across_registry_declaration_order(): first = registry_fingerprint(_registry()) - reordered = registry_fingerprint( - _registry(specs=(SPIN, CHAT, DENIED)) - ) + reordered = registry_fingerprint(_registry(specs=(SPIN, CHAT, DENIED))) assert first == reordered assert re.fullmatch(r"[0-9a-f]{64}", first) @@ -94,9 +92,7 @@ def test_registry_fingerprint_changes_with_intent_schema(): class ExtendedIntent(ExampleIntent): source: str | None = None - assert registry_fingerprint(_registry()) != registry_fingerprint( - _registry(intent_type=ExtendedIntent) - ) + assert registry_fingerprint(_registry()) != registry_fingerprint(_registry(intent_type=ExtendedIntent)) def test_registry_fingerprint_changes_with_authority_vocabulary(): @@ -108,9 +104,7 @@ def test_registry_fingerprint_changes_with_authority_vocabulary(): ), ) - assert registry_fingerprint(_registry()) != registry_fingerprint( - _registry(specs=(CHAT, DENIED, changed_spin)) - ) + assert registry_fingerprint(_registry()) != registry_fingerprint(_registry(specs=(CHAT, DENIED, changed_spin))) class RecordingModule: @@ -194,9 +188,7 @@ def test_classifier_does_not_use_fallback_after_success(example): mode=None, ) ) - fallback = RecordingFallback( - ExampleIntent(action="chat", confidence=0.1, brief="fallback") - ) + fallback = RecordingFallback(ExampleIntent(action="chat", confidence=0.1, brief="fallback")) result = DspyClassifier( registry=example.registry, diff --git a/tests/public/test_public_api.py b/tests/public/test_public_api.py index 1509bf6..ab91319 100644 --- a/tests/public/test_public_api.py +++ b/tests/public/test_public_api.py @@ -37,9 +37,7 @@ def test_supported_core_api_is_top_level(): def test_readme_uses_pypi_safe_absolute_documentation_links(): from pathlib import Path - contents = (Path(__file__).parents[2] / "README.md").read_text( - encoding="utf-8" - ) + contents = (Path(__file__).parents[2] / "README.md").read_text(encoding="utf-8") assert "](docs/" not in contents assert "https://github.com/hiivmind/agent-kernel/blob/main/docs/" in contents