{"record":{"id":"fc71e8020e9f6d8f","repo":"langchain-ai/deepagents","slug":"harnessprofileconfig-from-harness-profile-cannot-fc71e8","errorCode":null,"errorMessage":"HarnessProfileConfig.from_harness_profile() cannot serialize `excluded_middleware` class {entry.__name__!r}: it has no public `serialized_name` alias, and arbitrary class-path serialization is not currently supported. Either add a `serialized_name: ClassVar[str]` to the class for stable round-trips, or exclude it by `.name` instead.","messagePattern":"HarnessProfileConfig\\.from_harness_profile\\(\\) cannot serialize `excluded_middleware` class (.+?): it has no public `serialized_name` alias, and arbitrary class-path serialization is not currently supported\\. Either add a `serialized_name: ClassVar\\[str\\]` to the class for stable round-trips, or exclude it by `\\.name` instead\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/deepagents/deepagents/profiles/harness/harness_profiles.py","lineNumber":937,"sourceCode":"    Class entries are only serializable when the class advertises a public\n    `serialized_name` alias; arbitrary class-path serialization is not\n    currently supported.\n    \"\"\"\n    if isinstance(entry, str):\n        return entry\n\n    alias = getattr(entry, \"serialized_name\", None)\n    if isinstance(alias, str) and alias:\n        return alias\n\n    msg = (\n        \"HarnessProfileConfig.from_harness_profile() cannot serialize \"\n        f\"`excluded_middleware` class {entry.__name__!r}: it has no public \"\n        \"`serialized_name` alias, and arbitrary class-path serialization is \"\n        \"not currently supported. Either add a `serialized_name: ClassVar[str]` \"\n        \"to the class for stable round-trips, or exclude it by `.name` instead.\"\n    )\n    raise ValueError(msg)\n\n\n_HARNESS_PROFILES: dict[str, HarnessProfile] = {}\n\"\"\"Internal registry mapping harness-profile keys to `HarnessProfile` instances.\n\nKeys are either a full `provider:model` spec for per-model overrides or a\nbare provider name for provider-wide defaults. Lookup order is exact spec,\nthen provider prefix, then no match (returns `None`).\n\"\"\"\n\n\ndef _ensure_harness_profiles_loaded() -> None:\n    \"\"\"Ensure the lazy built-in/profile-plugin bootstrap has completed.\"\"\"\n    from deepagents.profiles._builtin_profiles import _ensure_builtin_profiles_loaded  # noqa: PLC0415\n\n    _ensure_builtin_profiles_loaded()\n\n","sourceCodeStart":919,"sourceCodeEnd":955,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/deepagents/deepagents/profiles/harness/harness_profiles.py#L919-L955","documentation":"When serializing a runtime `HarnessProfile` back to config form via `from_harness_profile()`, an `excluded_middleware` entry that is a middleware class must declare a `serialized_name: ClassVar[str]` for a stable round-trip. Arbitrary class-path serialization is intentionally unsupported, so anonymous or alias-less classes cannot be written to config.","triggerScenarios":"Calling `HarnessProfileConfig.from_harness_profile(profile)` where `profile.excluded_middleware` contains a custom `AgentMiddleware` subclass without `serialized_name`.","commonSituations":"Excluding a locally defined custom middleware class and then attempting to persist/export the profile; third-party middleware classes that never defined `serialized_name`.","solutions":["Add `serialized_name: ClassVar[str] = \"my_middleware\"` to the middleware class","Exclude the middleware by its `.name` string instead of the class object","Exclude it after deserialization in code rather than round-tripping it through config"],"exampleFix":"# before\nclass MyMiddleware(AgentMiddleware):\n    ...\n# after\nclass MyMiddleware(AgentMiddleware):\n    serialized_name: ClassVar[str] = \"my_middleware\"\n    ...","handlingStrategy":"try-catch","validationCode":"missing = [c for c in profile.excluded_middleware\n           if isinstance(c, type) and not hasattr(c, \"serialized_name\")]\nif missing:\n    raise ValueError(f\"middleware classes lack serialized_name: {missing}\")","typeGuard":"def has_serialized_name(cls: type) -> TypeGuard[type[AgentMiddleware]]:\n    return issubclass(cls, AgentMiddleware) and hasattr(cls, \"serialized_name\")","tryCatchPattern":"try:\n    cfg = HarnessProfileConfig.from_harness_profile(profile)\nexcept ValueError as e:\n    if \"serialized_name\" in str(e):\n        profile.excluded_middleware = [\n            c.serialized_name if isinstance(c, type) and hasattr(c, \"serialized_name\") else c\n            for c in profile.excluded_middleware\n        ]\n        cfg = HarnessProfileConfig.from_harness_profile(profile)\n    else:\n        raise","preventionTips":["Always declare `serialized_name: ClassVar[str]` on custom middleware classes","Exclude middleware by `.name` string when round-tripping through config is expected","Test serialize/deserialize round-trips for profiles containing custom middleware"],"tags":["serialization","middleware","config"],"backgroundTag":"serialization-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}