> ## Documentation Index
> Fetch the complete documentation index at: https://usefused.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# harnest.extensions

> Public Python signatures, fields, and methods.

[All Python modules](https://usefused.com/docs/harnest/reference/api/overview.md) · [Import and compatibility guidance](https://usefused.com/docs/harnest/build/python-imports.md)

## Exports

| Name | Kind |
| - | - |
| [`ActivatedExtension`](#activatedextension) | Class |
| [`Extension`](#extension) | Class |
| [`ExtensionContext`](#extensioncontext) | Class |
| [`ExtensionContextUnavailableError`](#extensioncontextunavailableerror) | Class |
| [`ExtensionImportError`](#extensionimporterror) | Class |
| [`ExtensionNamespaceError`](#extensionnamespaceerror) | Class |
| [`ExtensionStartContext`](#extensionstartcontext) | Class |
| [`activate_extensions`](#activate_extensions) | Function |
| [`extension_mutation`](#extension_mutation) | Function |
| [`extension_namespaces`](#extension_namespaces) | Function |
| [`release_extensions`](#release_extensions) | Function |

## ActivatedExtension

One validated namespace module and its authored singleton.

```python theme={null}
ActivatedExtension(
    descriptor: ExtensionDescriptor,
    module: ModuleType,
    extension: Extension[ExtensionContext],
) -> None
```

Fields (`—` means no declared default):

| Field | Type | Default |
| - | - | - |
| `descriptor` | `ExtensionDescriptor` | `—` |
| `module` | `ModuleType` | `—` |
| `extension` | `Extension[ExtensionContext]` | `—` |

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `descriptor` | `ExtensionDescriptor` | Required |
> | `module` | `ModuleType` | Required |
> | `extension` | `Extension[ExtensionContext]` | Required |
>
> ```python theme={null}
> from harnest.extensions import ActivatedExtension
>
> extension = ActivatedExtension(descriptor=..., module=..., extension=...)
> ```

## Extension

Application-owned extension with task-local invocation context.

```python theme={null}
Extension(*args: object, **kwargs: object) -> 'Extension[ContextT]'
```

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `*args` | `object` | Optional |
> | `**kwargs` | `object` | Optional |
>
> ```python theme={null}
> from harnest.extensions import Extension
>
> extension = Extension()
> ```

### Extension.start

```python theme={null}
async Extension.start(context: 'ExtensionStartContext') -> None
```

Initialize application-scoped resources after dependencies start.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `context` | `'ExtensionStartContext'` | Required |
>
> ```python theme={null}
> from harnest.extensions import Extension
>
> extension: Extension
> await extension.start(context=...)
> ```

### Extension.stop

```python theme={null}
async Extension.stop() -> None
```

Release application-scoped resources before dependencies stop.

> [accordion] Example
>
> ```python theme={null}
> from harnest.extensions import Extension
>
> extension: Extension
> await extension.stop()
> ```

### Extension.create\_context

```python theme={null}
Extension.create_context(context: ExtensionContext) -> ContextT
```

Adapt the managed invocation base to an extension-specific context.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `context` | `ExtensionContext` | Required |
>
> ```python theme={null}
> from harnest.extensions import Extension
>
> extension: Extension
> result = extension.create_context(context=...)
> ```

### Extension.context

Return the task-local extension context for the active invocation.

> [accordion] Example
>
> ```python theme={null}
> from harnest.extensions import Extension
>
> extension: Extension
> value = extension.context
> ```

## ExtensionContext

Revocable invocation base that extension-specific contexts may extend.

```python theme={null}
ExtensionContext(extension_name: str) -> None
```

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `extension_name` | `str` | Required |
>
> ```python theme={null}
> from harnest.extensions import ExtensionContext
>
> context = ExtensionContext(extension_name=...)
> ```

### ExtensionContext.extension\_name

Return the extension whose invocation authority this context carries.

> [accordion] Example
>
> ```python theme={null}
> from harnest.extensions import ExtensionContext
>
> context: ExtensionContext
> value = context.extension_name
> ```

### ExtensionContext.active

Report whether the owning managed invocation is still active.

> [accordion] Example
>
> ```python theme={null}
> from harnest.extensions import ExtensionContext
>
> context: ExtensionContext
> value = context.active
> ```

### ExtensionContext.continuations

Return provider-bound suspension authority for this invocation.

> [accordion] Example
>
> ```python theme={null}
> from harnest.extensions import ExtensionContext
>
> context: ExtensionContext
> value = context.continuations
> ```

## ExtensionContextUnavailableError

An extension context was used outside its managed invocation.

> [accordion] Example
>
> ```python theme={null}
> from harnest.extensions import ExtensionContextUnavailableError
>
> try:
>     ...
> except ExtensionContextUnavailableError as error:
>     ...
> ```

## ExtensionImportError

An authored extension module violates its export contract.

> [accordion] Example
>
> ```python theme={null}
> from harnest.extensions import ExtensionImportError
>
> try:
>     ...
> except ExtensionImportError as error:
>     ...
> ```

## ExtensionNamespaceError

An extension namespace cannot be activated or safely released.

> [accordion] Example
>
> ```python theme={null}
> from harnest.extensions import ExtensionNamespaceError
>
> try:
>     ...
> except ExtensionNamespaceError as error:
>     ...
> ```

## ExtensionStartContext

Application facts available while one same-process extension starts.

The context deliberately excludes invocation credentials and framework
storage authorities. Extensions may reuse only explicitly named application
storage whose lifecycle Harnest has already started.

Obtain this object from the owning Harnest API; its constructor includes runtime bindings.

Fields (`—` means no declared default):

| Field | Type | Default |
| - | - | - |
| `extension_name` | `str` | `—` |
| `framework` | `str` | `—` |
| `root_agent_name` | `str` | `—` |

> [accordion] Example
>
> ```python theme={null}
> from harnest.extensions import ExtensionStartContext
>
> context: ExtensionStartContext  # returned by Harnest, not constructed directly
> ```

### ExtensionStartContext.storage

```python theme={null}
ExtensionStartContext.storage(name: str, expected_type: type[Any] | None = None) -> Any
```

Return one named custom store without exposing the registry.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `name` | `str` | Required |
> | `expected_type` | `type[Any] \| None` | `None` |
>
> ```python theme={null}
> from harnest.extensions import ExtensionStartContext
>
> context: ExtensionStartContext
> result = context.storage(name=...)
> ```

### ExtensionStartContext.continuations

Return provider-bound completion authority when explicitly declared.

> [accordion] Example
>
> ```python theme={null}
> from harnest.extensions import ExtensionStartContext
>
> context: ExtensionStartContext
> value = context.continuations
> ```

## activate\_extensions

Activate a dependency-ordered extension set as one namespace transaction.

```python theme={null}
activate_extensions(descriptors: Sequence[ExtensionDescriptor]) -> tuple[ActivatedExtension, ...]
```

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `descriptors` | `Sequence[ExtensionDescriptor]` | Required |
>
> ```python theme={null}
> from harnest.extensions import activate_extensions
>
> result = activate_extensions(descriptors=...)
> ```

## extension\_mutation

Audit one exact durable operation after commit or on correlated failure.

```python theme={null}
extension_mutation(extension_name: str, operation: str, *, trigger: Literal['agent', 'user']) -> AsyncIterator[None]
```

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `extension_name` | `str` | Required |
> | `operation` | `str` | Required |
> | `trigger` | `Literal['agent', 'user']` | Required |
>
> ```python theme={null}
> from harnest.extensions import extension_mutation
>
> async with extension_mutation(extension_name=..., operation=..., trigger=...):
>     ...
> ```

## extension\_namespaces

Activate extensions for one bounded compiler or test operation.

```python theme={null}
extension_namespaces(descriptors: Sequence[ExtensionDescriptor]) -> Iterator[tuple[ActivatedExtension, ...]]
```

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `descriptors` | `Sequence[ExtensionDescriptor]` | Required |
>
> ```python theme={null}
> from harnest.extensions import extension_namespaces
>
> with extension_namespaces(descriptors=...):
>     ...
> ```

## release\_extensions

Release one acquisition without disturbing a competing extension set.

```python theme={null}
release_extensions(descriptors: Sequence[ExtensionDescriptor]) -> None
```

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `descriptors` | `Sequence[ExtensionDescriptor]` | Required |
>
> ```python theme={null}
> from harnest.extensions import release_extensions
>
> release_extensions(descriptors=...)
> ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.