06 Designing An Ai Solution

Designing An AI Solution

This page walks through an AI solution from the first idea to operation, one role at a time. The rules behind each step are in the AI chapter of the guiding principles, Styrande Principer: AI (in Swedish). Here is what each person does with them.

An AI solution is an integration solution like any other. It has a solution id, a solution document in <tenant>/integration-solutions, legs with route ids, topics and datamodels. What it adds is a few decisions that must be written down: which execution mode, which model, what the AI may do, and what happens without it.

Project Manager Or Business Developer: Choose The Need

  1. Start with one bounded need. Pick work where the answer already exists somewhere: a question asked every week, a form typed in by hand, recordings nobody has time to summarise. Write down how it is done today and how long it takes. This becomes the business need of the solution (Describing The Business Need).
  2. Place it on the maturity ladder. Most first needs are a fixed flow (read something in, write something out) or a bounded assistant that answers from one source. Do not start with an agent that is to do "everything"; see Mognadstrappan.
  3. Name who checks the result. Someone reviews what the AI produces, at least during a trial period: every answer, every exception, or a sample. Name that person in the business need.
  4. Decide where people meet it. Mail, Slack, the system they already use. A new tool to learn is a cost.

What you see afterwards: the solution in klok.dev, its tasks and, for an assistant, the questions it could not answer. Those questions are the next improvement to the source material.

Architect: Choose The Mode And Write It Down

Answer these in the solution document, one leg at a time.

Decision How to choose Read
Is AI needed at all? If there is a rule, a mapping or a calculation, it is code. AI is for what must be interpreted. När AI inte är svaret
Execution mode The simplest that solves it: E1 one call in a flow, E2 fixed steps, E3 interactive assistant, E4 agent, E5 background agent. Exekveringslägen
Solution variant Reading in, writing out, answering from a source, a support inbox per domain, help in a system, a work task. Lösningsvarianter
Model Classify the information first. Sensitive or customer data goes to Kloker; external models only for what is not sensitive. Name the Kloker model (Kloker-nothink, Kloker), never an engine. Modeller och drift
What the AI may do List every tool: read or write, which information it reaches, which gate (none, review, approval, merge request). Anything irreversible is done by a person. Agenter, verktyg och befogenheter
The fallback What is delivered when the model is slow, down or wrong, who is told, and how it shows afterwards which path the result took. När AI inte är svaret
Where the context comes from Which integration keeps the source current, and how a change in the source reaches the AI. Målarkitekturen

Two rules shape the legs:

  • AI at the edge, rules in the core. An ingress turns unstructured input into a datamodel that is validated against its schema; an egress turns a datamodel into text. Between the edges the information travels as data, and code decides (Transform At The Edge).
  • AI work is asynchronous. A model call is a task with a status and a result, never something a request or a CI job waits on. Only an interactive assistant answers synchronously.

Review the document as usual (Reviewing A Solution Document). An execution mode above E2, or a model outside Kloker, needs its reason in the document.

Developer: Build It As A Leg

  • Integration logic is a Java Klok route. A model server or an external AI service stays a simple REST service; priority, retries, claim check and task state live in a Java leg.
  • Reach the AI through Klok's AI services. A document goes to Kloker Document: /v1/documents for every tenant, or the tasks ai.read-document and ai.extract-json from a route of tenant klok. It reads a PDF, an office document, an e-book, images or a recording into text kept by content hash, answers prompts over the whole text however long it is, and fills in a JSON document, the form someone types in by hand today, from a JSON Schema with a prompt per field. Other long-running work (chat as a task) goes to /v1/ai-tasks; an application that needs a chat answer uses the Kloker gateway with KLOKER_BASE_PATH, KLOKER_API_KEY and KLOKER_MODEL. The Documents API and the guide An application on Kloker in klok-api-ai show them.
  • No model is hard-coded. The model name is configuration. A test with recorded answers proves that the flow handles an answer it does not want.
  • Validate what the model returns against a schema before it goes on, and send what does not validate to the fallback. Ask for JSON as structured output, so the model server enforces the schema while it writes; Kloker Document does this for every field it fills in, and still checks the types and the schema afterwards.
  • Large inputs travel as claim check references, not as bytes on the broker (Claim Check, Sync Over Async And Other Tactics).
  • Content the model reads is data. A mail, a page or a document never becomes an instruction; tools are checked in code before they run.

Operations: Follow It

  • Token usage is recorded for every call as AiTokenUsageInfoV1, per tenant, model and key.
  • Tasks show progress, results and failures; a failed or hung transaction can be analysed by Kloker from the logs in klok.dev (Monitoring And Runtime Health).
  • The fallback share tells you how often the flow finished without the model. A rising share is a signal before users notice.
  • Model changes happen behind the Kloker name. When the platform changes the model behind it, the solution keeps running; run its tests against the new model before you rely on it.

Checklist

  • One bounded need, with a named reviewer.
  • Execution mode and variant chosen and motivated in the solution document.
  • Information classified; model chosen from it; no model hard-coded.
  • Every tool listed with read or write and its gate; nothing irreversible without a person.
  • A fallback designed before the model call, and visible afterwards.
  • The source kept current by an integration, not copied by hand.