Skip to content

Aggregate Roots

Target Architecture — Final-State Design

The Agent Mesh domain is modeled as twelve aggregate roots, each owned by a single service and each carrying the cross-cutting metadata schema (tenantId, traceId, correlationId, timestamps). Aggregates persist via NHibernate on Azure SQL / PostgreSQL; hot state lives in Redis and large payloads in Blob. Domain events travel in the canonical envelope.

Aggregate Map

flowchart TB
    AD["AgentDefinition"] --> AV["AgentVersion"]
    SD["SkillDefinition"] --> SV["SkillVersion"]
    AT["AgentTask"] --> AE["AgentExecution"]
    AE --> SE["SkillExecution"]
    AE --> TI["ToolInvocation"]
    AE --> MI["ModelInvocation"]
    AE --> VR["ValidationResult"]
    VR --> CA["CorrectionAttempt"]
    AHS["AgentHealthStatus"]
Hold "Alt" / "Option" to enable pan & zoom

1. AgentDefinition

Purpose — Stable identity of an agent role; root of the agent's version history.

  • FieldsagentId, tenantId, cluster, displayName, description, status (Active/Deprecated), currentVersion, createdAt, updatedAt.
  • EntitiesAgentVersion (history, but versioned independently as its own aggregate for immutability; referenced here).
  • Value ObjectsPermissionScope (default scope), ClusterRef.
  • InvariantsagentId is unique per tenant and follows ConnectSoft.Agent.{Name}; currentVersion must reference a registered AgentVersion.
  • Domain EventsAgentRegistered, AgentDeprecated.
  • RepositoryAgentDefinitionRepository.
  • Persistence — Azure SQL / PostgreSQL (NHibernate); indexed by agentId, tenantId.

2. AgentVersion

Purpose — Immutable, semver-tagged snapshot of an agent's configuration.

  • FieldsagentId, version, tenantId, status, promptStrategy, correctionLimit, publishedAt.
  • Entities — none (leaf snapshot).
  • Value ObjectsSkillBinding (skillId + version range), ModelPolicyRef, PermissionScope, ToolPermission.
  • Invariants — immutable once published; every SkillBinding must resolve to a registered SkillVersion; PermissionScope must be authorized by Governance.
  • Domain EventsAgentRegistered (version), AgentVersionRetired.
  • RepositoryAgentVersionRepository.
  • Persistence — Azure SQL / PostgreSQL (NHibernate); indexed by agentId + version.

3. SkillDefinition

Purpose — Stable identity of a reusable capability.

  • FieldsskillId, tenantId, category, displayName, description, status, currentVersion, createdAt.
  • Entities — none.
  • Value ObjectsSkillCategory, ClusterAffinity.
  • InvariantsskillId unique per tenant, follows ConnectSoft.Skill.{Name}; currentVersion references a registered SkillVersion.
  • Domain EventsSkillRegistered, SkillDeprecated.
  • RepositorySkillDefinitionRepository.
  • Persistence — Azure SQL / PostgreSQL (NHibernate); indexed by skillId.

4. SkillVersion

Purpose — Immutable contract for a skill version (input/output, tools, validation).

  • FieldsskillId, version, tenantId, status, publishedAt.
  • Entities — none.
  • Value ObjectsInputContract, OutputContract, ToolRequirement, ModelExpectation, ValidationRuleSet.
  • Invariants — immutable once published; input/output contracts are schema-valid; tool requirements must be grantable.
  • Domain EventsSkillRegistered (version).
  • RepositorySkillVersionRepository.
  • Persistence — Azure SQL / PostgreSQL (NHibernate); indexed by skillId + version.

5. AgentTask

Purpose — The unit of assigned work; root of task lifecycle.

  • FieldstaskId, tenantId, projectId, moduleId, traceId, correlationId, agentRole, requestedSkill, status, createdAt, updatedAt, deadline.
  • Entities — none (executions are a separate aggregate, referenced).
  • Value ObjectsTaskInputs, ContextRequest, TaskConstraints (modelPolicyId, maxCorrectionAttempts).
  • Invariants — idempotent on taskId; status transitions follow the lifecycle; cannot complete without a passed ValidationResult.
  • Domain EventsAgentTaskAssigned, AgentTaskCompleted, AgentTaskFailed.
  • RepositoryAgentTaskRepository.
  • Persistence — Azure SQL / PostgreSQL (NHibernate); indexed by taskId, traceId, tenantId.

6. AgentExecution

