Agentra LabsAgentra Labs DocsPublic Documentation

AgenticContract

FFI Reference

AgenticContract provides a C FFI for embedding the policy engine in non-Rust applications.

AgenticContract provides a C FFI for embedding the policy engine in non-Rust applications.

Error Codes

CodeNameDescription
0ACON_OKSuccess
1ACON_ERR_NULL_PTRNull pointer argument
2ACON_ERR_INVALID_UTF8Invalid UTF-8 string
3ACON_ERR_NOT_FOUNDContract or entity not found
4ACON_ERR_IOI/O error
5ACON_ERR_FORMATFile format error
6ACON_ERR_POLICY_VIOLATIONPolicy violation
7ACON_ERR_RISK_EXCEEDEDRisk limit exceeded
8ACON_ERR_APPROVAL_REQUIREDApproval required
9ACON_ERR_INTERNALInternal error

Functions

acon_create

Create a new contract engine with an empty contract.

int32_t acon_create(AconHandle **out);

Parameters:

  • out — Pointer to receive the new handle

Returns: ACON_OK on success, error code on failure.

acon_open

Open an existing .acon file.

int32_t acon_open(const char *path, AconHandle **out);

Parameters:

  • path — Path to the .acon file (UTF-8)
  • out — Pointer to receive the handle

acon_close

Close and free a contract engine handle.

void acon_close(AconHandle *handle);

acon_save

Save the contract to a file.

int32_t acon_save(AconHandle *handle, const char *path);

acon_stats

Get JSON statistics about the contract.

int32_t acon_stats(const AconHandle *handle, char **out_json);

Note: Caller must free out_json with acon_free_string.

acon_policy_add

Add a policy to the contract.

int32_t acon_policy_add(AconHandle *handle, const char *label, int32_t scope, int32_t action);

Parameters:

  • label — Policy label (UTF-8)
  • scope — 0=Global, 1=Session, 2=Agent
  • action — 0=Allow, 1=Deny, 2=RequireApproval, 3=AuditOnly

acon_policy_check

Check if an action is allowed under current policies.

int32_t acon_policy_check(const AconHandle *handle, const char *action_desc, char **out_json);

acon_free_string

Free a string allocated by the FFI layer.

void acon_free_string(char *s);

Language Examples

Python (ctypes)

from agentic_contract import ContractEngine

engine = ContractEngine()
engine.add_policy("No deploys on Friday", scope="global", action="deny")
result = engine.check_policy("deploy to production")

C

#include "agentic_contract.h"

AconHandle *h;
acon_create(&h);
acon_policy_add(h, "spending-cap", 0, 1);
acon_close(h);