Skip to content

How AI Fits Together

Ed Mozley edited this page Dec 6, 2026 · 5 revisions

How AI fits together in FreeITSM

For developers. Written 5 December 2026, before the voice assistant was built, so it follows the rule below from the start. Read this before adding any "Ask AI" feature.

The rule

Every new "Ask AI" starts as tools in the shared tool set. Screens, chat and voice are different doors onto those tools.

Write the question once, as a read-only tool; every door that may use it gets it. Anything that changes records - proposals a person applies - is a separate layer on top, owned by the screen that offers it.

Why: a question answered in two places is answered differently in two places, and fixed in one. The tool set is where "who may see what" is checked, so a door that uses it cannot leak what the screens would not show.

The picture

                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ DOORS ────────────────────────┐
  War Room       β”‚  Warbot            (in a channel - everyone reads it)  β”‚
  MCP clients    β”‚  MCP server        (one person, by API key)            β”‚
  Talk page      β”‚  Talk              (one person, signed in)             β”‚
                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚ room-safe tools       β”‚ one-to-one tools (+ the room-safe ones)
                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  TOOLS          β”‚ warbotTools()            β”‚  β”‚ mcpTools()                         β”‚
                 β”‚ includes/warbot/tools.phpβ”‚  β”‚ includes/mcp/tools.php             β”‚
                 β”‚ operational facts only   β”‚  β”‚ module + company gate per tool     β”‚
                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  ENGINE                 aiProviderChatTools()  includes/ai_provider.php
                         (any provider: Anthropic, OpenAI, OpenRouter, Azure, your own server)
  SETTINGS               aiSettingsLoad('<ns>_ai')  includes/ai_settings.php - one entry per feature

Every tool there is, module by module, with the gaps: the generated AI tools dictionary (php scripts/gen_ai_tools_dictionary.php - rerun it at each release).

The shared parts

