Knowledge Portal · engineering documentation

Skip to content

Federated from workspace · PRD-001 · Dental Clinic Revenue Operating System/docs/technical/CLINIC_AGENT_ORCHESTRATION.md Do not edit canonical truth here — update the source repo, then re-run npm run docs:sync.


Clinic Agent Orchestration Layer ​

Status: Phase 1 implemented (2026-07-04)
Authority: AI module · App\Modules\AI\Application\Orchestration\ClinicAgent

Problem statement ​

The Clinic Agent previously routed messages through English keyword intent detection, then either:

  • returned static workflow templates (legacy-intent), or
  • dumped a daily operational snapshot (0 appointments today).

That is intent-based chatbot architecture, not modern agent architecture.

Target architecture ​

User message
    ↓
Conversation Manager (session state + DB thread)
    ↓
Context Builder (role, permissions, clinic snapshot, page)
    ↓
Goal Planner (what is the user trying to accomplish?)
    ↓
Task Planner (ordered steps + missing information)
    ↓
Tool Router (which tools, which arguments)
    ↓
Reasoning Engine (LLM with orchestration context)
    ↓
Tool Execution (observation loop)
    ↓
Reflection & Validation
    ↓
Response Composer

The LLM is one component. Business truth, permissions, and tool execution remain platform-owned.

Implemented components (Phase 1) ​

ComponentClassResponsibility
OrchestratorClinicAgentOrchestratorPipeline entry, LLM + deterministic fallback
Context BuilderClinicAgentContextBuilderRole, permissions, clinic snapshot
Goal PlannerClinicAgentGoalPlannerGoal type + missing information + follow-up memory
Task PlannerClinicAgentTaskPlannerStep plan with tool bindings
Tool RouterClinicAgentToolRouterTool ranking and argument assembly
Session StateClinicAgentSessionStateStoreGoal, entity references, active plan
Prompt BuilderClinicAgentOrchestrationPromptBuilderInjects plan into LLM system prompt
ReflectionClinicAgentReflectionValidatorBlocks ungrounded snapshot hallucinations
Deterministic ExecutorClinicAgentDeterministicExecutorTool plan execution when LLM unavailable

Removed anti-patterns (Phase 1) ​

  • legacy-intent execution path — removed from ClinicOperationsAgentService
  • Direct shouldAnswerFromClinicData() LLM bypass — all operational turns go through orchestrator
  • Static workflow dump without tools — workflows now include tool execution plan

Roadmap ​

PhaseCapabilityStatus
1Orchestration layer + remove legacy-intentDone
2LLM goal classifier (structured JSON)Planned
3Skill graph (register_patient, create_lead, book_appointment)Planned
4Full conversation state machine UIPlanned
5Entity memory + pronoun resolutionPartial (session state)
6Dedicated reasoning pass before toolsPlanned
7Stronger reflection against business policiesPartial
8RAG over admin help + clinic docsPlanned

Configuration ​

  • ai.copilot.agent_enabled — LLM path on/off (deterministic orchestration still runs)
  • ai.copilot.fallback_to_rules — when LLM fails, run deterministic tool plan
  • ai.copilot.max_tool_rounds — LLM tool loop cap

Testing ​

Feature tests: ClinicAgentConversationRoutingTest, ClinicAgentTest

Verify orchestration metadata on responses:

php
$response->metadata['orchestration'] === true
$response->metadata['goal']['type'] // e.g. register_patient

ZAIXOS Knowledge Portal — public engineering docs at /docs · Staff operations at /admin