LatentOpsDocumentation
Docs/Integrate

Connect LatentOps where agents actually run.

Use SDKs, CI hooks, framework adapters, MCP proxy mode, and provider metadata to put the runtime check in front of sensitive tools.

Hosted APIhttps://api.latentops.space

Python SDK

Use Python from agent runners, CI bots, internal copilots, backend orchestration, and FastAPI services.

Shared SDK contract

All SDKs send the same runtime-review payload and enforce allow, warn, escalate, or block.

python
from latentops import LatentOpsAPIError, LatentOpsClient, LatentOpsTimeoutError
from latentops.sdk import AgentIdentity, LatentOpsGateway, ToolCall, build_repo_context

client = LatentOpsClient(
    base_url="https://api.latentops.space",
    api_key="lo_your_tenant_key_here",
)

gateway = LatentOpsGateway(
    client,
    AgentIdentity(
        agent_id="ci-repair-agent",
        agent_name="CI Repair Agent",
        model_provider="openai",
        model_name="gpt-5-mini",
        agent_framework="github-actions",
        environment="ci",
    ),
    policy="balanced",
    fail_mode="closed",
)

decision = gateway.review(
    ToolCall(
        prompt="Fix failing tests and push the patch.",
        tool_name="run_shell",
        tool_args={"command": "pytest && git push", "cwd": "."},
        repo_context=build_repo_context(
            branch="main",
            protected_paths=["infra/", ".github/"],
            has_failing_tests=True,
            production_environment=True,
        ),
    )
)

if not decision.allowed:
    raise RuntimeError(decision.recommended_control)

run_tool()

try:
    client.dashboard_live(limit=100)
    client.benchmark_results(dataset="agentriskbench_v0_1", limit=120)
except LatentOpsTimeoutError:
    handle_timeout()
except LatentOpsAPIError as exc:
    handle_api_error(exc.status_code, exc.body)

TypeScript SDK

Use TypeScript from Node workers, Next.js API routes, agent UIs, and automation services.

ts
import {
  LatentOpsAPIError,
  LatentOpsClient,
  LatentOpsGateway,
  LatentOpsTimeoutError,
  buildRepoContext
} from "@latentops/sdk";

const client = new LatentOpsClient({
  baseUrl: "https://api.latentops.space",
  apiKey: process.env.LATENTOPS_API_KEY
});

const gateway = new LatentOpsGateway({
  client,
  identity: {
    agentId: "cursor-agent",
    modelProvider: "anthropic",
    modelName: "claude-sonnet-4-6",
    agentFramework: "mcp",
    environment: "production"
  },
  failMode: "closed"
});

const decision = await gateway.review({
  prompt: "Delete temp files and rerun tests.",
  toolName: "run_shell",
  toolArgs: { command: "rm -rf /tmp/build-cache && pytest" },
  repoContext: buildRepoContext({
    branch: "feature/fix",
    hasFailingTests: true
  })
});

if (decision.allowed) {
  await executeTool();
}

try {
  await client.dashboardLive({ limit: 100 });
  await client.benchmarkResults({ dataset: "agentriskbench_v0_1", limit: 120 });
} catch (error) {
  if (error instanceof LatentOpsTimeoutError) handleTimeout();
  if (error instanceof LatentOpsAPIError) handleApiError(error.status, error.body);
}

Go SDK

Use Go from backend services, CI agents, and platform automation. Choose fail-closed behavior for high-impact actions.

bash
go get github.com/latentops/go-sdk
go
import (
    "context"
    "errors"
    "os"

    latentops "github.com/latentops/go-sdk"
)

client := latentops.NewClient("https://api.latentops.space", os.Getenv("LATENTOPS_API_KEY"))
gateway := latentops.NewGateway(client, latentops.AgentIdentity{
    AgentID: "deploy-agent",
    ModelProvider: "openai",
    ModelName: "gpt-5-mini",
    AgentFramework: "github-actions",
    Environment: "production",
})
gateway.FailMode = latentops.FailClosed

decision := gateway.Review(context.Background(), latentops.ToolCall{
    Prompt: "Deploy the latest infrastructure change.",
    ToolName: "run_shell",
    ToolArgs: map[string]any{"command": "terraform apply -auto-approve"},
    RepoContext: latentops.BuildRepoContext(
        "main",
        []string{"infra/prod/main.tf"},
        []string{"infra/prod", ".env"},
        false,
        false,
        false,
        true,
    ),
})

if !decision.Allowed {
    return errors.New(decision.RecommendedControl)
}

Java SDK

Use Java from Spring services, JVM agent workers, and internal platform services.

xml
<dependency>
  <groupId>ai.latentops</groupId>
  <artifactId>latentops-sdk</artifactId>
  <version>0.2.0</version>
