Appearance
Building an action handler
An action handler (tool adapter) executes remediation steps against an external system. It is called by the tool broker — the single execution path that enforces 11 security checks before any step runs. No adapter is callable directly.
The ToolAdapter interface
Every action handler implements ToolAdapter from src/modules/agent-execution/tool-broker.service.ts:
typescript
export interface ToolAdapter {
/** System identifier — must match a SystemType value */
systemType: SystemType;
/** Human-readable name: 'Microsoft Entra ID', 'Palo Alto Networks' */
systemName: string;
/** Whether the adapter has credentials and can execute */
isConfigured(): boolean;
/** Whether this adapter uses shared (env-level) credentials
rather than per-tenant vault credentials. Drives tenant lock logic. */
usesSharedProviderCredentials?(): boolean;
/** Report the platform scopes/permissions the current credential has.
Used by the scope verification check. */
getGrantedScopes?(tenantId: string): Promise<string[] | undefined>;
/** Execute a single remediation step */
execute(
action: ToolAction,
credentialHandle?: string,
context?: ExecutionContext,
): Promise<StepResult>;
}Key types
SystemType
Every adapter targets a system type. Add yours to the union in src/modules/agent-execution/agent-execution.types.ts:
typescript
type SystemType =
| 'entra'
| 'sailpoint'
| 'servicenow'
| 'app_connector'
| 'internal'
| 'workday'
| 'cyberark'
| 'okta'
| 'network_device'
| 'my_platform'; // <-- your systemActionType
Every step the adapter can execute has a namespaced action type. Add yours to the ActionType union in the same file:
typescript
// Convention: system.verb_noun
type ActionType =
| 'entra.create_enterprise_app'
| 'entra.configure_saml_sso'
| 'entra.disable_user'
// ...
| 'my_platform.create_policy'
| 'my_platform.update_rule'
| 'my_platform.delete_exception';ToolAction
The input to execute():
typescript
interface ToolAction {
actionType: ActionType;
target: {
systemType: SystemType;
applicationId?: string;
resourceId?: string;
};
inputs: Record<string, unknown>; // Step-specific parameters
validationRules: ValidationRule[]; // Input validation constraints
}StepResult
The output from execute():
typescript
interface StepResult {
success: boolean;
output: Record<string, unknown>; // What the step produced
errorMessage?: string; // Why it failed (on failure)
evidenceIds: string[]; // Evidence artifacts collected
requiresManualAction?: boolean; // Step needs human intervention
automation?: { // What automation level was applied
mode: string;
policyVersion: string;
};
}ExecutionContext
Runtime context provided by the broker:
typescript
interface ExecutionContext {
tenantId: string;
sessionId: string;
stepId: string;
dryRun: boolean; // If true, validate but do not apply changes
actorId: string;
actorName: string;
}The 11 security checks
Before your execute() is called, the tool broker runs these checks in order. Your adapter never needs to implement them — they are enforced by the broker:
| # | Check | What it does |
|---|---|---|
| 1 | Allowlist | Action type must be in ALLOWED_ACTIONS |
| 2 | Session validation | Session must exist and be in an executable state |
| 3 | Tenant match | Session's tenant must match the caller's JWT tenant |
| 4a | Plan integrity | Step must be in the session's plan (no injected steps) |
| 4b | Scope verification | Adapter's granted scopes must cover the action's required scopes |
| 5 | Commercial grant | Tenant must have an active grant for the capability |
| 6 | RBAC permission | Caller must have the agents.execute permission |
| 7 | Prerequisite check | Earlier steps the plan declares as prerequisites must have succeeded |
| 8 | Automation policy | Tenant's policy must permit this action at the current mode |
| 9 | Replay protection | Step must not have already been executed |
| 10 | Dry-run gate | If the session is a dry run, execute() runs with context.dryRun = true |
| 11 | Premise check | Approval conditions must still hold (gap not closed, blast radius not escalated) |
If any check fails, the broker returns a refusal with the check name and reason. Your adapter is never called.
Using BaseApiAdapter
For HTTP-based integrations, extend BaseApiAdapter from src/modules/agent-execution/adapters/base-api.adapter.ts. It provides:
| Method | Purpose |
|---|---|
getOAuthToken(tenantId, config) | Cached OAuth 2.0 client_credentials flow |
apiCall(tenantId, options) | Hardened HTTP with SSRF protection, circuit breaker, retry, response size cap |
recordApiEvidence(...) | Evidence capture with automatic credential redaction |
successResult(output, evidenceIds) | Build a success StepResult |
failResult(errorMessage, evidenceIds) | Build a failure StepResult |
validateBaseUrl(url) | SSRF-safe URL validation |
validateUUID(value) | UUID format check |
validateString(value, maxLength) | String validation |
rejectUnknownFields(obj, allowed) | Reject unexpected input fields |
SSRF protection
apiCall() validates URLs against SSRF patterns before making requests:
- Private IP ranges (
10.*,172.16-31.*,192.168.*,127.*,169.254.*) are rejected - Link-local and metadata endpoints are rejected
- DNS rebinding is mitigated by resolving before connecting
Registration
Step 1: Add to the allowlist
In tool-broker.service.ts, add your action types to ALLOWED_ACTIONS and your system to DOMAIN_BY_SYSTEM:
typescript
const ALLOWED_ACTIONS = new Set<ActionType>([
// ... existing actions
'my_platform.create_policy',
'my_platform.update_rule',
'my_platform.delete_exception',
]);
const DOMAIN_BY_SYSTEM: Record<SystemType, string> = {
// ... existing systems
my_platform: 'network', // Which module domain this system belongs to
};Step 2: Add required scopes
In src/modules/agent-execution/action-scope-registry.ts, declare the minimum platform scopes each action needs:
typescript
const ACTION_SCOPES: Record<string, string[]> = {
// ... existing actions
'my_platform.create_policy': ['Policy.ReadWrite.All'],
'my_platform.update_rule': ['Rule.ReadWrite.All'],
'my_platform.delete_exception': ['Exception.ReadWrite.All'],
};Step 3: Register the adapter
In src/modules/agent-execution/index.ts:
typescript
import { myPlatformAdapter } from './adapters/my-platform.adapter';
registerAdapter(myPlatformAdapter);File structure
src/modules/agent-execution/adapters/
my-platform.adapter.ts — ToolAdapter implementation
my-platform.adapter.test.ts — Tests (required)Example: minimal adapter
typescript
import { BaseApiAdapter } from './base-api.adapter';
import type { ToolAdapter, ToolAction, StepResult } from '../tool-broker.service';
import type { ExecutionContext } from '../agent-execution.types';
class MyPlatformAdapter extends BaseApiAdapter implements ToolAdapter {
systemType = 'my_platform' as const;
systemName = 'My Security Platform';
isConfigured(): boolean {
return !!process.env.MY_PLATFORM_API_KEY;
}
async execute(
action: ToolAction,
credentialHandle?: string,
context?: ExecutionContext,
): Promise<StepResult> {
if (!this.isConfigured()) {
return this.failResult('My Platform is not configured', []);
}
switch (action.actionType) {
case 'my_platform.create_policy':
return this.createPolicy(action, context);
case 'my_platform.update_rule':
return this.updateRule(action, context);
case 'my_platform.delete_exception':
return this.deleteException(action, context);
default:
return this.failResult(
`Unknown action type: ${action.actionType}`, [],
);
}
}
private async createPolicy(
action: ToolAction,
context?: ExecutionContext,
): Promise<StepResult> {
const { policyName, rules } = action.inputs as {
policyName: string;
rules: unknown[];
};
// Validate inputs
this.validateString(policyName, 255);
// Dry run: validate without applying
if (context?.dryRun) {
return this.successResult(
{ dryRun: true, wouldCreate: policyName },
[],
);
}
// Real execution
const baseUrl = this.validateBaseUrl(
process.env.MY_PLATFORM_BASE_URL || '',
);
const response = await this.apiCall(context?.tenantId || '', {
method: 'POST',
url: `${baseUrl}/api/v1/policies`,
headers: {
Authorization: `Bearer ${process.env.MY_PLATFORM_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ name: policyName, rules }),
});
// Record evidence
const evidenceIds = await this.recordApiEvidence(
context?.tenantId || '',
context?.sessionId || '',
context?.stepId || '',
'my_platform.create_policy',
response,
);
if (response.status >= 400) {
return this.failResult(
`Failed to create policy: ${response.status}`,
evidenceIds,
);
}
return this.successResult(
{ policyId: response.body?.id, policyName },
evidenceIds,
);
}
private async updateRule(
action: ToolAction,
context?: ExecutionContext,
): Promise<StepResult> {
// Similar pattern — validate, dry-run check, execute, record evidence
return this.failResult('Not implemented', []);
}
private async deleteException(
action: ToolAction,
context?: ExecutionContext,
): Promise<StepResult> {
// Similar pattern
return this.failResult('Not implemented', []);
}
}
export const myPlatformAdapter = new MyPlatformAdapter();Recovery classification
Every action type must be classified for recovery in src/modules/agent-execution/recovery-classification.ts:
| Class | Meaning | Example |
|---|---|---|
reversible | Undo returns to the prior state with no side effects | Delete a firewall rule that was just created |
restorable | Config can be reverted but side effects occurred | Re-enable an account, but terminated sessions are gone |
irrecoverable | Cannot be undone | Triggered an external aggregation pipeline |
typescript
const RECOVERY_CLASS: Record<ActionType, RecoveryClass> = {
// ... existing classifications
'my_platform.create_policy': 'reversible',
'my_platform.update_rule': 'restorable',
'my_platform.delete_exception': 'irrecoverable',
};The broker uses this classification to generate recovery plans when a session pauses or fails. If your action type is missing from the registry, the broker fails closed and refuses to execute it.
Testing requirements
Your adapter tests should cover:
- isConfigured() — returns
falsewhen credentials are absent - Each action type — success path with expected inputs
- Dry-run mode — validates without applying changes
- Unknown action types — returns a failure, not an exception
- API failure — returns a
StepResultwithsuccess: falseand an error message - Input validation — rejects invalid inputs before making API calls
- Evidence —
recordApiEvidence()is called and evidence IDs are on the result
Checklist
- [ ]
SystemTypeadded to the union inagent-execution.types.ts - [ ]
ActionTypevalues added for every action the adapter handles - [ ] Actions added to
ALLOWED_ACTIONSintool-broker.service.ts - [ ] System added to
DOMAIN_BY_SYSTEMintool-broker.service.ts - [ ] Required scopes declared in
action-scope-registry.ts - [ ] Recovery classification declared for every action type
- [ ] Adapter extends
BaseApiAdapterand implementsToolAdapter - [ ]
execute()switches onactionTypewith a default failure case - [ ] Dry-run mode supported — validates without applying
- [ ] Evidence recorded via
recordApiEvidence() - [ ] Adapter registered via
registerAdapter()inagent-execution/index.ts - [ ] Tests cover configured/unconfigured, each action, dry-run, errors