
Picture a K2 demand form. Someone fills it in, submits it and waits for approval, thousands of times a year. We wanted to know what would happen if that form could think, without sending data to a public AI service, without upsetting the security team and without a per-request bill.
Agent Bob is the result: an AI assistant that lives inside K2 SmartForms and runs a small language model on a server we control.
The stack
- The model: Microsoft Phi-4-mini, run through Ollama on a Windows Server virtual machine with no GPU.
- The middleware: a .NET REST API hosted in IIS, with endpoints for prompting, data analysis, SQL, documents and plain-English database questions.
- The interface: a custom K2 JavaScript control that puts a chat panel straight into a SmartForm.
- The plumbing: K2 SmartObjects calling the API through the REST broker, described with Swagger files.
Getting it running
The server had no internet access, so everything arrived on USB: the .NET SDK, Ollama and several gigabytes of model weights. The first reply came back in about two and a half seconds. Most prompts take between 2 and 14 seconds on CPU, but large queries can take a minute or two, which shaped the design early on.
Making K2 understand the API
The K2 REST broker initially treated every response as one serialised blob instead of separate properties. The fix, found by studying a Swagger file that did work, was to describe responses with named definitions referenced by $ref, list the required fields, and give each definition a title.
"schema": { "$ref": "#/definitions/LlmResponse" }
"LlmResponse": {
"type": "object",
"title": "LlmResponse",
"required": ["Success", "Response", "Error"],
"properties": { ... }
}Returning every value as a string also helped, as K2 maps strings more reliably than booleans or numbers. Each endpoint needs its own Swagger file and service instance. It isn’t elegant, but it works.
The HTTPS trilogy
Calling the API from the browser brought three problems in a row. The K2 site was HTTPS and the API was HTTP. CORS headers were being added twice, once by IIS and once by the app. And Chrome rejected a self-signed certificate that had a common name but no subject alternative name. The end state is HTTPS for the browser control, plain HTTP for server-to-server SmartObject calls, and a note that production should use a certificate from an internal certificate authority.
What Bob can do
- Answer general questions from the model’s own knowledge.
- Analyse JSON, CSV or text passed to it, and pick out trends and recommendations.
- Run a SQL query against any database and explain the results, using Windows authentication so no passwords are stored.
- Read Word, Excel, CSV and text documents from a URL, file share or upload, entirely in memory.
- Answer questions about a database in plain English.
The last one is what makes people sit up. Ask “how many demands were created last month?” and Bob reads the table structure, has the model write a query, checks the query is a read-only SELECT, runs it, and returns a plain-English answer together with the SQL it used, so anyone can check its working.
Waiting without timing out
SmartObjects time out long before a slow model finishes. So Bob works as a job queue: the form submits a request and gets a job ID straight away, the work runs in the background, and the form polls for the result or a K2 workflow timer collects it later.
Where it becomes agentic
Answering commands is only the start. The interesting part is putting Bob inside the workflow, where it can read the form in front of the user and act on context. The use cases we are working on:
- Form-aware help, such as pointing out that a requested budget is well above similar approved demands.
- Approval insight, summarising how similar requests have fared before an approver decides.
- Tasks from conversation: “remind Dave to check the budget for demand 47 by Tuesday” becomes a K2 workflow with the right person and due date.
- Notifications that say what happened and what to do next, instead of a generic “approved” email.
What we learned
- Give the K2 REST broker named, titled definitions with required fields.
- Add CORS headers in one place only. We chose web.config.
- Return everything as strings.
- Filter in SQL, not in the model. Sending two rows instead of five hundred cut one query from 90 seconds to 10.
- Self-signed certificates need a subject alternative name.
- Use Windows authentication, so no credentials sit in config files or URLs.
The trade-off
A local model on CPU is slower than a cloud API: 15 to 50 seconds for many questions, and up to around two minutes for the hardest database ones. In return, no data leaves the network, there is no per-request cost, you control the model and security, and you can swap Phi-4-mini for another model by changing one setting.
Working behind an air gap
Some of the organisations that would gain most from AI can’t connect to the internet at all: defence, government, critical national infrastructure, regulated finance and healthcare. For them, the AI conversation usually ends at “we can’t send data to a third party”.
Bob was built in exactly that situation. Ollama runs fully offline with no licence checks or telemetry, the model is a single self-contained file, the API is an ordinary IIS application, and it uses the SQL Server those organisations already run. Updates go the same way as the original install: prepared outside, carried across on removable media.
What’s next
Conversation memory so follow-up questions work, drafting emails from workflow context, creating tasks from chat, and a knowledge base so Bob can answer from your own policies and procedures.
The whole thing runs on a single Windows Server VM with 16 GB of RAM and no GPU. Agent Bob isn’t a product. It’s a pattern for bringing real AI into existing enterprise platforms without replacing them.