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

# AI Functions

> Describe a typed function for a model to complete

`@marvin.fn` uses a function's signature, docstring, and arguments to create a task. Its return annotation defines the result type.

```python theme={null}
import marvin

@marvin.fn
def translate(text: str, language: str) -> str:
    """Translate text into the requested language."""
    ...

translation = translate("Hello", "Spanish")
```

The function body **does execute** to supply additional context to the model. Leave it as `...` if no context is needed. Its ordinary return value is context, not the final generated result.

## Configure the task

Set `instructions`, `agent`, `thread`, or `prompt` on the decorator. Calls also accept `_agent`, `_thread`, and `_instructions` overrides.

```python theme={null}
import marvin

@marvin.fn(instructions="Use formal language.")
def translate(text: str, language: str) -> str:
    """Translate text into the requested language."""
    ...

task = translate.as_task("Hello", "Spanish")
translation = task.run()
```

`as_task` creates the task without a model request, but still executes the function body to collect context.

For async usage, decorate an `async def` function and await the call. See [the API reference](https://askmarvin.ai/api-reference/marvin-fns-fn.md).


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