Ana içeriğe geç
Bu sayfa henüz Türkçeye çevrilmedi; İngilizce sürümü gösteriliyor.
Versiyon: 1.6

AI Worker

The AI Worker sends a prompt to an AI model and stores the answer as the job's result. Use it to run AI tasks on a schedule ("summarize yesterday's errors every morning") or as a step in a workflow, where the answer feeds the next step: an HTTP call, an email, a SQL insert or another prompt.

Providers​

TypeServiceNotes
AnthropicClaude (Messages API)Official Anthropic SDK. Default model claude-opus-5-5.
OpenAIOpenAI Chat CompletionsOfficial OpenAI SDK. With BaseUrl it works with any OpenAI-compatible API: Azure OpenAI, OpenRouter, Groq, DeepSeek, a local Ollama.
GeminiGoogle Gemini (Generative Language API)REST generateContent.

You can configure several providers, and several accounts of the same provider, each under its own name. A job picks one by name.

Worker Configuration​

{
"AiConfig": {
"DefaultConfigName": "Claude",
"Providers": {
"Claude": {
"Type": "Anthropic",
"ApiKey": "",
"DefaultModel": "claude-opus-5-5",
"Models": ["claude-sonnet-5-5", "claude-haiku-5-5"],
"TimeoutSeconds": 300
},
"OpenAI": {
"Type": "OpenAI",
"ApiKey": "",
"DefaultModel": "gpt-5",
"Models": ["gpt-5-mini"]
},
"Gemini": {
"Type": "Gemini",
"ApiKey": "",
"DefaultModel": "gemini-2.5-flash"
},
"LocalLlama": {
"Type": "OpenAI",
"BaseUrl": "http://ollama:11434/v1",
"DefaultModel": "llama3.1"
}
}
}
}
PropertyDescription
TypeAnthropic, OpenAI or Gemini
ApiKeyThe provider's API key. Set it through an environment variable such as AiConfig__Providers__Claude__ApiKey, not in the file.
BaseUrlOptional endpoint override (proxy, OpenAI-compatible service, local model)
DefaultModelModel used when the job does not name one
ModelsMore models to offer in the job form. DefaultModel is offered too.
TimeoutSecondsRequest timeout, default 300

Choosing the Model in the Dashboard​

When you create or edit a job for AiPromptJob, the job form shows drop-downs above the job data JSON: configName lists the provider configurations and model lists every configuration's DefaultModel and Models. Picking a value writes it into the JSON; you can still type any other model name into the JSON by hand.

You only need to pick the model. With configName left empty, the job runs on the configuration that lists that model, with that configuration's key. If you set both and the model is listed under a different configuration, the job fails with a message that names the right one, instead of sending, say, a GPT model to the Claude API.

To change the list, edit Models in the worker configuration and restart the worker.

Job Data Schema​

{
"configName": "Claude",
"model": "claude-opus-5-5",
"systemPrompt": "You are a release-notes writer. Write for end users, not developers.",
"prompt": "Write release notes from these commits:\n{{commits}}",
"variables": { "commits": "fix: login timeout\nfeat: dark mode" },
"responseFormat": "Text",
"maxTokens": 4096
}
PropertyDefaultDescription
configNameDefaultConfigNameProvider configuration to use
modelprovider's DefaultModelModel name. Pick it from the list in the job form or type another.
systemPromptInstructions. Supports {{variable}} placeholders.
promptrequiredThe prompt. Supports {{variable}} placeholders.
variablesValues for the placeholders. Text is inserted as is, objects and arrays as JSON.
responseFormatTextText, or Json to get a JSON object back, parsed
maxTokens4096Maximum output tokens
temperatureSampling temperature (OpenAI and Gemini; current Claude models do not take it)
effortlow, medium, high (Claude also xhigh, max). Claude's effort level, OpenAI's reasoning effort.
apiKeyOverrides the configured key. Use a secret reference like {{secret:openai-key}}, never a plain key; the dashboard's Secrets page is the easiest place to keep it.

A placeholder without a value stays in the prompt as written, so a typo is visible in the answer rather than silently empty.

Result​

{
"Text": "## What's new\n- Dark mode ...",
"Json": null,
"Provider": "Anthropic",
"ConfigName": "Claude",
"Model": "claude-opus-5-5",
"StopReason": "end",
"InputTokens": 412,
"OutputTokens": 233,
"DurationMs": 5120
}

With responseFormat: "Json" the worker asks the model for a single JSON object and puts the parsed object in Json. If the answer is not valid JSON the job fails and retries. StopReason is max_tokens when the answer was cut off; the worker logs a warning when that happens.

Using It in a Workflow​

Data mappings pass values between steps. Two patterns cover most cases.

Feed an earlier step's output into the prompt. Keep the prompt in the AI job's data with a placeholder, and map the earlier step's output into variables:

Step 1 (HTTP: fetch yesterday's orders) → result: { "body": "[...]" }
Step 2 (AI) job data: { "prompt": "Summarize these orders for the sales team:\n{{orders}}" }

Mapping on Step 2:
step1Id:body → variables.orders

Feed the answer into the next step. Map Text, or a field of Json:

Step 2 (AI, responseFormat Json) → result: { "Json": { "subject": "...", "body": "..." } }
Step 3 (Email)

Mapping on Step 3:
step2Id:json.subject → subject
step2Id:json.body → body

Retries and Errors​

SituationBehavior
Rate limit (429), timeout, server error (5xx), network errorRetried with the consumer's retry settings
Invalid request, wrong key, unknown model (4xx)Fails at once, no retry
The model declines the requestFails at once, no retry
Json requested but the answer is not JSONRetried; fails at once if the answer was cut off at maxTokens

Every call costs money at the provider. Keep MaxRetries low on the AiPromptJob consumer and set maxTokens to what the task needs.

Deployment​

Docker image: milvasoft/milvaion-ai-worker. In the Helm chart, enable workers.ai and pass each key from a Secret:

workers:
ai:
enabled: true
extraEnv:
- name: AiConfig__Providers__Claude__Type
value: Anthropic
- name: AiConfig__Providers__Claude__ApiKey
valueFrom:
secretKeyRef:
name: ai-keys
key: anthropic
- name: AiConfig__DefaultConfigName
value: Claude

Prompts and answers go to the provider you configure. Do not send data there that your policies do not allow to leave your network; for that, point an OpenAI provider at a model you host yourself.