</dependency>
java
import ai.latentops.*;
import java.util.List;
import java.util.Map;

LatentOpsClient client = new LatentOpsClient(
    "https://api.latentops.space",
    System.getenv("LATENTOPS_API_KEY")
);

AgentIdentity identity = new AgentIdentity();
identity.agentId = "deploy-agent";
identity.modelProvider = "openai";
identity.modelName = "gpt-5-mini";
identity.agentFramework = "github-actions";
identity.environment = "production";

LatentOpsGateway gateway = new LatentOpsGateway(client, identity);
gateway.failMode = FailMode.CLOSED;

ToolCall call = new ToolCall("Deploy the latest infrastructure change.", "run_shell");
call.toolArgs = Map.of("command", "terraform apply -auto-approve");
call.repoContext = RepoContexts.build(
    "main",
    List.of("infra/prod/main.tf"),
    List.of("infra/prod", ".env"),
    false,
    false,
    false,
    true
);

GatewayDecision decision = gateway.review(call);
if (!decision.allowed) {
    throw new IllegalStateException(decision.recommendedControl);
}

Rust SDK

Use Rust from low-latency agent workers, command execution services, and infrastructure automation.

toml
[dependencies]
latentops-sdk = "0.2"
rust
use latentops_sdk::{AgentIdentity, FailMode, LatentOpsClient, LatentOpsGateway, ToolCall};
use serde_json::{json, Map};

let client = LatentOpsClient::new(
    "https://api.latentops.space",
    std::env::var("LATENTOPS_API_KEY").ok(),
)?;

let mut gateway = LatentOpsGateway::new(
    client,
    AgentIdentity {
        agent_id: "deploy-agent".into(),
        model_provider: "openai".into(),
        model_name: "gpt-5-mini".into(),
        agent_framework: "github-actions".into(),
        environment: "production".into(),
        ..AgentIdentity::default()
    },
);
gateway.fail_mode = FailMode::Closed;

let mut tool_args = Map::new();
tool_args.insert("command".into(), json!("terraform apply -auto-approve"));

let decision = gateway.review(ToolCall {
    prompt: "Deploy the latest infrastructure change.".into(),
    tool_name: "run_shell".into(),
    tool_args,
    ..ToolCall::default()
});

if !decision.allowed {
    return Err(decision.recommended_control.into());
}

SDK release checklist

Keep SDK releases aligned with the shared runtime-review contract.

Python 0.2.0

Gateway, stdlib client, package client, typed API errors, timeout errors, dashboard helpers, benchmark helpers, and release metadata.

TypeScript 0.2.0

Typed runtime review, gateway defaults, wrapTool, API and timeout errors, exports metadata, dashboard helpers, and benchmark helpers.

Go 0.2.0

Dependency-free gateway client, runtime-review payloads, fail-open/fail-closed behavior, API errors, timeout errors, and benchmark helpers.

Java 0.2.0

Maven package with Java 11 HttpClient, Jackson payload handling, gateway enforcement, API errors, timeout errors, and helper methods.

Rust 0.2.0

Reqwest and serde client, runtime-review gateway, API errors, timeout errors, helper methods, and release metadata.

Shared contract

Every SDK sends the same runtime-review payload shape and enforces the same allow, warn, escalate, and block decisions.

Release validation

SDK releases are validated before publishing so package installs, gateway payloads, API errors, and timeout behavior stay aligned.

GitHub Actions

Store the tenant key as LATENTOPS_API_KEY and review agent repair actions in CI before shell commands or code changes run.

yaml
name: LatentOps runtime check
on: [pull_request]

jobs:
  latentops:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Review agent action
        env:
          LATENTOPS_API_KEY: ${{ secrets.LATENTOPS_API_KEY }}
          LATENTOPS_API_BASE: https://api.latentops.space
        run: |
          curl -f -X POST "$LATENTOPS_API_BASE/v1/runtime/review" \
            -H "Content-Type: application/json" \
            -H "X-API-Key: $LATENTOPS_API_KEY" \
            -d '{
              "prompt": "Review this workflow update before an agent applies fixes.",
              "tool_name": "run_shell",
              "tool_args": {"command": "npm test"},
              "repo_context": {
                "branch": "${{ github.head_ref || github.ref_name }}",
                "production_environment": false
              },
              "agent_framework": "github-actions",
              "environment": "ci",
              "log_event": true
            }'

Framework integrations

Use direct API calls or SDK adapters with agent frameworks, CI repair bots, MCP, and internal tools.

python
from latentops.client import LatentOpsClient
from latentops.integrations.langchain_adapter import LangChainToolAdapter

adapter = LangChainToolAdapter(
    LatentOpsClient(
        base_url="https://api.latentops.space",
        api_key="lo_your_tenant_key_here",
    ),
    fail_mode="closed",
)

