{"record":{"id":"f7c15023a84a3a0a","repo":"langchain-ai/deepagents","slug":"harnessprofileconfig-from-harness-profile-cannot","errorCode":null,"errorMessage":"HarnessProfileConfig.from_harness_profile() cannot export `extra_middleware`. Middleware instances and factories are runtime-only; keep them in `HarnessProfile`.","messagePattern":"HarnessProfileConfig\\.from_harness_profile\\(\\) cannot export `extra_middleware`\\. Middleware instances and factories are runtime-only; keep them in `HarnessProfile`\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/deepagents/deepagents/profiles/harness/harness_profiles.py","lineNumber":467,"sourceCode":"\n        Returns:\n            A declarative `HarnessProfileConfig`.\n\n        Raises:\n            ValueError: If `profile` contains runtime-only state such as\n                non-empty `extra_middleware`, or if a class-form\n                `excluded_middleware` entry has no `serialized_name` alias.\n            TypeError: If `tool_description_overrides` contains a non-string\n                key or value.\n        \"\"\"\n        extra = profile.extra_middleware\n        if callable(extra) or (isinstance(extra, tuple) and extra):\n            msg = (\n                \"HarnessProfileConfig.from_harness_profile() cannot export \"\n                \"`extra_middleware`. Middleware instances and factories are \"\n                \"runtime-only; keep them in `HarnessProfile`.\"\n            )\n            raise ValueError(msg)\n\n        return cls(\n            base_system_prompt=profile.base_system_prompt,\n            system_prompt_suffix=profile.system_prompt_suffix,\n            tool_description_overrides=_coerce_str_mapping(\n                dict(profile.tool_description_overrides),\n                \"tool_description_overrides\",\n            ),\n            excluded_tools=profile.excluded_tools,\n            excluded_middleware=frozenset(_serialize_runtime_excluded_middleware_entry(entry) for entry in profile.excluded_middleware),\n            general_purpose_subagent=profile.general_purpose_subagent,\n        )\n\n\n@dataclass(frozen=True)\nclass HarnessProfile:\n    \"\"\"Runtime configuration for deep agent behavior.\n","sourceCodeStart":449,"sourceCodeEnd":485,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/deepagents/deepagents/profiles/harness/harness_profiles.py#L449-L485","documentation":"HarnessProfileConfig is the serializable form of a profile, and middleware instances/factories are runtime-only objects that cannot be serialized. from_harness_profile() refuses to export a non-empty extra_middleware so callers do not silently lose middleware during conversion. Such middleware must remain on the HarnessProfile itself.","triggerScenarios":"Calling HarnessProfileConfig.from_harness_profile(profile) when profile.extra_middleware contains a middleware instance, a non-empty tuple entry, or a callable factory.","commonSituations":"Trying to serialize a HarnessProfile that has extra middleware registered (e.g. custom auth or logging middleware) into a dict/JSON for persistence or transmission.","solutions":["Strip extra_middleware from the HarnessProfile (set it to an empty list) before converting, or convert an equivalent profile built without it.","Persist middleware separately — e.g. store a string identifier and rebuild the middleware instance on load.","Use HarnessProfileConfig.from_dict/to_dict with only serializable fields, keeping runtime middleware in code."],"exampleFix":"// before\nconfig = HarnessProfileConfig.from_harness_profile(profile_with_extra_middleware)\n// after\nbare = replace(profile_with_extra_middleware, extra_middleware=[])\nconfig = HarnessProfileConfig.from_harness_profile(bare)","handlingStrategy":"validation","validationCode":"if getattr(profile, 'extra_middleware', None):\n    raise ValueError(\"Profile has runtime extra_middleware; strip before exporting to HarnessProfileConfig\")\nconfig = HarnessProfileConfig.from_harness_profile(profile)","typeGuard":null,"tryCatchPattern":"try:\n    config = HarnessProfileConfig.from_harness_profile(profile)\nexcept ValueError as e:\n    if \"cannot export\" in str(e):\n        config = HarnessProfileConfig.from_harness_profile(replace(profile, extra_middleware=[]))\n    else:\n        raise","preventionTips":["Treat HarnessProfileConfig as the serializable subset; keep middleware construction in code.","Persist middleware as string identifiers and rebuild instances on load.","Check profile.extra_middleware is empty before any serialization step."],"tags":["python","serialization","middleware","configuration"],"backgroundTag":"unserializable-runtime-object","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}