Part File What it is for
Calling the AI includes/ai_provider.php - aiProviderChat() (one answer), aiProviderChatTools() (the model calls tools, up to 6 rounds) Every provider through one function. New features use these, never a provider's API directly
AI settings includes/ai_settings.php - aiSettingsRegistry() Each feature has its own provider / model / key (knowledge_ai, cmdb_ai, workflow_ai, forms_ai, problem_ai, lms_ai, warroom_ai, projects_ai, help_ai). Adding one is a line here + its key in encryption.php. Turning one on changes no other feature
Room-safe tools includes/warbot/tools.php - warbotTools() Read-only, local SQL, no internet needed. They answer in a channel, so they return operational facts (counts, states, service names), never ticket bodies or a person's details
One-to-one tools includes/mcp/tools.php - mcpTools(), mcpToolAllowed(), mcpRunTool(); mcpPersonContext() for FreeITSM's own doors, mcpCompanySql() / mcpTicketScopeSql() for scoping Room-safe tools that pass the gate, plus tools only one person should see (projects in full, Knowledge search scoped to the reader). The gate: the module must be one the analyst can open, the capability held, and a tool that is not company-safe is offered on a multi-company install only to someone who sees every company
Which tools each door may use includes/ai_tool_doors.php - aiDoorToolAllowed(), aiDoorToolRows(), aiDoorToolSave() System β†’ AI tools: per tool, whether Talk and Warbot may use it (their answers go to the install's AI provider). Sensitive tools start off. MCP keys have their own ticks
Who may see what ticketScopeFilter() / analystCanAccessTicket(), KnowledgeViewer + knowledgeVisibilitySql(), projectVisibleSql() Tools scope with these, exactly as the screens do
Confidential tickets ticketAiAllowed() (includes/ticket_sensitivity.php) A confidential ticket is not sent to an AI unless Tickets -> Settings allows it. Every tool or feature that sends ticket text checks it
The service desk's own rules knowledgeAiRulesPrompt() (includes/knowledge/ai_rules.php) Rules written in Knowledge -> Settings -> AI, added last to customer-facing prompts
Remembering a conversation includes/ai_conversation.php History, long-term summary and "resume" for assistants that keep a thread (Projects, CMDB)

The features, and which door each is

Feature Kind Uses
Warbot (War Room) door room-safe tools, aiProviderChatTools(); slash commands run the same handlers when the AI cannot be reached
MCP server door one-to-one tools; no AI of its own - the client's AI calls the tools
Talk door one-to-one tools as the person (mcpPersonContext()), aiProviderChatTools() (chained mode); realtime voice next, calling the same tools
Projects assistant own assistant aiProviderChatTools() with its own tools, its own memory, and proposals you apply
CMDB assistant own assistant the same shape as Projects
Help assistant own assistant aiProviderChatTools() over FreeITSM's help
Knowledge AI chat, web chat answers from articles kbRetrieveArticles() + aiProviderChat()
Ticket helpers (summary, read, clean-up, merge summary), Problems, Messaging, Forms, LMS, Workflow steps helpers on one record or one step aiProviderChat() - or, for streaming with Anthropic, the older path below
Knowledge Assistant (gaps, write-ups, learning from web chats) helper write-up streaming via the older path; everything else aiProviderChat()

Text written by outsiders - the defences

Any tool that hands an AI text a stranger could have written (a customer's email, a note quoting one) calls includes/ai_untrusted.php: links and email addresses out, instruction-like sentences replaced, the text fenced as untrusted (aiUntrustedWrap()), a reading limit per key or person (aiTextReadAllowed()) and a record (aiTextReadRecord()). Doors stay read-only. Details: Talk - Developer Guide.

Which tools each door may use - System β†’ AI tools

After 6.0.3 (MCP expansion Wave 1). User page: System β†’ AI tools.

Talk and Warbot send each tool's answer to the AI provider an administrator set up. Whether a tool may go there is a choice per tool, per door - includes/ai_tool_doors.php. MCP is not part of it: an MCP key's client brings its own AI, and its ticks (key_tick, e.g. people_details) live on the key.

// includes/ai_tool_doors.php
function aiDoorToolAllowed(PDO $conn, string $door, string $tool, array $def): bool
{
    $choice = aiDoorToolChoices($conn)[$door][$tool] ?? null;
    return $choice === null ? empty($def['sensitive']) : (bool)$choice;
}
  • The default is the tool's own sensitive flag: on unless sensitive. Only differences from the default are stored - one system_settings row, ai_door_tools, {"talk": {"person_summary": true}, "warbot": {...}} - so a tool a later release adds (or re-flags) follows its default unless someone chose otherwise. (The design said rows per change; one JSON row holding only the changes gives the same behaviour with no new table and no Database Verification.)
  • Where each door reads it. Talk: mcpToolAllowed() - a context from mcpPersonContext() carries door => 'talk', so the typed answer (mcpToolsFor()), live voice (talkLiveTools()) and running a tool all follow it. Warbot: warbotToolsFor() (not offered) and warbotRunTool() (a typed command is refused with a sentence).
  • The screen's rows are the registries: aiDoorToolRows() merges mcpTools() (Talk) and warbotTools() (Warbot); a door a tool is not in shows why (Not for a channel / Warbot only) and cannot be ticked. aiDoorToolSave() ignores ticks for doors a tool is not on, stores the differences and writes each change to system_logs (log_type = 'ai_door_tools', {changes: [{door, tool, on}]}).
  • TRAP: read once per request. aiDoorToolChoices() caches (a Talk turn asks about every tool); aiDoorToolSave() refreshes it. Code that writes the setting any other way in the same request - a test - must call aiDoorToolChoices($conn, true) after.
  • Files: system/ai-tools/index.php (state rendered server-side, as on AI thinking), api/system/ai_tools.php (admin, CSRF), system/help/ai-tools.php, test tests/ai-door-tools.php.

Two untidy spots (known, not urgent)

  1. Two ways of calling the AI. includes/rfp_ai.php came first, for the RFP Builder. Its rfpAiCallAnthropicStreaming() is still how four features stream an Anthropic answer word by word: the Knowledge write-up, Forms Generate, ticket Clean up reply and the merge summary. With any other provider they use aiProviderChat(). The shared engine has no streaming yet; when it gets it, those four move over and rfp_ai.php serves the RFP Builder only. New code never uses rfp_ai.php.
  2. The CMDB assistant carries its own tools. It was built before the rule and knows things the shared set does not. When a door needs what it knows, add a read-only tool to the shared set that calls the same service code rather than copying the SQL - its move is in Wave 2 of the MCP expansion. The Projects assistant moved in Wave 1 (after 6.0.3): its list_tasks, list_stages, list_raid and list_milestones read through the functions the shared project tools use - projectAssistTaskRows(), projectAssistStageRows() (includes/projects/assistant.php), ProjectToolsService::raid(), projectMilestones() - and format their own lines with the ids its propose_* tools need. Its pickers (list_analysts, list_suppliers) and proposals stay its own: they choose ids for a change, not answer a question. tests/projects-assistant-reads.php proves the two sides list the same things.

Neither is a bug, and neither grows if the rule is followed.

Adding an "Ask AI" to a module - the checklist

  1. Read tools first, in mcpTools() (one-to-one) - or in warbotTools() and mcpWarbotToolMap() if it is a room-safe operational fact. Name, description the model reads, JSON schema, module, company_safe, capability, handler.
  2. Scope in the handler with the module's own scope helpers, and check ticketAiAllowed() before returning ticket text.
  3. Every column name read from information_schema, not memory - a wrong column reads as "nothing found", not as an error.
  4. A test that the tool returns what it should and nothing it should not (another company, a department the analyst is not in).
  5. Then the screen: the module's panel is aiProviderChatTools() over its tools, with its own entry in aiSettingsRegistry() if it needs its own provider.
  6. Changes (proposals applied by a person) are the screen's own code, on top - never a tool the doors can call.

See also

AI providers Β· MCP server Β· War Room - Developer Guide Β· Voice assistant - design Β· Code traps

FreeITSM

Getting Started

Modules

Multi-tenancy (planned)

Responses to feedback

Blue sky thinking

Bugs resolved

Pull requests

Links

Clone this wiki locally