**Source URL:** https://general.veevavault.dev/ai-agents/agent-context/how-to-create-custom-context-type.md

# How to Create Custom Context Types

<Aside type="note">The functionality described on this page is only available to customers who have licensed Veeva AI.</Aside>
To create a custom context type with Vault Java SDK:

<Steps>
1. Create a *Context Type Runtime Handler*:

```
@ExecuteAs(ExecuteAsUser.REQUEST_OWNER)
@AiContextTypeRuntimeHandlerInfo(scope = AiScope.DOCUMENT)
public class MyContextTypeRuntimeHandler implements AiContextTypeRuntimeHandler{
    @Override
    public AiContextTypeResolveResponse onResolve(AiContextTypeResolveContext context){
        AiDocumentScopeSource documentScopeSource = context.getScopeSource(AiScopeType.DOCUMENT);
        DocumentVersion documentVersion = documentScopeSource.getDocumentVersion();
        String documentName = documentVersion.getValue("name__v", ValueType.STRING);

        AiContextTypeOutputItem contextOutput = context.newOutputItemBuilder()
            .withText("The current document name is [" + documentName + "]")
            .build();

        return context.newSuccessResponseBuilder()
            .appendOutputItem(contextOutput)
            .build();
         }
     }

```

2. Create an `Aicontexttyperuntimecode` MDL record referencing the `AiContextTypeRuntimeHandler`, and create an `Aicontexttype` MDL record:

```
RECREATE Aicontexttype my_custom_context_type__c (
label('My Context Type'),
admin_configurable(true),
runtime_code('Aicontexttyperuntimecode.com.veeva.vault.custom.context.MyContextTypeRuntimeHandler')
      );

```

</Steps>

---

**Previous:** [Agent Context](/ai-agents/agent-context)  
**Next:** [Agent Tools](/ai-agents/agent-tools)