Skip to main content

C-11 Human-in-the-Loop

Brick C: Agents, autonomy, execution. French version: C-11-human-in-the-loop

1. Role and responsibilities​

Suspends a run on a risky action until a human decision in the portal, with separation of duties.

  • Create an approval request (action, risk, context)
  • Put the run in the waiting_approval state and wait for the decision (client.approvals.wait), then resume the turn with AgentLoop.resume(run_id)
  • The requester cannot approve

2. Position in the architecture and interactions​

  • Callers: Tool Gateway (requires_approval), OPA policies (approval obligation).
  • Execution path: Durable workflow: state waiting_approval, resume by signal.
  • Every interaction goes through the Control Plane API v1 (/v1) behind the API Gateway (D-14).

3. Open source component and developed part​

  • Open source: portal (Next.js); optional Temporal adapter for long waits
  • Developed: Approval model, notifications, expiry.
  • External integration through an adapter eai/integrations/<system>.py with an in-process fallback when the URL is not configured.

4. Data model​

Tables (schema eai, tenant_id RLS):

  • eai.approvals

Common columns: id uuid, tenant_id uuid NOT NULL, created_at, updated_at; RLS policy current_setting('app.tenant_id', true)::uuid.

5. Contract​

  • Applied contract: policy-contract (obligations) + execution-contract
  • JSON Schema: contracts/v1/execution-contract.schema.json, contracts/v1/policy-contract.schema.json
  • Key fields: state=waiting_approval, approval_id
  • Validation: POST /v1/contracts/{name}/validate; manifest apply: POST /v1/manifests/apply.

6. API endpoints​

  • GET /v1/approvals
  • POST /v1/approvals
  • GET /v1/approvals/{id}
  • POST /v1/approvals/{id}/decide

Request POST /v1/approvals/{id}/decide:

{
"decision": "approve",
"comment": "Amount checked"
}

Response:

{
"id": "apr_19",
"status": "approved",
"decided_by": "usr_42",
"run_id": "run_01J9"
}

7. SDK examples​

Python:

from enterprise_ai import EnterpriseAI

client = EnterpriseAI(base_url="<control-plane-url>", api_key="eai_xxx_secret")
client.approvals.decide("apr_19", decision="approve", comment="ok")

TypeScript:

import { EnterpriseAI } from "@enterprise-ai/sdk";

const client = new EnterpriseAI({ baseUrl: "<control-plane-url>", apiKey: process.env.EAI_API_KEY });
await client.approvals.decide("apr_19", { decision: "approve" });

Java:

EnterpriseAIClient client = EnterpriseAIClient.builder()
.baseUrl("<control-plane-url>")
.apiKey(System.getenv("EAI_API_KEY"))
.build();
client.approvals().decide("apr_19", Map.of("decision", "approve", "comment", "ok"));

Go:

c, _ := eai.NewClient(eai.WithBaseURL("<control-plane-url>"), eai.WithAPIKey(os.Getenv("EAI_API_KEY")))
c.Approvals.Decide(ctx, "apr_19", "approve", "ok")

8. Configuration​

  • Environment variables: EAI_APPROVAL_TTL_SECONDS=86400, EAI_DATABASE_URL
  • Helm values keys: controlPlane.config.EAI_APPROVAL_TTL_SECONDS

9. Security controls​

  • Separation of duties enforced server side
  • OpenFGA relation approver on the project
  • Every request carries the tenant resolved from the credential; PostgreSQL RLS
  • Every mutation and policy decision writes a hash-chained audit event

10. Observability​

  • Prometheus metrics: eai_approvals_pending, eai_approval_latency_seconds
  • Traces: OpenTelemetry spans with GenAI semantic conventions (gen_ai.operation.name, gen_ai.agent.id, gen_ai.tool.name), attributes eai.tenant_id, eai.run_id, traceparent propagation.
  • Audit actions: approval.request, approval.decide

11. FinOps units​

  • Waiting not billed as compute (sleeping workflow).
  • Emitted as Usage Event (POST /v1/finops/usage) with tenant, project, agent and run.

12. Failure modes and resilience​

  • Expiry -> automatic rejection
  • Idempotency-Key on decide
  • Normalized errors (error envelope, message_i18n en/fr)

13. Standalone adoption (client of a client)​

  • enterprise_ai.approvals + Control Plane.
  • SDK: enterprise_ai.agent (AgentsClient, RunsClient, SessionsClient)
  • Minimal deployment: Helm chart with controlPlane.enabled=true and PostgreSQL; disabled external components use their in-process fallback.

14. Acceptance tests​

  1. Requester approving -> 403
  2. Approve resumes the run
  3. Cross-tenant access refused
  4. Error returned in fr with Accept-Language: fr