D-02 Tool Gateway
Brick D: Tools, skills, plugins, MCP, connectors. French version: D-02-tool-gateway
1. Role and responsibilities
Single tool invocation point for agents: scopes, policy, DLP, approval, credential lease, cost, audit.
- Validate input against input_schema
- Evaluate OPA tool.invoke and its obligations
- DLP on input and output
- Obtain a lease (D-11) then call the endpoint or the sandbox
2. Position in the architecture and interactions
- Callers: Loop Controller (C-03), SDK.
- Execution path: Synchronous; can switch to approval wait (durable).
- 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: none (to develop)
- Developed: Fully developed.
- External integration through an adapter
eai/integrations/<system>.pywith an in-process fallback when the URL is not configured.
4. Data model
Tables (schema eai, tenant_id RLS):
eai.tool_invocations
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: tool-manifest
- JSON Schema:
contracts/v1/tool-manifest.schema.json - Key fields:
spec.requires_approval, spec.rate_limit, spec.sandbox_profile, spec.credential_ref - Validation:
POST /v1/contracts/{name}/validate; manifest apply:POST /v1/manifests/apply.
6. API endpoints
POST /v1/tools/{name}/invokeGET /v1/tools/invocations
Request POST /v1/tools/{name}/invoke:
{
"input": {
"q": "INC-42"
},
"run_id": "run_01J9",
"step_index": 4
}
Response:
{
"invocation_id": "tinv_77",
"status": "succeeded",
"output": {
"issues": [
{
"key": "INC-42"
}
]
},
"decision_id": "dec_51",
"cost": {
"amount": "0.001",
"currency": "EUR"
}
}
7. SDK examples
Python:
from enterprise_ai import EnterpriseAI
client = EnterpriseAI(base_url="<control-plane-url>", api_key="eai_xxx_secret")
out = client.tools.invoke("jira.search", {"q": "INC-42"}, run_id="run_01J9")
TypeScript:
import { EnterpriseAI } from "@enterprise-ai/sdk";
const client = new EnterpriseAI({ baseUrl: "<control-plane-url>", apiKey: process.env.EAI_API_KEY });
const out = await client.tools.invoke("jira.search", { arguments: { q: "INC-42" }, run_id: "run_01J9" });
Java:
EnterpriseAIClient client = EnterpriseAIClient.builder()
.baseUrl("<control-plane-url>")
.apiKey(System.getenv("EAI_API_KEY"))
.build();
JsonNode out = client.tools().invoke("jira.search", Map.of("arguments", Map.of("q", "INC-42")));
Go:
c, _ := eai.NewClient(eai.WithBaseURL("<control-plane-url>"), eai.WithAPIKey(os.Getenv("EAI_API_KEY")))
out, _ := c.Tools.Invoke(ctx, "jira.search", map[string]any{"arguments": map[string]any{"q": "INC-42"}})
8. Configuration
- Environment variables:
EAI_DATABASE_URL - Helm values keys:
controlPlane.config,controlPlane.secrets
9. Security controls
- Scope tools:invoke + scopes_required
- Secrets never exposed to the agent: lease injected gateway side
- Approval if requires_approval or OPA obligation
- 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_tool_invocations_total{tool,status},eai_tool_latency_seconds - Traces: OpenTelemetry spans with GenAI semantic conventions (
gen_ai.operation.name,gen_ai.agent.id,gen_ai.tool.name), attributeseai.tenant_id,eai.run_id,traceparentpropagation. - Audit actions:
tool.invoke,dlp.redact
11. FinOps units
- Tool calls (unit tool_call) and declared spec.cost.
- Emitted as Usage Event (
POST /v1/finops/usage) with tenant, project, agent and run.
12. Failure modes and resilience
- Non idempotent tool: no automatic retry
- Timeout and circuit breaker per tool
- Rate limit -> 429
- Normalized errors (error envelope, message_i18n en/fr)
13. Standalone adoption (client of a client)
- enterprise_ai.tools + Control Plane; OPA and OpenBao optional (fallbacks).
- SDK:
enterprise_ai.tools / mcp / skills / plugins / connectors / channels - Minimal deployment: Helm chart with
controlPlane.enabled=trueand PostgreSQL; disabled external components use their in-process fallback.
14. Acceptance tests
- Invocation without scope -> 403 policy_denied
- Output containing an IBAN masked
- requires_approval -> state waiting_approval
- Cross-tenant access refused
- Error returned in fr with Accept-Language: fr