Skip to content

OpenAI Agents

Gate every OpenAI Agents SDK tool call through LatchGate’s enforcement pipeline.

Terminal window
pip install latchgate-openai-agents
from agents import Agent, Runner
from latchgate_openai_agents import latchgate_tools
async def main():
tools = await latchgate_tools(gate_url="http://localhost:3000")
agent = Agent(
name="Secure Worker",
instructions="You have access to LatchGate-protected tools with full audit trail.",
tools=tools,
)
result = await Runner.run(agent, "Fetch https://httpbin.org/get")
print(result.final_output)

latchgate_tools() discovers all registered LatchGate actions via the REST API and wraps each one as an OpenAI Agents SDK FunctionTool. When the LLM calls a tool, the wrapper routes it through LatchGateClient.execute() — the full enforcement pipeline runs transparently.

tools = await latchgate_tools(
gate_url="http://localhost:3000",
include={"http_fetch", "github_read"},
exclude={"send_message"},
)
from latchgate import LatchGateClient
client = LatchGateClient(socket="/run/latchgate/gate.sock", agent_id="my-openai-agent")
tools = await latchgate_tools(client=client)

Use on_audit for programmatic access to receipt metadata after each successful execution:

def my_audit_handler(record):
# record.action_id, record.receipt_id, record.trace_id, record.verification
audit_log.store(record)
tools = await latchgate_tools(
gate_url="http://localhost:3000",
on_audit=my_audit_handler,
)

You can set LATCHGATE_URL instead of passing gate_url explicitly:

# With LATCHGATE_URL=http://localhost:3000 set:
tools = await latchgate_tools()

Control the HTTP timeout for the discovery phase (default 15 seconds):

tools = await latchgate_tools(
gate_url="http://localhost:3000",
discovery_timeout=10.0,
)

Full API reference: latchgate-integrations/openai-agents/README.md.