Setup
Get your API key from the Fabraix Dashboard. Official SDKs coming soon.Copy
npm install @fabraix/sdk
Basic Integration
Here’s a complete example of integrating Fabraix into your agent workflow:Copy
import uuid
import json
import time
from datetime import datetime
import requests
# Configuration
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://dev.fabraix.com/v1"
HEADERS = {
"x-api-key": API_KEY,
"Content-Type": "application/json"
}
# Step 1: Register a new agent run
def register_agent_run(agent_id, system_prompt):
response = requests.post(
f"{BASE_URL}/register-agent-run",
headers=HEADERS,
json={
"agent_id": str(agent_id),
"timestamp": datetime.now().isoformat(),
"system_prompt": system_prompt
}
)
return response.json()["trace_id"]
# Step 2: Log events during the agent loop
def log_event(trace_id, event_type, content, schema):
response = requests.post(
f"{BASE_URL}/event",
headers=HEADERS,
json={
"event_type": event_type,
"trace_id": trace_id,
"timestamp": time.time(),
"content": json.dumps(content),
"schema": json.dumps(schema)
}
)
return response.json()["event_id"]
# Step 3: Check actions before execution
def check_action(trace_id, action_content, action_schema):
response = requests.post(
f"{BASE_URL}/check",
headers=HEADERS,
json={
"event_type": "action_check",
"trace_id": trace_id,
"timestamp": time.time(),
"content": json.dumps(action_content),
"schema": json.dumps(action_schema)
}
)
result = response.json()
return result["is_safe"], result["reasoning"]
# Example usage
if __name__ == "__main__":
# Initialize agent session
agent_id = uuid.uuid4()
trace_id = register_agent_run(
agent_id=agent_id,
system_prompt="You are a helpful assistant."
)
# Log user input
log_event(
trace_id=trace_id,
event_type="user",
content={"message": "What's the weather in London?"},
schema={
"type": "object",
"properties": {
"message": {"type": "string"}
}
}
)
# Before executing a tool call, check if it's safe
is_safe, reasoning = check_action(
trace_id=trace_id,
action_content={
"location": "London, UK",
"units": "celsius"
},
action_schema={
"type": "function",
"name": "get_weather",
"description": "Get current weather",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"},
"units": {"type": "string"}
}
}
}
)
if is_safe:
print("✅ Action approved - executing tool")
# Execute your tool here
else:
print(f"❌ Action blocked: {reasoning}")

