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

# Lifecycle reference

> Find each lifecycle decorator, its allowed count, and its detailed guide.

Root files under `lifecycle/**/*.py` add behavior around the agent. Harnest discovers decorated functions and ignores ordinary helpers.

## Decorator index

| Decorator                                |                 Allowed | Purpose                          | Guide                                                                                             |
| ---------------------------------------- | ----------------------: | -------------------------------- | ------------------------------------------------------------------------------------------------- |
| `@lifecycle.resource`                    |                    Many | Application dependency           | [Application resources](/harnest/runtime/lifecycle/application-resources)                         |
| `@lifecycle.skills.source("name")`       | Many, with unique names | Dynamic skill catalog            | [Agent Skills](/harnest/build/agent-skills)                                                       |
| `@context("name")`                       |                    Many | Publish a resource               | [Application resources](/harnest/runtime/lifecycle/application-resources)                         |
| `@lifecycle.agent.before/after/on_error` |                    Many | Agent policy and observation     | [Invocation hooks](/harnest/runtime/lifecycle/invocation-hooks)                                   |
| `@lifecycle.model.before/after/on_error` |                    Many | Model policy and observation     | [Invocation hooks](/harnest/runtime/lifecycle/invocation-hooks)                                   |
| `@lifecycle.tool.before/after/on_error`  |                    Many | Tool policy and observation      | [Invocation hooks](/harnest/runtime/lifecycle/invocation-hooks)                                   |
| `@lifecycle.mcp.before/after/on_error`   |                    Many | Governed remote-tool policy      | [Invocation hooks](/harnest/runtime/lifecycle/invocation-hooks)                                   |
| `@lifecycle.http.before/after/on_error`  |                    Many | HTTP request and response policy | [Invocation hooks](/harnest/runtime/lifecycle/invocation-hooks)                                   |
| `@lifecycle.output_policy`               |             Zero or one | Public SubAgent messages         | [Output policy](/harnest/runtime/lifecycle/output-policy)                                         |
| `@lifecycle.adk_plugin`                  |                    Many | ADK-native behavior              | [Native integrations](/harnest/runtime/lifecycle/native-integrations)                             |
| `@lifecycle.langgraph_middleware`        |                    Many | LangGraph-native behavior        | [Native integrations](/harnest/runtime/lifecycle/native-integrations)                             |
| `@lifecycle.http_routes`                 |                    Many | Application HTTP routes          | [Custom HTTP endpoints](/harnest/runtime/custom-http-endpoints)                                   |
| `@lifecycle.storage.sessions`            |             Exactly one | Sessions and transcripts         | [Sessions](/harnest/runtime/session-storage)                                                      |
| `@lifecycle.storage.checkpoints`         |             Exactly one | In-progress execution            | [Checkpoints](/harnest/runtime/checkpoints)                                                       |
| `@lifecycle.storage.assets("name")`      | Many, with unique names | Multimodal asset storage         | [Store and retrieve media](/harnest/build/models-and-libraries/store-and-retrieve-media)          |
| `@lifecycle.storage.custom("name")`      | Many, with unique names | Domain repositories              | [Sessions and application storage](/harnest/runtime/session-storage#register-a-domain-repository) |
| `@lifecycle.authenticate`                |            Zero or more | Request identity                 | [Authentication](/harnest/runtime/authentication-and-credentials)                                 |
| `@lifecycle.credential_provider`         |             Zero or one | Downstream credentials           | [Authentication](/harnest/runtime/authentication-and-credentials)                                 |
| `@lifecycle.telemetry_exporter`          |                    Many | Trace and log destination        | [Telemetry](/harnest/runtime/telemetry)                                                           |

## Factory rules

| Rule            | Behavior                                                                                         |
| --------------- | ------------------------------------------------------------------------------------------------ |
| Signature       | Synchronous and zero-argument unless it is a callback; `http_routes` receives one `AgentInvoker` |
| Return type     | Must match the decorator's resource or policy type                                               |
| Duplicates      | Single-owner factories reject duplicates                                                         |
| Ordering        | Lower `order`, plugin dependency/source order, then source location                              |
| Ownership       | Root agent only                                                                                  |
| Startup failure | Application does not serve                                                                       |
| Shutdown        | Harnest closes resources it owns                                                                 |

<Card title="Lifecycle overview" icon="arrows-rotate" href="/harnest/runtime/lifecycle">
  Choose the extension type before opening its focused guide.
</Card>