Purpose — A single attempt to fulfil a task; the traceability hub for skill/model/tool calls.

  • FieldsexecutionId, taskId, tenantId, agentId, agentVersion, contextPackageId, status, tokensUsed, startedAt, completedAt.
  • EntitiesSkillExecution references; ModelInvocation/ToolInvocation references.
  • Value ObjectsExecutionOutcome, ArtifactReference[].
  • Invariants — exactly one active execution per task at a time; must reference a contextPackageId; terminal status is Completed or Failed.
  • Domain EventsAgentExecutionStarted, (contributes to) AgentTaskCompleted / AgentTaskFailed.
  • RepositoryAgentExecutionRepository.
  • Persistence — Azure SQL / PostgreSQL (NHibernate); hot status in Redis; indexed by executionId, taskId, traceId.

7. SkillExecution

Purpose — A record of one skill version run inside an execution.

  • FieldsskillExecutionId, executionId, skillId, skillVersion, tenantId, status, startedAt, completedAt.
  • Entities — none.
  • Value ObjectsSkillInputs, SkillOutputs, ArtifactReference[].
  • Invariants — inputs validate against the bound SkillVersion.InputContract; outputs validate against OutputContract before completion.
  • Domain EventsSkillExecutionStarted, SkillExecutionCompleted.
  • RepositorySkillExecutionRepository.
  • Persistence — Azure SQL / PostgreSQL (NHibernate); large payloads in Blob; indexed by executionId, skillId.

8. ToolInvocation

Purpose — A record of one MCP tool call.

  • FieldstoolInvocationId, executionId, tenantId, toolName, status, latencyMs, invokedAt.
  • Entities — none.
  • Value ObjectsToolArguments, ToolResultRef, PermissionScopeUsed.
  • Invariants — tool must be within the acting agent version's PermissionScope; non-idempotent tools execute at most once per stepId.
  • Domain EventsToolInvoked.
  • RepositoryToolInvocationRepository.
  • Persistence — Azure SQL / PostgreSQL (NHibernate); large results in Blob; indexed by executionId, toolName.

9. ModelInvocation

Purpose — A record of one model provider call.

  • FieldsmodelInvocationId, executionId, tenantId, provider, model, promptTokens, completionTokens, costEstimate, latencyMs, invokedAt.
  • Entities — none.
  • Value ObjectsModelPolicyRef, ProviderRef, PromptRef, ResponseRef.
  • Invariants — provider selection complies with the task's modelPolicyId and tenant routing; prompt/response payloads are classified before storage.
  • Domain EventsModelInvoked.
  • RepositoryModelInvocationRepository.
  • Persistence — Azure SQL / PostgreSQL (NHibernate); prompt/response bodies in Blob; indexed by executionId, provider.

10. ValidationResult

Purpose — The outcome of validating an execution's outputs.

  • FieldsvalidationResultId, executionId, tenantId, passed, evaluatedAt.
  • EntitiesRuleEvaluation (per-rule outcome).
  • Value ObjectsValidationRuleResult (rule, passed, message), RuleSetRef.
  • Invariantspassed is true only if all required rules (schema, naming, dependency, policy) pass; a failed result must record actionable messages for correction.
  • Domain EventsValidationFailed (when not passed), ValidationPassed.
  • RepositoryValidationResultRepository.
  • Persistence — Azure SQL / PostgreSQL (NHibernate); indexed by executionId.

11. CorrectionAttempt

Purpose — A record of one feedback-driven correction of a failed validation.

  • FieldscorrectionAttemptId, executionId, validationResultId, tenantId, attemptNumber, status, attemptedAt.
  • Entities — none.
  • Value ObjectsCorrectionFeedback, ResultingArtifactRef[].
  • InvariantsattemptNumber is monotonic and <= maxCorrectionAttempts; each attempt references the ValidationResult it addresses.
  • Domain EventsCorrectionAttempted.
  • RepositoryCorrectionAttemptRepository.
  • Persistence — Azure SQL / PostgreSQL (NHibernate); indexed by executionId, attemptNumber.

12. AgentHealthStatus

Purpose — The pooled health of an agent, owned by the AgentPoolManager.

  • FieldsagentId, tenantId, health (Healthy/Degraded/Unhealthy), warmInstances, busyInstances, maxConcurrency, lastProbedAt.
  • EntitiesPoolInstance (per-instance status).
  • Value ObjectsHealthSignal, ConcurrencyLimits.
  • InvariantsbusyInstances <= maxConcurrency; a transition only emits an event when the discrete health level changes.
  • Domain EventsAgentHealthChanged.
  • RepositoryAgentHealthStatusRepository.
  • Persistence — Redis (hot status) with relational history for audit; indexed by agentId, tenantId.