π§ Orchestration Layer¶
Overview¶
The ConnectSoft AI Software Factory Orchestration Layer is the autonomous backbone responsible for managing the lifecycle of AI-driven software creation, from user intent to full-stack delivery. It coordinates the execution of thousands of agents, interprets blueprints, sequences tasks, handles failures, provisions infrastructure, and integrates human decision-making when needed.
Built on Clean Architecture, DDD, and Event-Driven Principles, the orchestration layer ensures:
- Scalable coordination of distributed agents
- Resilient execution with retries, fallbacks, and timeouts
- Modular, reusable FSMs for service, infrastructure, and platform workflows
- Observability-first execution through tracing, metrics, and structured logs
- Blueprint-driven behavior, enabling conditional, dynamic workflows
- Support for human-in-the-loop escalation, approvals, and override paths
Role in the ConnectSoft AI Software Factory¶
The orchestration layer sits between:
- βοΈ User/Client Input (natural language, structured prompts, templates)
- π€ Agentic Workforce (100+ AI agents specialized by domain)
- π§± Reusable Templates, Blueprints, and Coordinators
- π Output Systems (Git repos, CI/CD, cloud infra, documentation, portals)
It is the central flow engine that turns declarative blueprints into deployed and tested software systems, using autonomous and semi-autonomous execution flows.
flowchart TD
U(User Prompt) --> O(Orchestration Layer)
O --> A1(Vision Architect Agent)
O --> A2(Enterprise Architect Agent)
O --> MAC(Microservice Assembly Coordinator)
MAC -->|Emit Events| Agents(Multiple AI Agents)
MAC --> Git(Commit, PR)
Agents --> QA(QA Agent)
QA --> O
subgraph Agent Network
A1
A2
Agents
QA
end
The orchestration layer:
- Bootstraps agent sessions (
sessionId,traceId) - Delegates tasks to the right agent or coordinator
- Tracks cross-agent flows
- Handles failures, timeouts, and event chaining
- Publishes lifecycle events and metrics to observability layers
Core Capabilities¶
| Capability | Description |
|---|---|
| Task Orchestration | Decomposes and routes execution plans using semantic routing |
| Coordinator FSMs | Finite-state machines manage assembly logic per domain (e.g., microservices, infra, UI) |
| Failure Recovery | Detects and resolves task, agent, and flow-level failures with resilience policies |
| Conditional Logic | Dynamically adapts execution paths based on blueprint metadata |
| Infrastructure as Code | Provisions cloud resources via dedicated IaC coordinators (e.g., Bicep, Terraform) |
| Human-in-the-Loop | Supports manual approvals and escalations when automation limits are reached |
| Observability | Fully traced, logged, and observable through OpenTelemetry + dashboard integrations |
| Modularity | All components are versioned, decoupled, and replaceable β built for extensibility |
Why It Matters¶
ConnectSoft aims to support the autonomous creation of 3,000+ modular SaaS systems, each with unique architectures, domains, and compliance requirements. This demands an orchestration layer that is:
- β Declarative (blueprint-first)
- π€ Collaborative (agent + human)
- π Recoverable (resilient to partial failures)
- π§© Composable (built from reusable modules)
- π Auditable (every step traced and reasoned)
- π Production-Ready (delivers infrastructure, not just code)
π§ Introduction to the Orchestration Layer¶
The Orchestration Layer is the central nervous system of the ConnectSoft AI Software Factory. It governs how product intents are transformed into coordinated actions across 100+ AI agents, agentic coordinators, and microservice assembly pipelines.
Unlike traditional workflow engines or static build scripts, the orchestration layer is:
- Dynamic β reacting to semantic inputs, events, and task outcomes.
- Distributed β coordinating across multiple agents and domains.
- Event-Driven β using commands and events to delegate, trace, and observe.
π Key Capabilities¶
| Capability | Description |
|---|---|
| Session Management | Creates scoped sessions with trace IDs for full observability |
| Semantic Task Planning | Decomposes user intents and blueprints into agent-ready tasks |
| Agent Routing | Dynamically chooses which agent should perform a task |
| Domain Event Handling | Publishes and subscribes to events across the entire AI Software Factory |
| State-Free Flow Control | Delegates micro-level state to domain coordinators |
| Human-in-the-Loop Routing | Supports manual escalation, review, or fallback routing |
| SLA Enforcement | Monitors task execution timelines and responds to delays/failures |
π§ What It Is Not¶
| Not... | Because... |
|---|---|
| A traditional orchestrator (like Temporal, Airflow) | It's semantic, modular, and agent-first, not job-pipeline-based |
| A state machine | The orchestration layer is stateless; coordination state is held by dedicated coordinators |
| A message bus | It uses a bus (e.g., MassTransit), but adds intelligence on top of it |
| A scheduler | It reacts to events and traces, not static time-based triggers |
β Example: From Prompt to System¶
Prompt:
βBuild a NotificationService with MongoDB and OpenTelemetry.β
Flow via Orchestration Layer:
| Step | Action |
|---|---|
| 1 | ProductIntentSubmitted β starts session: traceId = notif-001 |
| 2 | Delegates to Vision Architect Agent β generates system vision |
| 3 | Delegates to Enterprise Architect Agent β ports + use cases |
| 4 | Triggers StartMicroserviceAssembly β launches MicroserviceAssemblyCoordinator |
| 5 | Routes intermediate events (HandlerReady, AdapterReady) to subscribed agents |
| 6 | Commits code, triggers PR, activates QA phase |
| 7 | Ends orchestration when MicroserviceAssemblyCompleted + TestsPassed received |
π Interfaces¶
| Interface | Description |
|---|---|
ProductIntentSubmitted |
Entry event from external UI or agent |
StartAgentSession |
Internal command to spin up agent-specific scope |
StartMicroserviceAssembly |
Command sent to external coordinator |
RouteTaskToAgent |
Internal router logic (semantic/blueprint aware) |
AssemblyCompleted |
Final event used to trigger release or downstream systems |
π Key Design Principles¶
- Clean separation: orchestration does not manage local state β thatβs the job of domain-specific coordinators.
- Agent-first: all orchestration decisions are scoped to agents, not pipelines.
- Observable by default: every session is traceable across agent, task, and coordinator boundaries.
- Scalable: supports 1000s of concurrent microservice flows without coupling.
π§ Core Responsibilities of the Orchestration Layer¶
This section details the primary responsibilities of the Orchestration Layer within ConnectSoftβs AI Software Factory. These responsibilities enable the orchestrator to act intelligently and autonomously β coordinating AI agents, managing sessions, ensuring traceability, and maintaining cross-agent consistency across thousands of system generation flows.
π§© High-Level Responsibility Areas¶
| Responsibility Area | Description |
|---|---|
| Session & Trace Lifecycle | Creating, managing, and linking sessionId, traceId, and execution scopes |
| Task Decomposition & Planning | Splitting blueprints or user prompts into agent-executable commands |
| Agent Routing & Task Assignment | Selecting which agent or coordinator handles each task based on metadata |
| Event-Driven Execution Control | Subscribing, reacting, and emitting events to control execution flows |
| Observability Propagation | Injecting trace spans, telemetry, and logs across all execution steps |
| Failure Routing & Compensation | Detecting dropped tasks, timeouts, or errors β and rerouting or escalating |
| Context Preservation | Injecting semantic context and vector memory into downstream tasks |
| Cross-Agent Coordination | Managing dependencies and outputs between agents and flows (e.g., use cases β adapters β handlers) |
π Functional Responsibilities by Category¶
1. π§ Session & Identity Management¶
- Generate:
traceId: full orchestration lineagesessionId: scoped per agent or flowcomponentTag: e.g.NotificationService/HandlerGen
- Store and propagate context in every event
2. βοΈ Task Planning & Breakdown¶
- Example input:
"Build NotificationService with MongoDB" - Resulting sub-tasks:
- Generate strategic blueprint
- Define DDD architecture
- Start microservice assembly coordinator
- Generate handlers
- Commit code, trigger PR
- Each task is a command/event with routing metadata
3. π°οΈ Agent Routing¶
- Match task metadata with agent capabilities
- Use agent skill registry:
{
"agent": "Backend Developer Agent",
"skills": ["GenerateHandler", "CreateAggregate"],
"domains": ["Invoices", "Notifications", "Payments"]
}
RouteTaskToAgent with contextual inputs
4. π© Event Subscription & Dispatch¶
- Listens to:
BlueprintGeneratedPortsAndUseCasesReadyHandlerReadyAssemblyCompleted
- Emits:
StartAgentSessionStartMicroserviceAssemblyRouteToFrontendGenerator
- Maintains trace-linked task lineage
5. π Observability & Telemetry¶
- Injects:
- OpenTelemetry spans
- Structured logs (
AgentX completed task Y in Z ms) - Metrics on SLAs, retries, error rates
- Ensures end-to-end visibility even when agents are stateless
6. π Failure Detection & Recovery¶
- Detects:
- Unresponsive agent
- Event timeout (e.g.,
HandlerReadynot emitted in 60s) - Coordinator failure
- Responds with:
- Retry with alternative agent
- Escalation to human-in-the-loop
- Emit
TaskFailedorRouteToFallbackAgent
π§± Modular Structure¶
| Subsystem | Description |
|---|---|
SessionManager |
Creates and tracks orchestration sessions |
PlannerRouter |
Decides task decomposition and destination agent |
EventController |
Subscribes to and dispatches key domain events |
FailureRouter |
Handles timeout, error, and fallback logic |
TracerInjector |
Propagates OpenTelemetry and structured log metadata |
β Example: NotificationService¶
| Event | Action |
|---|---|
PortsAndUseCasesReady |
Orchestrator matches service to MicroserviceAssemblyCoordinator |
HandlerReady |
Orchestrator routes to CodeCommitterAgent and injects PR metadata |
TestResultsReady |
Orchestrator finalizes trace, emits AssemblyComplete |
π Design Rules Recap¶
- β Stateless orchestration logic
- β All coordination state handled by domain-specific coordinators
- β Event-driven and agent-pluggable
- β Observability-first and SLA-aware
- β Support for fallback, escalation, and async retry
π€ Agent-Aware Orchestration¶
In ConnectSoft, the orchestration layer is not just a message router β it is agent-aware.
This means it understands:
- The roles, skills, and domains of every agent
- The context in which each agent should be invoked
- How to dynamically select, schedule, and monitor agent tasks based on blueprint metadata
This section explains how orchestration intelligently matches the right agent (or coordinator) to each task.
π§ What Makes Orchestration βAgent-Awareβ?¶
| Capability | Description |
|---|---|
| 𧬠Agent Identity | Every agent has a globally unique name and metadata (agentId, agentType, skills) |
| π§ Skill Registry | The orchestrator maintains a registry of available agent skills and task patterns |
| πΊοΈ Blueprint Context Mapping | Orchestration uses service blueprints to identify task β agent mappings |
| π°οΈ Semantic Routing | Tasks are not routed statically β theyβre routed based on roles, load, and domain alignment |
| π Dynamic Fallback | If an agent is unavailable or fails, the orchestrator can reroute to alternatives with similar skills |
π§© Agent Metadata Model¶
{
"agentId": "backend-dev-agent-1",
"agentType": "Backend Developer Agent",
"skills": ["GenerateHandler", "CreateAggregate", "ValidateUseCase"],
"domains": ["Invoices", "Notifications", "Appointments"],
"availability": "Healthy"
}
π Orchestration Task β Agent Flow¶
Example Task: GenerateHandler: SendNotificationHandler¶
| Step | Action |
|---|---|
| 1 | Orchestrator receives task from coordinator or blueprint: taskType: GenerateHandler, domain: NotificationService |
| 2 | Looks up all agents with skills.includes("GenerateHandler") and domains.includes("Notifications") |
| 3 | Filters by availability and load |
| 4 | Selects best-fit agent and emits RouteTaskToAgent event |
| 5 | Waits for response event: HandlerReady |
π― Agent Selection Rules¶
| Rule | Description |
|---|---|
| Skill match | Agent must support the taskβs skill (GenerateHandler) |
| Domain affinity | Agent must have relevant domain tags (Notifications) |
| Availability | Agent must be online, not overloaded, and healthy |
| Fallback scoring | If no direct match, use fuzzy matching or backup agent class |
π Skill Registry Example (Internal Dictionary)¶
| Agent Type | Skills |
|---|---|
Backend Developer Agent |
GenerateHandler, BuildDomainLogic, ValidateAggregate |
Adapter Generator Agent |
CreateRepository, GenerateAdapter, ConfigurePersistence |
QA Agent |
RunUnitTests, RunIntegrationTests, EmitCoverageReport |
Frontend SPA Agent |
GenerateSPA, LinkAPIContracts, SetupRouting |
This registry is either:
- Static (JSON/config)
- Or discovered dynamically via agent registration events (e.g.,
AgentOnline,AgentCapabilityDeclared)
π Example Orchestration Logic¶
var candidates = agentRegistry
.Where(a => a.Skills.Contains("GenerateHandler") && a.Domains.Contains("Notifications"))
.OrderBy(a => a.LoadScore)
.FirstOrDefault();
if (candidates != null)
{
EmitRouteCommand(candidates.AgentId, taskPayload);
}
β Benefits of Agent-Aware Orchestration¶
| Benefit | Description |
|---|---|
| Pluggability | New agents can join with skill declarations β no code change needed |
| Load-balanced | Multiple agents can support the same skill across shards |
| Semantic | Uses domain and skill metadata, not hardcoded routing |
| Resilient | Agents can be replaced, scaled out, or rerouted at runtime |
| Composable | Agents can be assigned per stage in a multi-service system blueprint |
π Real-World Example: WellnessTrack¶
In the WellnessTrack project, orchestration:
- Receives task:
GenerateAdapterforUserProfileService - Finds all agents with:
skill: GenerateAdapterdomain: UserProfiles
- Selects
adapter-gen-agent-2 - Emits
RouteTaskToAgentβ includes traceId, blueprintId, and task context - Waits for
AdapterReadyβ routes to commit flow
π§Ύ Sessions and Traces¶
Sessions and traces are foundational to observability, state continuity, and cross-agent coordination in the ConnectSoft AI Software Factory. Every execution β from a single task to a full system blueprint β is wrapped in a structured session and connected by a traceId.
This section describes how sessions and traces are created, managed, and propagated through all orchestrated components: agents, coordinators, and infrastructure.
π§© Core Concepts¶
| Term | Description |
|---|---|
| traceId | Globally unique identifier for the full orchestration run (blueprint scope) |
| sessionId | Unique to each scoped process (e.g., per agent execution, per microservice coordinator) |
| componentTag | Identifies the agent, coordinator, or subflow handling a task (AdapterGen:NotificationService) |
| blueprintId | ID of the original input blueprint or system intent |
| parentTraceId | Optional link to a higher-level orchestration or external caller trace |
π§ Session Lifecycle¶
Step-by-Step¶
| Step | Event | Description |
|---|---|---|
| 1 | ProductIntentSubmitted |
Orchestrator generates traceId: wellness-456 |
| 2 | StartAgentSession |
For Vision Agent: sessionId: vision-001, links to traceId |
| 3 | StartMicroserviceAssembly |
Creates another session: sessionId: svc-appointment-001 |
| 4 | Downstream Commands | Each command (e.g., GenerateHandler) includes both traceId + sessionId |
| 5 | Completion | All Completed events trace back to original traceId for SLA and lineage |
π§Ύ Message Metadata Format¶
Every event/command emitted by the orchestration layer includes this envelope:
{
"traceId": "notif-001",
"sessionId": "notif-service-assembly-01",
"blueprintId": "blueprint-abc123",
"componentTag": "HandlerGeneratorAgent:CreateNotificationHandler",
"timestamp": "2025-05-04T13:10:00Z"
}
This metadata is:
- Injected by the orchestrator
- Verified and extended by each downstream coordinator or agent
- Used for observability and correlation
π Tracing Across Boundaries¶
1. Across Agents¶
- Task started in Vision Agent, continued in Architecture Agent β both share the same
traceId
2. Across Coordinators¶
MicroserviceAssemblyCoordinatoruses its ownsessionId, but shares parenttraceId
3. Across Systems¶
- If triggered by an external platform (e.g., DevOps CI),
parentTraceIdis preserved for trace continuity
π Observability Injection¶
The orchestrator integrates with OpenTelemetry:
| Propagated Field | Purpose |
|---|---|
traceparent / tracestate |
Injected into HTTP/gRPC headers |
traceId, sessionId |
Included in log scopes |
componentTag |
Used for log correlation ([AdapterGen], [PR Agent]) |
spanName |
Labeled per task (e.g., GenerateHandler:Notification) |
This enables:
- Jaeger / Azure Monitor / Grafana Tempo views of multi-agent flows
- Failure tracking across sub-systems
- SLA dashboards per blueprint, session, and domain
β Real-World Example¶
User Input: βBuild NotificationServiceβ
traceId: notif-001
βββ session: vision-001 β Vision Architect Agent
βββ session: arch-001 β Enterprise Architect Agent
βββ session: svc-001 β MicroserviceAssemblyCoordinator
βββ AdapterReady
βββ HandlerReady
βββ CommitComplete
βββ session: pr-001 β PR Agent
βββ session: qa-001 β QA Agent
Each node logs, emits telemetry, and routes events tagged with traceId: notif-001.
π§± Best Practices¶
- Always generate
sessionIdper execution scope (agent or coordinator) - Use deterministic
componentTagnaming:{AgentType}:{Task} - Store trace-mapped logs and events in structured stores (e.g., Application Insights, Elastic, OTLP backends)
- Span nesting: trace β session β span β event β log
π§ Orchestrator vs Coordinator β Division of Responsibility¶
This section defines the clear boundary between the Orchestration Layer and Coordinators (like the MicroserviceAssemblyCoordinator). Understanding this distinction is crucial to maintain modularity, scalability, and clean domain separation across the ConnectSoft AI Software Factory.
π§© High-Level Comparison¶
| Responsibility | Orchestrator Layer | Coordinator (e.g. AssemblyCoordinator) |
|---|---|---|
| Scope | Cross-agent, cross-domain | Micro-level, per-domain or per-microservice |
| Stateful? | β Stateless | β Stateful (FSM, persisted state) |
| Focus | Routing, session tracking, task dispatch | Lifecycle and sequencing of task execution |
| Knows About Agents? | β Yes (via registry) | β Yes (via events/subscriptions) |
| Knows Blueprint Structure? | β Partial (routing metadata) | β Deep (uses ports, adapters, use cases) |
| Failure Handling | Retry, reroute, fallback agents | Retry or compensate within the task lifecycle |
| Implements Business Logic? | β Never | β Orchestrates domain service assembly logic |
| Output | Routes commands/events across system | Emits domain events for specific microservice |
π Real Responsibilities¶
Orchestration Layer¶
β Manages:
- Trace/session lifecycle
- Semantic routing to 100+ AI agents
- Skill-based agent selection
- Triggering
StartMicroserviceAssembly - Routing
HandlerReady,AdapterGenerated, etc. - Observability, event logging, fallback
π« Does not:
- Sequence microservice scaffolding steps
- Track intermediate stage state (e.g.,
Scaffolded β HandlerReady) - Hold blueprint structure
Microservice Assembly Coordinator (MAC)¶
β Manages:
- Lifecycle of a single microservice: scaffold β handlers β adapter β commit
- Blueprint metadata for that microservice
- Event subscriptions for tasks (
HandlerReady,DTOsReady) - FSM-based state tracking (
AssemblyProgressState) - Compensation and retries at service level
π« Does not:
- Route to other microservices or frontend systems
- Track trace/session lineage across agents
- Choose which agent to assign a task to (delegated to orchestrator)
π Visual: Division of Responsibility¶
flowchart TD
UI[User Input] --> ORCH(Orchestration Layer)
ORCH -->|StartAssembly| MAC1(MicroserviceAssemblyCoordinator)
ORCH -->|RouteToAgent| AGENT1[Handler Generator Agent]
MAC1 -->|EmitEvent| ORCH
subgraph Microservice Assembly Coordinator
MAC1
end
- The orchestrator starts the coordinator, tracks its output, and routes intermediate tasks to agents.
- The coordinator knows which events to emit, but not where to send them β thatβs orchestrationβs job.
π§ Why This Separation Matters¶
| Concern | Without Separation | With Separation |
|---|---|---|
| Scalability | State and routing logic grow uncontrollably | Clean FSM scaling per domain |
| Agent Modularity | Tight coupling between task routing and logic | Loose coupling via events and contracts |
| Debuggability | Hard to trace who failed | Clear trace: coordinator emits β agent handles |
| Extensibility | Hard to reuse flows | Can build new coordinators using same orchestration hooks |
| Responsibility Clarity | Who owns what? | Orchestrator = router, Coordinator = builder |
β
Real-World Trace Example: NotificationService¶
| Component | Role |
|---|---|
| Orchestrator | Receives PortsAndUseCasesReady, triggers StartMicroserviceAssembly(traceId: notif-001) |
| Coordinator | Begins NotificationServiceAssemblyCoordinator, tracks FSM state |
| Orchestrator | Routes each emitted event (e.g., AdapterNeeded, HandlerReady) to best-fit agents |
| Coordinator | Emits MicroserviceAssemblyCompleted when done |
| Orchestrator | Triggers CreatePullRequest, RunTests to finalize flow |
π‘ Cycle 6: Event-Driven Architecture in Orchestration¶
The ConnectSoft Orchestration Layer is fully powered by an event-driven architecture (EDA), which enables decoupled, asynchronous, and scalable coordination across agents, coordinators, and system components.
This cycle explains how the orchestration layer uses commands, events, and event buses to drive the lifecycle of blueprint-based software generation.
βοΈ Event-Driven Design Principles¶
| Principle | Implementation in ConnectSoft |
|---|---|
| Asynchronous Task Flow | Every task is emitted as a message β not executed inline |
| Loose Coupling | Senders donβt need to know who handles the task |
| Reactive Agents | Agents subscribe to task/event types based on skill & domain |
| Replayable Execution | All events are persistable, observable, and traceable |
| Parallelizable Pipelines | Multiple coordinators and agents can operate simultaneously |
π Core Message Types¶
π₯ Commands¶
Commands represent intent to act. They are typically emitted by the Orchestrator or Coordinators.
| Command | Triggered By | Example Payload |
|---|---|---|
StartMicroserviceAssembly |
Orchestrator | { serviceName: "NotificationService" } |
GenerateAdapter |
Coordinator | { adapter: "INotificationRepository" } |
RouteTaskToAgent |
Orchestrator | { skill: "GenerateHandler", traceId: ... } |
CreatePullRequest |
Orchestrator | { repo: "svc-notification", branch: "feature/..." } |
π€ Events¶
Events represent something that has happened. They are published by agents and coordinators.
| Event | Emitted By | Description |
|---|---|---|
PortsAndUseCasesReady |
Enterprise Architect Agent | DDD architecture emitted for service |
HandlerReady |
Backend Developer Agent | Handler has been generated |
AdapterGenerated |
Adapter Generator Agent | Adapter complete |
MicroserviceAssemblyCompleted |
Coordinator | Full lifecycle for service is done |
TestResultsReady |
QA Agent | Unit/integration tests passed |
π Orchestrator Event Flow Example¶
sequenceDiagram
participant UI
participant Orchestrator
participant MAC as MicroserviceAssemblyCoordinator
participant Agent as Backend Dev Agent
UI->>Orchestrator: ProductIntentSubmitted
Orchestrator->>MAC: StartMicroserviceAssembly
MAC->>Orchestrator: AdapterNeeded
Orchestrator->>Agent: RouteTaskToAgent (GenerateAdapter)
Agent->>Orchestrator: AdapterGenerated
Orchestrator->>MAC: AdapterReady
MAC->>Orchestrator: MicroserviceAssemblyCompleted
π°οΈ Event Bus Integration¶
| Implementation | Details |
|---|---|
| Broker | Azure Service Bus or RabbitMQ |
| Middleware | MassTransit (message routing + FSM support) |
| Message Format | JSON-based contracts with tracing envelope |
| Error Handling | Retry policies, dead-letter queue, fallback routing |
| Security | Signed/encrypted payloads, tenant-aware envelopes |
π¦ Standard Envelope Format¶
Every command or event includes the orchestration envelope:
{
"traceId": "notif-001",
"sessionId": "notif-service-assembly-01",
"componentTag": "BackendDevAgent:GenerateHandler",
"timestamp": "2025-05-04T13:10:00Z",
"payload": { ... }
}
β Advantages of Event-Driven Orchestration¶
| Benefit | Impact |
|---|---|
| Agent Decoupling | Agents evolve independently; only contracts matter |
| Resilience | Retries and error isolation without full failure |
| Scalability | Easily parallelize 1000s of builds |
| Observability | Each event is logged, traced, and searchable |
| Auditability | Event history provides a full audit trail of software generation |
π Retry & Fallback¶
When events or commands fail:
- MassTransit handles retries (
x-retries, exponential backoff) - Orchestrator may emit
FallbackToAgent,RouteToHumanReview - Failed flows emit
TaskFailedorSessionTerminatedevents
π§ Cycle 7: Task Intake & Intent Decomposition¶
This section details how the Orchestration Layer processes initial product input (such as prompts, blueprints, or APIs) and decomposes it into a structured, semantic task plan that can be distributed to agents and coordinators.
This is the starting point for all autonomous workflows in the ConnectSoft AI Software Factory.
π― Input Sources¶
Task intake can originate from:
| Source | Example |
|---|---|
| UI Prompt | "Build NotificationService with MongoDB" |
| API Request | JSON blueprint POSTed to Orchestration Gateway |
| System-Level Trigger | Internal pipeline invoking new product build |
| Predefined Template | Reuse of stored blueprint with version/edits |
π© Entry Message¶
All inputs are wrapped into a common event:
ProductIntentSubmitted¶
{
"traceId": "notif-001",
"userPrompt": "Build a NotificationService with MongoDB and JWT auth",
"source": "UI",
"priority": "normal",
"submittedAt": "2025-05-04T10:02:00Z"
}
The Orchestrator uses this as the root of the execution plan.
π Step 1: Blueprint Inference (Optional)¶
If not pre-supplied, the orchestrator dispatches the prompt to:
β Vision Architect Agent¶
Task:
Resulting event:
StrategicBlueprintGenerated¶
{
"blueprintId": "blueprint-abc123",
"modules": ["NotificationService"],
"capabilities": ["Send", "Retrieve", "Mark as Read"],
"storage": "MongoDB",
"auth": "JWT"
}
π§ Step 2: Semantic Task Planning¶
The orchestrator now builds a task plan from the blueprint. This includes:
| Extracted From | Used To Plan |
|---|---|
modules[] |
One MicroserviceAssemblyCoordinator per module |
capabilities[] |
Use case handlers |
storage |
Adapter type (MongoRepository) |
auth |
Security layer (AddJwtAuth) |
blueprintId |
Global trace context |
π Step 3: Generate Task Plan¶
Each unit of work becomes a task dispatch. Examples:
| Command | Receiver | Purpose |
|---|---|---|
StartMicroserviceAssembly |
MicroserviceAssemblyCoordinator |
Begin service assembly |
GenerateUseCaseHandler |
Backend Developer Agent |
Implement SendNotificationHandler |
GenerateAdapter |
Adapter Generator Agent |
Build INotificationRepository |
ConfigureJWTAuth |
Security Architect Agent |
Add auth setup |
CreatePullRequest |
PR Agent |
Integrate assembled code |
π§Ύ Task Dispatch Format¶
Each task includes the blueprint context and trace data:
{
"traceId": "notif-001",
"sessionId": "svc-notification-01",
"componentTag": "AdapterGeneratorAgent:INotificationRepository",
"taskType": "GenerateAdapter",
"blueprintRef": "blueprint-abc123",
"metadata": {
"storage": "MongoDB",
"serviceName": "NotificationService"
}
}
π§± Planner Logic (Orchestration Subsystem)¶
| Subsystem | Role |
|---|---|
IntentParser |
Parses user prompt or blueprint |
TaskPlanner |
Breaks blueprint into atomic tasks |
TaskRouter |
Decides best-fit agent for each task |
SessionManager |
Assigns traceId, sessionId for each task stream |
β Benefits of This Model¶
| Benefit | Description |
|---|---|
| Fully Declarative Input | Prompts or JSON blueprints are enough to generate full delivery plan |
| Pluggable Task Types | New tasks can be introduced without changing orchestrator core |
| Scalable Work Decomposition | Thousands of tasks can be generated and distributed independently |
| Traceable & Observable | All tasks are trace-bound and self-contained |
| Multi-Agent Compatible | Output flows can span 10sβ100s of agents and coordinators |
π§ͺ Real Example Trace¶
Prompt: βBuild UserProfileService with SQL Server and role-based accessβ
Generated task stream:
StartMicroserviceAssembly("UserProfileService")GenerateHandler("CreateUserHandler")GenerateHandler("GetUserByIdHandler")GenerateAdapter("IUserRepository")ConfigureRBAC("UserProfileService")CommitCodeRunTestsCreatePullRequest
Each routed independently with full trace metadata.
π§ Cycle 8: Semantic Routing of Tasks¶
Once a task plan is generated (from a blueprint or user intent), the Orchestration Layer must route each task to the most appropriate agent or coordinator. This is done through a semantic routing engine β a pluggable system that matches tasks with agents based on skills, domains, capabilities, and runtime health.
This cycle details how routing decisions are made intelligently and dynamically in ConnectSoft.
π§ Semantic Routing Model¶
Semantic routing is built on the idea that tasks describe what needs to be done, and agents advertise what theyβre good at.
Routing Inputs:¶
taskType(e.g.,GenerateHandler)domain(e.g.,NotificationService)blueprintMetadata(e.g.,storage: MongoDB)agentRegistry(skills, availability, domain coverage)
Routing Output:¶
agentIdto send the task to
π Task Envelope for Routing¶
{
"taskType": "GenerateAdapter",
"service": "NotificationService",
"domain": "Notifications",
"blueprintId": "blueprint-abc123",
"traceId": "notif-001"
}
π Agent Capability Metadata¶
Each agent registers its capabilities at startup:
{
"agentId": "adapter-generator-2",
"agentType": "Adapter Generator Agent",
"skills": ["GenerateAdapter", "CreateRepository"],
"domains": ["Notifications", "Users", "Payments"],
"status": "Healthy"
}
βοΈ Routing Algorithm (Simplified)¶
var candidates = agentRegistry
.Where(a => a.Skills.Contains(task.TaskType))
.Where(a => a.Domains.Contains(task.Domain))
.Where(a => a.Status == "Healthy")
.OrderBy(a => a.Load)
.ToList();
var selectedAgent = candidates.FirstOrDefault();
You may enhance this with:
- Skill weight scoring
- Domain proximity
- Agent versioning or capability tiering
- Context-based fallback
π Subsystem: TaskRouter¶
The TaskRouter is a core component inside the Orchestrator. It:
- Receives tasks from the Planner
- Queries the Agent Registry
- Emits
RouteTaskToAgentcommands with full session context - Logs decision trails for observability
π‘ Routing Command Format¶
RouteTaskToAgent¶
{
"agentId": "adapter-generator-2",
"traceId": "notif-001",
"sessionId": "notif-service-assembly-01",
"taskType": "GenerateAdapter",
"blueprintId": "blueprint-abc123",
"componentTag": "AdapterGeneratorAgent:INotificationRepository",
"payload": {
"interface": "INotificationRepository",
"storage": "MongoDB"
}
}
β Routing Outcomes¶
| Outcome | Description |
|---|---|
| β Routed | Best-fit agent found and task assigned |
| π Reroute | Primary agent failed, fallback found |
| βΈοΈ Escalated | No agent available β human review |
| β Dropped | Error reported or task failed permanently |
π Observability & Auditing¶
Each routing decision is:
- Logged in the Orchestrator
- Emitted as an event:
TaskRouted,AgentNotFound,RoutingFallbackTriggered - Propagated into telemetry (OpenTelemetry spans)
- Recorded in task lineage reports (via
traceId)
π§ͺ Real Example: UserProfileService¶
Task:
GenerateHandler("CreateUserHandler")
Available agents:
- β
backend-dev-1: skills =["GenerateHandler"], domains =["Users", "Invoices"] - β
backend-dev-2: offline - β
backend-dev-3: not skilled in this domain
β
Selected β backend-dev-1
Routing result:
{
"event": "TaskRouted",
"toAgent": "backend-dev-1",
"componentTag": "BackendDevAgent:CreateUserHandler",
"traceId": "userprofile-002"
}
π Fallback Strategy¶
If routing fails:
- Retry 3x (configurable)
- Reroute to secondary agent
- Escalate to
FallbackAgentorHumanReviewerAgent - Emit
TaskRoutingFailedorTaskEscalated
π Cycle 9: Command and Event Lifecycle¶
In the ConnectSoft AI Software Factory, every orchestration action β from microservice generation to frontend wiring β is driven by a command-event lifecycle. This lifecycle enables complete decoupling, traceability, and reactivity across agents and coordinators in a multi-agent system.
This cycle documents the structure, lifecycle, and rules governing commands and events.
π§© Core Concepts¶
| Term | Description |
|---|---|
| Command | A directed instruction: βDo thisβ β always has an intended target |
| Event | A fact: βThis happenedβ β emitted by agents or coordinators after completing a task |
| Envelope | Metadata attached to all messages (traceId, sessionId, componentTag, etc.) |
| Bus | Transport layer: Azure Service Bus / RabbitMQ via MassTransit |
| Observer | Subsystems or agents that listen to events (e.g., for logging, chaining, or recovery) |
π¬ Command Structure¶
{
"type": "GenerateHandler",
"traceId": "svc-002",
"sessionId": "svc-002-handlergen",
"componentTag": "BackendDevAgent:CreateUserHandler",
"targetAgent": "backend-dev-1",
"payload": {
"service": "UserProfileService",
"handler": "CreateUserHandler",
"useCase": "CreateUser"
}
}
Command Properties:
type: task/command nametargetAgent: who should process it (determined via routing)payload: domain-specific inputtraceId/sessionId: orchestration-level contextcomponentTag: for telemetry and logs
π’ Event Structure¶
{
"type": "HandlerReady",
"traceId": "svc-002",
"sessionId": "svc-002-handlergen",
"componentTag": "BackendDevAgent:CreateUserHandler",
"emittedBy": "backend-dev-1",
"timestamp": "2025-05-04T13:32:00Z",
"payload": {
"file": "CreateUserHandler.cs",
"status": "completed"
}
}
Event Properties:
type: domain event (post-action)emittedBy: agent or coordinatortimestamp: event timepayload: result or reference- Fully traceable via
traceId,sessionId, andcomponentTag
π Lifecycle Flow (Simplified)¶
1. Task planned β Orchestrator emits `Command: GenerateHandler`
2. Agent receives & processes β emits `Event: HandlerReady`
3. Orchestrator consumes event β updates state, triggers next task
4. Event observers log, trace, and react (e.g., QA phase, PR phase)
π§ Example Message Sequence¶
sequenceDiagram
participant Orchestrator
participant Agent as Backend Dev Agent
participant Coordinator as Assembly Coordinator
Orchestrator->>Agent: GenerateHandler (Command)
Agent-->>Orchestrator: HandlerReady (Event)
Orchestrator->>Coordinator: HandlerReady
Coordinator-->>Orchestrator: AssemblyStageCompleted
π§Ύ Naming Conventions¶
| Message Type | Pattern |
|---|---|
| Command | VerbNoun (e.g., GenerateHandler, CreatePullRequest) |
| Event | NounVerb (e.g., HandlerReady, TestsPassed, AdapterGenerated) |
| Envelope Fields | camelCase (traceId, componentTag, sessionId) |
π Message Envelope Requirements¶
All orchestration messages MUST include:
| Field | Description |
|---|---|
traceId |
Global execution trace |
sessionId |
Scoped task/session ID |
componentTag |
Identifies source/role |
timestamp |
UTC ISO 8601 |
payload |
Domain/task-specific content |
π― Routing Rules¶
| Rule | Description |
|---|---|
| Commands | Routed directly to target agent or coordinator |
| Events | Broadcast to orchestrator, observers, and subscribed listeners |
| Internal Events | Used inside coordinators (e.g., state transitions) |
| Global Events | Used for cross-agent orchestration triggers (AssemblyCompleted) |
π‘ Integration with Bus¶
| Layer | Tool |
|---|---|
| Message Broker | Azure Service Bus or RabbitMQ |
| Bus Middleware | MassTransit (with saga/coordinator support) |
| Event Store (optional) | Azure Table Storage, MongoDB, or PostgreSQL for audit logs |
β Benefits of Command-Event Design¶
| Benefit | Description |
|---|---|
| Loose Coupling | Senders and receivers don't depend on direct invocation |
| Traceability | Every step logged and span-connected |
| Resilience | Failures donβt break entire flows; they emit observable TaskFailed |
| Observability | Events can be replayed, analyzed, or routed to dashboards |
| Modularity | New agents or tasks can be added by emitting or subscribing to events |
β οΈ Cycle 10: Failure Handling & Recovery¶
In an autonomous, distributed AI Software Factory, failures are expected β agents may timeout, coordinators may stall, events may be dropped, and tasks may fail due to misalignment or incomplete context. The orchestration layer must not only detect these failures but also respond intelligently and autonomously.
This cycle outlines how ConnectSoftβs Orchestration Layer handles execution failures, recovers workflows, and preserves delivery SLAs.
π₯ What Can Fail?¶
| Failure Type | Example |
|---|---|
| Agent Timeout | HandlerReady not received within 60s |
| Coordinator Crash | MicroserviceAssemblyCoordinator FSM terminated unexpectedly |
| Task Error | GenerateAdapter throws exception (invalid interface definition) |
| Routing Gap | No healthy agent found to handle GenerateHandler |
| Event Dropped | Message not consumed due to network/broker issue |
| Cascading Failure | One failed task prevents downstream handlers from running |
π§ Orchestration Failure Detection¶
1. Task Timeout Monitoring¶
- Each dispatched command has a TTL/SLA (e.g., 60s, 5m)
- If no response event received β emit
TaskTimedOut
2. Command Execution Failure¶
- If agent returns
TaskFailed, orchestrator logs and evaluates fallback
3. Routing Failures¶
- If no agent can handle a task β
RoutingFailed
4. Coordinator FSM Abandonment¶
- Coordinator crashes mid-way or enters invalid state β
CoordinatorHalted
π Recovery Strategies¶
| Scenario | Recovery Action |
|---|---|
| Agent timeout | Retry task with same agent (1β3 times, exponential backoff) |
| Agent unhealthy | Re-route task to alternate agent with same skill |
| Command failed | Route to fallback agent, or escalate |
| Coordinator crashed | Restart FSM (MassTransit saga rehydration) |
| Event lost | Re-emit or rehydrate from event store |
| Unrecoverable | Emit TaskEscalated to trigger human-in-the-loop path |
π¬ Failure Events¶
| Event Name | Trigger |
|---|---|
TaskTimedOut |
No event received within SLA |
TaskFailed |
Agent emitted explicit failure |
RoutingFailed |
No valid agent found |
CoordinatorHalted |
Coordinator FSM crashed |
TaskEscalated |
Orchestrator escalated task for human review |
Each includes full trace metadata:
{
"event": "TaskTimedOut",
"traceId": "svc-002",
"sessionId": "svc-002-handlergen",
"componentTag": "BackendDevAgent:CreateUserHandler",
"elapsedMs": 61000
}
βοΈ Subsystems Involved¶
| Subsystem | Role |
|---|---|
SLAWatcher |
Monitors task SLA windows |
RetryManager |
Handles retries and backoff logic |
FallbackRouter |
Finds alternative agents or coordinators |
EscalationService |
Triggers notifications or UI-based handoffs |
DeadLetterQueue |
Captures terminally failed messages for inspection |
β Recovery Policy Examples¶
| Task | Agent | Failure | Action |
|---|---|---|---|
GenerateHandler |
backend-dev-1 | Timeout | Retry once, reroute to backend-dev-2 |
ConfigureJWTAuth |
security-arch-1 | Exception | Escalate to SecurityReviewAgent |
AdapterGenerated |
β | Event dropped | Re-emit from event store |
AssemblyCoordinator |
β | FSM halted | Restart saga instance, restore state |
π Monitoring Dashboards¶
Failures are visualized and tracked via:
- OpenTelemetry alerts
- Azure Monitor or Grafana dashboards
- Trace Explorer logs per
traceId - Dead-letter queues (MassTransit + broker)
- SLA breach reports per service/blueprint
π§― Human-In-The-Loop Path¶
When all retries/fallbacks fail:
- Orchestrator emits
TaskEscalated - Message routed to
HumanReviewerAgentor UI system - Admin may approve, modify, or manually complete the task
- Resume orchestration flow
π€ Cycle 11: Multi-Agent Coordination Patterns¶
The ConnectSoft Orchestration Layer must coordinate multiple autonomous agents β often in parallel β to deliver complete, interdependent software systems. This cycle explores key multi-agent patterns used in orchestration flows, including sequential, parallel, conditional, and iterative coordination models.
π§ Coordination Principles¶
- Agents are decoupled but linked by shared trace/session metadata
- Orchestration layer handles flow sequencing, not task logic
- Coordination happens through event chaining and task dependencies
- Some agents may be coordinated directly (via
RouteTaskToAgent) or indirectly (via coordinator events)
π Coordination Pattern Types¶
1. Sequential (Waterfall)¶
Task A must complete before Task B starts
Example:
GenerateUseCaseHandlerβ then βGenerateAdapterβ then βCommitCode
graph TD
A[UseCase Handler] --> B[Adapter] --> C[Commit Code]
2. Parallel (Fan-Out)¶
Multiple tasks executed in parallel, orchestrator waits for all
Example:
- Generate
Create,Update, andGetByIdhandlers simultaneously
graph TD
A[Start Orchestration] --> B1[CreateHandler]
A --> B2[UpdateHandler]
A --> B3[GetByIdHandler]
B1 --> C[Commit Code]
B2 --> C
B3 --> C
3. Conditional (Branching)¶
Route based on context, blueprint, or previous event outcome
Example:
- If blueprint specifies
"auth": "JWT", route toConfigureJWTAuth
graph TD
A[Blueprint Analyzed]
A -->|Auth = JWT| B[ConfigureJWTAuth]
A -->|Auth = OAuth| C[ConfigureOAuthAuth]
4. Iterative (Per Item Fan-Out)¶
For each use case or port in the blueprint, emit a new task
Example:
- For each defined port β generate adapter and handler
graph TD
A[Ports = 3] --> B1[GenerateAdapter:Port1]
A --> B2[GenerateAdapter:Port2]
A --> B3[GenerateAdapter:Port3]
π Orchestration Flow Model¶
Each pattern uses orchestration constructs:
| Construct | Role |
|---|---|
RouteTaskToAgent |
Initiates agent task with trace context |
TaskRouted, TaskCompleted |
Used to trigger next step or join point |
TaskGroup |
Logical group of tasks (e.g., useCaseHandlers[]) |
JoinStrategy |
Wait-all, wait-any, or N-of-M before continuing |
ContextEvaluator |
Decides if/which branch to activate based on blueprint/metadata |
β Example: NotificationService Flow (Simplified)¶
| Step | Pattern | Agents Involved |
|---|---|---|
1. GenerateVisionBlueprint |
Sequential | Vision Architect Agent |
2. GenerateUseCaseHandlers[] |
Parallel | Backend Dev Agents |
3. GenerateAdapters[] |
Parallel | Adapter Generator Agents |
4. ConfigureAuth |
Conditional | Security Architect Agent |
5. RunTests β CreatePR |
Sequential | QA Agent β PR Agent |
π Join/Wait Logic¶
Orchestrator tracks task group completions:
{
"taskGroupId": "notif-usecases",
"expectedCount": 3,
"completed": ["CreateHandler", "UpdateHandler", "GetByIdHandler"],
"status": "complete"
}
Once completed:
- Trigger downstream task:
CommitCode - Emit
TaskGroupCompleted
π Advanced Use Cases¶
| Scenario | Pattern | Coordination |
|---|---|---|
| Multi-microservice system | Parallel (per service) | 1 coordinator per service |
| API Gateway + SPA + Mobile | Parallel + Conditional | Based on frontend flags |
| Retry N-of-M tasks | Iterative + Wait N | Accept 2 of 3 tasks before moving on |
| Blue/Green deployment | Conditional | Branch for CI/CD steps |
π± Cycle 12: Coordinating Frontend, API Gateway, and Mobile in Parallel¶
When generating a full-stack SaaS product, the Orchestration Layer must coordinate multiple surface layers in parallel:
- API Gateway (e.g., for routing/auth)
- SPA Web Frontend
- Mobile App (Cross-platform)
This cycle demonstrates how ConnectSoft's orchestrator uses parallel, conditional, and join-based coordination patterns to deliver a fully assembled front door to the system.
π§ Scenario Setup¶
Input Prompt: βBuild a BookingSystem with API Gateway, a mobile app, and a responsive web portal (SPA). Use OAuth2 auth.β
Blueprint inference returns:
{
"modules": ["BookingService", "UserService"],
"frontend": {
"spa": true,
"mobile": true
},
"gateway": {
"enabled": true,
"auth": "OAuth2"
}
}
π Orchestration Flow Overview¶
1. Start System Assembly¶
2. In Parallel:¶
- Start
MicroserviceAssemblyCoordinatorfor each service - Start
FrontendCoordinatorfor SPA - Start
MobileAppCoordinator - Start
ApiGatewayCoordinator
π‘ Flow Diagram¶
flowchart TD
A[ProductIntentSubmitted] --> B[StartSystemAssembly]
B --> MS1[BookingService Coordinator]
B --> MS2[UserService Coordinator]
B --> SPA[SPA Frontend Coordinator]
B --> MOBILE[Mobile App Coordinator]
B --> GW[API Gateway Coordinator]
MS1 --> PR[CreatePullRequest]
SPA --> PR
MOBILE --> PR
GW --> PR
All coordinators emit events like:
FrontendGeneratedGatewayConfiguredMobileAppReadyPullRequestCreated
These events are tracked by the orchestrator using a TaskGroup with a wait-all strategy.
π TaskGroup Coordination¶
taskGroupId: booking-ui-stack¶
| Expected Events | Source |
|---|---|
FrontendGenerated |
SPA Agent |
MobileAppReady |
Mobile Agent |
GatewayConfigured |
API Gateway Agent |
Join Point:¶
Once all 3 are complete β Orchestrator triggers:
β Example Event Payload¶
{
"event": "FrontendGenerated",
"traceId": "booking-001",
"componentTag": "FrontendSPAAgent:BookingPortal",
"sessionId": "spa-booking-001",
"filesGenerated": 42
}
π§ Conditional Execution Example¶
If blueprint only includes "spa": true, then:
- Orchestrator skips
MobileAppCoordinator - SPA + Gateway still run in parallel
- Join logic waits only for defined artifacts
π Observability Across Surface Layers¶
Each session logs and traces:
| Coordinator | SessionId | Span Name |
|---|---|---|
| SPA Frontend | spa-booking-001 |
Frontend:GenerateSPA |
| Mobile | mobile-booking-001 |
Mobile:GenerateFlutterApp |
| API Gateway | gateway-booking-001 |
Gateway:ConfigureRoutes |
All are tied together by traceId: booking-001.
π§Ύ Final Assembly Event¶
When all layers complete:
{
"event": "FullStackReady",
"traceId": "booking-001",
"components": ["SPA", "Mobile", "Gateway"],
"prLink": "https://dev.azure.com/.../pullrequest/235"
}
π§ͺ Summary of Parallel Coordination¶
| Task | Coordinator | Pattern |
|---|---|---|
Frontend SPA |
FrontendCoordinator |
Parallel |
Mobile App |
MobileAppCoordinator |
Parallel |
API Gateway |
ApiGatewayCoordinator |
Parallel |
Join & PR |
Orchestrator | Join-All |
π§© Cycle 13: Conditional Execution Based on Blueprint Metadata¶
The ConnectSoft Orchestration Layer is designed to adaptively execute based on blueprint metadata β activating, skipping, or rerouting tasks depending on user prompts, inferred structure, or explicit config.
This cycle explains how orchestration uses conditional logic gates to make execution dynamic, blueprint-aware, and minimal-by-design.
π§ Why Conditional Execution?¶
Blueprints may define optional or variant behaviors:
| Metadata Field | Affects |
|---|---|
"auth": "JWT" |
Auth strategy: use ConfigureJWTAuth |
"mobile": true |
Launch MobileAppCoordinator |
"platform": "Flutter" |
Select Flutter Agent |
"gateway": { enabled: false } |
Skip API Gateway |
"features": ["booking", "calendar"] |
Add feature-specific flows |
"spa": false |
Do not generate web frontend |
π Execution Decision Flow¶
flowchart TD
BP[Blueprint Ingested]
BP --> AUTH{auth defined?}
AUTH -->|JWT| AJWT[Route to ConfigureJWTAuth]
AUTH -->|OAuth2| AOAUTH[Route to ConfigureOAuth2]
AUTH -->|false| SKIPAUTH[Skip Auth Coordination]
BP --> MOBILE{mobile enabled?}
MOBILE -->|true| MMOB[Start Mobile Coordinator]
MOBILE -->|false| SKIPMOB[Skip Mobile]
BP --> GATEWAY{gateway.enabled}
GATEWAY -->|true| GWCOORD[Start GatewayCoord]
GATEWAY -->|false| SKIPGW[Skip Gateway]
π Orchestration Subsystems Involved¶
| Subsystem | Role |
|---|---|
BlueprintInterpreter |
Parses structure and flags |
ContextEvaluator |
Evaluates conditional logic gates |
RoutePlanner |
Only includes enabled paths in task plan |
JoinManager |
Dynamically tracks expected task completions per context |
β Real Example: Auth Routing¶
Given:
Orchestration will:
- Skip
ConfigureJWTAuth - Route to
SecurityArchitectAgentwith:
If:
Then:
- No auth agent flows triggered
- Coordinator is instructed to skip auth setup phase
π Feature Flag Conditionals¶
Example:
Triggers:
SearchModuleCoordinatorCalendarEventServiceCoordinator
Skipped:
NotificationsCoordinator(not listed)RemindersService(not listed)
π Dynamic Join Tracking¶
If blueprint only includes:
Then orchestration waits for:
FrontendGeneratedGatewayConfigured
But not:
MobileAppReady
Join group is built dynamically per taskGroupId.
π§ Decision DSL (internal)¶
You can define blueprint rules declaratively:
if:
metadata.auth == "OAuth2"
then:
route: ConfigureOAuth2
else if:
metadata.auth == "JWT"
then:
route: ConfigureJWTAuth
else:
skip: true
π§ Cycle 14: Coordinator Blueprints and Internal FSM Design¶
Domain-specific coordinators (e.g., MicroserviceAssemblyCoordinator, ApiGatewayCoordinator) encapsulate the stateful logic of assembling their targets using an internal FSM (finite state machine). These coordinators operate as sub-orchestrators, executing only on a scoped blueprint fragment.
This cycle details how these coordinators:
- Interpret service blueprints
- Emit task commands
- Transition between well-defined states
- Recover from partial executions
π§© Coordinator Responsibilities¶
| Responsibility | Description |
|---|---|
| π‘ Interpret Fragment | Parse service/module-specific blueprint section |
| π FSM Execution | Progress through domain-defined lifecycle states |
| π§Ύ Emit Events | Notify orchestrator when stages complete or fail |
| π¦ Track Artifacts | Monitor generated handlers, adapters, DTOs, etc. |
| π Retry & Recovery | Reissue commands or resume from state snapshot |
| π§ Decentralized Control | Act independently within orchestration trace context |
π Coordinator Blueprint Input (Fragment Example)¶
{
"serviceName": "NotificationService",
"useCases": ["SendNotification", "GetNotification"],
"storage": "MongoDB",
"auth": "JWT",
"features": ["scheduling"]
}
This is passed to the coordinator via:
π Coordinator FSM (MassTransit Saga)¶
MicroserviceAssemblyCoordinator FSM:
stateDiagram-v2
[*] --> Scaffolding
Scaffolding --> PortsReady
PortsReady --> UseCasesReady
UseCasesReady --> AdapterReady
AdapterReady --> AuthReady
AuthReady --> TestsReady
TestsReady --> PRCreated
PRCreated --> Complete
Each state emits events:
| State | Event |
|---|---|
PortsReady |
PortsAndUseCasesReady |
AdapterReady |
AdapterGenerated |
AuthReady |
AuthConfigured |
PRCreated |
PullRequestCreated |
π§ State Transitions Logic¶
FSM is implemented via MassTransit Saga:
- Each transition waits for a specific event (e.g.,
HandlerReady) - Timeout and retry logic built in per state
- Event handling is idempotent and resume-capable
During(UseCasesReady)
.When(AdapterGenerated)
.TransitionTo(AdapterReady)
.Publish(new ConfigureAuth(...));
π Artifact Tracker¶
Each coordinator tracks internal sub-tasks and artifacts:
When all required elements complete β AssemblyCompleted is emitted.
π Resilience & Replayability¶
| Feature | Mechanism |
|---|---|
| Task retry | Task TTL + requeue logic |
| FSM checkpoint | Saga state persisted in Mongo/Postgres |
| Resume logic | Replay messages from last known state |
| Idempotency | All handler events have unique IDs + dedup logic |
β Coordinator Completion¶
Final state:
{
"event": "MicroserviceAssemblyCompleted",
"traceId": "notif-001",
"sessionId": "notif-service-01",
"service": "NotificationService",
"pullRequest": "https://dev.azure.com/.../pr/442"
}
Triggers downstream actions:
- Orchestrator emits
RunTests - QA Agent is routed automatically
π§± Cycle 15: Coordinators for Cross-Cutting Concerns (Auth, Storage, Observability)¶
In ConnectSoft, cross-cutting concerns like authentication, persistence, logging, and metrics are managed by specialized coordinators, not embedded into service-specific flows. This enables:
- Centralized patterns for common infrastructure
- Isolated FSMs for reusability
- Pluggable execution based on blueprint metadata
This cycle explains how these coordinators are structured and integrated.
π§ Why Use Dedicated Coordinators?¶
| Benefit | Description |
|---|---|
| π Reusability | ConfigureJWTAuth logic used across all services |
| π§© Modularity | Cross-cutting concerns stay outside of domain logic |
| π Observability | Instrumentation added uniformly via ObservabilityCoordinator |
| π‘οΈ Security | All auth logic is encapsulated and versioned independently |
| π§ Extensibility | Coordinators can support multiple strategies (JWT, OAuth, Keycloak, etc.) |
π¦ Example Coordinators¶
| Name | Purpose |
|---|---|
| AuthCoordinator | Handles security layer setup (e.g., JWT, OAuth2) |
| StorageCoordinator | Configures NHibernate/Mongo/SQL persistence |
| ObservabilityCoordinator | Adds tracing, logging, metrics instrumentation |
| SecretsCoordinator | Integrates Azure Key Vault or HashiCorp Vault |
| ResilienceCoordinator | Adds retries, circuit breakers, timeout patterns |
| FeatureFlagsCoordinator | Adds LaunchDarkly or Azure App Config wiring |
π Coordination Flow (Example: JWT)¶
sequenceDiagram
participant Orchestrator
participant AuthCoord
participant Agent as Security Architect Agent
Orchestrator->>AuthCoord: StartAuthAssembly
AuthCoord->>Agent: ConfigureJWTAuth
Agent-->>AuthCoord: AuthConfigured
AuthCoord-->>Orchestrator: AuthLayerReady
- Blueprint specifies
"auth": "JWT" - Orchestrator dispatches to
AuthCoordinator - Coordinator triggers
ConfigureJWTAuthvia agent - Response is tracked and reported back to orchestrator
π AuthCoordinator FSM¶
stateDiagram-v2
[*] --> AuthPending
AuthPending --> AuthConfigured
AuthConfigured --> Complete
- Similar FSM design as microservice coordinator
- Timeout, retry, fallback all supported
- Can be versioned independently per auth mechanism
π Blueprint Mapping (Auth Example)¶
β Maps to:
AuthCoordinatorβConfigureOAuth2Auth- Passes
provider: AzureADto select appropriate strategy
β Resulting Event¶
{
"event": "AuthLayerReady",
"strategy": "OAuth2",
"provider": "AzureAD",
"componentTag": "AuthCoordinator",
"traceId": "booking-001"
}
Triggers:
RunTestsif all other coordinators complete- Optional
SecurityReviewAgentfor audits
π Tracking Across Concerns¶
Each coordinator emits:
Started,Configured,Ready, andFailedevents- Owns
sessionIdand participates in sharedtraceId
Join strategy waits for:
TaskGroup: infra-setup |
|---|
AuthLayerReady |
StorageReady |
ObservabilityReady |
π‘ Reusability Strategy¶
These coordinators live in separate solutions:
-
Each has:
-
MassTransit-based FSM
- Well-defined contracts (
ConfigureOAuth2,StorageReady) - Sub-agent mappings (e.g.,
StorageAgent)
β Maintains separation of orchestration layers by domain vs infrastructure.
π Cycle 16: Pull Request, Testing, and CI/CD Coordination¶
After microservices and cross-cutting layers are assembled, the ConnectSoft Orchestration Layer coordinates integration, testing, and CI/CD actions. This cycle outlines the post-assembly phase: turning generated artifacts into working code in source control, running tests, and optionally triggering deployments.
π§ Key Concepts¶
| Component | Role |
|---|---|
| PR Agent | Creates pull requests from generated code branches |
| QA Agent | Runs unit, integration, and service tests |
| CI Coordinator | Integrates with Azure Pipelines or GitHub Actions |
| Release Agent | Handles pre-release tasks (tagging, publishing, documentation) |
π Flow Overview¶
sequenceDiagram
participant Orchestrator
participant Coordinator as MicroserviceAssemblyCoordinator
participant PR as PR Agent
participant QA as QA Agent
participant CI as CI Coordinator
Coordinator-->>Orchestrator: MicroserviceAssemblyCompleted
Orchestrator->>QA: RunTests
QA-->>Orchestrator: TestResultsReady
Orchestrator->>PR: CreatePullRequest
PR-->>Orchestrator: PullRequestCreated
Orchestrator->>CI: TriggerPipeline
π¦ Task Group: postAssemblyFlow¶
Triggered by:¶
Tasks:¶
| Task | Agent/Coordinator |
|---|---|
RunTests |
QA Agent |
CreatePullRequest |
PR Agent |
TriggerPipeline |
CI Coordinator |
π§ͺ Test Flow (QA Agent)¶
Command: RunTests
{
"service": "NotificationService",
"testScope": ["Unit", "Integration"],
"branch": "feature/notif-001"
}
Expected:
π Pull Request Flow (PR Agent)¶
Command: CreatePullRequest
{
"branch": "feature/notif-001",
"targetRepo": "svc-notification",
"title": "feat(notification): initial implementation"
}
Returns:
βοΈ CI/CD Coordination¶
Triggered by:¶
PullRequestCreated(orTestResultsReady)- Blueprint may include
ci: true,autoDeploy: false, etc.
Command: TriggerPipeline
{
"pipelineId": "ci-notification",
"branch": "feature/notif-001",
"buildConfig": "Debug"
}
π Optional Post-PR Tasks¶
| Task | Agent |
|---|---|
GenerateChangelog |
Release Agent |
NotifyStakeholders |
Notification Agent |
CreateReleaseTag |
Release Agent |
AutoMergeOnApprove |
GitOps Agent |
π§ Blueprint Control Example¶
Triggers:
- Run unit + E2E tests
- Create PR, do not auto-merge
- Trigger CI pipeline, skip deploy
β Summary of Post-Assembly Coordination¶
| Step | Component |
|---|---|
β
RunTests |
QA Agent |
β
CreatePullRequest |
PR Agent |
β
TriggerPipeline |
CI Coordinator |
β
PublishRelease (optional) |
Release Agent |
All steps are:
- Traced under
traceId - Session-bound (
postassembly-notif-001) - Observed via
TaskGroup: postAssemblyFlow
ποΈ Cycle 17: Blueprint-Driven Infrastructure Provisioning (IaC)¶
Many SaaS solutions require cloud infrastructure provisioning alongside service generation. ConnectSoft handles this via blueprint-driven orchestration flows, triggering Infrastructure-as-Code (IaC) Coordinators that work with agents skilled in Bicep, Terraform, ARM, and Azure DevOps environment creation.
This cycle covers how infrastructure plans are derived, managed, and integrated into delivery pipelines.
π§© When IaC Is Triggered¶
Blueprint-Driven¶
{
"infrastructure": {
"provision": true,
"cloud": "Azure",
"services": ["AppService", "PostgreSQL", "KeyVault"],
"region": "westeurope",
"strategy": "Bicep"
}
}
β Orchestrator triggers:
π Key Coordinators¶
| Coordinator | Purpose |
|---|---|
| IaCCoordinator | Main FSM to manage infra plan creation & apply |
| SecretsCoordinator | Bootstrap secrets stores (e.g., Azure Key Vault) |
| NetworkingCoordinator | VNet, DNS, IP, routing setup |
| StorageCoordinator | DB, blob, cache provisioning |
| MonitoringCoordinator | Logging, tracing, alerting infra (e.g., App Insights) |
π§± IaC FSM Example¶
stateDiagram-v2
[*] --> PlanGenerated
PlanGenerated --> Approved
Approved --> ResourcesCreated
ResourcesCreated --> Complete
Events:¶
IaCPlanGeneratedProvisioningApprovedResourcesProvisioned
π§ͺ Example IaC Flow (Azure + Bicep)¶
Command: StartInfrastructureProvisioning
{
"strategy": "Bicep",
"services": ["AppService", "PostgreSQL"],
"region": "westeurope"
}
Coordinated Steps:
- Generate Bicep templates
- Validate and simulate (
what-if) - Await approval (manual or auto)
- Apply via Azure CLI or DevOps pipeline
- Emit
ResourcesProvisioned
π Secrets Coordination¶
{
"vault": "notif-app-kv",
"secrets": [
{ "name": "JwtSigningKey", "source": "Random256" },
{ "name": "DbPassword", "source": "Generated" }
]
}
SecretsCoordinator will:
- Provision vault
- Generate or pull values
- Store securely
- Emit
SecretsProvisionedwith references
π Resulting Events¶
{
"event": "ResourcesProvisioned",
"strategy": "Bicep",
"resources": ["notif-appservice", "notif-db", "notif-kv"],
"traceId": "notif-001"
}
Triggers:
- Service config updates (e.g., connection strings)
- Readiness signals for QA or release phases
π¦ IaC Strategies Supported¶
| Strategy | Toolchain | Notes |
|---|---|---|
| Bicep | Azure CLI, AZ DevOps | Native to Azure, declarative |
| Terraform | azurerm provider | Multi-cloud capable |
| ARM | Legacy fallback | Complex, verbose |
| Pulumi (planned) | TS/.NET Infra-as-Code | Future support |
π§ Blueprint-to-Infrastructure Mapping¶
| Blueprint Field | Infrastructure Action |
|---|---|
"storage": "PostgreSQL" |
Provision Azure Database for PostgreSQL |
"auth": "OAuth2" |
Add App Registration in Entra ID |
"monitoring": true |
Add AppInsights, log analytics |
"autoscale": true |
Configure App Service autoscaling rules |
β Benefits of IaC Coordination¶
| Benefit | Description |
|---|---|
| βοΈ Full Cloud Automation | All infra components built from orchestration |
| π Repeatable | Idempotent and versioned IaC plans |
| π§© Blueprint-Aware | Aligned to service needs, not static templates |
| π Secure by Design | Secrets, RBAC, and networks centrally handled |
| π§ͺ Testable | All infra plans support plan and apply phases |
π Cycle 18: Observability, Tracing, and Telemetry in Orchestration¶
To operate autonomously and at scale, the ConnectSoft Orchestration Layer requires deep observability: tracing every command, event, agent action, and failure across thousands of tasks and flows.
This cycle explains how observability is implemented using OpenTelemetry, structured logs, span-based tracing, and agent-level metrics.
π‘ Key Observability Pillars¶
| Pillar | Implementation |
|---|---|
| π Traces | Distributed across commands, agents, coordinators |
| π Logs | Structured JSON logs with context (traceId, sessionId, componentTag) |
| π Metrics | Collected from agents, queues, coordinator FSMs |
| π Dashboards | Visualizations via Grafana, Azure Monitor, or Kibana |
π Span-Based Tracing Model¶
Each orchestration traceId contains:
- Parent:
ProductIntentSubmitted - Child spans:
StartMicroserviceAssemblyGenerateHandlerAdapterGeneratedCreatePullRequestRunTests
All spans propagate:
{
"traceId": "booking-001",
"spanId": "generate-handler-1",
"parentSpanId": "start-assembly",
"componentTag": "BackendDevAgent:CreateBookingHandler",
"status": "completed",
"durationMs": 1842
}
π§Ύ Log Format (per Event or Command)¶
{
"timestamp": "2025-05-04T14:22:00Z",
"level": "Information",
"traceId": "booking-001",
"sessionId": "svc-booking-001",
"component": "PR Agent",
"event": "PullRequestCreated",
"message": "Created PR #442 for BookingService"
}
- Emitted via Serilog (JSON sink)
- Correlates with task outcomes, coordinator transitions, retries, etc.
π Metrics Model¶
| Metric | Labels | Source |
|---|---|---|
orchestrator_task_duration_ms |
taskType, agentId |
Orchestrator |
agent_error_count |
agentType, errorType |
Each agent |
fsm_state_transitions_total |
coordinatorName, state |
Coordinators |
command_queue_length |
commandType |
MassTransit queues |
Prometheus-compatible endpoints are exposed for scraping.
π Example Grafana Dashboard Panels¶
- Task durations per agent
- Failed task count per service/module
- Active coordinator sessions by state
- Top failing commands/events
- SLA breaches (timeouts)
π§ Integration Points¶
| Component | Observability Hook |
|---|---|
| Orchestrator | Logs, spans, metrics for all command dispatches |
| Agents | Emit AgentActionStarted, AgentActionCompleted |
| Coordinators | FSM transition logging and metrics |
| MassTransit | Built-in diagnostics for queue size, retry, DLQ |
| CI/CD | Pipeline run logs linked by traceId |
π Sensitive Data Handling¶
- PII removed from logs
- Secrets masked in all command/event payloads
- Sensitive config stored via secure logging keys
π SLA & Health Monitoring¶
Orchestrator monitors:
task SLA breachesagent health checks(ping or heartbeat)DLQ overflow warningsretry exhaustion thresholds
Alerts can be routed to:
- Ops dashboard
- Incident response bot
- Email/SMS
β Benefits of Unified Observability¶
| Benefit | Impact |
|---|---|
| π Full Traceability | Every build, task, and flow can be reconstructed |
| π¨ Fast Failure Detection | Agents failing or coordinators crashing β instant alerts |
| π Optimization | Long-running tasks or bottlenecks are visible |
| π§ͺ Test Coverage | QA and post-assembly flows are traced and validated |
| π Audit Trail | Immutable event logs tied to blueprint and session IDs |
πββοΈ Cycle 19: Human-in-the-Loop & Approval Escalation Paths¶
While ConnectSoft aims for fully autonomous software delivery, some actions require human confirmation, intervention, or override β especially for:
- High-risk configurations (auth, infrastructure)
- Missing data
- Unresolvable errors
- Compliance-driven reviews
This cycle outlines how the orchestration layer supports manual approval, escalation paths, and human-agent collaboration using TaskEscalated, ApprovalRequired, and dedicated HumanReviewAgent.
π§ Human-In-The-Loop Scenarios¶
| Scenario | Trigger |
|---|---|
| β All agents failed | RoutingFailed β TaskEscalated |
| β±οΈ SLA expired | TaskTimedOut β EscalationPolicy = manual |
| π¨ Sensitive task | Blueprint specifies approvalRequired: true |
| π§© Incomplete blueprint | Orchestrator canβt decompose properly |
| π§Ύ Release or PR approval | Manual gate required by org policy |
π Event-Driven Escalation¶
Example:¶
{
"event": "TaskEscalated",
"traceId": "svc-345",
"taskType": "ConfigureOAuth2",
"reason": "Agent unavailable",
"escalationTarget": "HumanReviewerAgent"
}
This is routed to a HumanReviewAgent via a UI, Slack, Teams, or web portal.
π€ HumanReviewerAgent Responsibilities¶
| Task | Description |
|---|---|
| π Complete missing blueprint fields | |
| β Approve plan or infrastructure | |
| π Reroute failed task manually | |
| βοΈ Provide override values | |
| π Cancel or pause orchestration flow |
π© Command for Manual Approval¶
RequestApproval¶
{
"sessionId": "infra-notif-001",
"target": "User",
"reason": "Provisioning PostgreSQL in production",
"payload": {
"templateName": "infra-prod-notif.bicep",
"resources": ["PostgreSQL", "KeyVault"]
}
}
User approves via connected UI β emits:
ApprovalGranted¶
π‘οΈ Approval Flow Diagram¶
sequenceDiagram
participant Orchestrator
participant Agent as IaC Coordinator
participant Human as HumanReviewerAgent
Agent->>Orchestrator: RequestApproval
Orchestrator->>Human: ApprovalRequired
Human-->>Orchestrator: ApprovalGranted
Orchestrator->>Agent: ResumeProvisioning
π UI & UX Integration¶
- Review dashboards with:
- Task details
- Blueprint fragment
- Action buttons: Approve, Reject, Edit
- Built-in audit logs
- Integrated with GitHub Checks, Azure DevOps gates, or Slack approvals
π Retry & Resume After Approval¶
When approval granted:
- Original coordinator resumes from saved FSM state
- Commands regenerated with approved payload
- All context preserved (traceId, sessionId, taskGroup)
β Benefits of Escalation Pathing¶
| Benefit | Impact |
|---|---|
| π Safe Boundaries | Humans intervene at risky junctions |
| π Flow Continuity | Failed automation doesnβt stall full pipeline |
| π Governance | Policy approval enforced without manual micromanagement |
| π¬ Collaboration | Human + agent system for flexible delivery |
π¦ Cycle 20: Modularization and Packaging of Orchestration Components¶
To support independent evolution, versioning, and reuse at scale, the ConnectSoft orchestration layer is designed as a modular system. Coordinators, agents, FSMs, schemas, and blueprints are developed in separate repositories and solutions, versioned and released independently.
This final cycle describes the principles and practices for modularizing and distributing orchestration components.
π§± Modular Component Types¶
| Component | Description | Repo/Unit |
|---|---|---|
| Coordinator FSMs | MassTransit Sagas (e.g., MicroserviceAssembly, Auth, Infra) |
ConnectSoft.Orchestration.Coordinators.* |
| Task & Event Schemas | Shared envelope, message contracts | ConnectSoft.Contracts.Orchestration |
| Task Handlers | Reusable AI agent handlers | ConnectSoft.Agents.* |
| Blueprint Templates | JSON/YAML fragments for coordinators | ConnectSoft.Blueprints |
| DSL Condition Rules | YAML or JSON conditions for conditional routing | ConnectSoft.Orchestration.Rules |
| Deployment Scripts | Bicep, Terraform IaC | ConnectSoft.Infrastructure.* |
π Packaging Format¶
| Tooling | Purpose |
|---|---|
| .NET NuGet Packages | For coordinators, contracts, and orchestration libraries |
| JSON/YAML Blueprint Registry | For task plans and coordination specs |
| Docker Images | For coordinators running as durable workers |
| Helm Charts / Bicep Modules | For deploying orchestrators and agents to AKS |
π§© Coordinator Repo Structure (Example)¶
/ConnectSoft.Orchestration.Coordinators.MicroserviceAssembly/
β
βββ StateMachines/
β βββ MicroserviceAssemblyState.cs
βββ Contracts/
β βββ StartMicroserviceAssembly.cs
βββ Events/
β βββ MicroserviceAssemblyCompleted.cs
βββ Blueprints/
β βββ microservice-template.json
βββ README.md
βββ nuspec/
βββ tests/
Versioned independently:
- Semantic versioning (
v2.1.0) - Compatibility matrix to platform SDK
π§ͺ Blueprint Template Example¶
{
"name": "NotificationService",
"useCases": ["Send", "MarkRead"],
"auth": "JWT",
"storage": "MongoDB",
"infra": {
"provision": true,
"region": "westeurope"
}
}
Used to:
- Trigger coordinators
- Define orchestrator routing
- Control agent behavior
π§ Runtime Composition¶
At runtime, orchestrator loads:
- Coordinator assemblies via DI
- Blueprint from artifact registry or user prompt
- Routing rules from condition engine
- Agents from discovery metadata registry
All combined into execution manifest per trace/session.
π§° Development & CI Practices¶
| Practice | Description |
|---|---|
| β Unit tests | FSM transitions, message contract compliance |
| β Integration tests | Agent+Coordinator E2E |
| β Versioning | Coordinators are independently released via Git tags |
| β Reusability | Coordinators can be embedded into other orchestrations |
| β Canary Support | Multiple coordinator versions co-exist for testing |
π GitOps & Deployment Patterns¶
- Orchestrator core deployed once (canary/stable)
- Coordinators packaged as:
.nupkgfor internal SDK.dllplugins for runtime loadingdocker imagefor long-running durable workers
- Coordinators declare compatibility via:
β Benefits of Modularization¶
| Benefit | Outcome |
|---|---|
| π Replaceable | Coordinators or agents can be swapped per domain |
| π Upgradable | Coordinators evolve independently (e.g., v1 vs v2 for Infra) |
| β»οΈ Reusable | Same InfraCoordinator used across 30+ microservices |
| π¬ Testable | Each module has clear CI contract tests |
| π§© Composable | Multiple orchestrators can share agent libraries and flow logic |
Related Documentation¶
Runtime & Execution¶
- Runtime & Control Plane Overview β Operational view of Factory runtime
- Control Plane β Control plane vs data plane separation
- Execution Engine β How runs and jobs are executed through the queueing model
- Failure & Recovery β Failure handling and recovery patterns
Architecture & Design¶
- Overall Platform Architecture β High-level Factory architecture
- Agentic System Design β Multi-agent system architecture
- Knowledge and Memory System β Knowledge storage and retrieval