Chat engram for building conversational steps with OpenAI (and Azure OpenAI). Supports batch (Kubernetes Job) and streaming (Deployment/StatefulSet) modes, function tools, structured outputs, and story dispatch.
- Chat Completions API (models like
gpt-4*,gpt-3.5-turbo,gpt-4o*) - Per-request overrides for model/temperature/system prompt
- Function tools (function calling)
- Structured outputs via a designated tool
- Tool dispatch to stories via
actionRequest - Azure OpenAI support via env-prefixed secrets
- OpenAI (required for OpenAI API):
OPENAI_API_KEY(required)OPENAI_BASE_URL(optional)OPENAI_ORG_ID(optional)
- Azure OpenAI (optional; enables Azure mode when
AZURE_ENDPOINTis present):AZURE_API_KEY(required in Azure mode)AZURE_ENDPOINT(required in Azure mode)AZURE_API_VERSION(default:2024-08-01-preview)AZURE_DEPLOYMENT(maps requested model → deployment)
Engram template defines two logical secrets openai and azure, both with mountType: env and prefixes OPENAI_ and AZURE_ respectively.
defaultModel: gpt-4o-mini
defaultTemperature: 0.2
defaultSystemPrompt: "You are a helpful assistant."
# Optional function tools exposed to the model
tools:
- name: run_story
description: "Trigger a follow-up story with inputs"
parameters:
type: object
properties:
storyName: { type: string, required: true }
inputs: { type: object }
- name: extract_fields
description: "Extract structured fields from user input"
parameters:
type: object
properties:
title: { type: string }
priority: { type: string, enum: [low, medium, high] }
tags: { type: array, items: { type: string } }
# Name of the tool whose arguments should be returned as structured output
structuredToolName: extract_fields
# Map tool → storyName. If the model calls one of these tools,
# the engram emits actionRequest automatically.
dispatchTools:
run_story: "create-ticket-story"{
"history": [
{ "role": "user", "content": "Create a ticket for server outage." }
],
"systemPrompt": "Be concise.",
"userPrompt": "Priority should be high and tags: ops, urgent",
"temperature": 0.1,
"model": "gpt-4o-mini"
}Supported fields:
history: prior messages (role∈system|developer|user|assistant;developeris mapped to system for Chat Completions)systemPrompt,userPrompt,developerPrompt,assistantPrompttemperature,model
{
"text": "Created ticket with title 'Server outage' and priority 'high'.",
"structured": {
"title": "Server outage",
"priority": "high",
"tags": ["ops", "urgent"]
},
"actionRequest": {
"storyName": "create-ticket-story",
"inputs": {
"title": "Server outage",
"priority": "high",
"tags": ["ops", "urgent"]
}
},
"toolCalls": [
{
"name": "extract_fields",
"arguments": "{\"title\":\"Server outage\",\"priority\":\"high\",\"tags\":[\"ops\",\"urgent\"]}"
},
{
"name": "run_story",
"arguments": "{\"storyName\":\"create-ticket-story\",\"inputs\":{...}}"
}
]
}Notes:
structuredappears when the model calls the tool named instructuredToolName; it contains the parsed JSON arguments.actionRequestappears when the model calls a tool listed indispatchTools. If the tool arguments already contain{storyName, inputs}, it passes through; else the arguments are wrapped under the configuredstoryName.toolCallsincludes all raw function calls for advanced routing or debugging.
- Batch (Job): default; processes a single input and writes the output to the StepRun.
- Streaming (Deployment/StatefulSet): processes a stream of inputs and emits an output per input message (not token-by-token). Use when you need low-latency multi-turn chat within a long-running service.
- Client: currently uses
github.com/sashabaranov/go-openaiChat Completions. - Planned: optional Responses API support using the official library to unify multimodal and structured outputs.
- OpenAI official Go SDK (Responses, Realtime, Webhooks, Azure helpers):
https://github.com/openai/openai-go - n8n OpenAI node capabilities (for parity context):
https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-langchain.openai/