Direct SDK reference
Register tools, authorize attempts and report execution with a direct client.
On this page
Direct clientsRuns and EventsCreate a machine clientRegister native factsRead the current policy contractPrepare one immutable attemptAuthorize, then executeReport executionApproval and retryComplete the RunDirect clients
Python Client(base_url, *, api_key, agent_name) is synchronous. After OpenEight acknowledges tool registration, pass the returned tool version IDs to get_tool_readiness. Use collect_selected_values to extract the tool inputs required by the active policies.
Tell us which framework you use and how your agent runs. We’ll help you choose the integration approach. Keep credentials and private application data out of your message.
Email us at hello@openeight.ai.
Runs and Events
Managed integrations report Runs and supported tool Events automatically. Direct integrations own Run identity, Event submission and delivery. Buffered telemetry is not crash-durable.
Continuation inside execute_attempt, after its authorization and identity checks have passed. Use the guarded helper; never call the effect from this fragment without those checks.
effect(json.loads(retained)) # Detached view of the same complete snapshot, never caller-owned input.
run.submit_event(Event(name=tool.name, observation_kind="tool_call", operation_kind="invoke",
occurred_at=datetime.now(timezone.utc), outcome="success", decision_id=decision.decision_id,
tool_id=tool.id, tool_version_id=version.id, tool_name=tool.name,
input={"input": prepared["input"], "policy_contract_set_digest": prepared["policy_contract_set_digest"], "selected_values": prepared["selected_values"]}))
run.flush() # Acknowledgment, not permission to repeat the effect on failure.Expected result · The Event carries the same Decision, Run, tool version and selected policy inputs. A delivery failure must not trigger another effect.
Create a machine client
Use synchronous Python Client on the server. Machine credentials identify the Agent; they never create a human console Session. The client does not invoke your business function.
- Register tools and retain the acknowledged ToolVersion IDs.
- Read exact-version readiness and freeze the native arguments for one attempt.
- Request authorization; if approval is required, wait and replay that same request.
- Execute only after the authorization checks pass, then report the correlated Event.
- Settle delivery and complete the Run without repeating the effect.
Register native facts
Register name, description and JSON input schema; inspect every registration result and retain acknowledged Tool/ToolVersion IDs. The direct example deliberately calls its catalog tool refund.create, while the local function is refund_create. Reject partial or conflicted registration.
Excerpt from the complete simulated-refund API demo. Keep its imports, helper functions and validation together. This fragment is not a standalone authorization boundary.
results = client.register_tools([ToolRegistration(name="refund.create", description="Simulate a refund in whole major units with an explicit currency", input_schema=SCHEMA)])
if len(results) != 1 or results[0].status not in ("registered", "replayed") or results[0].tool is None or results[0].tool_version is None:
raise RuntimeError("Tool publication not acknowledged; reconcile in console")
tool, version = results[0].tool, results[0].tool_version
print("Published:", tool.name, tool.id, version.id)
if command == "publish":
returnExpected result · Retain the acknowledged ToolVersion before reading readiness.
Read the current policy contract
Request exact-version readiness and require the configured executable contract before preparing a write. Console configuration owns selectors and policies. These programmatic checks protect execution; they are not another onboarding screen or authorization by themselves.
Excerpt from the complete simulated-refund API demo. Keep its imports, helper functions and validation together. This fragment is not a standalone authorization boundary.
readiness = client.get_tool_readiness(tool_version_ids=[version.id])
contracts = [c for c in readiness.tools if c.tool_id == tool.id and c.tool_version_id == version.id]
if len(contracts) != 1 or not contracts[0].eligible or not contracts[0].policy_ready or contracts[0].reason != "ready" or not contracts[0].policy_contract_set_digest:
raise RuntimeError("Configure this exact ToolVersion in console before running")Expected result · Missing or unready exact-version contracts stop execution.
Prepare one immutable attempt
Before any asynchronous authorization, deep-snapshot all native arguments into private retained state. Derive the minimal selected native path/value union from that snapshot, send input: {}, and retain the contract digest. Execute only a detached view of those same retained arguments, never a caller object read after a wait.
Python retains explicit Run/Decision IDs and source time for Client.decide. The selected-value helper alone does not freeze all unselected business arguments. Reject unsnapshotable values; never fall back to the original mutable object.
Excerpt from the complete simulated-refund API demo. Keep its imports, helper functions and validation together. This fragment is not a standalone authorization boundary.
retained = snapshot_arguments(arguments) # Before projection or any wait; never log this.
prepared = dict(decision_id=uuid7(), run_id=run.run_id,
source_time=datetime.now(timezone.utc).isoformat(), tool_id=tool.id,
tool_version_id=version.id, input={},
policy_contract_set_digest=contract.policy_contract_set_digest,
selected_values=collect_selected_values(json.loads(retained), contract))
request = json.dumps(prepared, allow_nan=False) # Private exact request retained alongside arguments.
prepared = json.loads(request) # Normalize tuple selections to JSON arrays for Event input.Expected result · Retain both the full native arguments and the prepared request. Later caller mutations cannot change the authorized effect; retries reuse the same IDs, time and request values.
Report execution
Submit the execution Event with the authorized Decision, Run, Tool, ToolVersion and frozen policy envelope. Queue acceptance is local ownership; flush confirms server acknowledgment. A telemetry error must not cause the effect to run again.
Continuation inside execute_attempt, after its authorization and identity checks have passed. Use the guarded helper; never call the effect from this fragment without those checks.
effect(json.loads(retained)) # Detached view of the same complete snapshot, never caller-owned input.
run.submit_event(Event(name=tool.name, observation_kind="tool_call", operation_kind="invoke",
occurred_at=datetime.now(timezone.utc), outcome="success", decision_id=decision.decision_id,
tool_id=tool.id, tool_version_id=version.id, tool_name=tool.name,
input={"input": prepared["input"], "policy_contract_set_digest": prepared["policy_contract_set_digest"], "selected_values": prepared["selected_values"]}))
run.flush() # Acknowledgment, not permission to repeat the effect on failure.Expected result · The Event carries the same Decision, Run, tool version and selected policy inputs. A delivery failure must not trigger another effect.
Approval and retry
Wait using machine approval-state reads. After approved, replay the identical request and check the same Decision/Run IDs. The immutable approval_required verdict plus replayed=true is a valid approved continuation after successful revalidation; there is no approvalState field on DecisionResult.
Transport retries reuse the same IDs, time and bytes. A genuinely new policy contract requires a new attempt. In-memory identity retention is not crash recovery, distributed fencing or exactly-once effects.
Follow the guarded helper rather than implementing a separate approval path.
Expected result · Approval must be observed and the identical request successfully replayed before execution.
Complete the Run
Flush and close the Run with its actual lifecycle, then close the client. Keep unresolved identities in application-owned durable state before extending this example to real payments. The complete API demo simulates receipts; it never contacts a payment provider.
Excerpt from the complete simulated-refund API demo. Keep its imports, helper functions and validation together. This fragment is not a standalone authorization boundary.
run_id, started_at = uuid7(), datetime.now(timezone.utc).isoformat()
receipts = []
with client.governed_run(run_id=run_id, started_at=started_at) as run:
execute_attempt(client, run, tool, version, contracts[0], {"amount": amount, "currency": currency}, lambda args: receipts.append({**args, "simulated": True}))Expected result · Python exits the governed_run context after the helper settles. Client cleanup does not promise restart-safe or exactly-once business execution.