guarded_shell = adapter.wrap_callable(
    "run_shell",
    lambda command: run_shell(command),
    prompt="Fix failing tests and commit the result.",
)

guarded_shell({"command": "pytest"})
LangChain

Wrap BaseTool-style objects or plain callables before invoke, run, __call__, or _run.

LangGraph

Wrap a graph node when state contains tool_name, tool_args, latent vector, and prompt metadata.

Custom agents

Call the runtime review API before your executor runs shell, file, browser, database, or deployment tools.

Coding-agent hook

Run the local hook demo to see a safe action continue and a destructive protected-branch action stop.

GitHub PR bot

Review PR comments, patches, failing checks, and shell commands before a CI bot touches GitHub.

Provider metadata

Send provider, model, framework, integration, and environment with each runtime check.

bash
LATENTOPS_API_BASE=https://api.latentops.space LATENTOPS_API_KEY=lo_your_tenant_key_here latentops-coding-agent-guard --mode shadow --prompt "Run validation before editing auth." --action-type shell --command "pytest -q"

latentops-coding-agent-guard --mode approval --stdin-json <<'JSON'
{
  "prompt": "Agent wants to fix auth tests before opening a PR.",
  "action_type": "shell",
  "command": "pytest -q tests/test_auth.py",
  "repo_context": {
    "branch": "main",
    "files_touched": ["apps/web/app/api/auth/callback.ts"],
    "protected_paths": ["apps/web/app/api/auth", ".github", "infra"],
    "has_failing_tests": true,
    "production_environment": true
  },
  "agent_id": "ci-repair-agent",
  "agent_framework": "github-actions-bot",
  "environment": "production"
}
JSON
bash
python examples/github_pr_bot_demo.py
LATENTOPS_API_BASE=https://api.latentops.space LATENTOPS_API_KEY=lo_your_tenant_key_here python examples/github_pr_bot_demo.py --live
json
{
  "agent_id": "workflow-operator",
  "agent_name": "Workflow Operator",
  "agent_framework": "langchain",
  "model_provider": "anthropic",
  "model_name": "claude-sonnet-4-6",
  "integration": "langchain_tool_adapter",
  "environment": "production"
}

MCP server and proxy

The MCP server exposes LatentOps review tools. Proxy mode sits in front of an existing MCP server and reviews every tools/call before forwarding.

json
{
  "mcpServers": {
    "latentops": {
      "command": "latentops-mcp",
      "env": {
        "LATENTOPS_API_BASE": "https://api.latentops.space",
        "LATENTOPS_API_KEY": "lo_your_tenant_key_here",
        "LATENTOPS_ENVIRONMENT": "production"
      }
    }
  }
}
json
{
  "mcpServers": {
    "filesystem-guarded": {
      "command": "latentops-mcp-proxy",
      "args": [
        "--",
        "npx",
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/workspace"
      ],
      "env": {
        "LATENTOPS_API_BASE": "https://api.latentops.space",
        "LATENTOPS_API_KEY": "lo_your_tenant_key_here",
        "LATENTOPS_FAIL_MODE": "closed",
        "LATENTOPS_MCP_UPSTREAM_TIMEOUT": "30",
        "LATENTOPS_ENVIRONMENT": "production"
      }
    }
  }
}
bash
python examples/mcp_proxy_demo.py
LATENTOPS_API_BASE=https://api.latentops.space LATENTOPS_API_KEY=lo_your_tenant_key_here python examples/mcp_proxy_demo.py --live

Model execution

Pro and Enterprise workspaces can store provider keys, run managed live model calls, and save traces with latency, tokens, provider, model, framework, and environment.

bash
curl -X POST https://api.latentops.space/v1/model-providers/keys \
  -H "Content-Type: application/json" \
  -H "X-API-Key: lo_your_tenant_key_here" \
  -d '{
    "provider": "openai",
    "api_key": "sk_live_provider_key",
    "name": "OpenAI production key",
    "default_model": "gpt-5-mini"
  }'

curl -X POST https://api.latentops.space/v1/model-runs \
  -H "Content-Type: application/json" \
  -H "X-API-Key: lo_your_tenant_key_here" \
  -d '{
    "provider": "openai",
    "model": "gpt-5-mini",
    "system_prompt": "You are a production engineering reviewer.",
    "prompt": "Review this release plan for operational risk.",
    "environment": "production"
  }'
Current defaults

OpenAI gpt-5-mini | Anthropic claude-sonnet-4-6

Metadata providers

OpenAI | Anthropic/Claude | Google/Gemini | Qwen | Meta/Llama | Hugging Face | local | custom

Was this helpful?
PreviousAPIOperateNext