Skip to content

Latest commit

 

History

History
147 lines (106 loc) · 7.03 KB

quickstart.md

File metadata and controls

147 lines (106 loc) · 7.03 KB
title Quickstart
description Instrument an agent, score a profile, or check your install in a few lines.

Three copy-paste blocks. Pick the one that matches your setup and run it.

1. Instrument an existing Claude Agent SDK agent

pip install "agentegrity[claude]"
from claude_agent_sdk import ClaudeSDKClient, ClaudeAgentOptions
from agentegrity.claude import hooks, report

async with ClaudeSDKClient(options=ClaudeAgentOptions(hooks=hooks())) as sdk:
    await sdk.query("Summarize the latest LLM safety papers")
print(report())

hooks() lazily builds a default adapter with a generic AgentProfile, the full four-layer evaluator (adversarial, cortical, governance, recovery), and measure-only semantics. It never blocks tool calls unless you pass enforce=True. report() returns a session summary: evaluation count, attestation chain length, whether the chain verifies.

1b. Instrument LangChain / LangGraph, OpenAI Agents, CrewAI, or Google ADK

Same shape, one import per framework. Pick the extra that matches your stack:

pip install "agentegrity[langchain]"     # covers LangChain + LangGraph
pip install "agentegrity[openai-agents]"
pip install "agentegrity[crewai]"
pip install "agentegrity[google-adk]"
# LangChain
from agentegrity.langchain import instrument_chain, report
chain = instrument_chain(my_chain); chain.invoke({"input": "..."}); print(report())

# LangGraph
from agentegrity.langchain import instrument_graph, report
graph = instrument_graph(my_compiled_graph); graph.invoke(state); print(report())

# OpenAI Agents SDK
from agents import Runner
from agentegrity.openai_agents import run_hooks, report
await Runner.run(agent, input="...", hooks=run_hooks()); print(report())

# CrewAI
from agentegrity.crewai import instrument, report
instrument(); crew.kickoff(); print(report())

# Google ADK
from agentegrity.google_adk import instrument, report
instrument(agent); runner.run(...); print(report())

Each module exposes the same report() / reset() / adapter() surface as agentegrity.claude, with AgentProfile.default() and the full four-layer evaluator. Pass profile=, client=, or enforce=True to any of the entry points to override.

1c. Export session data to a dashboard or external sink

Every adapter exposes register_exporter(exporter). Subscribe anything that implements the SessionExporter protocol (on_session_start, on_event, on_session_end) and it receives live session data as JSON-ready dicts:

from agentegrity.langchain import register_exporter, instrument_graph

class PrintExporter:
    async def on_session_start(self, session_id, adapter_name, profile):
        print(f"[{adapter_name}] session {session_id} started")
    async def on_event(self, session_id, event):
        print(f"  {event['event_type']}")
    async def on_session_end(self, session_id, summary):
        print(f"[{session_id}] score={summary}")

register_exporter(PrintExporter())
graph = instrument_graph(my_graph)

Exporter exceptions are caught and logged, so the exporter can never break the instrumented agent. For a production dashboard, use the Agentegrity Pro console and point the agent at it by setting AGENTEGRITY_EXPORTER_URL and AGENTEGRITY_TOKEN. The default adapter picks them up automatically and streams every session over the published exporter HTTP API.

Non-Python agents use the same contract via one of the six TypeScript adapters, each shipping a 2–3 line zero-config enable. Pick the one that matches your framework:

npm i @agentegrity/claude-sdk      # Claude Agent SDK: options.hooks = hooks()
npm i @agentegrity/langchain       # LangChain JS: callbacks: [instrument()]
npm i @agentegrity/openai-agents   # OpenAI Agents SDK: instrument(new Runner())
npm i @agentegrity/crewai          # CrewAI TypeScript: instrument(crewaiEventBus, { crew })
npm i @agentegrity/google-adk      # Google ADK: instrument(agent)
npm i @agentegrity/vercel-ai       # Vercel AI SDK: experimental_telemetry: instrument()

Each re-exports registerExporter(), report(), and reset() for the same fan-out contract as the Python adapters. The low-level @agentegrity/client reporter is still available for custom frameworks. The wire format is published as JSON Schema in schemas/exporter/ and OpenAPI 3.1 in schemas/openapi.yaml, so any language can produce or consume events.

1d. Instrument a coding agent (Claude Code, Codex)

Coding agents run commands through one generic shell tool, so they are instrumented through their hook systems instead of a library call. Install the library for the python3 on your PATH, then the plugin for your host:

pip install "agentegrity>=0.12.0"
codex plugin marketplace add cogensec/agentegrity      # Codex: then trust the hooks once with /hooks
# Claude Code: /plugin marketplace add cogensec/agentegrity
#              /plugin install agentegrity@agentegrity

Each hook runs python3 -m agentegrity hook --host <host>, and one daemon per session keeps the full conversation in view. Piping a download into a shell or wiping logs is denied; sending data out after a secret was read asks on Claude Code and is denied on Codex. Set AGENTEGRITY_HOOK_MODE=alert to record verdicts without enforcing them, and verify a session afterwards:

agentegrity verify-decisions ~/.agentegrity/codex/<session>.chain.json

See Claude Code and Codex for configuration and limits.

2. Score an arbitrary agent profile

pip install agentegrity
from agentegrity import AgentegrityClient

client = AgentegrityClient()
score = client.evaluate(client.create_profile(name="my-agent"))
print(f"{score.composite:.3f}  ({score.action})")

Use this for one-off profile scoring, CI gates, or agents outside the Claude SDK.

3. Confidence test from the terminal

python -m agentegrity          # version + adapter availability
python -m agentegrity doctor   # end-to-end self-check, prints composite score

If doctor prints a composite score and OK, your install is wired correctly.


Next steps

  • Custom thresholds, layer weights, and threat detectors: drop down to IntegrityEvaluator and the individual layers (see Configuration).
  • Cryptographic attestation signing: pip install "agentegrity[crypto]" and call AttestationRecord.sign(private_key) to produce verifiable records.
  • LLM-backed cortical checks: pip install "agentegrity[llm]" and pass LLMCorticalCheck instances to CorticalLayer(llm_checks=[...]) for semantic reasoning-chain validation.
  • Governance policies: customize GovernanceLayer(policy_set=...) or register custom policy rules. See the governance layer spec.
  • Full specification: spec/SPECIFICATION.md is the source of truth for the property definitions, layer contracts, and scoring methodology.