> ## 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.context

> 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)

Use `from harnest import context` for capabilities bound to the current managed invocation. Access to a capability does not extend its lifetime beyond that invocation.

## Invocation capabilities

These attributes are resolved at runtime rather than stored as module globals. Use the linked types for their methods; accessing a managed property during import or outside its required runtime raises an availability error.

| Attribute | API |
| - | - |
| `context.current()` | [`AgentContext`](#agentcontext): invocation identity and named resources. |
| `context.agent` | [`LocalAgentRuntime`](#localagentruntime): start or access a root agent session from task execution. |
| `context.session` | [`SessionContext`](#sessioncontext): current session data. |
| `context.memory` | [`MemoryContext`](#memorycontext): user-scoped long-term memory. |
| `context.assets` | [`ScopedAssets`](#scopedassets): user/session-scoped assets. |
| `context.sandboxes["name"]` | [Named sandbox execution](#sandboxhandle): execute only through an assigned sandbox. |
| `context.extensions("name")` | [`ExtensionContext`](https://usefused.com/docs/harnest/reference/api/extensions#extensioncontext): installed extension capability; see its typed extension reference. |
| `context.storage` | [`StorageContext`](#storagecontext): named custom storage. |
| `context.credentials` | [`CredentialContext`](https://usefused.com/docs/harnest/reference/api/credentials#credentialcontext): credential resolution. |
| `context.mcp` | [`MCPContext`](https://usefused.com/docs/harnest/reference/api/mcp#mcpcontext): governed MCP calls. |
| `context.skills` | [`SkillAccess`](https://usefused.com/docs/harnest/reference/api/skills#skillaccess): current agent's skills. |
| `context.decisions` | [`DecisionContext`](https://usefused.com/docs/harnest/reference/api/decisions#decisioncontext): registered typed decisions. |

Identity properties such as `context.user_id`, `context.session_id`, and `context.invocation_id` read from the active `AgentContext`. See [Agent runtime principals](https://usefused.com/docs/harnest/runtime/agent-runtime-principals.md) for authorization and [Tasks](https://usefused.com/docs/harnest/build/queued-tasks.md#start-a-fresh-agent-session) for task-initiated agent calls.

## Memory operations

| Operation | Behavior |
| - | - |
| `put(key, content, ...)` | Explicitly insert or replace one scoped record |
| `get(key)` | Return a live record or `None` |
| `list(limit=20, after=None)` | Return a bounded page in ascending key order |
| `search(query, limit=20, after=None)` | Return literal, case-sensitive content matches |
| `delete(key, ...)` | Remove the record and its index references; return whether it existed |

## Session operations

| Operation | Behavior |
| - | - |
| `get(key, default=None)` | Returns a detached value |
| `set(key, value)` | Replaces one value |
| `update(values)` | Writes several keys under one session lease |
| `delete(key)` | Deletes one key and returns whether it existed |
| `namespace(name)` | Isolates domain or plugin keys |

## Exports

| Name | Kind |
| - | - |
| [`AgentContext`](#agentcontext) | Class |
| [`AgentContinuationUnsupportedError`](#agentcontinuationunsupportederror) | Class |
| [`AgentInvocationTimeout`](#agentinvocationtimeout) | Class |
| [`AgentInvocationUnavailableError`](#agentinvocationunavailableerror) | Class |
| [`AgentPendingResponse`](#agentpendingresponse) | Class |
| [`AgentResponse`](#agentresponse) | Class |
| [`AgentSession`](#agentsession) | Class |
| [`AgentSessionNotFoundError`](#agentsessionnotfounderror) | Class |
| [`AgentStreamItem`](#agentstreamitem) | Class |
| [`ContextRegistration`](#contextregistration) | Class |
| [`ContextResourceError`](#contextresourceerror) | Class |
| [`ContextUnavailableError`](#contextunavailableerror) | Class |
| [`LocalAgentRuntime`](#localagentruntime) | Class |
| [`MemoryContext`](#memorycontext) | Class |
| [`ScopedAssets`](#scopedassets) | Class |
| [`SessionContext`](#sessioncontext) | Class |
| [`SessionDataError`](#sessiondataerror) | Class |
| [`StorageContext`](#storagecontext) | Class |
| [`activate_agent_scope`](#activate_agent_scope) | Function |
| [`current`](#current) | Function |
| [`derive_agent_context`](#derive_agent_context) | Function |
| [`provider`](#provider) | Function |
| [`resource`](#resource) | Function |

## AgentContext

Stable invocation identity and its explicitly exported resources.

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

Fields (`—` means no declared default):

| Field | Type | Default |
| - | - | - |
| `framework` | `str` | `—` |
| `agent_name` | `str` | `—` |
| `invocation_id` | `str` | `—` |
| `user_id` | `str` | `—` |
| `session_id` | `str` | `—` |
| `metadata` | `Mapping[str, Any]` | `—` |
| `parent_agent_name` | `str \| None` | `—` |
| `depth` | `int` | `—` |

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

### AgentContext.resource

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

Return one named capability without exposing the whole registry.

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

### AgentContext.is\_root

Report whether this scope represents the compiled root agent.

> [accordion] Example
>
> ```python theme={null}
> from harnest.context import AgentContext
>
> context: AgentContext
> value = context.is_root
> ```

## AgentContinuationUnsupportedError

A local invocation reached a continuation its caller cannot service.

```python theme={null}
AgentContinuationUnsupportedError(kind: str) -> None
```

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

## AgentInvocationTimeout

An in-process agent invocation exceeded its configured deadline.

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

## AgentInvocationUnavailableError

No compiled runtime is bound to the current authored task.

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

## AgentPendingResponse

A persisted external wait that can be resumed by the owning runtime.

```python theme={null}
AgentPendingResponse(
    status: Literal['in_progress'],
    session_id: str,
    invocation_id: str,
    pending_action: Mapping[str, str],
) -> None
```

Fields (`—` means no declared default):

| Field | Type | Default |
| - | - | - |
| `status` | `Literal['in_progress']` | `—` |
| `session_id` | `str` | `—` |
| `invocation_id` | `str` | `—` |
| `pending_action` | `Mapping[str, str]` | `—` |

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `status` | `Literal['in_progress']` | Required |
> | `session_id` | `str` | Required |
> | `invocation_id` | `str` | Required |
> | `pending_action` | `Mapping[str, str]` | Required |
>
> ```python theme={null}
> from harnest.context import AgentPendingResponse
>
> response = AgentPendingResponse(
>     status=...,
>     session_id=...,
>     invocation_id=...,
>     pending_action=...,
> )
> ```

### AgentPendingResponse.as\_dict

```python theme={null}
AgentPendingResponse.as_dict() -> dict[str, Any]
```

Expose only provider-neutral durable continuation metadata.

> [accordion] Example
>
> ```python theme={null}
> from harnest.context import AgentPendingResponse
>
> response: AgentPendingResponse
> result = response.as_dict()
> ```

## AgentResponse

Framework-neutral result returned by an in-process invocation.

```python theme={null}
AgentResponse(
    output_text: str,
    result: Any,
    events: tuple[RuntimeEvent, ...],
    session_id: str,
    invocation_id: str,
    metadata: Mapping[str, Any],
    usage: TokenUsage | None = None,
) -> None
```

Fields (`—` means no declared default):

| Field | Type | Default |
| - | - | - |
| `output_text` | `str` | `—` |
| `result` | `Any` | `—` |
| `events` | `tuple[RuntimeEvent, ...]` | `—` |
| `session_id` | `str` | `—` |
| `invocation_id` | `str` | `—` |
| `metadata` | `Mapping[str, Any]` | `—` |
| `usage` | `TokenUsage \| None` | `None` |

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `output_text` | `str` | Required |
> | `result` | `Any` | Required |
> | `events` | `tuple[RuntimeEvent, ...]` | Required |
> | `session_id` | `str` | Required |
> | `invocation_id` | `str` | Required |
> | `metadata` | `Mapping[str, Any]` | Required |
> | `usage` | `TokenUsage \| None` | `None` |
>
> ```python theme={null}
> from harnest.context import AgentResponse
>
> response = AgentResponse(
>     output_text=...,
>     result=...,
>     events=...,
>     session_id=...,
>     invocation_id=...,
>     metadata=...,
> )
> ```

### AgentResponse.as\_dict

```python theme={null}
AgentResponse.as_dict() -> dict[str, Any]
```

Return strict JSON without stringifying unsupported output objects.

> [accordion] Example
>
> ```python theme={null}
> from harnest.context import AgentResponse
>
> response: AgentResponse
> result = response.as_dict()
> ```

## AgentSession

One persisted session owned by a local in-process runtime identity.

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

Fields (`—` means no declared default):

| Field | Type | Default |
| - | - | - |
| `id` | `str` | `—` |
| `user_id` | `str` | `—` |

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

### AgentSession.invoke

```python theme={null}
async AgentSession.invoke(
    value: Any,
    *,
    metadata: Mapping[str, Any] | None = None,
    request_timeout: float | None = None,
    agent_principal: AgentRuntimePrincipal | None = None,
) -> AgentResponse | AgentPendingResponse
```

Run one non-streaming turn through the complete runtime pipeline.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `value` | `Any` | Required |
> | `metadata` | `Mapping[str, Any] \| None` | `None` |
> | `request_timeout` | `float \| None` | `None` |
> | `agent_principal` | `AgentRuntimePrincipal \| None` | `None` |
>
> ```python theme={null}
> from harnest.context import AgentSession
>
> session: AgentSession
> response = await session.invoke(value=...)
> ```

### AgentSession.stream

```python theme={null}
AgentSession.stream(
    value: Any,
    *,
    metadata: Mapping[str, Any] | None = None,
    request_timeout: float | None = None,
    agent_principal: AgentRuntimePrincipal | None = None,
) -> AsyncIterator[AgentStreamItem]
```

Stream portable events and a final response with cancellation cleanup.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `value` | `Any` | Required |
> | `metadata` | `Mapping[str, Any] \| None` | `None` |
> | `request_timeout` | `float \| None` | `None` |
> | `agent_principal` | `AgentRuntimePrincipal \| None` | `None` |
>
> ```python theme={null}
> from harnest.context import AgentSession
>
> session: AgentSession
> async for item in session.stream(value=...):
>     ...
> ```

## AgentSessionNotFoundError

An identity-scoped local session does not exist.

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

## AgentStreamItem

One portable runtime event or the validated terminal response.

```python theme={null}
AgentStreamItem(
    kind: Literal['event', 'completed', 'pending'],
    sequence: int,
    event: RuntimeEvent | None = None,
    response: AgentResponse | None = None,
    pending: AgentPendingResponse | None = None,
) -> None
```

Fields (`—` means no declared default):

| Field | Type | Default |
| - | - | - |
| `kind` | `Literal['event', 'completed', 'pending']` | `—` |
| `sequence` | `int` | `—` |
| `event` | `RuntimeEvent \| None` | `None` |
| `response` | `AgentResponse \| None` | `None` |
| `pending` | `AgentPendingResponse \| None` | `None` |

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `kind` | `Literal['event', 'completed', 'pending']` | Required |
> | `sequence` | `int` | Required |
> | `event` | `RuntimeEvent \| None` | `None` |
> | `response` | `AgentResponse \| None` | `None` |
> | `pending` | `AgentPendingResponse \| None` | `None` |
>
> ```python theme={null}
> from harnest.context import AgentStreamItem
>
> item = AgentStreamItem(kind=..., sequence=...)
> ```

### AgentStreamItem.as\_dict

```python theme={null}
AgentStreamItem.as_dict() -> dict[str, Any]
```

Serialize a stable local envelope without importing HTTP contracts.

> [accordion] Example
>
> ```python theme={null}
> from harnest.context import AgentStreamItem
>
> item: AgentStreamItem
> result = item.as_dict()
> ```

## ContextRegistration

Metadata declaring the name and order of one context provider.

```python theme={null}
ContextRegistration(name: str, order: int = 0) -> None
```

Fields (`—` means no declared default):

| Field | Type | Default |
| - | - | - |
| `name` | `str` | `—` |
| `order` | `int` | `0` |

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `name` | `str` | Required |
> | `order` | `int` | `0` |
>
> ```python theme={null}
> from harnest.context import ContextRegistration
>
> registration = ContextRegistration(name=...)
> ```

## ContextResourceError

Raised when an invocation does not contain a requested resource.

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

## ContextUnavailableError

Raised when agent context is accessed outside a Harnest invocation.

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

## LocalAgentRuntime

Invoke a final compiled runtime driver without an HTTP round trip.

```python theme={null}
LocalAgentRuntime(
    driver: RuntimeDriver,
    *,
    user_id: str,
    transport: str = 'local',
    trigger: Literal['agent', 'cron', 'user'] = 'user',
    request_timeout: float = 300,
    identity_namespace: str | None = None,
    metadata: Mapping[str, Any] | None = None,
) -> None
```

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `driver` | `RuntimeDriver` | Required |
> | `user_id` | `str` | Required |
> | `transport` | `str` | `'local'` |
> | `trigger` | `Literal['agent', 'cron', 'user']` | `'user'` |
> | `request_timeout` | `float` | `300` |
> | `identity_namespace` | `str \| None` | `None` |
> | `metadata` | `Mapping[str, Any] \| None` | `None` |
>
> ```python theme={null}
> from harnest.context import LocalAgentRuntime
>
> runtime = LocalAgentRuntime(driver=..., user_id=...)
> ```

### LocalAgentRuntime.user\_id

Return the session owner selected by the local caller.

> [accordion] Example
>
> ```python theme={null}
> from harnest.context import LocalAgentRuntime
>
> runtime: LocalAgentRuntime
> value = runtime.user_id
> ```

### LocalAgentRuntime.create\_session

```python theme={null}
async LocalAgentRuntime.create_session(
    *,
    state: Mapping[str, Any] | None = None,
    session_id: str | None = None,
    reuse_existing: bool = False,
) -> AgentSession
```

Create one persisted session under the configured local identity.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `state` | `Mapping[str, Any] \| None` | `None` |
> | `session_id` | `str \| None` | `None` |
> | `reuse_existing` | `bool` | `False` |
>
> ```python theme={null}
> from harnest.context import LocalAgentRuntime
>
> runtime: LocalAgentRuntime
> session = await runtime.create_session()
> ```

### LocalAgentRuntime.open\_session

```python theme={null}
async LocalAgentRuntime.open_session(session_id: str) -> AgentSession
```

Open an existing session without revealing another owner's records.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `session_id` | `str` | Required |
>
> ```python theme={null}
> from harnest.context import LocalAgentRuntime
>
> runtime: LocalAgentRuntime
> session = await runtime.open_session(session_id=...)
> ```

## MemoryContext

Access explicit memories across sessions within one application/user scope.

```python theme={null}
MemoryContext(active: Any, namespace: str = 'default') -> None
```

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `active` | `Any` | Required |
> | `namespace` | `str` | `'default'` |
>
> ```python theme={null}
> from harnest.context import MemoryContext
>
> context = MemoryContext(active=...)
> ```

### MemoryContext.namespace

```python theme={null}
MemoryContext.namespace(name: str) -> MemoryContext
```

Select a logical collection without changing application/user ownership.

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

### MemoryContext.put

```python theme={null}
async MemoryContext.put(
    key: str,
    content: str,
    *,
    metadata: Optional[Mapping[str, Any]] = None,
    expires_at: float | None = None,
    expected_revision: str | None = None,
) -> harnest.memory.MemoryRecord
```

Deliberately save or replace a memory, recording invocation provenance.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `key` | `str` | Required |
> | `content` | `str` | Required |
> | `metadata` | `Optional[Mapping[str, Any]]` | `None` |
> | `expires_at` | `float \| None` | `None` |
> | `expected_revision` | `str \| None` | `None` |
>
> ```python theme={null}
> from harnest.context import MemoryContext
>
> context: MemoryContext
> record = await context.put(key=..., content=...)
> ```

### MemoryContext.get

```python theme={null}
async MemoryContext.get(key: str) -> harnest.memory.MemoryRecord | None
```

Read a scoped key without adding it to model context.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `key` | `str` | Required |
>
> ```python theme={null}
> from harnest.context import MemoryContext
>
> context: MemoryContext
> record = await context.get(key=...)
> ```

### MemoryContext.list

```python theme={null}
async MemoryContext.list(*, limit: int = 20, after: str | None = None) -> harnest.memory.MemoryPage
```

List a bounded page of explicit memories across this user's sessions.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `limit` | `int` | `20` |
> | `after` | `str \| None` | `None` |
>
> ```python theme={null}
> from harnest.context import MemoryContext
>
> context: MemoryContext
> page = await context.list()
> ```

### MemoryContext.search

```python theme={null}
async MemoryContext.search(query: str, *, limit: int = 20, after: str | None = None) -> harnest.memory.MemoryPage
```

Search literal text on explicit request, without model calls.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `query` | `str` | Required |
> | `limit` | `int` | `20` |
> | `after` | `str \| None` | `None` |
>
> ```python theme={null}
> from harnest.context import MemoryContext
>
> context: MemoryContext
> page = await context.search(query=...)
> ```

### MemoryContext.delete

```python theme={null}
async MemoryContext.delete(key: str, *, expected_revision: str | None = None) -> bool
```

Explicitly forget a memory and its provider index references.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `key` | `str` | Required |
> | `expected_revision` | `str \| None` | `None` |
>
> ```python theme={null}
> from harnest.context import MemoryContext
>
> context: MemoryContext
> result = await context.delete(key=...)
> ```

## ScopedAssets

Named asset capabilities restricted to one authenticated invocation.

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

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

### ScopedAssets.**call**

```python theme={null}
ScopedAssets.__call__(store: str) -> 'ScopedAssets'
```

Select one named store without exposing its backing implementation.

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

### ScopedAssets.save

```python theme={null}
async ScopedAssets.save(
    *,
    media_type: str,
    chunks: AsyncIterable[bytes],
    metadata: AssetMediaMetadata | None = None,
    retention_seconds: float | None = None,
    path: str | None = None,
    label: str | None = None,
    store: str | None = None,
) -> AssetRef
```

Persist streamed bytes and return a reference carrying store routing.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `media_type` | `str` | Required |
> | `chunks` | `AsyncIterable[bytes]` | Required |
> | `metadata` | `AssetMediaMetadata \| None` | `None` |
> | `retention_seconds` | `float \| None` | `None` |
> | `path` | `str \| None` | `None` |
> | `label` | `str \| None` | `None` |
> | `store` | `str \| None` | `None` |
>
> ```python theme={null}
> from harnest.context import ScopedAssets
>
> assets: ScopedAssets
> ref = await assets.save(media_type=..., chunks=...)
> ```

### ScopedAssets.stat

```python theme={null}
async ScopedAssets.stat(reference: Any, *, store: str | None = None) -> AssetRecord
```

Return safe metadata for an owned asset or fail closed.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `reference` | `Any` | Required |
> | `store` | `str \| None` | `None` |
>
> ```python theme={null}
> from harnest.context import ScopedAssets
>
> assets: ScopedAssets
> record = await assets.stat(reference=...)
> ```

### ScopedAssets.open

```python theme={null}
ScopedAssets.open(reference: Any, *, store: str | None = None) -> AsyncIterator[bytes]
```

Stream owned bytes without exposing the backing storage object.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `reference` | `Any` | Required |
> | `store` | `str \| None` | `None` |
>
> ```python theme={null}
> from harnest.context import ScopedAssets
>
> assets: ScopedAssets
> result = assets.open(reference=...)
> ```

### ScopedAssets.get

```python theme={null}
async ScopedAssets.get(reference: Any, *, store: str | None = None, max_bytes: int = 10485760) -> bytes
```

Read a bounded asset for APIs that require an in-memory payload.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `reference` | `Any` | Required |
> | `store` | `str \| None` | `None` |
> | `max_bytes` | `int` | `10485760` |
>
> ```python theme={null}
> from harnest.context import ScopedAssets
>
> assets: ScopedAssets
> result = await assets.get(reference=...)
> ```

### ScopedAssets.delete

```python theme={null}
async ScopedAssets.delete(reference: Any, *, store: str | None = None) -> bool
```

Delete an owned asset without revealing another scope's content.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `reference` | `Any` | Required |
> | `store` | `str \| None` | `None` |
>
> ```python theme={null}
> from harnest.context import ScopedAssets
>
> assets: ScopedAssets
> result = await assets.delete(reference=...)
> ```

### ScopedAssets.url

```python theme={null}
async ScopedAssets.url(reference: Any, *, expires_in: float, store: str | None = None) -> str
```

Ask an explicitly URL-capable storage for a fresh temporary URL.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `reference` | `Any` | Required |
> | `expires_in` | `float` | Required |
> | `store` | `str \| None` | `None` |
>
> ```python theme={null}
> from harnest.context import ScopedAssets
>
> assets: ScopedAssets
> result = await assets.url(reference=..., expires_in=...)
> ```

## SessionContext

Provide JSON-safe access to the current session's application-data lane.

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

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

### SessionContext.get

```python theme={null}
async SessionContext.get(key: str, default: Any = None) -> Any
```

Return a detached value without exposing mutable store-owned state.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `key` | `str` | Required |
> | `default` | `Any` | `None` |
>
> ```python theme={null}
> from harnest.context import SessionContext
>
> context: SessionContext
> result = await context.get(key=...)
> ```

### SessionContext.set

```python theme={null}
async SessionContext.set(key: str, value: Any) -> None
```

Persist one value without projecting it into framework model state.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `key` | `str` | Required |
> | `value` | `Any` | Required |
>
> ```python theme={null}
> from harnest.context import SessionContext
>
> context: SessionContext
> await context.set(key=..., value=...)
> ```

### SessionContext.update

```python theme={null}
async SessionContext.update(values: Mapping[str, Any]) -> None
```

Persist a bounded mapping in one lease-owned write.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `values` | `Mapping[str, Any]` | Required |
>
> ```python theme={null}
> from harnest.context import SessionContext
>
> context: SessionContext
> await context.update(values=...)
> ```

### SessionContext.delete

```python theme={null}
async SessionContext.delete(key: str) -> bool
```

Delete one value and report whether the current namespace contained it.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `key` | `str` | Required |
>
> ```python theme={null}
> from harnest.context import SessionContext
>
> context: SessionContext
> result = await context.delete(key=...)
> ```

### SessionContext.namespace

```python theme={null}
SessionContext.namespace(name: str) -> 'SessionContext'
```

Return a nested view so teams and plugins can avoid key collisions.

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

## SessionDataError

Raised when application session data violates its scoped contract.

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

## StorageContext

Resolve custom storage without exposing sessions or checkpoints.

```python theme={null}
StorageContext()
```

> [accordion] Example
>
> ```python theme={null}
> from harnest.context import StorageContext
>
> context = StorageContext()
> ```

### StorageContext.**call**

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

Return one named custom resource for concise authored access.

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

### StorageContext.resource

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

Resolve a custom store while keeping the registry non-enumerable.

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

## activate\_agent\_scope

Narrow managed identity to the framework component currently executing.

```python theme={null}
activate_agent_scope(agent_name: str | None) -> Iterator[AgentContext | None]
```

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `agent_name` | `str \| None` | Required |
>
> ```python theme={null}
> from harnest.context import activate_agent_scope
>
> with activate_agent_scope(agent_name=...):
>     ...
> ```

## current

Return the active managed invocation context.

```python theme={null}
current() -> AgentContext
```

> [accordion] Example
>
> ```python theme={null}
> from harnest.context import current
>
> context = current()
> ```

## derive\_agent\_context

Create a child view that shares only its parent's revocable capabilities.

```python theme={null}
derive_agent_context(active: AgentContext, *, agent_name: str) -> AgentContext
```

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `active` | `AgentContext` | Required |
> | `agent_name` | `str` | Required |
>
> ```python theme={null}
> from harnest.context import derive_agent_context
>
> context = derive_agent_context(active=..., agent_name=...)
> ```

## provider

Declare one invocation-scoped resource on the public context namespace.

```python theme={null}
provider(name: str, *, order: int = 0) -> Callable[[_ProviderT], _ProviderT]
```

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `name` | `str` | Required |
> | `order` | `int` | `0` |
>
> ```python theme={null}
> from harnest.context import provider
>
> @provider(name=...)
> def my_function():
>     ...
> ```

## resource

Resolve one explicitly published invocation resource.

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

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

## SandboxHandle

Access this facade through `context.sandboxes["name"]`; its implementation type is not a public import.

A revocable agent-and-invocation-bound execution capability.

### SandboxHandle.execute

```python theme={null}
SandboxHandle.execute(code: str, *, input_files: tuple[SandboxFile, ...] = ()) -> SandboxResult
```

Execute tool-authored code with immutable provider policy and identity.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `code` | `str` | Required |
> | `input_files` | `tuple[SandboxFile, ...]` | `()` |
>
> ```python theme={null}
> from harnest import context
>
> result = context.sandboxes["name"].execute(code=...)
> ```

### SandboxHandle.aexecute

```python theme={null}
async SandboxHandle.aexecute(code: str, *, input_files: tuple[SandboxFile, ...] = ()) -> SandboxResult
```

Keep blocking providers off the event loop and revoke cancelled work.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `code` | `str` | Required |
> | `input_files` | `tuple[SandboxFile, ...]` | `()` |
>
> ```python theme={null}
> from harnest import context
>
> result = await context.sandboxes["name"].aexecute(code=...)
> ```


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